Author: tilman
Date: Tue Sep 15 06:43:22 2026
New Revision: 1938226

Log:
PDFBOX-6264: improve clamp test; add toRGB() test by ChatGPT

Modified:
   
pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/color/PDLabTest.java

Modified: 
pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/color/PDLabTest.java
==============================================================================
--- 
pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/color/PDLabTest.java
    Tue Sep 15 06:34:42 2026        (r1938225)
+++ 
pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/color/PDLabTest.java
    Tue Sep 15 06:43:22 2026        (r1938226)
@@ -15,6 +15,9 @@
  */
 package org.apache.pdfbox.pdmodel.graphics.color;
 
+import java.io.IOException;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -97,6 +100,12 @@ class PDLabTest
     void testClamp()
     {
         PDLab lab = new PDLab();
+        assertEquals(-100, lab.getARange().getMin(), 0f);
+        assertEquals(100, lab.getARange().getMax(), 0f);
+        assertEquals(-100, lab.getBRange().getMin(), 0f);
+        assertEquals(100, lab.getBRange().getMax(), 0f);
+        assertEquals("[0.0, 100.0, -100.0, 100.0, -100.0, 100.0]", 
+                Arrays.toString(lab.getDefaultDecode(1)));
         PDRange aRange = new PDRange();
         aRange.setMin(-160);
         aRange.setMax(160);
@@ -121,4 +130,30 @@ class PDLabTest
         assertEquals("[100.0, 160.0, 160.0]", Arrays.toString(lab4));
         assertEquals("[100.0, 160.0, 160.0]", Arrays.toString(lab5));
     }
+
+    @Test
+    void testToRGB() throws IOException
+    {
+        // Author: ChatGPT
+        PDLab lab = new PDLab();
+
+        // PDF Lab values: L* is 0..100, a* and b* are -100..100.
+        float[] black = lab.toRGB(new float[] { 0, 0, 0 });
+        float[] white = lab.toRGB(new float[] { 100, 0, 0 });
+        float[] red = lab.toRGB(new float[] { 53, 80, 67 });
+
+        // Black and white should be at the ends of the RGB range.
+        assertArrayEquals(new float[] { 0, 0, 0 }, black, 0.01f);
+        assertArrayEquals(new float[] { 1, 1, 1 }, white, 0.02f);
+
+        // Red should have a higher red component than green and blue.
+        assertTrue(red[0] > red[1]);
+        assertTrue(red[0] > red[2]);
+
+        // All RGB components must be in the valid range.
+        for (float component : red)
+        {
+            assertTrue(component >= 0 && component <= 1);
+        }
+    }
 }

Reply via email to