Mercurial > hg > forks > libbpg
changeset 27:4aa0611ad85a
Some adjustments to EXIF support in TIFF input.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 10 May 2017 16:03:04 +0300 |
parents | a6e11adda0be |
children | 76a105267445 |
files | bpgenc.c |
diffstat | 1 files changed, 15 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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);