From d81e552cb7855b2a5e17f736393232b18f160088 Mon Sep 17 00:00:00 2001 From: Robin Mills Date: Thu, 7 Jan 2016 19:05:06 +0000 Subject: [PATCH] #1074 -pC now works on tiff files. Added test convenience targets to Makefile --- Makefile | 33 +++++++++++++++------ src/exiv2.1 | 2 +- src/tiffimage.cpp | 57 +++++++++++++++++++++--------------- test/bugfixes-test.sh | 9 ++++++ test/data/bugfixes-test.out | Bin 1849505 -> 1849520 bytes 5 files changed, 67 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index b94542e0..ba76ab40 100644 --- a/Makefile +++ b/Makefile @@ -67,18 +67,33 @@ uninstall: config/config.mk doc: config/config.mk cd doc && $(MAKE) $(MAKECMDGOALS) -samples: config/config.mk - cd samples && $(MAKE) $(MAKECMDGOALS) - -tests: - cd test && $(MAKE) test - -teste testx testv: - cd test && $(MAKE) $@ - +# exiv2 application and programs required by test suite exiv2 conntest exifprint remotetest: cd src && $(MAKE) $0 +samples: config/config.mk + cd samples && $(MAKE) $(MAKECMDGOALS) + +# test suite +tests: + cd test && $(MAKE) test + +# test suite sub groups +teste testx testv: + cd test && $(MAKE) $@ + +# convenience for running individual tests +bugfixes-test.sh crw-test.sh curliotest.sh eps-preview-test.sh eps-test.sh exifdata-test.sh \ +exiv2-test.sh httpiotest.sh imagetest.sh iotest.sh iptctest.sh modify-test.sh \ +path-test.sh preview-test.sh sshiotest.sh stringto-test.sh tiff-test.sh video-test.sh \ +write-test.sh write-video-test.sh write2-test.sh xmpparser-test.sh : + cd test && ./$@ + +# convenience target for running bugfixes-test.sh +bugtest bugstest testbugs bugfixes: + cd test && ./bugfixes-test.sh + +# convenience target for building individual sample programs addmoddel exifcomment exifvalue httptest iptctest mmap-test stringto-test \ exifdata iotest key-test path-test taglist write2-test write-test \ convert-test exifdata-test exiv2json iptceasy largeiptc-test prevtest tiff-test \ diff --git a/src/exiv2.1 b/src/exiv2.1 index 29050f26..ec2e844c 100644 --- a/src/exiv2.1 +++ b/src/exiv2.1 @@ -315,7 +315,7 @@ c : JPEG comment .br p : list available image previews, sorted by preview image size in pixels .br -C : print image ICC Profile (jpg and png only) +C : print image ICC Profile (jpg, png, tiff only) .br R : print image structure recursively (jpg, png, tiff only) .br diff --git a/src/tiffimage.cpp b/src/tiffimage.cpp index aa76c2d8..b56c663b 100644 --- a/src/tiffimage.cpp +++ b/src/tiffimage.cpp @@ -444,6 +444,10 @@ namespace Exiv2 { { return type == 700 && option == kpsXMP; } + static bool isPrintICC(uint16_t type, Exiv2::PrintStructureOption option) + { + return type == 0x8773 && option == kpsIccProfile; + } #define MIN(a,b) ((a)<(b))?(b):(a) @@ -463,9 +467,6 @@ namespace Exiv2 { throw Error(15); } - if ( option == kpsIccProfile ) { - throw Error(13, io_->path()); - } io_->seek(0,BasicIo::beg); printTiffStructure(io(),out,option,depth-1); @@ -486,16 +487,20 @@ namespace Exiv2 { uint16_t dirLength = byteSwap2(dir,0,bSwap); bool tooBig = dirLength > 200 ; + bool bPrint = option == kpsBasic || option == kpsRecursive; - if ( bFirst && (option == kpsBasic || option == kpsRecursive) ) { + if ( bFirst && bPrint ) { out << indent(depth) << Internal::stringFormat("STRUCTURE OF TIFF FILE (%c%c): ",c,c) << io.path() << std::endl; if ( tooBig ) out << indent(depth) << "dirLength = " << dirLength << std::endl; } // Read the dictionary for ( int i = 0 ; !tooBig && i < dirLength ; i ++ ) { - if ( bFirst ) - out << indent(depth) << " address | tag | type | count | offset | value\n"; + if ( bFirst && bPrint ) { + out << indent(depth) + << " address | tag | " + << " type | count | offset | value\n"; + } bFirst = false; io.read(dir.pData_, 12); @@ -504,23 +509,23 @@ namespace Exiv2 { uint32_t count = byteSwap4(dir,4,bSwap); uint32_t offset = byteSwap4(dir,8,bSwap); - std::string sp = "" ; // output spacer + std::string sp = "" ; // output spacer //prepare to print the value - uint16_t kount = isPrintXMP(tag,option) ? count // restrict long arrays - : isStringType(type) ? (count > 32 ? 32 : count) - : count > 5 ? 5 - : count - ; - uint32_t pad = isStringType(type) ? 1 : 0; - uint32_t size = isStringType(type) ? 1 - : is2ByteType(type) ? 2 - : is4ByteType(type) ? 4 - : 1 - ; - uint32_t Offset = 0 ; // used by ExifTag == 0x8769 && MakerNote == 0x927c to locate an FID + uint16_t kount = isPrintXMP(tag,option) ? count // restrict long arrays + : isPrintICC(tag,option) ? count // + : isStringType(type) ? (count > 32 ? 32 : count) + : count > 5 ? 5 + : count + ; + uint32_t pad = isStringType(type) ? 1 : 0; + uint32_t size = isStringType(type) ? 1 + : is2ByteType(type) ? 2 + : is4ByteType(type) ? 4 + : 1 + ; - // if ( offset > io.size() ) offset = 0; + // if ( offset > io.size() ) offset = 0; // Denial of service? 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 @@ -531,12 +536,13 @@ namespace Exiv2 { std::memcpy(buf.pData_,dir.pData_+8,12); } - if ( option == kpsBasic || option == kpsRecursive ) { + uint32_t Offset = isLongType(type) ? byteSwap4(buf,0,bSwap) : 0 ; + + if ( bPrint ) { uint32_t address = start + 2 + i*12 ; out << indent(depth) << Internal::stringFormat("%8u | %#06x %-25s |%10s |%9u |%9u | " ,address,tag,tagName(tag,25),typeName(type),count,offset); - if ( isShortType(type) ){ for ( uint16_t k = 0 ; k < kount ; k++ ) { out << sp << byteSwap2(buf,k*size,bSwap); @@ -545,7 +551,6 @@ namespace Exiv2 { } else if ( isLongType(type) ){ for ( uint16_t k = 0 ; k < kount ; k++ ) { out << sp << byteSwap4(buf,k*size,bSwap); - if ( k == 0 ) Offset = byteSwap4(buf,k*size,bSwap) ; sp = " "; } } else if ( isRationalType(type) ){ @@ -564,6 +569,7 @@ namespace Exiv2 { } else if ( isStringType(type) ) { out << sp << Internal::binaryToString(buf, kount); } + sp = kount == count ? "" : " ..."; out << sp << std::endl; if ( option == kpsRecursive @@ -579,6 +585,9 @@ namespace Exiv2 { buf.pData_[count]=0; out << (char*) buf.pData_; } + if ( isPrintICC(tag,option) ) { + out.write((const char*)buf.pData_,buf.size_); + } } io.read(dir.pData_, 4); start = tooBig ? 0 : byteSwap4(dir,0,bSwap); @@ -593,7 +602,7 @@ namespace Exiv2 { void TiffImage::printTiffStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStructureOption option,int depth) { - if ( option == kpsBasic || option == kpsXMP || option == kpsRecursive ) { + if ( option == kpsBasic || option == kpsXMP || option == kpsRecursive || option == kpsIccProfile ) { // buffer const size_t dirSize = 32; DataBuf dir(dirSize); diff --git a/test/bugfixes-test.sh b/test/bugfixes-test.sh index 8b20e321..b7a4257b 100755 --- a/test/bugfixes-test.sh +++ b/test/bugfixes-test.sh @@ -414,6 +414,15 @@ source ./functions.source copyTestFile $filename runTest exiv2 -pa -g zone $filename + num=1074 + filename=exiv2-bug$num.jpg + printf "$num " >&3 + echo '------>' Bug $num '<-------' >&2 + copyTestFile imagemagick.png $filename + runTest exiv2 -pC $filename | wc + runTest exiv2 -pC http://dev.exiv2.org/attachments/download/821/Reagan.tiff | wc + runTest exiv2 -pC http://dev.exiv2.org/attachments/download/820/Reagan.jpg | wc + num=1112 filename=exiv2-bug$num.xmp printf "$num " >&3 diff --git a/test/data/bugfixes-test.out b/test/data/bugfixes-test.out index af815cf33d230fc925a2df7fd062d2e7e2c73bce..45fdb4772720c4af6f22d63df6650c2072396870 100644 GIT binary patch delta 173 zcmZ4Zv0%f;f`%5x7N!>F7M2#)7Pc1l7LFFq7OocV7M>Q~7QPn#7J(MQ7NHj57LgXw z7O@ub7Ks+g7O5@Liwmaz3y{v6{yLVia{Gfq=^tyt4a`jxY;+-jO92dwjKGwki6w|O dHMKN@N*J0!B#gldj15gpa7t`HB`0%T5&$hYE-C;3 delta 94 zcmV-k0HOb|@o=H>aDapXgaU*Egam{Iga(8Mgb0KQgbIWUgbaiYgbsucgb;)ggc5`k zgcO7ogcgJsgcyVwgc`IPqi~m&dK*@k{!klkm+M^td6r=tZMXMv8;h*B=N=r%8B&lV A#sB~S