From 5a0776993051a0af54c148702f36dbbf1064b917 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Sun, 16 Jul 2023 23:27:11 +0200 Subject: [PATCH] Workaround libtiff-4.5.1 This release of libtiff removes the DNG tags so they need to be readded --- process_pipeline.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/process_pipeline.c b/process_pipeline.c index 6bb177b..624c5f6 100644 --- a/process_pipeline.c +++ b/process_pipeline.c @@ -24,7 +24,10 @@ #define SCRIPT_FORMAT "%s/millipixels/%s" -#define TIFFTAG_FORWARDMATRIX1 50964 +#define DNGTAG_FORWARDMATRIX1 50964 +#define DNGTAG_FORWARDMATRIX2 50965 +#define DNGTAG_CFAREPEATPATTERNDIM 33421 +#define DNGTAG_CFAPATTERN 33422 static const float colormatrix_srgb[] = { 3.2409, -1.5373, -0.4986, -0.9692, 1.8759, 0.0415, 0.0556, -0.2039, 1.0569 }; @@ -107,8 +110,14 @@ static void register_custom_tiff_tags(TIFF *tif) { static const TIFFFieldInfo custom_fields[] = { - { TIFFTAG_FORWARDMATRIX1, -1, -1, TIFF_SRATIONAL, FIELD_CUSTOM, 1, 1, + { DNGTAG_FORWARDMATRIX1, -1, -1, TIFF_SRATIONAL, FIELD_CUSTOM, 1, 1, "ForwardMatrix1" }, + { DNGTAG_FORWARDMATRIX2, -1, -1, TIFF_SRATIONAL, FIELD_CUSTOM, 1, 1, + "ForwardMatrix2" }, + { DNGTAG_CFAPATTERN, -1, -1, TIFF_BYTE, FIELD_CUSTOM, 1, 1, + "CFAPattern" }, + { DNGTAG_CFAREPEATPATTERNDIM, -1, -1, TIFF_SHORT, FIELD_CUSTOM, 1, 1, + "CFARepeatPatternDim" }, }; // Add missing dng fields @@ -382,7 +391,7 @@ save_dng(const MPImage *image, char *fname) TIFFSetField(tif, TIFFTAG_COLORMATRIX1, 9, colormatrix_srgb); } if (module.camera->forwardmatrix[0]) { - TIFFSetField(tif, TIFFTAG_FORWARDMATRIX1, 9, module.camera->forwardmatrix); + TIFFSetField(tif, DNGTAG_FORWARDMATRIX1, 9, module.camera->forwardmatrix); } if (module.camera->colormatrix[0] && module.camera->forwardmatrix[0]) { float neutral[3]; @@ -429,14 +438,21 @@ save_dng(const MPImage *image, char *fname) TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1); TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); static const short cfapatterndim[] = { 2, 2 }; - TIFFSetField(tif, TIFFTAG_CFAREPEATPATTERNDIM, cfapatterndim); - const char *cfa_pattern = mp_pixel_format_to_cfa_pattern(image->pixel_format); -#if (TIFFLIB_VERSION < 20201219) && !LIBTIFF_CFA_PATTERN - TIFFSetField(tif, TIFFTAG_CFAPATTERN, cfa_pattern); +#if (TIFFLIB_VERSION > 20230000) + TIFFSetField(tif, DNGTAG_CFAREPEATPATTERNDIM, 2, cfapatterndim); + TIFFSetField(tif, + DNGTAG_CFAPATTERN, + 4, + mp_pixel_format_to_cfa_pattern(image->pixel_format)); #else - TIFFSetField(tif, TIFFTAG_CFAPATTERN, 4, cfa_pattern); + TIFFSetField(tif, DNGTAG_CFAREPEATPATTERNDIM, cfapatterndim); + TIFFSetField(tif, + DNGTAG_CFAPATTERN, + 4, + mp_pixel_format_to_cfa_pattern(image->pixel_format)); #endif + //printf("TIFF version %d\n", TIFFLIB_VERSION); int whitelevel = module.camera->whitelevel; if (!whitelevel) { -- 2.41.0