[
https://issues.apache.org/jira/browse/PDFBOX-5970?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17933907#comment-17933907
]
Simon Steiner commented on PDFBOX-5970:
---------------------------------------
Seems it wasnt part of pdfbox, its not letting me attach it
{code:java}
.../graphics/color/DeviceCMYKColorSpace.java | 93 +++++++++++++++++++
.../pdmodel/graphics/color/PDDeviceCMYK.java | 15 +++
.../graphics/color/PDDeviceCMYKTestCase.java | 38 ++++++++
3 files changed, 146 insertions(+)
create mode 100644
pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/DeviceCMYKColorSpace.java
create mode 100644
pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYKTestCase.java
diff --git
a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/DeviceCMYKColorSpace.java
b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/DeviceCMYKColorSpace.java
new file mode 100644
index 00000000..462c8e09
--- /dev/null
+++
b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/DeviceCMYKColorSpace.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.pdfbox.pdmodel.graphics.color;
+
+import java.awt.color.ColorSpace;
+
+/**
+ * This class represents an uncalibrated CMYK color space.
+ */
+public class DeviceCMYKColorSpace extends ColorSpace {
+
+ private static final long serialVersionUID = 2925508946083542974L;
+
+ /** The name for the uncalibrated CMYK pseudo-profile */
+ public static final String PSEUDO_PROFILE_NAME = "#CMYK";
+
+ /**
+ * Constructs an uncalibrated CMYK ColorSpace object with
ColorSpace#TYPE_CMYK and
+ * 4 components.
+ * @see java.awt.color.ColorSpace#ColorSpace(int, int)
+ */
+ public DeviceCMYKColorSpace() {
+ super(TYPE_CMYK, 4);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public float[] toRGB(float[] colorvalue) {
+ return new float [] {
+ (1 - colorvalue[0]) * (1 - colorvalue[3]),
+ (1 - colorvalue[1]) * (1 - colorvalue[3]),
+ (1 - colorvalue[2]) * (1 - colorvalue[3])};
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public float[] fromRGB(float[] rgbvalue) {
+ assert rgbvalue.length == 3;
+ //Note: this is an arbitrary conversion, not a color-managed one!
+ float r = rgbvalue[0];
+ float g = rgbvalue[1];
+ float b = rgbvalue[2];
+ if (r == g && r == b) {
+ return new float[] {0, 0, 0, 1 - r};
+ } else {
+ float c = 1 - r;
+ float m = 1 - g;
+ float y = 1 - b;
+ float k = Math.min(c, Math.min(m, y));
+ return new float[] {c, m, y, k};
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public float[] toCIEXYZ(float[] colorvalue) {
+ throw new UnsupportedOperationException("NYI");
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public float[] fromCIEXYZ(float[] colorvalue) {
+ throw new UnsupportedOperationException("NYI");
+ }
+
+ /** {@inheritDoc} */
+ public String getProfileName() {
+ return PSEUDO_PROFILE_NAME;
+ }
+
+ /** {@inheritDoc} */
+ public String getProfileURI() {
+ return null; //No URI
+ }
+
+}
diff --git
a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java
b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java
index c1fa6016..aaa11a91 100644
---
a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java
+++
b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java
@@ -16,8 +16,13 @@
*/
package org.apache.pdfbox.pdmodel.graphics.color;
+import java.awt.Color;
+import java.awt.Paint;
+import java.awt.geom.AffineTransform;
import java.net.URL;
import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.rendering.PDFRenderer;
+import org.apache.pdfbox.util.Matrix;
import java.awt.color.ICC_ColorSpace;
import java.awt.color.ICC_Profile;
@@ -126,4 +131,14 @@ public class PDDeviceCMYK extends PDDeviceColorSpace
{
return toRGBImageAWT(raster, awtColorSpace);
}
+
+ public Paint toPaint(PDFRenderer renderer, PDColor color, Matrix
subStreamMatrix,
+ AffineTransform xform) throws IOException
+ {
+ float[] components = color.getComponents();
+ if (components.length == 4) {
+ return new Color(new DeviceCMYKColorSpace(), components, 1);
+ }
+ return super.toPaint(renderer, color, subStreamMatrix, xform);
+ }
}
diff --git
a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYKTestCase.java
b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYKTestCase.java
new file mode 100644
index 00000000..08df972e
--- /dev/null
+++
b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYKTestCase.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+package org.apache.pdfbox.pdmodel.graphics.color;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.awt.Color;
+import java.awt.color.ColorSpace;
+import java.io.IOException;
+
+public class PDDeviceCMYKTestCase {
+ @Test
+ public void testCMYK() throws IOException {
+ float[] black = {0, 0, 0, 1};
+ PDColor pdColor = new PDColor(black, null);
+ Color color = (Color) new PDDeviceCMYK().toPaint(null, pdColor, null,
null);
+ Assert.assertEquals(color.getColorSpace().getType(),
ColorSpace.TYPE_CMYK);
+ float[] blackWithAlpha = {0, 0, 0, 1, 1};
+ Assert.assertArrayEquals(color.getComponents(null), blackWithAlpha, 0);
+ }
+}
--
2.48.1
{code}
> CMYK color converted to RGB
> ---------------------------
>
> Key: PDFBOX-5970
> URL: https://issues.apache.org/jira/browse/PDFBOX-5970
> Project: PDFBox
> Issue Type: Bug
> Reporter: Simon Steiner
> Priority: Major
> Attachments: adobe4.pdf, screenshot-1.png
>
>
> In pdfbox 2, if i set a breakpoint on PageDrawer:
> protected Paint getPaint(PDColor color) throws IOException
> And call org.apache.pdfbox.tools.PDFToImage
> I see cmyk black text is converted to RGB, i expect result should be
> Color.black as pdfbox used to do via:
> float[] components = color.getComponents();
> return new Color(new DeviceCMYKColorSpace(), components, 1);
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]