Save This Page
Home » pdfbox-1.1.0-src » org.apache.pdfbox.pdmodel.graphics.color » [javadoc | source]
    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.color.ColorSpace;
   20   
   21   import org.apache.pdfbox.pdmodel.common.PDMatrix;
   22   
   23   /**
   24    * This class represents a CalRGB color space.
   25    *
   26    * In the first place this implementation is needed to support CalRGB.
   27    * To keep it simple, the CalRGB colorspace is treated similar to a DeviceRGB colorspace.
   28    * There is no conversion including the gamma, whitepoint, blackpoint or matrix values yet.
   29    * This should be suitable for displaying and simple printings.
   30    *  
   31    * @author <a href="mailto:andreas@lehmi.de">Andreas Lehmkühler</a>
   32    * @version $Revision: 1.0 $
   33    */
   34   public class ColorSpaceCalRGB extends ColorSpace
   35   {
   36       private PDGamma gamma = null;
   37       private PDTristimulus whitepoint = null;
   38       private PDTristimulus blackpoint = null;
   39       private PDMatrix matrix = null;
   40       
   41       /**
   42        * ID for serialization.
   43        */
   44       private static final long serialVersionUID = -6362864473145799405L;
   45   
   46       /**
   47        *  Constructor.
   48        */
   49       public ColorSpaceCalRGB()
   50       {
   51           super(ColorSpace.TYPE_3CLR,3);
   52       }
   53   
   54       /**
   55        * Constructor.
   56        * @param gammaValue Gamma
   57        * @param whitept Whitepoint
   58        * @param blackpt Blackpoint
   59        * @param linearMatrix Matrix value
   60        */
   61       public ColorSpaceCalRGB(PDGamma gammaValue, PDTristimulus whitept, PDTristimulus blackpt, PDMatrix linearMatrix)
   62       {
   63           this();
   64           this.gamma = gammaValue;
   65           this.whitepoint = whitept;
   66           this.blackpoint = blackpt;
   67           this.matrix = linearMatrix;
   68       }
   69   
   70       /**
   71        *  Converts colorvalues from RGB-colorspace to CIEXYZ-colorspace.
   72        *  @param rgbvalue RGB colorvalues to be converted.
   73        *  @return Returns converted colorvalues.
   74        */
   75       private float[] fromRGBtoCIEXYZ(float[] rgbvalue) 
   76       {
   77           ColorSpace colorspaceRGB = ColorSpace.getInstance(CS_sRGB);
   78           return colorspaceRGB.toCIEXYZ(rgbvalue);
   79       }
   80       
   81       /**
   82        *  Converts colorvalues from CIEXYZ-colorspace to RGB-colorspace.
   83        *  @param rgbvalue CIEXYZ colorvalues to be converted.
   84        *  @return Returns converted colorvalues.
   85        */
   86       private float[] fromCIEXYZtoRGB(float[] xyzvalue) 
   87       {
   88           ColorSpace colorspaceXYZ = ColorSpace.getInstance(CS_CIEXYZ);
   89           return colorspaceXYZ.toRGB(xyzvalue);
   90       }
   91   
   92       /**
   93        * {@inheritDoc}
   94        */
   95       public float[] fromCIEXYZ(float[] colorvalue)
   96       {
   97           if (colorvalue != null && colorvalue.length == 3)
   98           {
   99               // We have to convert from XYV to RGB
  100               return fromCIEXYZtoRGB(colorvalue);
  101           }
  102           return null;
  103       }
  104   
  105       /**
  106        * {@inheritDoc}
  107        */
  108       public float[] fromRGB(float[] rgbvalue) 
  109       {
  110           if (rgbvalue != null && rgbvalue.length == 3) 
  111           {
  112               return rgbvalue;
  113           }
  114           return null;
  115       }
  116   
  117       /**
  118        * {@inheritDoc}
  119        */
  120       public float[] toCIEXYZ(float[] colorvalue) 
  121       {
  122           if (colorvalue != null && colorvalue.length == 4)
  123           {
  124               // We have to convert from RGB to XYV
  125               return fromRGBtoCIEXYZ(toRGB(colorvalue));
  126           }
  127           return null;
  128       }
  129   
  130       /**
  131        * {@inheritDoc}
  132        */
  133       public float[] toRGB(float[] colorvalue) 
  134       {
  135           if (colorvalue != null && colorvalue.length == 3) 
  136           {
  137               return colorvalue;
  138           }
  139           return null;
  140       }
  141   
  142   }

Save This Page
Home » pdfbox-1.1.0-src » org.apache.pdfbox.pdmodel.graphics.color » [javadoc | source]