GraphicsMagick: coders/tiff.c Fix for multiple frames. Do not im...
GraphicsMagick Commits <[email protected]> Thu, 11 Jan 2024 15:10:14 -0600
| Newsgroups | gmane.comp.video.graphicsmagick.cvs |
|---|---|
| Message-ID | <mailman.2147.1705007427.16032.graphicsmagick-commit@lists.sourceforge.net> |
changeset 993b2006a8d1 in /hg/GraphicsMagick details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=993b2006a8d1 summary: coders/tiff.c Fix for multiple frames. Do not import TIFFTAG_COMPRESSION, TIFFTAG_IMAGELENGTH, TIFFTAG_IMAGEWIDTH ... from EXIF. diffstat: ChangeLog | 6 ++++++ coders/tiff.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 3 deletions(-) diffs (105 lines): diff -r 2751bfeaf95d -r 993b2006a8d1 ChangeLog --- a/ChangeLog Wed Jan 10 09:56:37 2024 -0600 +++ b/ChangeLog Thu Jan 11 22:09:47 2024 +0100 @@ -1,3 +1,9 @@ +2024-01-11 Fojtik Jaroslav <[email protected]> + + coders/tiff.c Fix for multiple frames. Do not import + TIFFTAG_COMPRESSION, TIFFTAG_IMAGELENGTH, TIFFTAG_IMAGEWIDTH ... + from EXIF. + 2024-01-10 Bob Friesenhahn <[email protected]> * coders/tiff.c (EXPERIMENTAL_EXIF_TAGS): Change diff -r 2751bfeaf95d -r 993b2006a8d1 coders/tiff.c --- a/coders/tiff.c Wed Jan 10 09:56:37 2024 -0600 +++ b/coders/tiff.c Thu Jan 11 22:09:47 2024 +0100 @@ -4496,16 +4496,23 @@ (void)LogMagickEvent(CoderEvent,GetMagickModule(),"Extracted tag from EXIF %xh, Field %d, Long2 %d, val %d %s", Tag, Field, Long2, Value, FipFieldName(fip)); + if(Tag==TIFFTAG_COMPRESSION || + Tag==TIFFTAG_IMAGELENGTH || Tag==TIFFTAG_IMAGEWIDTH || + Tag==TIFFTAG_SAMPLESPERPIXEL || Tag==TIFFTAG_BITSPERSAMPLE || Tag==TIFFTAG_SAMPLEFORMAT) + { + goto NextItem; /* Banned TIFF tags that cannot be obtained from EXIF. */ + } + if(Tag == TIFFTAG_EXIFIFD) { if((Flags & FLAG_EXIF) != 0) - FieldCount += AddIFDExifFields(tiff, profile_data, profile_data+Value, profile_length, logging, Flags); + FieldCount += AddIFDExifFields(tiff, profile_data, profile_data+Value, profile_length, logging, Flags|FLAG_BASE); goto NextItem; } if(Tag == TIFFTAG_GPSIFD) { if((Flags & FLAG_GPS) != 0) - FieldCount += AddIFDExifFields(tiff, profile_data, profile_data+Value, profile_length, logging, Flags); + FieldCount += AddIFDExifFields(tiff, profile_data, profile_data+Value, profile_length, logging, Flags|FLAG_BASE); goto NextItem; } @@ -5992,6 +5999,21 @@ (void) TIFFSetField(tiff,TIFFTAG_XRESOLUTION,image->x_resolution); (void) TIFFSetField(tiff,TIFFTAG_YRESOLUTION,image->y_resolution); } + +#if defined(EXPERIMENTAL_EXIF_TAGS) +#if TIFFLIB_VERSION >= 20120922 + if(status!=MagickFail) + { + const unsigned char *profile_data; + size_t profile_length; + if((profile_data=GetImageProfile(image,"Exif",&profile_length)) != 0) + { + AddExifFields(tiff,profile_data,profile_length,logging, FLAG_BASE); + } + } +#endif /* TIFFLIB_VERSION >= 20120922 */ +#endif /* defined(EXPERIMENTAL_EXIF_TAGS) */ + if (image->chromaticity.white_point.x != 0.0) { float @@ -6664,9 +6686,18 @@ size_t profile_length; if((profile_data=GetImageProfile(image,"Exif",&profile_length)) != 0) { + /* + * Unfortunately it depends on the prehistory, what number TIFFCurrentDirectory() will get back. + * Therefore, the current main IFD number has to be adapted. However, this is an inconsistency in LibTIFF which should be + * corrected. This means that the provided code to determÃne/handle current directory number here is just a current work around. + */ + tdir_t current_mainifd = TIFFCurrentDirectory(tiff); + if(TIFFCurrentDirOffset(tiff) > 0 && current_mainifd > 0) current_mainifd--; + + if(TIFFCreateEXIFDirectory(tiff) == 0) { - if(AddExifFields(tiff,profile_data,profile_length,logging, FLAG_EXIF|FLAG_BASE) > 0) + if(AddExifFields(tiff,profile_data,profile_length,logging, FLAG_EXIF) > 0) { // Now write the directory of Exif data uint64_t dir_offset = 0; if(!TIFFWriteCustomDirectory(tiff, &dir_offset)) @@ -6700,6 +6731,20 @@ TIFFSetDirectory(tiff, 0); } */ + /* Save changed tiff-directory to file */ + if(!TIFFWriteDirectory(tiff)) + { + (void)LogMagickEvent(CoderEvent, GetMagickModule(), "TIFFWriteDirectory returns failed status!"); + } + /* Re configure directory status for next image. Reset current IFD number. */ + if(!TIFFSetDirectory(tiff, current_mainifd)) + { + fprintf(stderr, "TIFFSetDirectory() failed.\n"); + } + if(!TIFFCreateDirectory(tiff)) + { + fprintf(stderr, "TIFFCreateDirectory() failed.\n"); + } } } #endif /* TIFFLIB_VERSION >= 20120922 */