Examples of PDFColorSpace


Examples of com.sun.pdfview.colorspace.PDFColorSpace

     * number of bits per component and decode array
     *
     * @param bpc the number of bits per component
     */
    private ColorModel createColorModel() {
        PDFColorSpace cs = getColorSpace();

        if (cs instanceof IndexedColor) {
            IndexedColor ics = (IndexedColor) cs;

            byte[] components = ics.getColorComponents();
            int num = ics.getCount();

            // process the decode array
            if (decode != null) {
                byte[] normComps = new byte[components.length];

                // move the components array around
                for (int i = 0; i < num; i++) {
                    byte[] orig = new byte[1];
                    orig[0] = (byte) i;

                    float[] res = normalize(orig, null, 0);
                    int idx = (int) res[0];

                    normComps[i * 3] = components[idx * 3];
                    normComps[(i * 3) + 1] = components[(idx * 3) + 1];
                    normComps[(i * 3) + 2] = components[(idx * 3) + 2];
                }

                components = normComps;
            }

            // make sure the size of the components array is 2 ^ numBits
            // since if it's not, Java will complain
            int correctCount = 1 << getBitsPerComponent();
            if (correctCount < num) {
                byte[] fewerComps = new byte[correctCount * 3];

                System.arraycopy(components, 0, fewerComps, 0, correctCount * 3);

                components = fewerComps;
                num = correctCount;
            }
            if (colorKeyMask == null || colorKeyMask.length == 0) {
                return new IndexColorModel(getBitsPerComponent(), num, components,
                        0, false);
            } else {
                byte[] aComps = new byte[num * 4];
                int idx = 0;
                for (int i = 0; i < num; i++) {
                    aComps[idx++] = components[(i * 3)];
                    aComps[idx++] = components[(i * 3) + 1];
                    aComps[idx++] = components[(i * 3) + 2];
                    aComps[idx++] = (byte) 0xFF;
                }
                for (int i = 0; i < colorKeyMask.length; i += 2) {
                    for (int j = colorKeyMask[i]; j <= colorKeyMask[i + 1]; j++) {
                        aComps[(j * 4) + 3] = 0;    // make transparent
                    }
                }
                return new IndexColorModel(getBitsPerComponent(), num, aComps,
                        0, true);
            }
        } else {
            int[] bits = new int[cs.getNumComponents()];
            for (int i = 0; i < bits.length; i++) {
                bits[i] = getBitsPerComponent();
            }

            return decode != null ?
                    new DecodeComponentColorModel(cs.getColorSpace(), bits) :
                    new PdfComponentColorModel(cs.getColorSpace(), bits);
        }
    }
View Full Code Here

