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

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


            {
                colorspaces = new HashMap<String,PDColorSpace>();
                for( COSName csName : csDictionary.keySet() )
                {
                    COSBase cs = csDictionary.getDictionaryObject( csName );
                    PDColorSpace colorspace = null;
                    try
                    {
                        colorspace = PDColorSpaceFactory.createColorSpace( cs );
                    }
                    catch (IOException exception)
View Full Code Here


     */
    public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
    {
        // (PDF 1.1) Set color space for stroking operations
        COSName name = (COSName)arguments.get( 0 );
        PDColorSpace cs = PDColorSpaceFactory.createColorSpace( name, context.getColorSpaces(),
                context.getResources().getPatterns() );
        PDColorState colorInstance = context.getGraphicsState().getNonStrokingColor();
        colorInstance.setColorSpace( cs );
        int numComponents = cs.getNumberOfComponents();
        float[] values = EMPTY_FLOAT_ARRAY;
        if( numComponents >= 0 )
        {
            values = new float[numComponents];
            for( int i=0; i<numComponents; i++ )
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();
            }

            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

     * @throws IOException If an error occurs while processing the font.
     */
    public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
    {
        PDColorState colorInstance = context.getGraphicsState().getStrokingColor();
        PDColorSpace colorSpace = colorInstance.getColorSpace();

        if (colorSpace != null)
        {
            PDSeparation sep = (PDSeparation) colorSpace;
            colorSpace = sep.getAlternateColorSpace();
View Full Code Here

     */
    public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
    {
        //(PDF 1.1) Set color space for stroking operations
        COSName name = (COSName)arguments.get( 0 );
        PDColorSpace cs = PDColorSpaceFactory.createColorSpace( name, context.getColorSpaces(),
                context.getResources().getPatterns() );
        PDColorState color = context.getGraphicsState().getStrokingColor();
        color.setColorSpace( cs );
        int numComponents = cs.getNumberOfComponents();
        float[] values = EMPTY_FLOAT_ARRAY;
        if( numComponents >= 0 )
        {
            values = new float[numComponents];
            for( int i=0; i<numComponents; i++ )
View Full Code Here

     * @throws IOException If an error occurs while processing the font.
     */
    public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
    {
        PDColorState colorInstance = context.getGraphicsState().getStrokingColor();
        PDColorSpace colorSpace = colorInstance.getColorSpace();

        if (colorSpace != null)
        {
            PDDeviceN sep = (PDDeviceN) colorSpace;
            colorSpace = sep.getAlternateColorSpace();
View Full Code Here

            coords[4] = pageHeight + translateY - coords[4];
        }
        // colorSpace
        try
        {
            PDColorSpace cs = shadingType3.getColorSpace();
            if (!(cs instanceof PDDeviceRGB))
            {
                // we have to create an instance of the shading colorspace if it isn't RGB
                shadingColorSpace = cs.getJavaColorSpace();
            }
        }
        catch (IOException exception)
        {
            LOG.error("error while creating colorSpace", exception);
View Full Code Here

            coords[3] = pageHeight + translateY - coords[3];
        }
        // colorSpace
        try
        {
            PDColorSpace cs = shadingType2.getColorSpace();
            if (!(cs instanceof PDDeviceRGB))
            {
                // we have to create an instance of the shading colorspace if it isn't RGB
                shadingColorSpace = cs.getJavaColorSpace();
            }
        }
        catch (IOException exception)
        {
            LOG.error("error while creating colorSpace", exception);
View Full Code Here

     * @throws IOException If there is an error getting the colorspace.
     */
    public PDColorSpace getColorSpace() throws IOException
    {
        COSBase cs = getCOSStream().getDictionaryObject( COSName.COLORSPACE, COSName.CS );
        PDColorSpace retval = null;
        if( cs != null )
        {
            retval = PDColorSpaceFactory.createColorSpace( cs );
            if (retval == null)
            {
View Full Code Here

            int bpc = getBitsPerComponent();
           
            byte[] array = getPDStream().getByteArray();
   
            // Get the ColorModel right
            PDColorSpace colorspace = getColorSpace();
            if (colorspace == null)
            {
                log.error("getColorSpace() returned NULL.  Predictor = " + getPredictor());
                return null;
            }
           
            ColorModel cm = null;
            if (colorspace instanceof PDIndexed)
            {
                PDIndexed csIndexed = (PDIndexed)colorspace;
                ColorModel baseColorModel = csIndexed.getBaseColorSpace().createColorModel(bpc);
                int size = csIndexed.getHighValue();
                byte[] index = csIndexed.getLookupData();
                boolean hasAlpha = baseColorModel.hasAlpha();
                COSArray maskArray = getMask();
                if( baseColorModel.getTransferType() != DataBuffer.TYPE_BYTE )
                {
                    throw new IOException( "Not implemented" );
                }
                byte[] r = new byte[size+1];
                byte[] g = new byte[size+1];
                byte[] b = new byte[size+1];
                byte[] a = hasAlpha ? new byte[size+1] : null;
                byte[] inData = new byte[baseColorModel.getNumComponents()];
                for( int i = 0; i <= size; i++ )
                {
                    System.arraycopy(index, i * inData.length, inData, 0, inData.length);
                    r[i] = (byte)baseColorModel.getRed(inData);
                    g[i] = (byte)baseColorModel.getGreen(inData);
                    b[i] = (byte)baseColorModel.getBlue(inData);
                    if( hasAlpha )
                    {
                        a[i] = (byte)baseColorModel.getAlpha(inData);
                    }
                }
                if (hasAlpha)
                {
                    cm = new IndexColorModel(bpc, size+1, r, g, b, a);
                }
                else {
                    if (maskArray != null)
                    {
                        cm = new IndexColorModel(bpc, size+1, r, g, b, maskArray.getInt(0));
                    }
                    else
                    {
                        cm = new IndexColorModel(bpc, size+1, r, g, b);
                    }
                }
            }
            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 if (colorspace instanceof PDICCBased)
                {
                    if ( ((PDICCBased)colorspace).getNumberOfComponents() == 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
            {
                if (colorspace instanceof PDICCBased)
                {
                    if (((PDICCBased)colorspace).getNumberOfComponents() == 1)
                    {
                        byte[] map = new byte[] {(byte)0xff};
                        cm = new IndexColorModel(bpc, 1, map, map, map, Transparency.OPAQUE);
                    }
                    else
                        cm = colorspace.createColorModel( bpc );
                }
                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

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.