[libpng16] fix: Update the cICP implementation yet more

For the sake of completeness:
 * Add the cICP entry to the list of known chunks to ignore inside
   `png_set_keep_unknown_chunks`.
 * Handle cICP in `png_read_end`, alongside cHRM, gAMA, iCCP, sRGB.
 * In pngtest.c, move the cICP test code near cHRM, gaMA, iCCP, sRGB.

This is a cherry-pick of commit 27c2ac722fd99b8622cead655034208ce96346ac
from branch 'libpng18'.

Reviewed-by: John Bowler <jbowler@acm.org>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
diff --git a/pngread.c b/pngread.c
index 175d601..49e19a4 100644
--- a/pngread.c
+++ b/pngread.c
@@ -1,6 +1,6 @@
 /* pngread.c - read a PNG file
  *
- * Copyright (c) 2018-2024 Cosmin Truta
+ * Copyright (c) 2018-2025 Cosmin Truta
  * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
  * Copyright (c) 1996-1997 Andreas Dilger
  * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
@@ -173,6 +173,7 @@
       else if (chunk_name == png_cHRM)
          png_handle_cHRM(png_ptr, info_ptr, length);
 #endif
+
 #ifdef PNG_READ_cICP_SUPPORTED
       else if (chunk_name == png_cICP)
          png_handle_cICP(png_ptr, info_ptr, length);
@@ -855,6 +856,11 @@
          png_handle_cHRM(png_ptr, info_ptr, length);
 #endif
 
+#ifdef PNG_READ_cICP_SUPPORTED
+      else if (chunk_name == png_cICP)
+         png_handle_cICP(png_ptr, info_ptr, length);
+#endif
+
 #ifdef PNG_READ_eXIf_SUPPORTED
       else if (chunk_name == png_eXIf)
          png_handle_eXIf(png_ptr, info_ptr, length);
diff --git a/pngset.c b/pngset.c
index 383a256..462b50c 100644
--- a/pngset.c
+++ b/pngset.c
@@ -1,6 +1,6 @@
 /* pngset.c - storage of image information into info struct
  *
- * Copyright (c) 2018-2024 Cosmin Truta
+ * Copyright (c) 2018-2025 Cosmin Truta
  * Copyright (c) 1998-2018 Glenn Randers-Pehrson
  * Copyright (c) 1996-1997 Andreas Dilger
  * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
@@ -1420,6 +1420,7 @@
       static const png_byte chunks_to_ignore[] = {
          98,  75,  71,  68, '\0',  /* bKGD */
          99,  72,  82,  77, '\0',  /* cHRM */
+         99,  73,  67,  80, '\0',  /* cICP */
         101,  88,  73, 102, '\0',  /* eXIf */
         103,  65,  77,  65, '\0',  /* gAMA */
         104,  73,  83,  84, '\0',  /* hIST */
diff --git a/pngtest.c b/pngtest.c
index dbbcf1e..c029266 100644
--- a/pngtest.c
+++ b/pngtest.c
@@ -1,6 +1,6 @@
 /* pngtest.c - a test program for libpng
  *
- * Copyright (c) 2018-2024 Cosmin Truta
+ * Copyright (c) 2018-2025 Cosmin Truta
  * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
  * Copyright (c) 1996-1997 Andreas Dilger
  * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
@@ -1167,6 +1167,21 @@
 #endif
 #endif /* Floating point */
 #endif /* Fixed point */
+#ifdef PNG_cICP_SUPPORTED
+   {
+      png_byte colour_primaries;
+      png_byte transfer_function;
+      png_byte matrix_coefficients;
+      png_byte video_full_range_flag;
+
+      if (png_get_cICP(read_ptr, read_info_ptr,
+                       &colour_primaries, &transfer_function,
+                       &matrix_coefficients, &video_full_range_flag) != 0)
+         png_set_cICP(write_ptr, write_info_ptr,
+                      colour_primaries, transfer_function,
+                      matrix_coefficients, video_full_range_flag);
+   }
+#endif
 #ifdef PNG_iCCP_SUPPORTED
    {
       png_charp name;
@@ -1205,21 +1220,6 @@
          png_set_bKGD(write_ptr, write_info_ptr, background);
    }
 #endif
-#ifdef PNG_cICP_SUPPORTED
-   {
-      png_byte colour_primaries;
-      png_byte transfer_function;
-      png_byte matrix_coefficients;
-      png_byte video_full_range_flag;
-
-      if (png_get_cICP(read_ptr, read_info_ptr,
-                       &colour_primaries, &transfer_function,
-                       &matrix_coefficients, &video_full_range_flag) != 0)
-         png_set_cICP(write_ptr, write_info_ptr,
-                      colour_primaries, transfer_function,
-                      matrix_coefficients, video_full_range_flag);
-   }
-#endif
 #ifdef PNG_READ_eXIf_SUPPORTED
    {
       png_bytep exif = NULL;