# HG changeset patch # User Matti Hamalainen # Date 1494421384 -10800 # Node ID 4aa0611ad85aa5843cb5ce67670bcf5aa19a3ae1 # Parent a6e11adda0be98f094930e469b3daf71da5e356e Some adjustments to EXIF support in TIFF input. diff -r a6e11adda0be -r 4aa0611ad85a bpgenc.c --- a/bpgenc.c Wed May 10 14:26:20 2017 +0300 +++ b/bpgenc.c Wed May 10 16:03:04 2017 +0300 @@ -1110,10 +1110,14 @@ uint16_t img_depth, img_spp, img_pconfig, img_pmetric, *buf2 = NULL, *img_colormap_r, *img_colormap_g, *img_colormap_b; int img_alpha, err_spp, offs, x, y, idx; - toff_t tmp_offs; size_t img_linesize; ColorConvertState cvt; RGBConvertFunc *convert_func; +#ifdef HAVE_LIBEXIF + toff_t tmp_offs; + ExifMem *exif_mem = NULL; + ExifData *exif = NULL; +#endif // Set warning handler to silence dubious warnings about unknown fields TIFFSetWarningHandler(tiff_warning_handler); @@ -1315,12 +1319,10 @@ // Due to insanity of libtiff's "API", we have to go roundabout way to // reconstruct the EXIF data through libexif and fetching TIFF tags .. // even though the data already supposedly exists in desired format .. :( - ExifMem *exif_mem = exif_mem_new_default(); - if (exif_mem == NULL) + if ((exif_mem = exif_mem_new_default()) == NULL) goto err; - ExifData *exif = exif_data_new_mem(exif_mem); - if (exif == NULL) + if ((exif = exif_data_new_mem(exif_mem)) == NULL) goto err; exif_data_set_option(exif, EXIF_DATA_OPTION_FOLLOW_SPECIFICATION); @@ -1330,12 +1332,10 @@ int added = 0; tiff_tags_convert(tif, tiff_tag_convert_table, exif_mem, exif, &added); - if (TIFFGetField(tif, TIFFTAG_EXIFIFD, &tmp_offs)) + if (TIFFGetField(tif, TIFFTAG_EXIFIFD, &tmp_offs) && + TIFFReadEXIFDirectory(tif, tmp_offs)) { - if (TIFFReadEXIFDirectory(tif, tmp_offs)) - { - tiff_tags_convert(tif, exif_tag_convert_table, exif_mem, exif, &added); - } + tiff_tags_convert(tif, exif_tag_convert_table, exif_mem, exif, &added); } if (added) @@ -1354,6 +1354,11 @@ #endif err: +#ifdef HAVE_LIBEXIF + if (exif != NULL) + exif_data_free(exif); +#endif + if (buf != NULL) _TIFFfree(buf);