001: /**
002: * Copyright (c) 2004, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.pdmodel.graphics.color;
031:
032: import java.awt.Transparency;
033:
034: import java.awt.color.ColorSpace;
035:
036: import java.awt.image.ColorModel;
037: import java.awt.image.ComponentColorModel;
038: import java.awt.image.DataBuffer;
039:
040: import java.io.IOException;
041:
042: /**
043: * This class represents an RGB color space.
044: *
045: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
046: * @version $Revision: 1.8 $
047: */
048: public class PDDeviceRGB extends PDColorSpace {
049: /**
050: * The name of this color space.
051: */
052: public static final String NAME = "DeviceRGB";
053:
054: /**
055: * The abbreviated name of this color space.
056: */
057: public static final String ABBREVIATED_NAME = "RGB";
058:
059: /**
060: * This is the single instance of this class.
061: */
062: public static final PDDeviceRGB INSTANCE = new PDDeviceRGB();
063:
064: /**
065: * This class is immutable.
066: */
067: private PDDeviceRGB() {
068: //only here to make immutable.
069: }
070:
071: /**
072: * This will return the name of the color space.
073: *
074: * @return The name of the color space.
075: */
076: public String getName() {
077: return NAME;
078: }
079:
080: /**
081: * This will get the number of components that this color space is made up of.
082: *
083: * @return The number of components in this color space.
084: *
085: * @throws IOException If there is an error getting the number of color components.
086: */
087: public int getNumberOfComponents() throws IOException {
088: return 3;
089: }
090:
091: /**
092: * Create a Java colorspace for this colorspace.
093: *
094: * @return A color space that can be used for Java AWT operations.
095: *
096: * @throws IOException If there is an error creating the color space.
097: */
098: public ColorSpace createColorSpace() throws IOException {
099: return ColorSpace.getInstance(ColorSpace.CS_sRGB);
100: }
101:
102: /**
103: * Create a Java color model for this colorspace.
104: *
105: * @param bpc The number of bits per component.
106: *
107: * @return A color model that can be used for Java AWT operations.
108: *
109: * @throws IOException If there is an error creating the color model.
110: */
111: public ColorModel createColorModel(int bpc) throws IOException {
112: int[] nbBits = { bpc, bpc, bpc };
113: ComponentColorModel componentColorModel = new ComponentColorModel(
114: createColorSpace(), nbBits, false, false,
115: Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
116:
117: return componentColorModel;
118: }
119: }
|