Package java.awt.image.renderable

Examples of java.awt.image.renderable.RenderableImage


        ParameterBlock pb = new ParameterBlock();
        pb.add(paramBlock.getObjectParameter(0)).add(res).add(subImage);
        RenderedImage iipRes = JAI.create("iipresolution", pb);
        Vector sources = new Vector(1);
        sources.add(iipRes);
        RenderableImage ri =
            new MultiResolutionRenderableImage(sources, 0.0F, 0.0F,
                                               1.0F);

        // Filtering.
        if((opMask & MASK_FILTER) != 0) {
            float filter = paramBlock.getFloatParameter(2);
            pb = (new ParameterBlock()).addSource(ri).add(filter);
            ri = new RenderableImageOp(new FilterCRIF(), pb);
        }

        // Color-twist.
        // Cache the original number of bands in case the number of bands
        // changes due to addition of chroma and/or alpha channels in the
        // color-twist procedure.
  int nBands = iipRes.getSampleModel().getNumBands();
        if((opMask & MASK_COLOR_TWIST) != 0) {
      double[][] ctw = getColorTwistMatrix(iipRes.getColorModel(),
             paramBlock);
            pb = (new ParameterBlock()).addSource(ri).add(ctw);
            ri = JAI.createRenderable("bandcombine", pb);
      nBands = ctw.length;
        }

        // Contrast.
        if((opMask & MASK_CONTRAST) != 0) {
            int csType = iipRes.getColorModel().getColorSpace().getType();
            boolean isPYCC =
                csType != ColorSpace.TYPE_GRAY &&
                csType != ColorSpace.TYPE_RGB;

            if(isPYCC) {
                double[][] matrix;
                if(nBands == 3) { // PYCC
                    matrix = composeMatrices(YCC_TO_RGB, YCC_TO_RGB_CONST);
                } else { // PYCC-A
                    matrix = composeMatrices(YCCA_TO_RGBA, YCCA_TO_RGBA_CONST);
                }
                pb = (new ParameterBlock()).addSource(ri).add(matrix);
                ri = JAI.createRenderable("bandcombine", pb);
            }

            float contrast = paramBlock.getFloatParameter(4);
            LookupTableJAI lut = createContrastLUT(contrast, nBands);

            pb = (new ParameterBlock()).addSource(ri).add(lut);
            ri = JAI.createRenderable("lookup", pb);

            if(isPYCC) {
                double[][] matrix;
                if(nBands == 3) { // PYCC
                    matrix = composeMatrices(RGB_TO_YCC, RGB_TO_YCC_CONST);
                } else { // PYCC-A
                    matrix = composeMatrices(RGBA_TO_YCCA, RGBA_TO_YCCA_CONST);
                }
                pb = (new ParameterBlock()).addSource(ri).add(matrix);
                ri = JAI.createRenderable("bandcombine", pb);
            }
        }

        // Source rectangle of interest.
        if((opMask & MASK_ROI_SOURCE) != 0) {
            // Get the source rectangle of interest.
            Rectangle2D rect = (Rectangle2D)paramBlock.getObjectParameter(5);

            // Check for intersection with source bounds.
            if(!rect.intersects(0.0, 0.0, aspectRatioSource, 1.0)) {
                throw new RuntimeException(JaiI18N.getString("IIPCRIF5"));
            }

            // Create the source rectangle.
            Rectangle2D rectS = new Rectangle2D.Float(0.0F, 0.0F,
                                                      aspectRatioSource, 1.0F);

            // Crop out the desired region.
            if(!rect.equals(rectS)) {
                // Clip to the source bounds.
                rect = rect.createIntersection(rectS);

                // Crop to the clipped rectangle of interest.
                pb = (new ParameterBlock()).addSource(ri);
                pb.add((float)rect.getMinX()).add((float)rect.getMinY());
                pb.add((float)rect.getWidth()).add((float)rect.getHeight());
                ri = JAI.createRenderable("crop", pb);

                /* XXX
                // Embed the cropped image in an image the size of the source.
                pb = (new ParameterBlock()).addSource(ri);
                pb.add((float)rectS.getMinX()).add((float)rectS.getMinY());
                pb.add((float)rectS.getWidth()).add((float)rectS.getHeight());
                ri = JAI.createRenderable("crop", pb);
                */
            }
        }

        // Spatial orientation.
        if((opMask & MASK_TRANSFORM) != 0) {
            AffineTransform afn =
                (AffineTransform)paramBlock.getObjectParameter(6);
            try {
                // The transform parameter is a backward mapping so invert it.
                afn = afn.createInverse();
            } catch(java.awt.geom.NoninvertibleTransformException e) {
                // This should never happen due to descriptor check.
                listener.errorOccurred(JaiI18N.getString("AffineNotInvertible"),
                                       e, this, false);

            }
            pb = (new ParameterBlock()).addSource(ri).add(afn);
            if(hints != null && hints.containsKey(JAI.KEY_INTERPOLATION)) {
                pb.add(hints.get(JAI.KEY_INTERPOLATION));
            }
            ri = JAI.createRenderable("affine", pb);
        }

        // Destination rectangle of interest.
        // Set the destination rectangle of interest.
        Rectangle2D rgn = (opMask & MASK_ROI_DESTINATION) != 0 ?
            (Rectangle2D)paramBlock.getObjectParameter(8) : bounds2D;

        // Verify that the region is non-empty.
        if(rgn.isEmpty()) {
            throw new RuntimeException(JaiI18N.getString("IIPCRIF3"));
        }

        // Create a Rectangle2D for the current image.
        Rectangle2D riRect = new Rectangle2D.Float((float)ri.getMinX(),
                                                   (float)ri.getMinY(),
                                                   (float)ri.getWidth(),
                                                   (float)ri.getHeight());

        // If the current image bounds are not those of the requested
        // region then crop the image.
        if(!rgn.equals(riRect)) {
            // Intersect rgn with source image bounds.
            rgn = rgn.createIntersection(riRect);

            // Crop to the rectangle of interest.
            pb = (new ParameterBlock()).addSource(ri);
            pb.add((float)rgn.getMinX()).add((float)rgn.getMinY());
            pb.add((float)rgn.getWidth()).add((float)rgn.getHeight());
            ri = JAI.createRenderable("crop", pb);
        }

        // Return the rendering.
        return ri.createRendering(renderContext);
    }
