1 31 package org.pdfbox.pdmodel.graphics.color; 32 33 import org.pdfbox.cos.COSArray; 34 import org.pdfbox.cos.COSBase; 35 import org.pdfbox.cos.COSDictionary; 36 import org.pdfbox.cos.COSFloat; 37 import org.pdfbox.cos.COSName; 38 import org.pdfbox.cos.COSNumber; 39 40 import java.awt.color.ColorSpace ; 41 import java.awt.image.ColorModel ; 42 43 import java.io.IOException ; 44 45 51 public class PDCalGray extends PDColorSpace 52 { 53 56 public static final String NAME = "CalGray"; 57 58 private COSArray array; 59 private COSDictionary dictionary; 60 61 64 public PDCalGray() 65 { 66 array = new COSArray(); 67 dictionary = new COSDictionary(); 68 array.add( COSName.getPDFName( NAME ) ); 69 array.add( dictionary ); 70 } 71 72 77 public PDCalGray( COSArray gray ) 78 { 79 array = gray; 80 dictionary = (COSDictionary)array.getObject( 1 ); 81 } 82 83 90 public int getNumberOfComponents() throws IOException 91 { 92 return 1; 93 } 94 95 100 public String getName() 101 { 102 return NAME; 103 } 104 105 112 public ColorSpace createColorSpace() throws IOException 113 { 114 throw new IOException ( "Not implemented" ); 115 } 116 117 126 public ColorModel createColorModel( int bpc ) throws IOException 127 { 128 throw new IOException ( "Not implemented" ); 129 } 130 131 136 public COSBase getCOSObject() 137 { 138 return array; 139 } 140 141 147 public float getGamma() 148 { 149 float retval = 1.0f; 150 COSNumber gamma = (COSNumber)dictionary.getDictionaryObject( COSName.getPDFName( "Gamma" ) ); 151 if( gamma != null ) 152 { 153 retval = gamma.floatValue(); 154 } 155 return retval; 156 } 157 158 163 public void setGamma( float value ) 164 { 165 dictionary.setItem( COSName.getPDFName( "Gamma" ), new COSFloat( value ) ); 166 } 167 168 175 public PDTristimulus getWhitepoint() 176 { 177 COSArray wp = (COSArray)dictionary.getDictionaryObject( COSName.getPDFName( "WhitePoint" ) ); 178 if( wp == null ) 179 { 180 wp = new COSArray(); 181 wp.add( new COSFloat( 1.0f ) ); 182 wp.add( new COSFloat( 1.0f ) ); 183 wp.add( new COSFloat( 1.0f ) ); 184 dictionary.setItem( COSName.getPDFName( "WhitePoint" ), wp ); 185 } 186 return new PDTristimulus( wp ); 187 } 188 189 195 public void setWhitepoint( PDTristimulus wp ) 196 { 197 COSBase wpArray = wp.getCOSObject(); 198 if( wpArray != null ) 199 { 200 dictionary.setItem( COSName.getPDFName( "WhitePoint" ), wpArray ); 201 } 202 } 203 204 211 public PDTristimulus getBlackPoint() 212 { 213 COSArray bp = (COSArray)dictionary.getDictionaryObject( COSName.getPDFName( "BlackPoint" ) ); 214 if( bp == null ) 215 { 216 bp = new COSArray(); 217 bp.add( new COSFloat( 0.0f ) ); 218 bp.add( new COSFloat( 0.0f ) ); 219 bp.add( new COSFloat( 0.0f ) ); 220 dictionary.setItem( COSName.getPDFName( "BlackPoint" ), bp ); 221 } 222 return new PDTristimulus( bp ); 223 } 224 225 231 public void setBlackPoint( PDTristimulus bp ) 232 { 233 COSBase bpArray = null; 234 if( bp != null ) 235 { 236 bpArray = bp.getCOSObject(); 237 } 238 dictionary.setItem( COSName.getPDFName( "BlackPoint" ), bpArray ); 239 } 240 } | Popular Tags |