Examples of PDFColorSpace


Examples of com.sun.pdfview.colorspace.PDFColorSpace

        // see if we have a colorspace
        try {
            PDFObject csObj = dict.getDictRef("ColorSpace");
            if (csObj != null) {
                // we do, so get the number of components
                PDFColorSpace cs = PDFColorSpace.getColorSpace(csObj, null);
                numComponents = cs.getNumComponents();
            }
        } catch (IOException ioe) {
            // oh well
        }
       
View Full Code Here

Examples of com.sun.pdfview.colorspace.PDFColorSpace

            PDFObject csObj = obj.getDictRef("ColorSpace");
            if (csObj == null) {
                throw new PDFParseException("No ColorSpace for image: " + obj);
            }

            PDFColorSpace cs = PDFColorSpace.getColorSpace(csObj, resources);
            image.setColorSpace(cs);
        }

        // read the decode array
        PDFObject decodeObj = obj.getDictRef("Decode");
View Full Code Here

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

                                    // first make sure we can get the unadjusted raster
                                    final Raster raster = jpegReader.readRaster(0, param);

                                    // and now use it with a YCCK converting color space.
                                    PDFImage.this.colorSpace = new PDFColorSpace(new YCCKColorSpace(colorSpace.getColorSpace()));
                                    // re-calculate the color model since the color space has changed
                                    cm = PDFImage.this.createColorModel();
                                    return new BufferedImage(
                                        cm,
                                        Raster.createWritableRaster(raster.getSampleModel(), raster.getDataBuffer(), null),
View Full Code Here

Examples of com.sun.pdfview.colorspace.PDFColorSpace

        // read the color space (required)
        PDFObject csObj = shaderObj.getDictRef("ColorSpace");
        if (csObj == null) {
            throw new PDFParseException("No colorspace defined!");
        }
        PDFColorSpace cs = PDFColorSpace.getColorSpace(csObj, resources);
        shader.setColorSpace(cs);
       
        // read the background color (optional)
        PDFObject bgObj = shaderObj.getDictRef("Background");
        if (bgObj != null) {
            PDFObject[] bgObjs = bgObj.getArray();
            float[] bgArray = new float[bgObjs.length];
            for (int i = 0; i < bgArray.length; i++) {
                bgArray[i] = bgObjs[i].getFloatValue();
            }
            PDFPaint paint = cs.getPaint(bgArray);
            shader.setBackground(paint);         
        }
       
        // read the bounding box (optional)
        PDFObject bboxObj = shaderObj.getDictRef("BBox");
View Full Code Here

Examples of com.sun.pdfview.colorspace.PDFColorSpace

                                    // first make sure we can get the unadjusted raster
                                    final Raster raster = jpegReader.readRaster(0, param);

                                    // and now use it with a YCCK converting color space.
                                    PDFImage.this.colorSpace = new PDFColorSpace(new YCCKColorSpace(colorSpace.getColorSpace()));
                                    // re-calculate the color model since the color space has changed
                                    cm = PDFImage.this.createColorModel();
                                    return new BufferedImage(
                                        cm,
                                        Raster.createWritableRaster(raster.getSampleModel(), raster.getDataBuffer(), null),
View Full Code Here

Examples of com.sun.pdfview.colorspace.PDFColorSpace

        // read the color space (required)
        PDFObject csObj = shaderObj.getDictRef("ColorSpace");
        if (csObj == null) {
            throw new PDFParseException("No colorspace defined!");
        }
        PDFColorSpace cs = PDFColorSpace.getColorSpace(csObj, resources);
        shader.setColorSpace(cs);
       
        // read the background color (optional)
        PDFObject bgObj = shaderObj.getDictRef("Background");
        if (bgObj != null) {
            PDFObject[] bgObjs = bgObj.getArray();
            float[] bgArray = new float[bgObjs.length];
            for (int i = 0; i < bgArray.length; i++) {
                bgArray[i] = bgObjs[i].getFloatValue();
            }
            PDFPaint paint = cs.getPaint(bgArray);
            shader.setBackground(paint);         
        }
       
        // read the bounding box (optional)
        PDFObject bboxObj = shaderObj.getDictRef("BBox");
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 x0 = (float) this.start.getX();
          float y0 = (float) this.start.getY();

          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)];

          // for each device coordinate
          for (int j = 0; j < h; j++) {
            for (int i = 0; i < w; i += 1) {
              boolean render = true;
              // find t for that user coordinate
              float xp = getXPrime(i + x, j + y, x0, y0);
              float t = 0;
              if (xp >= 0 && xp <= 1) t = getMinT() + (dt1t0 * xp);
              else if (xp < 0 && extendStart) t = getMinT();
              else if (xp > 1 && extendEnd) t = getMaxT();
              else render = false;

              if (render) {
                // calculate the pixel values at t
                inputs[0] = t;
                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 (functions[0].getNumOutputs() != numComponents) {
                  //CMYK
                  outputRBG = shadeCSpace.getColorSpace().toRGB(outputs);
                }
                else outputRBG = outputs;

                int base = (j * w + i) * (numComponents + 1);
                for (int c = 0; c < numComponents; c++) {
View Full Code Here

Examples of com.sun.pdfview.colorspace.PDFColorSpace

      PDFObject csObj = obj.getDictRef("ColorSpace");
      if (csObj == null) {
        throw new PDFParseException("No ColorSpace for image: " + obj);
      }

      PDFColorSpace cs = PDFColorSpace.getColorSpace(csObj, resources);
      image.setColorSpace(cs);

      // read the decode array
      PDFObject decodeObj = obj.getDictRef("Decode");
      if (decodeObj != null) {
View Full Code Here

Examples of com.sun.pdfview.colorspace.PDFColorSpace

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

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

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

      // process the decode array
      if (this.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 (this.colorKeyMask == null || this.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 < this.colorKeyMask.length; i += 2) {
          for (int j = this.colorKeyMask[i]; j <= this.colorKeyMask[i + 1]; j++) {
            aComps[(j * 4) + 3] = 0; // make transparent
          }
        }
        return new IndexColorModel(getBitsPerComponent(), num, aComps,
            0, true);
      }
    } else if (cs instanceof AlternateColorSpace) {
      // ColorSpace altCS = new AltColorSpace(((AlternateColorSpace)
      // cs).getFunktion(), cs.getColorSpace());
      ColorSpace altCS = cs.getColorSpace();
      int[] bits = new int[altCS.getNumComponents()];
      for (int i = 0; i < bits.length; i++) {
        bits[i] = getBitsPerComponent();
      }
      return new DecodeComponentColorModel(altCS, bits);
    } else {
      // CMYK color space has been converted to RGB in DCTDecode
      if (cs.getColorSpace().getType() == ColorSpace.TYPE_CMYK) {
        ColorSpace rgbCS = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        int[] bits = new int[rgbCS.getNumComponents()];
        for (int i = 0; i < bits.length; i++) {
          bits[i] = getBitsPerComponent();
        }
        return new DecodeComponentColorModel(rgbCS, bits);
      }
      int[] bits = new int[cs.getNumComponents()];
      for (int i = 0; i < bits.length; i++) {
        bits[i] = getBitsPerComponent();
      }

      return new DecodeComponentColorModel(cs.getColorSpace(), bits);
    }
  }
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.