1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.pdfbox.pdmodel.graphics.color; 18 19 import java.awt.Transparency; 20 21 import java.awt.color.ColorSpace; 22 23 import java.awt.image.ColorModel; 24 import java.awt.image.ComponentColorModel; 25 import java.awt.image.DataBuffer; 26 27 import java.io.IOException; 28 29 /** 30 * This class represents an RGB color space. 31 * 32 * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a> 33 * @version $Revision: 1.8 $ 34 */ 35 public class PDDeviceRGB extends PDColorSpace 36 { 37 /** 38 * The name of this color space. 39 */ 40 public static final String NAME = "DeviceRGB"; 41 42 /** 43 * The abbreviated name of this color space. 44 */ 45 public static final String ABBREVIATED_NAME = "RGB"; 46 47 /** 48 * This is the single instance of this class. 49 */ 50 public static final PDDeviceRGB INSTANCE = new PDDeviceRGB(); 51 52 /** 53 * This class is immutable. 54 */ 55 private PDDeviceRGB() 56 { 57 //only here to make immutable. 58 } 59 60 /** 61 * This will return the name of the color space. 62 * 63 * @return The name of the color space. 64 */ 65 public String getName() 66 { 67 return NAME; 68 } 69 70 /** 71 * This will get the number of components that this color space is made up of. 72 * 73 * @return The number of components in this color space. 74 * 75 * @throws IOException If there is an error getting the number of color components. 76 */ 77 public int getNumberOfComponents() throws IOException 78 { 79 return 3; 80 } 81 82 /** 83 * Create a Java colorspace for this colorspace. 84 * 85 * @return A color space that can be used for Java AWT operations. 86 */ 87 protected ColorSpace createColorSpace() 88 { 89 return ColorSpace.getInstance( ColorSpace.CS_sRGB ); 90 } 91 92 /** 93 * Create a Java color model for this colorspace. 94 * 95 * @param bpc The number of bits per component. 96 * 97 * @return A color model that can be used for Java AWT operations. 98 * 99 * @throws IOException If there is an error creating the color model. 100 */ 101 public ColorModel createColorModel( int bpc ) throws IOException 102 { 103 int[] nbBits = { bpc, bpc, bpc }; 104 ComponentColorModel componentColorModel = 105 new ComponentColorModel( getJavaColorSpace(), 106 nbBits, 107 false, 108 false, 109 Transparency.OPAQUE, 110 DataBuffer.TYPE_BYTE ); 111 112 return componentColorModel; 113 } 114 }