forked from apache/pdfbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PDFBOX-1851: improved CMYK color space conversion as proposed by John…
… Hewson git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1559486 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
7 changed files
with
113 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 0 additions & 150 deletions
150
pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/ColorSpaceCMYK.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,20 +16,25 @@ | |
*/ | ||
package org.apache.pdfbox.pdmodel.graphics.color; | ||
|
||
import org.apache.pdfbox.io.IOUtils; | ||
import org.apache.pdfbox.util.ResourceLoader; | ||
|
||
import java.awt.color.ColorSpace; | ||
import java.awt.color.ICC_ColorSpace; | ||
import java.awt.color.ICC_Profile; | ||
import java.awt.image.ColorModel; | ||
import java.io.IOException; | ||
|
||
import java.awt.Transparency; | ||
import java.awt.image.ComponentColorModel; | ||
import java.awt.image.DataBuffer; | ||
|
||
import java.io.InputStream; | ||
import java.util.Properties; | ||
|
||
/** | ||
* This class represents a CMYK color space. | ||
* | ||
* @author <a href="mailto:[email protected]">Ben Litchfield</a> | ||
* @version $Revision: 1.6 $ | ||
*/ | ||
public class PDDeviceCMYK extends PDColorSpace | ||
{ | ||
|
@@ -48,6 +53,28 @@ public class PDDeviceCMYK extends PDColorSpace | |
*/ | ||
public static final String ABBREVIATED_NAME = "CMYK"; | ||
|
||
/** | ||
* The external resources | ||
*/ | ||
private static Properties defaultProfile = new Properties(); | ||
|
||
static | ||
{ | ||
try | ||
{ | ||
ResourceLoader.loadProperties( | ||
"org/apache/pdfbox/resources/PDDeviceCMYK.properties", | ||
defaultProfile); | ||
} | ||
catch (IOException io) | ||
{ | ||
throw new RuntimeException("Error loading resources", io); | ||
} | ||
} | ||
|
||
/** | ||
* Constructs a new PDDeviceCMYK object. | ||
*/ | ||
private PDDeviceCMYK() | ||
{ | ||
} | ||
|
@@ -79,9 +106,25 @@ public int getNumberOfComponents() throws IOException | |
* | ||
* @return A color space that can be used for Java AWT operations. | ||
*/ | ||
protected ColorSpace createColorSpace() | ||
protected ColorSpace createColorSpace() throws IOException | ||
{ | ||
return new ColorSpaceCMYK(); | ||
ColorSpace colorSpace; | ||
InputStream profile = null; | ||
try | ||
{ | ||
profile = ResourceLoader.loadResource(defaultProfile.getProperty("DeviceCMYK")); | ||
if (profile == null) | ||
{ | ||
throw new IOException("Default CMYK color profile cannot be opened"); | ||
} | ||
ICC_Profile iccProfile = ICC_Profile.getInstance(profile); | ||
colorSpace = new ICC_ColorSpace(iccProfile); | ||
} | ||
finally | ||
{ | ||
IOUtils.closeQuietly(profile); | ||
} | ||
return colorSpace; | ||
} | ||
|
||
/** | ||
|
@@ -93,18 +136,18 @@ protected ColorSpace createColorSpace() | |
* | ||
* @throws IOException If there is an error creating the color model. | ||
*/ | ||
public ColorModel createColorModel( int bpc ) throws IOException | ||
public ColorModel createColorModel(int bpc) throws IOException | ||
{ | ||
|
||
int[] nbBits = { bpc, bpc, bpc, bpc }; | ||
ComponentColorModel componentColorModel = | ||
new ComponentColorModel( getJavaColorSpace(), | ||
nbBits, | ||
false, | ||
false, | ||
Transparency.OPAQUE, | ||
DataBuffer.TYPE_BYTE ); | ||
return componentColorModel; | ||
ComponentColorModel componentColorModel = | ||
new ComponentColorModel(getJavaColorSpace(), | ||
nbBits, | ||
false, | ||
false, | ||
Transparency.OPAQUE, | ||
DataBuffer.TYPE_BYTE); | ||
return componentColorModel; | ||
|
||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
pdfbox/src/main/resources/org/apache/pdfbox/resources/PDDeviceCMYK.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# 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. | ||
|
||
########################################################################### | ||
|
||
# Adobe Acrobat uses "U.S. Web Coated (SWOP) v2" as the default | ||
# CMYK profile, however it is not available under an open license. | ||
# Instead, the "ISO Coated v2 300% (basICColor)" is used, which | ||
# is an open alternative to the "ISO Coated v2 300% (ECI)" profile. | ||
|
||
DeviceCMYK=org/apache/pdfbox/resources/icc/ISOcoated_v2_300_bas.icc |
Binary file added
BIN
+1 MB
pdfbox/src/main/resources/org/apache/pdfbox/resources/icc/ISOcoated_v2_300_bas.icc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters