Пример #1
0
 private RenderedOp createScaledImage(
     RenderedImage sourceImage, S2Resolution resolution, int level) {
   int sourceWidth = sourceImage.getWidth();
   int sourceHeight = sourceImage.getHeight();
   int targetWidth = imageLayouts[0].width >> level;
   int targetHeight = imageLayouts[0].height >> level;
   float scaleX = (float) targetWidth / (float) sourceWidth;
   float scaleY = (float) targetHeight / (float) sourceHeight;
   float corrFactorX = resolution == S2Resolution.R20M ? R20M_X_FACTOR : R60M_X_FACTOR;
   float corrFactorY = resolution == S2Resolution.R20M ? R20M_Y_FACTOR : R60M_Y_FACTOR;
   final Dimension tileDim = getTileDim(targetWidth, targetHeight);
   ImageLayout imageLayout = new ImageLayout();
   imageLayout.setTileWidth(tileDim.width);
   imageLayout.setTileHeight(tileDim.height);
   RenderingHints renderingHints =
       new RenderingHints(
           JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(BorderExtender.BORDER_ZERO));
   renderingHints.put(JAI.KEY_IMAGE_LAYOUT, imageLayout);
   RenderedOp scaledImage =
       ScaleDescriptor.create(
           sourceImage,
           scaleX * corrFactorX,
           scaleY * corrFactorY,
           0F,
           0F,
           Interpolation.getInstance(Interpolation.INTERP_NEAREST),
           renderingHints);
   if (scaledImage.getWidth() != targetWidth || scaledImage.getHeight() != targetHeight) {
     return CropDescriptor.create(
         scaledImage, 0.0F, 0.0F, (float) targetWidth, (float) targetHeight, null);
   } else {
     return scaledImage;
   }
 }
    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;
    }