From ee1ca29d096ba3a4540cc1b6f75ceea4898aeeeb Mon Sep 17 00:00:00 2001 From: Robin Mills Date: Sat, 2 May 2015 13:03:31 +0000 Subject: [PATCH] #1073 test/tiff-test.sh rewritten to no longer require external utility exifprobe --- src/image.cpp | 11 ++- src/tiffimage.cpp | 18 ++-- test/data/bugfixes-test.out | Bin 1838577 -> 1838574 bytes test/data/tiff-test.out | 172 +++++++++++++++++------------------- test/tiff-test.sh | 101 +++++++++++++++++++-- 5 files changed, 193 insertions(+), 109 deletions(-) diff --git a/src/image.cpp b/src/image.cpp index a50ba1f3..f134aca4 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -367,7 +367,7 @@ namespace Exiv2 { while (rc < 0 && again--) { if ( buffer ) delete[] buffer; - need *= 2 ; + need *= 2 ; buffer = new char[need]; if ( buffer ) { va_list args; // variable arg list @@ -390,9 +390,12 @@ namespace Exiv2 { size += start; while (start < size) { - int c = (int) buff[start++] ; - if (c < ' ' || c > 127) c = '.' ; - result += (char) c ; + int c = (int) buff[start++] ; + bool bTrailingNull = c == 0 && start == size; + if ( !bTrailingNull ) { + if (c < ' ' || c > 127) c = '.' ; + result += (char) c ; + } } return result; } diff --git a/src/tiffimage.cpp b/src/tiffimage.cpp index 1f6e6509..4e5c1fcd 100644 --- a/src/tiffimage.cpp +++ b/src/tiffimage.cpp @@ -303,15 +303,15 @@ namespace Exiv2 { } bool isBigEndian() - { - union { - uint32_t i; - char c[4]; - } e = { 0x01000000 }; + { + union { + uint32_t i; + char c[4]; + } e = { 0x01000000 }; - return e.c[0]?true:false; - } - bool isLittleEndian() { return !isBigEndian(); } + return e.c[0]?true:false; + } + bool isLittleEndian() { return !isBigEndian(); } // http://en.wikipedia.org/wiki/Endianness @@ -504,7 +504,7 @@ namespace Exiv2 { : 1 ; - DataBuf buf(MIN(size*kount + pad,48)); // allocate a buffer + DataBuf buf(MIN(size*kount + pad,48)); // allocate a buffer if ( isStringType(type) || count*size > 4 ) { // data is in the directory => read into buffer size_t restore = io_->tell(); // save io_->seek(offset,BasicIo::beg); // position diff --git a/test/data/bugfixes-test.out b/test/data/bugfixes-test.out index bc89940df7ed0fda353a29971acedfc2705f4dea..3b0a94f25f57ecc658e754db348087296058dff5 100644 GIT binary patch delta 79 zcmV~$M-6~506@{OXW6@M06|FL@SEVEhuR>)13Ea9;DGl&v%O~9v9NJ)@$d-$>;b1S2r8v delta 79 zcmV~$M-6~506@{ODSNNFp@xva;X`oHLv4^C0VP~XaKL-7Sw6F@SlBqYc=!Z_2qIz< eQZjN1N-Am^S~_|LMy69L^o-o~jZ~M| 17 entries starting at file offset 0xfe=254 -@0x00000fe=254 : <0x00fe= 254> NewSubFileType [4 =LONG 1] = 0 = 'primary' -@0x000010a=266 : <0x0100= 256> ImageWidth [3 =SHORT 1] = 9 -@0x0000116=278 : <0x0101= 257> ImageLength [3 =SHORT 1] = 9 -@0x0000122=290 : <0x0102= 258> BitsPerSample [3 =SHORT 3] = @0x1ce=462 -@0x000012e=302 : <0x0103= 259> Compression [3 =SHORT 1] = 1 = 'uncompressed' -@0x000013a=314 : <0x0106= 262> PhotometricInterpretation [3 =SHORT 1] = 2 = 'RGB' -@0x0000146=326 : <0x010d= 269> DocumentName [2 =ASCII 24] = @0x1d4=468 -@0x0000152=338 : <0x010e= 270> ImageDescription [2 =ASCII 18] = @0x1ec=492 -@0x000015e=350 : <0x0111= 273> StripOffsets [4 =LONG 1] = @8 -@0x000016a=362 : <0x0112= 274> Orientation [3 =SHORT 1] = 1 = '0,0 is top left' -@0x0000176=374 : <0x0115= 277> SamplesPerPixel [3 =SHORT 1] = 3 -@0x0000182=386 : <0x0116= 278> RowsPerStrip [3 =SHORT 1] = 64 -@0x000018e=398 : <0x0117= 279> StripByteCounts [4 =LONG 1] = 243 -@0x000019a=410 : <0x011a= 282> XResolution [5 =RATIONAL 1] = @0x1fe=510 -@0x00001a6=422 : <0x011b= 283> YResolution [5 =RATIONAL 1] = @0x206=518 -@0x00001b2=434 : <0x011c= 284> PlanarConfiguration [3 =SHORT 1] = 1 = 'chunky/contig' -@0x00001be=446 : <0x0128= 296> ResolutionUnit [3 =SHORT 1] = 2 = 'pixels per inch' -@0x00001ca=458 : **** next IFD offset 0 -@0x00001ce=462 : ============= VALUES, IFD 0 ============ -@0x00001ce=462 : BitsPerSample = 8,8,8 -@0x00001d4=468 : DocumentName = '/home/ahuggel/mini9.tif\0' -@0x00001ec=492 : ImageDescription = 'Created with GIMP\0' -@0x00001fe=510 : XResolution = 72 -@0x0000206=518 : YResolution = 72 -@0x000020d=525 : -@0x0000008=8 : <=-=-=> Start of TIFF RGB uncompressed image data for IFD 0, data length 243 - 0x0000008=8 : ff 00 00 ff 00 00 ff 00 00 ff 00 00 00 ff 00 00 |................| - 0x0000018=24 : 00 ff ff 00 00 ff 00 00 ff 00 00 00 ff 00 00 ff |................| - 0x0000028=40 : 00 00 ff 00 3f 7f bf 3f 7f bf 3f 7f bf 00 ff 00 |....?..?..?.....| - 0x0000038=56 : 00 ff 00 00 ff 00 00 00 ff 00 00 ff 3f 7f bf ff |............?...| etc... -@0x00000fa=250 : End of image data --0x000020d=525 : END OF FILE -@0x0000008=8 : Start of TIFF RGB uncompressed primary image [9x9] length 243 (IFD 0) --0x00000fa=250 : End of TIFF primary image data -Number of images = 1 -File Format = TIFFEP +exiv2 -pa output +NewSubfileType Long 1 "Primary image" +ImageWidth Short 1 "9" +ImageLength Short 1 "9" +BitsPerSample Short 3 "8 8 8" +Compression Short 1 "Uncompressed" +PhotometricInterpretation Short 1 "RGB" +DocumentName Ascii 24 "/home/ahuggel/mini9.tif" +ImageDescription Ascii 18 "Created with GIMP" +StripOffsets Long 1 "8" +Orientation Short 1 "top, left" +SamplesPerPixel Short 1 "3" +RowsPerStrip Short 1 "64" +StripByteCounts Long 1 "243" +XResolution Rational 1 "72" +YResolution Rational 1 "72" +PlanarConfiguration Short 1 "1" +ResolutionUnit Short 1 "inch" +exiv2 -pS output +NewSubfileType LONG 1 "0" +ImageWidth SHORT 1 "9" +ImageLength SHORT 1 "9" +BitsPerSample SHORT 3 "8 8 8" +Compression SHORT 1 "1" +PhotometricInterpretation SHORT 1 "2" +DocumentName ASCII 24 "/home/ahuggel/mini9.tif" +ImageDescription ASCII 18 "Created with GIMP" +StripOffsets LONG 1 "8" +Orientation SHORT 1 "1" +SamplesPerPixel SHORT 1 "3" +RowsPerStrip SHORT 1 "64" +StripByteCounts LONG 1 "243" +XResolution RATIONAL 1 "510/0" +YResolution RATIONAL 1 "518/0" +PlanarConfiguration SHORT 1 "1" +ResolutionUnit SHORT 1 "2" +Analysis +count = 17 COUNT = 17 Test 1: Writing empty Exif data without original binary data: ok. Test 2: Writing empty Exif data with original binary data: ok. Test 3: Wrote non-empty Exif data without original binary data: @@ -86,53 +83,50 @@ Exif.Image.YResolution 0x011b Rational 1 1207959552/16 Exif.Image.PlanarConfiguration 0x011c Short 1 1 Exif.Image.ResolutionUnit 0x0128 Short 1 2 Exif.Photo.DateTimeOriginal 0x9003 Ascii 18 Yesterday at noon -File Name = mini9.tif -File Type = TIFF:II -File Size = 574 -@000000000=0 : TIFF(II=0x4949) magic=0x002a='*\0' ifd offset = 0x8/8 -@0x0000008=8 : 18 entries starting at file offset 0xa=10 -@0x000000a=10 : <0x00fe= 254> NewSubFileType [4 =LONG 1] = 0 = 'primary' -@0x0000016=22 : <0x0100= 256> ImageWidth [3 =SHORT 1] = 9 -@0x0000022=34 : <0x0101= 257> ImageLength [3 =SHORT 1] = 9 -@0x000002e=46 : <0x0102= 258> BitsPerSample [3 =SHORT 3] = @0xe6=230 -@0x000003a=58 : <0x0103= 259> Compression [3 =SHORT 1] = 1 = 'uncompressed' -@0x0000046=70 : <0x0106= 262> PhotometricInterpretation [3 =SHORT 1] = 2 = 'RGB' -@0x0000052=82 : <0x010d= 269> DocumentName [2 =ASCII 24] = @0xec=236 -@0x000005e=94 : <0x010e= 270> ImageDescription [2 =ASCII 18] = @0x104=260 -@0x000006a=106 : <0x0111= 273> StripOffsets [4 =LONG 1] = @330 -@0x0000076=118 : <0x0112= 274> Orientation [3 =SHORT 1] = 1 = '0,0 is top left' -@0x0000082=130 : <0x0115= 277> SamplesPerPixel [3 =SHORT 1] = 3 -@0x000008e=142 : <0x0116= 278> RowsPerStrip [3 =SHORT 1] = 64 -@0x000009a=154 : <0x0117= 279> StripByteCounts [4 =LONG 1] = 243 -@0x00000a6=166 : <0x011a= 282> XResolution [5 =RATIONAL 1] = @0x116=278 -@0x00000b2=178 : <0x011b= 283> YResolution [5 =RATIONAL 1] = @0x11e=286 -@0x00000be=190 : <0x011c= 284> PlanarConfiguration [3 =SHORT 1] = 1 = 'chunky/contig' -@0x00000ca=202 : <0x0128= 296> ResolutionUnit [3 =SHORT 1] = 2 = 'pixels per inch' -@0x00000d6=214 : <0x8769=34665> ExifIFDPointer [4 =LONG 1] = @0x126=294 -@0x00000e2=226 : **** next IFD offset 0 -@0x00000e6=230 : ============= VALUES, IFD 0 ============ -@0x00000e6=230 : BitsPerSample = 8,8,8 -@0x00000ec=236 : DocumentName = '/home/ahuggel/mini9.tif\0' -@0x0000104=260 : ImageDescription = 'Created with GIMP\0' -@0x0000116=278 : XResolution = 72 -@0x000011e=286 : YResolution = 72 -@0x0000126=294 : (in IFD 0) 1 entries starting at file offset 0x128=296 -@0x0000128=296 : <0x9003=36867> DateTimeOriginal [2 =ASCII 18] = @0x138=312 -@0x0000134=308 : **** next IFD offset 0 -@0x0000138=312 : ============= VALUES, EXIF IFD ============ -@0x0000138=312 : DateTimeOriginal = 'Yesterday at noon\0' --0x0000149=329 : -@0x0000149=329 : -@0x000014a=330 : <=-=-=> Start of TIFF RGB uncompressed image data for IFD 0, data length 243 - 0x000014a=330 : ff 00 00 ff 00 00 ff 00 00 ff 00 00 00 ff 00 00 |................| - 0x000015a=346 : 00 ff ff 00 00 ff 00 00 ff 00 00 00 ff 00 00 ff |................| - 0x000016a=362 : 00 00 ff 00 3f 7f bf 3f 7f bf 3f 7f bf 00 ff 00 |....?..?..?.....| - 0x000017a=378 : 00 ff 00 00 ff 00 00 00 ff 00 00 ff 3f 7f bf ff |............?...| etc... -@0x000023c=572 : End of image data --0x000023d=573 : END OF FILE -@0x000014a=330 : Start of TIFF RGB uncompressed primary image [9x9] length 243 (IFD 0) --0x000023c=572 : End of TIFF primary image data -Number of images = 1 -File Format = TIFFEP/EXIF +exiv2 -pa output +NewSubfileType Long 1 "Primary image" +ImageWidth Short 1 "9" +ImageLength Short 1 "9" +BitsPerSample Short 3 "8 8 8" +Compression Short 1 "Uncompressed" +PhotometricInterpretation Short 1 "RGB" +DocumentName Ascii 24 "/home/ahuggel/mini9.tif" +ImageDescription Ascii 18 "Created with GIMP" +StripOffsets Long 1 "330" +Orientation Short 1 "top, left" +SamplesPerPixel Short 1 "3" +RowsPerStrip Short 1 "64" +StripByteCounts Long 1 "243" +XResolution Rational 1 "72" +YResolution Rational 1 "72" +PlanarConfiguration Short 1 "1" +ResolutionUnit Short 1 "inch" +ExifTag Long 1 "294" +DateTimeOriginal Ascii 18 "Yesterday at noon" +exiv2 -pS output +NewSubfileType LONG 1 "0" +ImageWidth SHORT 1 "9" +ImageLength SHORT 1 "9" +BitsPerSample SHORT 3 "8 8 8" +Compression SHORT 1 "1" +PhotometricInterpretation SHORT 1 "2" +DocumentName ASCII 24 "/home/ahuggel/mini9.tif" +ImageDescription ASCII 18 "Created with GIMP" +StripOffsets LONG 1 "330" +Orientation SHORT 1 "1" +SamplesPerPixel SHORT 1 "3" +RowsPerStrip SHORT 1 "64" +StripByteCounts LONG 1 "243" +XResolution RATIONAL 1 "278/0" +YResolution RATIONAL 1 "286/0" +PlanarConfiguration SHORT 1 "1" +ResolutionUnit SHORT 1 "2" +ExifTag LONG 1 "294" +Analysis +count = 19 COUNT = 18 +TAG DateTimeOriginal mismatch +TYPE ASCII mismatch +Length 18 mismatch +Value Yesterday at noon mismatch diff --git a/test/tiff-test.sh b/test/tiff-test.sh index 6cc17996..fef74ca2 100644 --- a/test/tiff-test.sh +++ b/test/tiff-test.sh @@ -1,13 +1,99 @@ #!/bin/bash # TIFF parser test driver -# ---------------------------------------------------------------------- -# Check if the exifprobe tool is available -exifprobe 2>/dev/null >/dev/null -if [ "$?" != "0" ] ; then - echo "tiff-test.sh: exifprobe not found. Skipping TIFF tests." - exit 0 -fi +exifprobe() +{ + f=$1 + + # References + # process pipe : http://stackoverflow.com/questions/7612320/bash-weird-variable-scope-when-populating-array-with-results + # to uppercase : http://unix.stackexchange.com/questions/51983/bash-how-to-uppercase-the-command-line-argument + # --------------------------------------- + # Parse -pa output + # Exif.Image.ImageDescription Ascii 18 Created with GIMP + tags=() + typs=() + lens=() + vals=() + while read line; do + tag=$(echo $line|cut -d. -f 3 | cut -d' ' -f 1) ; tags+=($tag) + typ=$(echo $line|cut -d' ' -f 2- | sed -E -e 's/ +/ /g' -e 's/^ //' | cut -d' ' -f 1 ); typs+=($typ) + len=$(echo $line|cut -d' ' -f 2- | sed -E -e 's/ +/ /g' -e 's/^ //' | cut -d' ' -f 2 ); lens+=($len) + val=$(echo $line|cut -d' ' -f 2- | sed -E -e 's/ +/ /g' -e 's/^ //' | cut -d' ' -f 3-); vals+=("$val") + done < <(exiv2 -pa $f 2>/dev/null) # process pipe + count=${#tags[@]} + + echo exiv2 -pa output + index=0 + while [ $index -lt $count ]; do + tag=${tags[$index]} + typ=${typs[$index]} + len=${lens[$index]} + val=${vals[$index]} + echo ${tag} $'\t' ${typ} $'\t' ${len} $'\t' '"'${val}'"' + index=$((index+1)) + done + + # Parse -pS output + # address | tag | type | count | offset | value + # 254 | 0x00fe NewSubfileType | LONG | 1 | 0 | 0 + TAGS=() + TYPS=() + LENS=() + OFFS=() + VALS=() + k=0 + while read line; do + k=$((k+1)) # skip the first couple of lines + if [ $k -gt 2 ]; then + TAG=$(echo $line| cut -d'|' -f 2 | cut -d' ' -f 3 ); TAGS+=($TAG); + TYP=$(echo $line| cut -d'|' -f 3 | sed -E -e's/ +//g'); TYPS+=($TYP) + LEN=$(echo $line| cut -d'|' -f 4 | sed -E -e's/ +//g'); LENS+=($LEN) + OFF=$(echo $line| cut -d'|' -f 5 | sed -E -e's/ +//g'); OFFS+=($OFF) + VAL=$(echo $line| cut -d'|' -f 6- | sed -e's/^ //' ); VALS+=($"$VAL") + fi + done < <(exiv2 -pS $f 2>/dev/null) + COUNT=${#TAGS[@]} + + echo '' + echo exiv2 -pS output + INDEX=0 + while [ $INDEX -lt $COUNT ]; do + TAG=${TAGS[$INDEX]} + TYP=${TYPS[$INDEX]} + LEN=${LENS[$INDEX]} + OFF=${OFFS[$INDEX]} + VAL=${VALS[$INDEX]} + ECHO ${TAG} $'\t' ${TYP} $'\t' ${LEN} $'\t' '"'${VAL}'"' + INDEX=$((INDEX+1)) + done + + # --------------------------------------- + # Compare + echo '' + echo "Analysis" + echo "count = " $count "COUNT = " $COUNT + index=0 + while [ $index -lt $count ]; do + TAG=${TAGS[$index]} + tag=${tags[$index]} + if [ "$TAG" != "$tag" ]; then echo TAG $TAG $tag mismatch ; fi + + TYP=${TYPS[$index]^^} # to uppercase + typ=${typs[$index]^^} + if [ "$TYP" != "$typ" ]; then echo TYPE $TYP $typ mismatch ; fi + + LEN=${LENS[$index]} + len=${lens[$index]} + if [ "$LEN" != "$len" ]; then echo Length $LEN $len mismatch ; fi + + VAL=${VALS[$index]} + val=${vals[$index]} + if [[ "${typ}" == "ASCII" && "$VAL" != "$val" ]]; then echo Value $VAL $val mismatch ; fi + + index=$((index+1)) + done +} # ---------------------------------------------------------------------- # Setup @@ -18,6 +104,7 @@ source ./functions.source testfile=mini9.tif copyTestFile ${testfile} exifprobe ${testfile} + runTest tiff-test ${testfile} exifprobe ${testfile}