Package com.sun.pdfview.colorspace

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


        }
       
        @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

TOP

Related Classes of com.sun.pdfview.colorspace.PDFColorSpace

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.