コード例 #1
0
ファイル: LCMS.java プロジェクト: grimtraveller/LightZone
  private static ByteInterleavedRaster normalizeRaster(ByteInterleavedRaster raster) {
    boolean reallocBuffer = false;
    int scanLineStride = raster.getScanlineStride();
    int dataOffsets[] = raster.getDataOffsets();
    for (int i = 0; i < dataOffsets.length; i++)
      if (dataOffsets[i] != i) {
        reallocBuffer = true;
        break;
      }
    int bands = raster.getNumBands();
    if (!reallocBuffer
        && (raster.getPixelStride() != bands || scanLineStride != raster.getWidth() * bands))
      reallocBuffer = true;
    if (reallocBuffer) {
      PixelInterleavedSampleModel sm = (PixelInterleavedSampleModel) raster.getSampleModel();

      PixelInterleavedSampleModel newSM =
          new PixelInterleavedSampleModel(
              sm.getDataType(),
              raster.getWidth(),
              raster.getHeight(),
              bands,
              bands * raster.getWidth(),
              bands == 1 ? new int[] {0} : new int[] {0, 1, 2});

      ByteInterleavedRaster newRaster =
          new ByteInterleavedRaster(newSM, new Point(raster.getMinX(), raster.getMinY()));
      Functions.copyData(newRaster, raster);
      raster = newRaster;
    }
    return raster;
  }
コード例 #2
0
 private static BufferedImage getGaussianBlur(int size, BufferedImage image) {
   KernelJAI kernel = Functions.getGaussKernel(size / 3.0);
   ParameterBlock pb = new ParameterBlock();
   pb.addSource(image);
   pb.add(kernel);
   RenderingHints hints =
       new RenderingHints(
           JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(BorderExtender.BORDER_COPY));
   hints.add(JAIContext.noCacheHint);
   return JAI.create("LCSeparableConvolve", pb, hints).getAsBufferedImage();
 }
コード例 #3
0
  private BufferedImage cropScaleGrayscale(Rectangle visibleRect, RenderedImage image) {
    int minX = image.getMinX();
    int minY = image.getMinY();
    int width = image.getWidth();
    int height = image.getHeight();

    Rectangle bounds = new Rectangle(minX, minY, width, height);

    visibleRect = bounds.intersection(visibleRect);

    if (bounds.contains(visibleRect)) {
      ParameterBlock pb = new ParameterBlock();
      pb.addSource(image);
      pb.add((float) visibleRect.x);
      pb.add((float) visibleRect.y);
      pb.add((float) visibleRect.width);
      pb.add((float) visibleRect.height);
      image = JAI.create("Crop", pb, JAIContext.noCacheHint);
    }
    Dimension previewSize = getSize();

    if ((visibleRect.width > previewSize.width) || (visibleRect.height > previewSize.height)) {
      float scale =
          Math.min(
              previewSize.width / (float) visibleRect.width,
              previewSize.height / (float) visibleRect.height);

      image = ConvolveDescriptor.create(image, Functions.getGaussKernel(.25 / scale), null);
      ParameterBlock pb = new ParameterBlock();
      pb.addSource(image);
      pb.add(scale);
      pb.add(scale);
      image = JAI.create("Scale", pb, JAIContext.noCacheHint);
    }
    image = Functions.toColorSpace(image, JAIContext.systemColorSpace, null);

    if (image.getSampleModel().getDataType() == DataBuffer.TYPE_USHORT) {
      image = Functions.fromUShortToByte(image, null);
    }
    return Functions.toFastBufferedImage(image);
  }
コード例 #4
0
ファイル: LCMS.java プロジェクト: grimtraveller/LightZone
 public void doTransform(ShortInterleavedRaster input, ShortInterleavedRaster output) {
   if (cmsTransform != null) {
     ShortInterleavedRaster ri = normalizeRaster(input);
     ShortInterleavedRaster ro;
     int outBands = output.getNumBands();
     if (!input.getBounds().equals(output.getBounds())) {
       int[] offsets = outBands == 1 ? new int[] {0} : new int[] {0, 1, 2};
       SampleModel sm =
           new PixelInterleavedSampleModel(
               DataBuffer.TYPE_USHORT,
               ri.getWidth(),
               ri.getHeight(),
               outBands,
               outBands * ri.getWidth(),
               offsets);
       ro = new ShortInterleavedRaster(sm, new Point(ri.getMinX(), ri.getMinY()));
     } else ro = normalizeRaster(output);
     int pixels =
         outBands == 1 ? ro.getDataStorage().length : ro.getDataStorage().length / outBands;
     cmsDoTransform(cmsTransform.handle, ri.getDataStorage(), ro.getDataStorage(), pixels);
     if (ro != output) Functions.copyData(output, ro);
   }
 }
