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.color.ColorSpace;
033:
034: import java.awt.image.ColorModel;
035: import java.awt.image.ComponentColorModel;
036: import java.awt.image.DataBuffer;
037: import java.awt.Transparency;
038:
039: import java.io.IOException;
040:
041: /**
042: * This class represents a Gray color space.
043: *
044: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
045: * @version $Revision: 1.6 $
046: */
047: public class PDDeviceGray extends PDColorSpace {
048: /**
049: * The name of this color space.
050: */
051: public static final String NAME = "DeviceGray";
052:
053: /**
054: * The abbreviated name of this color space.
055: */
056: public static final String ABBREVIATED_NAME = "G";
057:
058: /**
059: * This will return the name of the color space.
060: *
061: * @return The name of the color space.
062: */
063: public String getName() {
064: return NAME;
065: }
066:
067: /**
068: * This will get the number of components that this color space is made up of.
069: *
070: * @return The number of components in this color space.
071: *
072: * @throws IOException If there is an error getting the number of color components.
073: */
074: public int getNumberOfComponents() throws IOException {
075: return 1;
076: }
077:
078: /**
079: * Create a Java colorspace for this colorspace.
080: *
081: * @return A color space that can be used for Java AWT operations.
082: *
083: * @throws IOException If there is an error creating the color space.
084: */
085: public ColorSpace createColorSpace() throws IOException {
086: return ColorSpace.getInstance(ColorSpace.CS_GRAY);
087: }
088:
089: /**
090: * Create a Java color model for this colorspace.
091: *
092: * @param bpc The number of bits per component.
093: *
094: * @return A color model that can be used for Java AWT operations.
095: *
096: * @throws IOException If there is an error creating the color model.
097: */
098: public ColorModel createColorModel(int bpc) throws IOException {
099: ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
100: int[] nBits = { bpc };
101: ColorModel colorModel = new ComponentColorModel(cs, nBits,
102: false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
103: return colorModel;
104:
105: }
106: }
|