libtiff: Merge branch 'tiffcp_cancel_ycbcr' into 'master'

From 2cccf6d75bfe962d9b6e5c4b856c774a8a92a952 Mon Sep 17 00:00:00 2001
From: Even Rouault <[EMAIL REDACTED]>
Date: Sat, 7 Oct 2023 00:40:50 +0200
Subject: [PATCH 1/2] tiffcp: replace PHOTOMETRIC_YCBCR with PHOTOMETRIC_RGB
 when outputing to compression != JPEG (refs #571)

---
 tools/tiffcp.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/tiffcp.c b/tools/tiffcp.c
index 8a660481..d2dd6b17 100644
--- a/tools/tiffcp.c
+++ b/tools/tiffcp.c
@@ -893,7 +893,12 @@ static int tiffcp(TIFF *in, TIFF *out)
                      samplesperpixel == 1 ? PHOTOMETRIC_LOGL
                                           : PHOTOMETRIC_LOGLUV);
     else
-        CopyTag(TIFFTAG_PHOTOMETRIC, 1, TIFF_SHORT);
+    {
+        if (input_photometric == PHOTOMETRIC_YCBCR)
+            TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
+        else
+            CopyTag(TIFFTAG_PHOTOMETRIC, 1, TIFF_SHORT);
+    }
     if (fillorder != 0)
         TIFFSetField(out, TIFFTAG_FILLORDER, fillorder);
     else

From 86d31b233b78be10929ce29d9f286009eb99e728 Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Sun, 8 Oct 2023 20:20:04 +0200
Subject: [PATCH 2/2] tiffcp: preserve TIFFTAG_REFERENCEBLACKWHITE when doing
 YCbCr JPEG -> YCbCr JPEG

---
 tools/tiffcp.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/tiffcp.c b/tools/tiffcp.c
index d2dd6b17..3f761feb 100644
--- a/tools/tiffcp.c
+++ b/tools/tiffcp.c
@@ -879,6 +879,12 @@ static int tiffcp(TIFF *in, TIFF *out)
                 {
                     TIFFGetFieldDefaulted(in, TIFFTAG_YCBCRSUBSAMPLING,
                                           &subsamplinghor, &subsamplingver);
+
+                    float *refBW = NULL;
+                    if (TIFFGetField(in, TIFFTAG_REFERENCEBLACKWHITE, &refBW))
+                    {
+                        TIFFSetField(out, TIFFTAG_REFERENCEBLACKWHITE, refBW);
+                    }
                 }
                 TIFFSetField(out, TIFFTAG_YCBCRSUBSAMPLING, subsamplinghor,
                              subsamplingver);