From e794d76bd0bc75916edc5a9ff2a54aecf4e12ca2 Mon Sep 17 00:00:00 2001
From: Arnav Singh <me@arnavion.dev>
Date: Tue, 11 Jun 2024 18:07:35 +0200
Subject: [PATCH] Don't pass length parameter for
 TIFFSetField(TIFFTAG_CFAREPEATPATTERNDIM)

libtiff broke its API again and now requires the original
three-parameter way of setting TIFFTAG_CFAREPEATPATTERNDIM instead of
the new four-parameter way. It has possibly been like this since v4.5.1.

Megapixels upstream is considering a more permanent way to become immune to
these breakages (switching from libtiff to libdng), but for now this commit
makes the existing release work.

Ref: https://gitlab.com/megapixels-org/Megapixels/-/issues/4
Tweaked-By: Oliver Smith <ollieparanoid@postmarketos.org>
---
 process_pipeline.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/process_pipeline.c b/process_pipeline.c
index 624c5f6..bbc88fa 100644
--- a/process_pipeline.c
+++ b/process_pipeline.c
@@ -277,7 +277,7 @@ compute_statistics(uint32_t *dst, const uint32_t width, const uint32_t height, s
 		stats->balance_adjust = -1;
 	if (b > r * 1.3)
 		stats->balance_adjust = 1;
-	
+
 	if (debug) printf(" awb %d", stats->balance_adjust);
 	if (debug) printf(" sharp %d", (int) sharp / 10000);
 	if (debug) printf("\n");
@@ -305,7 +305,7 @@ process_image_for_preview(const MPImage *image)
 	{
 		static char msg[128] = {};
 		struct image_stats stats;
-	  
+
 		compute_statistics((uint32_t *) pixels, surface_width, surface_height, &stats);
 
 		debug_message = msg;
@@ -439,19 +439,11 @@ save_dng(const MPImage *image, char *fname)
 	TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
 	static const short cfapatterndim[] = { 2, 2 };
 
-#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, 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;
-- 
2.45.1