コード例 #5
0
    public PlanarImage setFront() {
      if (chroma_domain == 0 && chroma_range == 0 && luma_domain == 0 && luma_range == 0)
        return back;

      PlanarImage front = back;

      ColorScience.LinearTransform transform = new ColorScience.YST();

      double[][] rgb2yst = transform.fromRGB(back.getSampleModel().getDataType());
      double[][] yst2rgb = transform.toRGB(back.getSampleModel().getDataType());

      ParameterBlock pb = new ParameterBlock();
      pb.addSource(back);
      pb.add(rgb2yst);
      RenderedOp ystImage = JAI.create("BandCombine", pb, null);

      RenderingHints mfHints =
          new RenderingHints(
              JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(BorderExtender.BORDER_COPY));

      if (chroma_domain != 0 && chroma_range != 0) {
        pb = new ParameterBlock();
        pb.addSource(ystImage);
        pb.add(chroma_domain * scale);
        pb.add(0.02f + 0.001f * chroma_domain);
        // pb.add(0.1f);
        ystImage = JAI.create("BilateralFilter", pb, mfHints);
        ystImage.setProperty(JAIContext.PERSISTENT_CACHE_TAG, Boolean.TRUE);
      }

      if (luma_domain != 0 && luma_range != 0) {
        pb = new ParameterBlock();
        pb.addSource(ystImage);
        pb.add(new int[] {0});
        RenderedOp y = JAI.create("bandselect", pb, null);

        pb = new ParameterBlock();
        pb.addSource(ystImage);
        pb.add(new int[] {1, 2});
        RenderedOp cc = JAI.create("bandselect", pb, JAIContext.noCacheHint);

        pb = new ParameterBlock();
        pb.addSource(y);
        pb.add((2 + luma_domain / 10f) * scale);
        pb.add(0.005f * luma_domain);
        y = JAI.create("BilateralFilter", pb, mfHints);

        RenderingHints layoutHints =
            new RenderingHints(JAI.KEY_IMAGE_LAYOUT, Functions.getImageLayout(ystImage));
        pb = new ParameterBlock();
        pb.addSource(y);
        pb.addSource(cc);
        layoutHints.add(JAIContext.noCacheHint);
        ystImage = JAI.create("BandMerge", pb, layoutHints);
      }

      pb = new ParameterBlock();
      pb.addSource(ystImage);
      pb.add(yst2rgb);
      front = JAI.create("BandCombine", pb, null);
      front.setProperty(JAIContext.PERSISTENT_CACHE_TAG, Boolean.TRUE);

      return front;
    }
コード例 #6
0
  protected synchronized void paintComponent(Graphics gr) {
    Graphics2D g2d = (Graphics2D) gr;

    if (bins == null) engine.update(null, false);

    Dimension bounds = getSize();

    final float minx = 0;
    final float miny = 0;
    final float width = bounds.width;
    final float height = bounds.height - 18;

    g2d.setColor(Color.lightGray);
    g2d.fill(new Rectangle2D.Float(minx, miny, width, height + 18));

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    if (bins != null) {
      final int max = binmax();

      class scaler {
        int yscale(double y) {
          return (int) (height - (height - 4) * (y / (double) max) + 0.5 + miny);
        }
      }

      scaler s = new scaler();

      for (int c = 0; c < bins.length; c++) {
        Color color = Color.BLACK;

        if (bins.length > 1)
          switch (c) {
            case 0:
              color = Color.RED;
              break;
            case 1:
              color = Color.GREEN;
              break;
            case 2:
              color = Color.BLUE;
              break;
          }

        g2d.setColor(color);

        int numBins = bins[c].length;

        int zeroY = s.yscale(0);
        float xstep = (width + 1) / numBins;

        GeneralPath gp = new GeneralPath();

        gp.moveTo(minx, zeroY);
        float lastx = minx;
        float lasty = zeroY;
        for (int i = 0; i < numBins; i++) {
          int y = s.yscale(bins[c][i]);
          float x = xstep * i + minx;
          if (lasty != zeroY || y != zeroY) {
            gp.lineTo(x, y);
            lastx = x;
            lasty = y;
          }
        }
        if (lasty != zeroY) gp.lineTo(lastx, zeroY);

        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
        g2d.fill(gp);
        g2d.setComposite(AlphaComposite.SrcOver);
        g2d.draw(gp);
      }
    }

    float step = width / 16.0f;
    for (int i = 0; i < 16; i++) {
      if (i == currentFocusZone) g2d.setColor(Color.yellow);
      else {
        float color = (float) ((Math.pow(2, i * 8.0 / (16 - 1)) - 1) / 255.);
        float[] srgbColor =
            Functions.fromLinearToCS(
                JAIContext.systemColorSpace, new float[] {color, color, color});

        g2d.setColor(
            new Color(
                (int) (255 * srgbColor[0]),
                (int) (255 * srgbColor[1]),
                (int) (255 * srgbColor[2])));
      }
      g2d.fill(new Rectangle2D.Float(minx + step * i, height + miny, step + 0.5f, 18));
    }
  }