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 39 import org.pdfbox.pdmodel.common.PDMatrix; 40 41 import java.awt.color.ColorSpace ; 42 import java.awt.image.ColorModel ; 43 44 import java.io.IOException ; 45 46 52 public class PDCalRGB extends PDColorSpace 53 { 54 57 public static final String NAME = "CalRGB"; 58 59 private COSArray array; 60 private COSDictionary dictionary; 61 62 65 public PDCalRGB() 66 { 67 array = new COSArray(); 68 dictionary = new COSDictionary(); 69 array.add( COSName.getPDFName( NAME ) ); 70 array.add( dictionary ); 71 } 72 73 78 public PDCalRGB( COSArray rgb ) 79 { 80 array = rgb; 81 dictionary = (COSDictionary)array.getObject( 1 ); 82 } 83 84 91 public int getNumberOfComponents() throws IOException 92 { 93 return 3; 94 } 95 96 101 public String getName() 102 { 103 return NAME; 104 } 105 106 113 public ColorSpace createColorSpace() throws IOException 114 { 115 throw new IOException ( "Not implemented" ); 116 } 117 118 127 public ColorModel createColorModel( int bpc ) throws IOException 128 { 129 throw new IOException ( "Not implemented" ); 130 } 131 132 137 public COSBase getCOSObject() 138 { 139 return array; 140 } 141 142 149 public PDTristimulus getWhitepoint() 150 { 151 COSArray wp = (COSArray)dictionary.getDictionaryObject( COSName.getPDFName( "WhitePoint" ) ); 152 if( wp == null ) 153 { 154 wp = new COSArray(); 155 wp.add( new COSFloat( 1.0f ) ); 156 wp.add( new COSFloat( 1.0f ) ); 157 wp.add( new COSFloat( 1.0f ) ); 158 dictionary.setItem( COSName.getPDFName( "WhitePoint" ), wp ); 159 } 160 return new PDTristimulus( wp ); 161 } 162 163 169 public void setWhitepoint( PDTristimulus wp ) 170 { 171 COSBase wpArray = wp.getCOSObject(); 172 if( wpArray != null ) 173 { 174 dictionary.setItem( COSName.getPDFName( "WhitePoint" ), wpArray ); 175 } 176 } 177 178 185 public PDTristimulus getBlackPoint() 186 { 187 COSArray bp = (COSArray)dictionary.getDictionaryObject( COSName.getPDFName( "BlackPoint" ) ); 188 if( bp == null ) 189 { 190 bp = new COSArray(); 191 bp.add( new COSFloat( 0.0f ) ); 192 bp.add( new COSFloat( 0.0f ) ); 193 bp.add( new COSFloat( 0.0f ) ); 194 dictionary.setItem( COSName.getPDFName( "BlackPoint" ), bp ); 195 } 196 return new PDTristimulus( bp ); 197 } 198 199 205 public void setBlackPoint( PDTristimulus bp ) 206 { 207 208 COSBase bpArray = null; 209 if( bp != null ) 210 { 211 bpArray = bp.getCOSObject(); 212 } 213 dictionary.setItem( COSName.getPDFName( "BlackPoint" ), bpArray ); 214 } 215 216 222 public PDGamma getGamma() 223 { 224 COSArray gamma = (COSArray)dictionary.getDictionaryObject( COSName.getPDFName( "Gamma" ) ); 225 if( gamma == null ) 226 { 227 gamma = new COSArray(); 228 gamma.add( new COSFloat( 1.0f ) ); 229 gamma.add( new COSFloat( 1.0f ) ); 230 gamma.add( new COSFloat( 1.0f ) ); 231 dictionary.setItem( COSName.getPDFName( "Gamma" ), gamma ); 232 } 233 return new PDGamma( gamma ); 234 } 235 236 241 public void setGamma( PDGamma value ) 242 { 243 COSArray gamma = null; 244 if( value != null ) 245 { 246 gamma = value.getCOSArray(); 247 } 248 dictionary.setItem( COSName.getPDFName( "Gamma" ), gamma ); 249 } 250 251 258 public PDMatrix getLinearInterpretation() 259 { 260 PDMatrix retval = null; 261 COSArray matrix = (COSArray)dictionary.getDictionaryObject( COSName.getPDFName( "Matrix" ) ); 262 if( matrix == null ) 263 { 264 retval = new PDMatrix(); 265 setLinearInterpretation( retval ); 266 } 267 else 268 { 269 retval = new PDMatrix( matrix ); 270 } 271 return retval; 272 } 273 274 280 public void setLinearInterpretation( PDMatrix matrix ) 281 { 282 COSArray matrixArray = null; 283 if( matrix != null ) 284 { 285 matrixArray = matrix.getCOSArray(); 286 } 287 dictionary.setItem( COSName.getPDFName( "Matrix" ), matrixArray ); 288 } 289 } | Popular Tags |