View Full Code Here


     * Returns the default rendering of the RenderableImage produced by
     * the "iip" operation.
     */
    public RenderedImage create(ParameterBlock paramBlock,
                                RenderingHints renderHints) {
        RenderableImage iipImage = JAI.createRenderable("iip", paramBlock);

        return iipImage.createDefaultRendering();
    }
View Full Code Here

                       JaiI18N.getString("CropDescriptor5"));
            return false;
        }

        // Check for out-of-bounds
        RenderableImage src = (RenderableImage)args.getSource(0);

        Rectangle2D rect_src =
            new Rectangle2D.Float(src.getMinX(),
                                  src.getMinY(),
                                  src.getWidth(),
                                  src.getHeight());

        if (!rect_src.contains(rect_req)) {
            msg.append(getName() + " " +
                       JaiI18N.getString("CropDescriptor6"));
            return false;
View Full Code Here

                for (int i = 0; i < sources.size(); i++) {
                    RenderContext rcOut =
                        crif.mapRenderContext(i, rcIn,
                                              renderedPB,
                                              this);
                    RenderableImage src =
                        (RenderableImage)sources.elementAt(i);
                    RenderedImage renderedImage = src.createRendering(rcOut);
                    if (renderedImage == null) {
                        return null;
                    }
                   
                    // Add this rendered image to the ParameterBlock's
View Full Code Here

                 i,
                 renderContext,
                 nodeSupport.getParameterBlock(),
                 this);

      RenderableImage src = (RenderableImage)source;
      rdrdImage = src.createRendering(rcOut);
        else if (source instanceof RenderedOp) {
      rdrdImage = ((RenderedOp)source).getRendering();
        } else if (source instanceof RenderedImage) {
      rdrdImage = (RenderedImage)source;
        }
View Full Code Here

        if (numSources == 0) {
            return null;
        }

        RenderableImage src = paramBlock.getRenderableSource(0);
        Rectangle2D.Float box1 = new Rectangle2D.Float(src.getMinX(),
                                                       src.getMinY(),
                                                       src.getWidth(),
                                                       src.getHeight());

        for (int i = 1; i < numSources; i++) {
            src  = paramBlock.getRenderableSource(i);
            Rectangle2D.Float box2 =
                new Rectangle2D.Float(src.getMinX(), src.getMinY(),
                                      src.getWidth(), src.getHeight());
            box1 = (Rectangle2D.Float)box1.createIntersection(box2);
            if(box1.isEmpty()) {
                break;
            }
        }
View Full Code Here

    /**
     * Gets the bounding box for the output of <code>TranslateOpImage</code>.
     * This method satisfies the implementation of CRIF.
     */
    public Rectangle2D getBounds2D(ParameterBlock paramBlock) {
        RenderableImage source = paramBlock.getRenderableSource(0);

        float x_center = paramBlock.getFloatParameter(0);
        float y_center = paramBlock.getFloatParameter(1);
        float angle = paramBlock.getFloatParameter(2);
        Interpolation interp = (Interpolation)paramBlock.getObjectParameter(3);

        //
        // Convert angle to degrees (within some precision) given PI's
        // transcendantal nature. All this, to check if we can call
        // simpler methods like Copy or Transpose for certain angles
        // viz., 0, 90, 180, 270, 360, 450, .....
        //
        int dangle = 0;
        double tmp_angle = 180.0F * angle / Math.PI;
        double rnd_angle = Math.round(tmp_angle);

        if (Math.abs(rnd_angle - tmp_angle) < 0.0001) {
            dangle = (int) rnd_angle;
        } else {
            dangle = (int) tmp_angle;
        }

        //
        // It's a copy if angle is 0 degrees or multiple of 360 degrees
        //
        if (dangle % 360 == 0) {
            return new Rectangle2D.Float(source.getMinX(),
                                         source.getMinY(),
                                         source.getWidth(),
                                         source.getHeight());
        }

        //
        // It's a transpose if angle is mutiple of 270, 180, 90 degrees
        //
        float x0 = (float)source.getMinX();
        float y0 = (float)source.getMinY();
        float s_width = (float)source.getWidth();
        float s_height = (float)source.getHeight();
        float x1 = x0 + s_width - 1;
        float y1 = y0 + s_height - 1;

        float tx0 = 0;
        float ty0 = 0;
        float tx1 = 0;
        float ty1 = 0;

        if (dangle % 270 == 0) {
            if (dangle < 0) {
                // -270 degrees
                tx0 = s_height - y1 - 1;
                ty0 = x0;
                tx1 = s_height - y0 - 1;
                ty1 = x1;
                return new Rectangle2D.Float(tx0,
                                             ty0,
                                             tx1 - tx0 + 1,
                                             ty1 - ty0 + 1);
            } else {
                // 270 degrees
                tx0 = y0;
                ty0 = s_width - x1 - 1;
                tx1 = y1;
                ty1 = s_width - x0 - 1;
                return new Rectangle2D.Float(tx0,
                                             ty0,
                                             tx1 - tx0 + 1,
                                             ty1 - ty0 + 1);
            }
        }

        if (dangle % 180 == 0) {
            tx0 = s_width - x1 - 1;
            ty0 = s_height - y1 - 1;
            tx1 = s_width - x0 - 1;
            ty1 = s_height - y0 - 1;
            // 180 degrees
            return new Rectangle2D.Float(tx0,
                                         ty0,
                                         tx1 - tx0 + 1,
                                         ty1 - ty0 + 1);
        }

        if (dangle % 90 == 0) {
            if (dangle < 0) {
                // -90 degrees
                tx0 = y0;
                ty0 = s_width - x1 - 1;
                tx1 = y1;
                ty1 = s_width - x0 - 1;
                return new Rectangle2D.Float(tx0,
                                             ty0,
                                             tx1 - tx0 + 1,
                                             ty1 - ty0 + 1);
            } else {
                // 90 degrees
                tx0 = s_height - y1 - 1;
                ty0 = x0;
                tx1 = s_height - y0 - 1;
                ty1 = x1;
                return new Rectangle2D.Float(tx0,
                                             ty0,
                                             tx1 - tx0 + 1,
                                             ty1 - ty0 + 1);
            }
        }

        //
        // It's a Affine
        //
        AffineTransform rotate =
            AffineTransform.getRotateInstance(angle, x_center, y_center);

        //
        // Get sx0,sy0 coordinates and width & height of the source
        //
        float sx0 = (float) source.getMinX();
        float sy0 = (float) source.getMinY();
        float sw = (float) source.getWidth();
        float sh = (float) source.getHeight();

        //
        // The 4 points (clockwise order) are
        //      (sx0, sy0),    (sx0+sw, sy0)
        //      (sx0, sy0+sh), (sx0+sw, sy0+sh)
View Full Code Here

    /**
     * Gets the bounding box for output of <code>TranslateOpImage</code>.
     * This method satisfies the implementation of CRIF.
     */
    public Rectangle2D getBounds2D(ParameterBlock paramBlock) {
        RenderableImage source = paramBlock.getRenderableSource(0);
        float xTrans = paramBlock.getFloatParameter(0);
        float yTrans = paramBlock.getFloatParameter(1);

        return new Rectangle2D.Float(source.getMinX() + xTrans,
                                     source.getMinY() + yTrans,
                                     source.getWidth(),
                                     source.getHeight());
    }
View Full Code Here

/* 105 */     return RC;
/*     */   }
/*     */
/*     */   public Rectangle2D getBounds2D(ParameterBlock paramBlock)
/*     */   {
/* 114 */     RenderableImage source = paramBlock.getRenderableSource(0);
/*     */
/* 116 */     double scaleX = paramBlock.getDoubleParameter(0);
/* 117 */     double scaleY = paramBlock.getDoubleParameter(1);
/*     */
/* 120 */     float x0 = source.getMinX();
/* 121 */     float y0 = source.getMinY();
/* 122 */     float w = source.getWidth();
/* 123 */     float h = source.getHeight();
/*     */
/* 126 */     float d_x0 = (float)(x0 * scaleX);
/* 127 */     float d_y0 = (float)(y0 * scaleY);
/* 128 */     float d_w = (float)(w * scaleX);
/* 129 */     float d_h = (float)(h * scaleY);
 
View Full Code Here

/* 228 */     return RC;
/*     */   }
/*     */
/*     */   public Rectangle2D getBounds2D(ParameterBlock paramBlock)
/*     */   {
/* 237 */     RenderableImage source = paramBlock.getRenderableSource(0);
/*     */
/* 239 */     float scale_x = paramBlock.getFloatParameter(0);
/* 240 */     float scale_y = paramBlock.getFloatParameter(1);
/* 241 */     float trans_x = paramBlock.getFloatParameter(2);
/* 242 */     float trans_y = paramBlock.getFloatParameter(3);
/* 243 */     Interpolation interp = (Interpolation)paramBlock.getObjectParameter(4);
/*     */
/* 246 */     float x0 = source.getMinX();
/* 247 */     float y0 = source.getMinY();
/* 248 */     float w = source.getWidth();
/* 249 */     float h = source.getHeight();
/*     */
/* 252 */     float d_x0 = x0 * scale_x + trans_x;
/* 253 */     float d_y0 = y0 * scale_y + trans_y;
/* 254 */     float d_w = w * scale_x;
/* 255 */     float d_h = h * scale_y;
 
View Full Code Here

TOP

Related Classes of java.awt.image.renderable.RenderableImage

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.