Changeset 12061

Show
Ignore:
Timestamp:
09/04/07 09:36:25 (1 year ago)
Author:
warmerdam
Message:

rework byte swapping for small exif values (#1786)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gdal/frmts/jpeg/jpgdataset.cpp

    r12059 r12061  
    9494    CPLErr EXIFExtractMetadata(FILE *, int); 
    9595    int    EXIFInit(FILE *); 
    96     void   EXIFPrintByte(char *, const char*, TIFFDirEntry* ); 
    97     void   EXIFPrintShort(char *, const char*, TIFFDirEntry*); 
    9896    void   EXIFPrintData(char *, GUInt16, GUInt32, unsigned char* ); 
    9997 
     
    162160                JPGMaskBand( JPGDataset *poDS ); 
    163161}; 
    164  
    165 /************************************************************************/ 
    166 /*                         EXIFPrintByte()                              */ 
    167 /************************************************************************/ 
    168 void JPGDataset::EXIFPrintByte(char *pszData,  
    169                                const char* fmt, TIFFDirEntry* dp) 
    170 { 
    171   char* sep = ""; 
    172    
    173   if (bSwabflag) { 
    174     switch ((int)dp->tdir_count) { 
    175     case 4: sprintf(pszData, fmt, sep, dp->tdir_offset&0xff); 
    176       sep = " "; 
    177     case 3: sprintf(pszData, fmt, sep, (dp->tdir_offset>>8)&0xff); 
    178       sep = " "; 
    179     case 2: sprintf(pszData, fmt, sep, (dp->tdir_offset>>16)&0xff); 
    180       sep = " "; 
    181     case 1: sprintf(pszData, fmt, sep, dp->tdir_offset>>24); 
    182     } 
    183   } else { 
    184     switch ((int)dp->tdir_count) { 
    185     case 4: sprintf(pszData, fmt, sep, dp->tdir_offset>>24); 
    186       sep = " "; 
    187     case 3: sprintf(pszData, fmt, sep, (dp->tdir_offset>>16)&0xff); 
    188       sep = " "; 
    189     case 2: sprintf(pszData, fmt, sep, (dp->tdir_offset>>8)&0xff); 
    190       sep = " "; 
    191     case 1: sprintf(pszData, fmt, sep, dp->tdir_offset&0xff); 
    192     } 
    193   } 
    194 } 
    195  
    196 /************************************************************************/ 
    197 /*                         EXIFPrintShort()                             */ 
    198 /************************************************************************/ 
    199 void JPGDataset::EXIFPrintShort(char *pszData, const char* fmt,  
    200                              TIFFDirEntry* dp) 
    201 { 
    202   char *sep = ""; 
    203   if (bSwabflag) { 
    204     switch (dp->tdir_count) { 
    205     case 2: sprintf(pszData, fmt, sep, dp->tdir_offset&0xffff); 
    206       sep = " "; 
    207     case 1: sprintf(pszData, fmt, sep, dp->tdir_offset>>16); 
    208     } 
    209   } else { 
    210     switch (dp->tdir_count) { 
    211     case 2: sprintf(pszData, fmt, sep, dp->tdir_offset>>16); 
    212       sep = " "; 
    213     case 1: sprintf(pszData, fmt, sep, dp->tdir_offset&0xffff); 
    214     } 
    215   } 
    216 } 
    217162 
    218163/************************************************************************/ 
     
    557502/* -------------------------------------------------------------------- */ 
    558503        if (space >= 0 && space <= 4) { 
    559             switch (poTIFFDirEntry->tdir_type) { 
    560               case TIFF_FLOAT:  
    561               { 
    562                   unsigned char data[4]; 
    563                   memcpy(data, &poTIFFDirEntry->tdir_offset, 4); 
    564                   if (bSwabflag) 
    565                       TIFFSwabLong((GUInt32*) data); 
    566  
    567                   EXIFPrintData(pszTemp, 
    568                                 poTIFFDirEntry->tdir_type,  
    569                                 poTIFFDirEntry->tdir_count, data); 
     504 
     505            unsigned char data[4]; 
     506            memcpy(data, &poTIFFDirEntry->tdir_offset, 4); 
     507            if (bSwabflag) 
     508            { 
     509                // Unswab 32bit value, and reswab per data type. 
     510                TIFFSwabLong((GUInt32*) data); 
     511 
     512                switch (poTIFFDirEntry->tdir_type) { 
     513                  case TIFF_LONG: 
     514                  case TIFF_SLONG: 
     515                  case TIFF_FLOAT:  
     516                    TIFFSwabLong((GUInt32*) data); 
     517                    break; 
     518 
     519                  case TIFF_SSHORT: 
     520                  case TIFF_SHORT: 
     521                    TIFFSwabArrayOfShort((GUInt16*) data,  
     522                                         poTIFFDirEntry->tdir_count); 
    570523                  break; 
    571               } 
    572  
    573               case TIFF_ASCII:  
    574                 EXIFPrintData(pszTemp, 
    575                               poTIFFDirEntry->tdir_type,  
    576                               poTIFFDirEntry->tdir_count,  
    577                               (unsigned char *)&(poTIFFDirEntry->tdir_offset)); 
    578                 break; 
    579  
    580               case TIFF_UNDEFINED: 
    581               case TIFF_BYTE: 
    582                 EXIFPrintByte(pszTemp, "%s%#02x", poTIFFDirEntry); 
    583                 break; 
    584  
    585               case TIFF_SBYTE: 
    586                 EXIFPrintByte(pszTemp, "%s%d", poTIFFDirEntry); 
    587                 break; 
    588  
    589               case TIFF_SHORT: 
    590                 EXIFPrintShort(pszTemp, "%s%u", poTIFFDirEntry); 
    591                 break; 
    592  
    593               case TIFF_SSHORT: 
    594                 EXIFPrintShort(pszTemp, "%s%d", poTIFFDirEntry); 
    595                 break; 
    596  
    597               case TIFF_LONG: 
    598                 // should this be swabbed? 
    599                 sprintf(pszTemp, "%lu",(long) poTIFFDirEntry->tdir_offset); 
    600                 break; 
    601  
    602               case TIFF_SLONG: 
    603                 // should this be swabbed? 
    604                 sprintf(pszTemp, "%lu",(long) poTIFFDirEntry->tdir_offset); 
    605                 break; 
     524 
     525                  default: 
     526                    break; 
     527                } 
    606528            } 
    607          
     529 
     530            EXIFPrintData(pszTemp, 
     531                          poTIFFDirEntry->tdir_type,  
     532                          poTIFFDirEntry->tdir_count, data); 
    608533        } 
    609534/* -------------------------------------------------------------------- */