Examples of com.sun.pdfview.colorspace.PDFColorSpace

        }
       
        @Override
    public Raster getRaster(int x, int y, int w, int h) {
            ColorSpace cs = getColorModel().getColorSpace();
            PDFColorSpace shadeCSpace = getColorSpace();
           
            PDFFunction functions[] = getFunctions();
           
            int numComponents = cs.getNumComponents();

            float[] c1 = new float[2];
           
            float[] inputs = new float[1];
            float[] outputs = new float[shadeCSpace.getNumComponents()];
            float[] outputRBG = new float[numComponents];
           
            // all the data, plus alpha channel
            int[] data = new int[w * h * (numComponents + 1)];
          float lastInput = Float.POSITIVE_INFINITY;
          final float tol = TOLERANCE * (getMaxT() - getMinT());
           
            final int advance = 1;
            // for each device coordinate
            for (int j = 0; j < h; j++) {
              for (int i = 0; i < w; i += advance) {
                //Get point in user space
                invXform.transform(new float[]{x + i, y + j}, 0, c1, 0, 1);
                boolean render = true;
                float[] s = calculateInputValues(c1[0], c1[1]);
                //s[0] <= s[1] holds
                //if (s[0] >= 0 && s[1] <= 1) s[1] = s[1];
                if (s[1] >= 0 && s[1] <= 1) s[1] = s[1];
                else if (extendEnd == true && s[1] >= 0 && radius1 + s[1]*dr1r0 >= 0) {
                  s[1] = s[1];
                }
                else if (s[0] >= 0 && s[0] <= 1) s[1] = s[0];
                else if (extendStart == true && s[1] <= 0 && radius1 + s[1]*dr1r0 >= 0) {
                  s[1] = s[1];
                }
                else if (extendStart == true && s[0] <= 1 && radius1 + s[0]*dr1r0 >= 0) {
                  s[1] = s[0];
                }
                else render = false;
               
                if (render) {
                  float t = (getMinT() + s[1]*(getMaxT() - getMinT()));
                  // calculate the pixel values at t
                  inputs[0] = t;
                  if (Math.abs(lastInput - t) > tol) {

                    if (functions.length == 1) {
                      functions[0].calculate(inputs, 0, outputs, 0);
                    } else {
                      for (int c = 0; c < functions.length; c++) {
                        functions[c].calculate(inputs, 0, outputs, c);
                      }
                    }
                   
                  if (!shadeCSpace.getColorSpace().isCS_sRGB()) {
                    //Can be quite slow
                    outputRBG = shadeCSpace.getColorSpace().toRGB(outputs);
                  }
                  else outputRBG = outputs;

                  lastInput = t;
                  }
View Full Code Here

Examples of org.apache.fop.pdf.PDFColorSpace

            if (hasMask) {
                // if the mask is binary then we could convert it into a bitmask
                BitmapImage fopimg = new BitmapImage("TempImageMask:"
                                             + img.toString(), buf.getWidth(),
                                             buf.getHeight(), mask, null);
                fopimg.setColorSpace(new PDFColorSpace(PDFColorSpace.DEVICE_GRAY));
                PDFXObject xobj = pdfDoc.addImage(resourceContext, fopimg);
                ref = xobj.referencePDF();

                if (outputStream != null) {
                    try {
View Full Code Here

Examples of org.apache.fop.pdf.PDFColorSpace

                if (count > 0 && count < cols.length - 1) {
                    theBounds.add(new Double(fractions[count]));
                }
            }

            PDFColorSpace aColorSpace;
            aColorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
            PDFPattern myPat = pdfDoc.getFactory().makeGradient(
                    resourceContext, false, aColorSpace,
                    someColors, theBounds, theCoords, theMatrix);
            currentStream.write(myPat.getColorSpaceOut(fill));

            return true;
        }
        if (paint instanceof RadialGradientPaint) {
            RadialGradientPaint rgp = (RadialGradientPaint)paint;

            // There is essentially no way to support repeate
            // in PDF for radial gradients (the one option would
            // be to 'grow' the outer circle until it fully covered
            // the bounds and then grow the stops accordingly, the
            // problem is that this may require an extremely large
            // number of stops for cases where the focus is near
            // the edge of the outer circle).  so we rasterize.
            MultipleGradientPaint.CycleMethodEnum cycle = rgp.getCycleMethod();
            if (cycle != MultipleGradientPaint.NO_CYCLE) {
                return false;
            }

            AffineTransform transform;
            transform = new AffineTransform(graphicsState.getTransform());
            transform.concatenate(getTransform());
            transform.concatenate(rgp.getTransform());

            List theMatrix = new java.util.ArrayList();
            double [] mat = new double[6];
            transform.getMatrix(mat);
            for (int idx = 0; idx < mat.length; idx++) {
                theMatrix.add(new Double(mat[idx]));
            }

            double ar = rgp.getRadius();
            Point2D ac = rgp.getCenterPoint();
            Point2D af = rgp.getFocusPoint();

            List theCoords = new java.util.ArrayList();
            double dx = af.getX() - ac.getX();
            double dy = af.getY() - ac.getY();
            double d = Math.sqrt(dx * dx + dy * dy);
            if (d > ar) {
                // the center point af must be within the circle with
                // radius ar centered at ac so limit it to that.
                double scale = (ar * .9999) / d;
                dx = dx * scale;
                dy = dy * scale;
            }

            theCoords.add(new Double(ac.getX() + dx)); // Fx
            theCoords.add(new Double(ac.getY() + dy)); // Fy
            theCoords.add(new Double(0));
            theCoords.add(new Double(ac.getX()));
            theCoords.add(new Double(ac.getY()));
            theCoords.add(new Double(ar));

            Color[] cols = rgp.getColors();
            List someColors = new java.util.ArrayList();
            for (int count = 0; count < cols.length; count++) {
                Color cc = cols[count];
                if (cc.getAlpha() != 255) {
                    return false// PDF can't do alpha
                }

                someColors.add(new PDFColor(cc.getRed(), cc.getGreen(),
                                            cc.getBlue()));
            }

            float[] fractions = rgp.getFractions();
            List theBounds = new java.util.ArrayList();
            for (int count = 1; count < fractions.length - 1; count++) {
                float offset = fractions[count];
                theBounds.add(new Double(offset));
            }
            PDFColorSpace colSpace;
            colSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);

            PDFPattern myPat = pdfDoc.getFactory().makeGradient
                (resourceContext, true, colSpace,
                 someColors, theBounds, theCoords, theMatrix);

View Full Code Here

Examples of org.apache.fop.pdf.PDFColorSpace

            String maskRef = null;
            if (mask != null) {
                BitmapImage fopimg = new BitmapImage
                    ("TempImageMask:" + pctx.toString(), devW, devH, mask, null);
                fopimg.setColorSpace(new PDFColorSpace(PDFColorSpace.DEVICE_GRAY));
                PDFXObject xobj = pdfDoc.addImage(resourceContext, fopimg);
                maskRef = xobj.referencePDF();

                if (outputStream != null) {
                    try {
View Full Code Here

Examples of org.apache.fop.pdf.PDFColorSpace

            fopImage.load(FopImage.ORIGINAL_DATA);
        } else {
            fopImage.load(FopImage.BITMAP);
        }
        ICC_Profile prof = fopImage.getICCProfile();
        PDFColorSpace pdfCS = toPDFColorSpace(fopImage.getColorSpace());
        if (prof != null) {
            pdfICCStream = doc.getFactory().makePDFICCStream();
            pdfICCStream.setColorSpace(prof, pdfCS);
        }
        //Handle transparency mask if applicable
        if (fopImage.hasSoftMask()) {
            byte [] softMask = fopImage.getSoftMask();
            if (softMask == null) {
                return;
            }
            BitmapImage fopimg = new BitmapImage
                ("Mask:" + key, fopImage.getWidth(), fopImage.getHeight(),
                 softMask, null);
            fopimg.setColorSpace(new PDFColorSpace(PDFColorSpace.DEVICE_GRAY));
            PDFXObject xobj = doc.addImage(null, fopimg);
            softMaskRef = xobj.referencePDF();
        }
        if (doc.getPDFAMode().isPDFA1LevelB()) {
            if (pdfCS != null
                    && pdfCS.getColorSpace() != PDFColorSpace.DEVICE_RGB
                    && pdfCS.getColorSpace() != PDFColorSpace.DEVICE_GRAY
                    && prof == null) {
                //See PDF/A-1, ISO 19005:1:2005(E), 6.2.3.3
                //FOP is currently restricted to DeviceRGB if PDF/A-1 is active.
                throw new PDFConformanceException(
                        "PDF/A-1 does not allow mixing DeviceRGB and DeviceCMYK.");
View Full Code Here

Examples of org.apache.fop.pdf.PDFColorSpace

    public static PDFColorSpace toPDFColorSpace(ColorSpace cs) {
        if (cs == null) {
            return null;
        }

        PDFColorSpace pdfCS = new PDFColorSpace(0);
        switch(cs.getType()) {
            case ColorSpace.TYPE_CMYK:
                pdfCS.setColorSpace(PDFColorSpace.DEVICE_CMYK);
            break;
            case ColorSpace.TYPE_RGB:
                pdfCS.setColorSpace(PDFColorSpace.DEVICE_RGB);
            break;
            case ColorSpace.TYPE_GRAY:
                pdfCS.setColorSpace(PDFColorSpace.DEVICE_GRAY);
            break;
        }
        return pdfCS;
    }
View Full Code Here

Examples of org.apache.fop.pdf.PDFColorSpace

            pdfFilter = new DCTFilter();
            pdfFilter.setApplied(true);
            isDCT = true;

            ICC_Profile prof = fopImage.getICCProfile();
            PDFColorSpace pdfCS = toPDFColorSpace(fopImage.getColorSpace());
            if (prof != null) {
                pdfICCStream = doc.getFactory().makePDFICCStream();
                pdfICCStream.setColorSpace(prof, pdfCS);
            }
        } else if ("image/tiff".equals(fopImage.getMimeType())
                    && fopImage instanceof TIFFImage) {
            TIFFImage tiffImage = (TIFFImage) fopImage;
            if (tiffImage.getStripCount() == 1) {
                int comp = tiffImage.getCompression();
                if (comp == 1) {
                    // Nothing to do
                } else if (comp == 3) {
                    pdfFilter = new CCFFilter();
                    pdfFilter.setApplied(true);
                    isCCF = true;
                } else if (comp == 4) {
                    pdfFilter = new CCFFilter();
                    pdfFilter.setApplied(true);
                    ((CCFFilter)pdfFilter).setDecodeParms("<< /K -1 /Columns "
                        + tiffImage.getWidth() + " >>");
                    isCCF = true;
                } else if (comp == 6) {
                    pdfFilter = new DCTFilter();
                    pdfFilter.setApplied(true);
                    isDCT = true;
                }
            }
        }
        if (isPS || isDCT || isCCF) {
            fopImage.load(FopImage.ORIGINAL_DATA);
        } else {
            fopImage.load(FopImage.BITMAP);
        }
        //Handle transparency mask if applicable
        if (fopImage.hasSoftMask()) {
            byte [] softMask = fopImage.getSoftMask();
            if (softMask == null) {
                return;
            }
            BitmapImage fopimg = new BitmapImage
                ("Mask:" + key, fopImage.getWidth(), fopImage.getHeight(),
                 softMask, null);
            fopimg.setColorSpace(new PDFColorSpace(PDFColorSpace.DEVICE_GRAY));
            PDFXObject xobj = doc.addImage(null, fopimg);
            softMaskRef = xobj.referencePDF();
        }
    }
View Full Code Here

Examples of org.apache.fop.pdf.PDFColorSpace

    public static PDFColorSpace toPDFColorSpace(ColorSpace cs) {
        if (cs == null) {
            return null;
        }

        PDFColorSpace pdfCS = new PDFColorSpace(0);
        switch(cs.getType()) {
            case ColorSpace.TYPE_CMYK:
                pdfCS.setColorSpace(PDFColorSpace.DEVICE_CMYK);
            break;
            case ColorSpace.TYPE_RGB:
                pdfCS.setColorSpace(PDFColorSpace.DEVICE_RGB);
            break;
            case ColorSpace.TYPE_GRAY:
                pdfCS.setColorSpace(PDFColorSpace.DEVICE_GRAY);
            break;
        }
        return pdfCS;
    }
View Full Code Here

Examples of org.apache.fop.pdf.PDFColorSpace

            pdfFilter.setApplied(true);
            isDCT = true;

            JpegImage jpegimage = (JpegImage) fopImage;
            ICC_Profile prof = jpegimage.getICCProfile();
            PDFColorSpace pdfCS = toPDFColorSpace(jpegimage.getColorSpace());
            if (prof != null) {
                pdfICCStream = doc.getFactory().makePDFICCStream();
                pdfICCStream.setColorSpace(prof, pdfCS);
            }
        } else if ("image/tiff".equals(fopImage.getMimeType())
                    && fopImage instanceof TIFFImage) {
            TIFFImage tiffImage = (TIFFImage) fopImage;
            if (tiffImage.getStripCount() == 1) {
                int comp = tiffImage.getCompression();
                if (comp == 1) {
                    // Nothing to do
                } else if (comp == 3) {
                    pdfFilter = new CCFFilter();
                    pdfFilter.setApplied(true);
                    isCCF = true;
                } else if (comp == 4) {
                    pdfFilter = new CCFFilter();
                    pdfFilter.setApplied(true);
                    ((CCFFilter)pdfFilter).setDecodeParms("<< /K -1 /Columns "
                        + tiffImage.getWidth() + " >>");
                    isCCF = true;
                } else if (comp == 6) {
                    pdfFilter = new DCTFilter();
                    pdfFilter.setApplied(true);
                    isDCT = true;
                }
            }
        }
        if (isPS || isDCT || isCCF) {
            fopImage.load(FopImage.ORIGINAL_DATA);
        } else {
            fopImage.load(FopImage.BITMAP);
        }
        //Handle transparency mask if applicable
        if (fopImage.hasSoftMask()) {
            byte [] softMask = fopImage.getSoftMask();
            if (softMask == null) {
                return;
            }
            BitmapImage fopimg = new BitmapImage
                ("Mask:" + key, fopImage.getWidth(), fopImage.getHeight(),
                 softMask, null);
            fopimg.setColorSpace(new PDFColorSpace(PDFColorSpace.DEVICE_GRAY));
            PDFXObject xobj = doc.addImage(null, fopimg);
            softMaskRef = xobj.referencePDF();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.