Package org.apache.pdfbox.pdmodel.graphics.color

Examples of org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace


     */
    public static PDColorSpace createColorSpace( COSBase colorSpace, Map<String, PDColorSpace> colorSpaces,
            Map<String,PDPatternResources> patterns)
    throws IOException
    {
        PDColorSpace retval = null;
        if( colorSpace instanceof COSName )
        {
            retval = createColorSpace( ((COSName)colorSpace).getName(), colorSpaces );
        }
        else if( colorSpace instanceof COSArray )
View Full Code Here


     * @throws IOException If the color space name is unknown.
     */
    public static PDColorSpace createColorSpace( String colorSpaceName, Map<String, PDColorSpace> colorSpaces )
    throws IOException
    {
        PDColorSpace cs = null;
        if( colorSpaceName.equals( PDDeviceCMYK.NAME ) ||
                 colorSpaceName.equals( PDDeviceCMYK.ABBREVIATED_NAME ) )
        {
            cs = PDDeviceCMYK.INSTANCE;
        }
View Full Code Here

     *
     * @throws IOException If the color space name is unknown.
     */
    public static PDColorSpace createColorSpace( PDDocument doc, ColorSpace cs ) throws IOException
    {
        PDColorSpace retval = null;
        if( cs.isCS_sRGB() )
        {
            retval = PDDeviceRGB.INSTANCE;
        }
        else if( cs instanceof ICC_ColorSpace )
View Full Code Here

     * @param arguments List
     * @throws IOException If an error occurs while processing the font.
     */
    public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
    {
        PDColorSpace colorSpace = context.getGraphicsState().getStrokingColor().getColorSpace();
        if (colorSpace != null)
        {
            OperatorProcessor newOperator = null;
            if (colorSpace instanceof PDDeviceGray)
            {
                newOperator = new SetStrokingGrayColor();
            }
            else if (colorSpace instanceof PDDeviceRGB)
            {
                newOperator = new SetStrokingRGBColor();
            }
            else if (colorSpace instanceof PDDeviceCMYK)
            {
                newOperator = new SetStrokingCMYKColor();
            }
            else if (colorSpace instanceof PDICCBased)
            {
                newOperator = new SetStrokingICCBasedColor();
            }
            else if (colorSpace instanceof PDCalRGB)
            {
                newOperator = new SetStrokingCalRGBColor();
            }  
            else if (colorSpace instanceof PDSeparation)
            {
                newOperator = new SetStrokingSeparation();
            }
            else if (colorSpace instanceof PDDeviceN)
            {
                newOperator = new SetStrokingDeviceN();
            }
            else if (colorSpace instanceof PDPattern)
            {
                newOperator = new SetStrokingPattern();
            }
            else if (colorSpace instanceof PDIndexed)
            {
                newOperator = new SetStrokingIndexed();
            }

            if (newOperator != null)
            {
                newOperator.setContext(getContext());
                newOperator.process(operator, arguments);
            }
            else
            {
                log.info("Not supported colorspace "+colorSpace.getName()
                        + " within operator "+operator.getOperation());
            }
        }
        else
        {
View Full Code Here

     * @param arguments List
     * @throws IOException If an error occurs while processing the font.
     */
    public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
    {
        PDColorSpace colorSpace = context.getGraphicsState().getNonStrokingColor().getColorSpace();
        if (colorSpace != null)
        {
            OperatorProcessor newOperator = null;
            if (colorSpace instanceof PDDeviceGray)
            {
                newOperator = new SetNonStrokingGrayColor();
            }
            else if (colorSpace instanceof PDDeviceRGB)
            {
                newOperator = new SetNonStrokingRGBColor();
            }
            else if (colorSpace instanceof PDDeviceCMYK)
            {
                newOperator = new SetNonStrokingCMYKColor();
            }
            else if (colorSpace instanceof PDICCBased)
            {
                newOperator = new SetNonStrokingICCBasedColor();
            }
            else if (colorSpace instanceof PDCalRGB)
            {
                newOperator = new SetNonStrokingCalRGBColor();
            }  
            else if (colorSpace instanceof PDSeparation)
            {
                newOperator = new SetNonStrokingSeparation();
            }
            else if (colorSpace instanceof PDDeviceN)
            {
                newOperator = new SetNonStrokingDeviceN();
            }
            else if (colorSpace instanceof PDPattern)
            {
                newOperator = new SetNonStrokingPattern();
            }
            else if (colorSpace instanceof PDIndexed)
            {
                newOperator = new SetNonStrokingIndexed();
            }

            if (newOperator != null)
            {
                newOperator.setContext(getContext());
                newOperator.process(operator, arguments);
            }
            else
            {
                log.warn("Not supported colorspace "+colorSpace.getName()
                        + " within operator "+operator.getOperation());
            }
        }
        else
        {
View Full Code Here

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        removeAllFiltersButDCT(os);
        os.close();
        byte[] img = os.toByteArray();
       
        PDColorSpace cs = getColorSpace();
        try
        {
            if (cs instanceof PDDeviceCMYK
                    || (cs instanceof PDICCBased && cs.getNumberOfComponents() == 4))
            {
                // JPEGs may contain CMYK, YCbCr or YCCK decoded image data
                int transform = getApp14AdobeTransform(img);
                // create BufferedImage based on the converted color values
                if (transform == 0)
                {
                    bi = convertCMYK2RGB(readImage(img), cs);
                }
                else if (transform == 1)
                {
                    // TODO YCbCr
                }
                else if (transform == 2)
                {
                    bi = convertYCCK2RGB(readImage(img));
                }
            }
            else if (cs instanceof PDSeparation)
            {
                // create BufferedImage based on the converted color values
                bi = processTintTransformation(readImage(img),
                        ((PDSeparation)cs).getTintTransform(), cs.getJavaColorSpace());
            }
            else if (cs instanceof PDDeviceN)
            {
                // create BufferedImage based on the converted color values
                bi = processTintTransformation(readImage(img),
                        ((PDDeviceN)cs).getTintTransform(), cs.getJavaColorSpace());
            }
            else
            {
                ByteArrayInputStream bai = new ByteArrayInputStream(img);
                bi = ImageIO.read(bai);
View Full Code Here

            }
            int width = getWidth();
            int height = getHeight();
            int bpc = getBitsPerComponent();

            PDColorSpace colorspace = getColorSpace();
            if (colorspace == null)
            {
                LOG.error("getColorSpace() returned NULL.");
                return null;
            }
            // Get the ColorModel right
            ColorModel cm = null;
            if (colorspace instanceof PDIndexed)
            {
                PDIndexed csIndexed = (PDIndexed)colorspace;
                COSBase maskArray = getMask();
                if (maskArray != null && maskArray instanceof COSArray)
                {
                    cm = csIndexed.createColorModel(bpc, ((COSArray)maskArray).getInt(0));
                }
                else
                {
                    cm = csIndexed.createColorModel(bpc);
                }
            }
            else if (colorspace instanceof PDSeparation)
            {
                PDSeparation csSeparation = (PDSeparation)colorspace;
                int numberOfComponents = csSeparation.getAlternateColorSpace().getNumberOfComponents();
                PDFunction tintTransformFunc = csSeparation.getTintTransform();
                COSArray decode = getDecode();
                // we have to invert the tint-values,
                // if the Decode array exists and consists of (1,0)
                boolean invert = decode != null && decode.getInt(0) == 1;
                // TODO add interpolation for other decode values then 1,0
                int maxValue = (int)Math.pow(2,bpc) - 1;
                // destination array
                byte[] mappedData = new byte[width*height*numberOfComponents];
                int rowLength = width*numberOfComponents;
                float[] input = new float[1];
                for ( int i = 0; i < height; i++ )
                {
                    int rowOffset = i * rowLength;
                    for (int j = 0; j < width; j++)
                    {
                        // scale tint values to a range of 0...1
                        int value = (array[ i * width + j ] + 256) % 256;
                        if (invert)
                        {
                            input[0] = 1-(value / maxValue);
                        }
                        else
                        {
                            input[0] =  value / maxValue;
                        }
                        float[] mappedColor = tintTransformFunc.eval(input);
                        int columnOffset = j * numberOfComponents;
                        for ( int k = 0; k < numberOfComponents; k++ )
                        {
                            // redo scaling for every single color value
                            float mappedValue = mappedColor[k];
                            mappedData[ rowOffset + columnOffset + k] = (byte)(mappedValue * maxValue);
                        }
                    }
                }
                array = mappedData;
                cm = colorspace.createColorModel( bpc );
            }
            else if (bpc == 1)
            {
                byte[] map = null;
                if (colorspace instanceof PDDeviceGray)
                {
                    COSArray decode = getDecode();
                    // we have to invert the b/w-values,
                    // if the Decode array exists and consists of (1,0)
                    if (decode != null && decode.getInt(0) == 1)
                    {
                        map = new byte[] {(byte)0xff};
                    }
                    else
                    {
                        map = new byte[] {(byte)0x00, (byte)0xff};
                    }
                }
                else
                {
                    map = new byte[] {(byte)0x00, (byte)0xff};
                }
                cm = new IndexColorModel(bpc, map.length, map, map, map, Transparency.OPAQUE);
            }
            else
            {
                cm = colorspace.createColorModel( bpc );
            }

            LOG.debug("ColorModel: " + cm.toString());
            WritableRaster raster = cm.createCompatibleWritableRaster( width, height );
            DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();
View Full Code Here

            // at least one of the values has to have a valid value
            rows = Math.max(rows, height);
        }
        byte[] bufferData = null;
        ColorModel colorModel = null;
        PDColorSpace colorspace = getColorSpace();
        // most likely there is no colorspace as a CCITT-filter uses 1-bit values mapped to black/white
        // in some rare cases other colorspaces maybe used such as an indexed colorspace, see PDFBOX-1638
        if (colorspace instanceof PDIndexed)
        {
            PDIndexed csIndexed = (PDIndexed) colorspace;
View Full Code Here

        return image;
         */


        //verify again pci32.pdf before changing below
        PDColorSpace pcs = params.getColorSpace( colorSpaces );
        ColorModel colorModel;
        if(pcs != null)
        {
            colorModel =
                pcs.createColorModel(
                        params.getBitsPerComponent() );
        }
        else
        {
            byte[] transparentColors = new
View Full Code Here

        return image;
         */


        //verify again pci32.pdf before changing below
        PDColorSpace pcs = params.getColorSpace( colorSpaces );
        ColorModel colorModel;
        if(pcs != null)
        {
            colorModel =
                pcs.createColorModel(
                        params.getBitsPerComponent() );
        }
        else
        {
            byte[] transparentColors = new
View Full Code Here

TOP

Related Classes of org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.