Package javax.media.jai

Examples of javax.media.jai.ParameterBlockJAI


        InputStream stream = TestUtilities.doImageTranscodeTest(
                expectations, rule, fileName, parameters, enableGif);

        ImageReader reader = null;
        ParameterBlockJAI pblock = new ParameterBlockJAI("ImageRead");
        pblock.setParameter("Input", ImageIO.createImageInputStream(stream));
        if (rule.equals(OutputImageRules.WBMP)) {
            // wbmps do not have a magic number so
            // ImageRead operation cannot recognize them.
            pblock.setParameter("Reader",
                ImageIO.getImageReadersByFormatName("wbmp").next());
        }
        RenderedOp image = JAI.create("ImageRead", pblock);

        return image;
View Full Code Here


            result = JAI.create("bandselect", selectPB);
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Generating alpha channel");
            }
            ParameterBlockJAI constPb = new ParameterBlockJAI("constant");
            constPb.setParameter("width", new Float(src.getWidth()));
            constPb.setParameter("height", new Float(src.getHeight()));
            // half transparent
            constPb.setParameter("bandValues", new Byte[]{(byte) 127});
            result = JAI.create("constant", constPb);
        }
        return result;
    }
View Full Code Here

            logger.debug("format performed " + ImageInformation.asString(src));
        }

        // create an optimized color map for the dithering process. This helps
        // avoid speckled looking areas of uniform colour
        ParameterBlockJAI pb2 = new ParameterBlockJAI("ColorQuantizer");
        pb2.addSource(src);
        pb2.setParameter("maxColorNum", colormapSize);
        RenderedOp dithered = JAI.create("ColorQuantizer", pb2, hints);

        if (kernel != null) {
            // defer computation of the lookup table. Note that "LUT" should really
            // be "JAI.LookupTable" according to the docs
View Full Code Here

            LOGGER.debug("Writing the image to ouputstream...");
            ImageLogger.log(image);
        }

        try {
            ParameterBlockJAI p = new ParameterBlockJAI("ImageWrite");
            p.addSource(image);
            p.setParameter("Output", os);
            p.setParameter("Format", fileFormat);
            p.setParameter("WriteParam", getImageWriteParam(image, params));
            JAI.create("ImageWrite", p);

        } catch (Exception e) {
            LOGGER.error("jai-operation-failure", "ImageWrite");
            throw new ImageWriterException(e);
View Full Code Here

            }

            stream.reset();
            stream.mark();

            ParameterBlockJAI paramBlock = new ParameterBlockJAI("ImageWrite");
            paramBlock.addSource(src);
            paramBlock.setParameter("Format", "jpeg");
            paramBlock.setParameter("WriteParam", jpegParam);
            paramBlock.setParameter("Output", stream);
            JAI.create("ImageWrite", paramBlock);

            int maxLength = params.getInteger(ParameterNames.MAX_IMAGE_SIZE);
            long length = stream.getSize();
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Compression quality is " + currentQuality +
                             " image size is " + length + " bytes.");
            }

            float nextQuality;
            float diff;

            while ((length > maxLength) && (currentQuality > minQuality)) {
                stream.reset();
                stream.mark();
                nextQuality =
                    (currentQuality * (float) maxLength) / (float) length;
                diff = (currentQuality - nextQuality) * 1.5F;

                if (diff < 0.01F) {
                    diff = 0.01F;
                }

                currentQuality = currentQuality - diff;

                if (currentQuality < minQuality) {
                    currentQuality = minQuality;
                }

                paramBlock = new ParameterBlockJAI("ImageWrite");
                paramBlock.addSource(src);
                paramBlock.setParameter("Format", "jpeg");
                paramBlock.setParameter("WriteParam", jpegParam);
                paramBlock.setParameter("Output", stream);
                JAI.create("ImageWrite", paramBlock);

                length = stream.getSize();
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Compression quality is " + currentQuality +
View Full Code Here

        float origHeight = uncroppedImage.getHeight();
       
        AffineTransform xform = org.photovault.image.ImageXform.getRotateXform(
                rot, origWidth, origHeight );
       
        ParameterBlockJAI rotParams = new ParameterBlockJAI( "affine" );
        rotParams.addSource( uncroppedImage );
        rotParams.setParameter( "transform", xform );
        rotParams.setParameter( "interpolation",
                Interpolation.getInstance( Interpolation.INTERP_NEAREST ) );
        RenderingHints hints = new RenderingHints( null );
        /*
         In practice, JAI optimizes the pipeline so that this trasnformation is
         concatenated with scaling from MultiresolutionImage to desired resolution.
         This transformation obeys KYE_INTERPOLATION hint so we must set it here,
         otherwise nearest neighborough interpolation will be used regardless of
         the settings on parameter block.
         */
        hints.put( JAI.KEY_INTERPOLATION, new InterpolationBilinear() );
        rotatedImage = JAI.createRenderable( "affine", rotParams, hints );
       
        ParameterBlockJAI cropParams = new ParameterBlockJAI( "crop" );
        cropParams.addSource( rotatedImage );
        float cropWidth = (float) (cropMaxX - cropMinX);
        cropWidth = ( cropWidth > 0.000001 ) ? cropWidth : 0.000001f;
        float cropHeight = (float) (cropMaxY - cropMinY);
        cropHeight = ( cropHeight > 0.000001 ) ? cropHeight : 0.000001f;
       
        float cropX = (float)(rotatedImage.getMinX() + cropMinX * rotatedImage.getWidth());
        float cropY = (float)(rotatedImage.getMinY() + cropMinY * rotatedImage.getHeight());
        float cropW = cropWidth * rotatedImage.getWidth();
        float cropH = cropHeight * rotatedImage.getHeight();
        Rectangle2D.Float cropRect = new Rectangle2D.Float( cropX, cropY, cropW, cropH );
        Rectangle2D.Float srcRect = new Rectangle2D.Float( rotatedImage.getMinX(), rotatedImage.getMinY(),
                rotatedImage.getWidth(), rotatedImage.getHeight() );
        if ( !srcRect.contains( cropRect ) ) {
            // Crop rectangle must fit inside source image
            Rectangle2D.intersect( srcRect, cropRect, cropRect );
            if ( !srcRect.contains( cropRect ) ) {
                // Ups, we have a problem... this can happen due to rounding errors
                // (for example, if cropY is just above zero). Disable cropping
                // to avoid error.
                cropX = rotatedImage.getMinX();
                cropY = rotatedImage.getMinY();
                cropW = rotatedImage.getWidth();
                cropH = rotatedImage.getHeight();
            }
        }
       
        cropParams.setParameter( "x", cropX );
        cropParams.setParameter( "y", cropY );
        cropParams.setParameter( "width", cropW );
        cropParams.setParameter( "height", cropH );
        croppedImage = JAI.createRenderable("crop", cropParams, hints );
        // Translate the image so that it begins in origo
        ParameterBlockJAI pbXlate = new ParameterBlockJAI( "translate" );
        pbXlate.addSource( croppedImage );
        pbXlate.setParameter( "xTrans", (float) (-croppedImage.getMinX() ) );
        pbXlate.setParameter( "yTrans", (float) (-croppedImage.getMinY() ) );
        xformCroppedImage = JAI.createRenderable( "translate", pbXlate );
        return xformCroppedImage;
    }
View Full Code Here

        float origHeight = originalImage.getHeight();
       
        AffineTransform xform = org.photovault.image.ImageXform.getRotateXform(
                rot, origWidth, origHeight );

        ParameterBlockJAI rotParams = (ParameterBlockJAI) rotatedImage.getParameterBlock();
        rotParams.setParameter( "transform", xform );
        rotParams.setParameter( "interpolation",
                Interpolation.getInstance( Interpolation.INTERP_NEAREST ) );
        rotatedImage.setParameterBlock( rotParams );
       
        ParameterBlockJAI cropParams = (ParameterBlockJAI) croppedImage.getParameterBlock();
        float cropWidth = (float) (cropMaxX - cropMinX);
        cropWidth = ( cropWidth > 0.000001 ) ? cropWidth : 0.000001f;
        float cropHeight = (float) (cropMaxY - cropMinY);
        cropHeight = ( cropHeight > 0.000001 ) ? cropHeight : 0.000001f;       
        float cropX = (float)(rotatedImage.getMinX() + cropMinX * rotatedImage.getWidth());
        float cropY = (float)(rotatedImage.getMinY() + cropMinY * rotatedImage.getHeight());
        float cropW = cropWidth * rotatedImage.getWidth();
        float cropH = cropHeight * rotatedImage.getHeight();
        cropParams.setParameter( "x", cropX );
        cropParams.setParameter( "y", cropY );
        cropParams.setParameter( "width", cropW );
        cropParams.setParameter( "height", cropH );
        croppedImage.setParameterBlock( cropParams );
       
        // Translate the image so that it begins in origo
        ParameterBlockJAI pbXlate = (ParameterBlockJAI) xformCroppedImage.getParameterBlock();
        pbXlate.addSource( croppedImage );
        pbXlate.setParameter( "xTrans", (float) (-croppedImage.getMinX() ) );
        pbXlate.setParameter( "yTrans", (float) (-croppedImage.getMinY() ) );
        xformCroppedImage.setParameterBlock( pbXlate );
    }
View Full Code Here

    }
   
    protected PlanarImage getScaled( RenderableOp unscaledImage, int maxWidth, int maxHeight ) {
        AffineTransform thumbScale = org.photovault.image.ImageXform.getFittingXform( maxWidth, maxHeight,
                0, unscaledImage.getWidth(), unscaledImage.getHeight() );
        ParameterBlockJAI scaleParams = new ParameterBlockJAI( "affine" );
        scaleParams.addSource( unscaledImage );
        scaleParams.setParameter( "transform", thumbScale );
        scaleParams.setParameter( "interpolation",
                Interpolation.getInstance( Interpolation.INTERP_NEAREST ) );
       
        RenderedOp scaledImage = JAI.create( "affine", scaleParams );
        return scaledImage;       
    }
View Full Code Here

    }
   
    protected PlanarImage getScaled( PlanarImage unscaledImage, double scale ) {
        AffineTransform thumbScale = org.photovault.image.ImageXform.getScaleXform( scale,
                0, unscaledImage.getWidth(), unscaledImage.getHeight() );
        ParameterBlockJAI scaleParams = new ParameterBlockJAI( "affine" );
        scaleParams.addSource( unscaledImage );
        scaleParams.setParameter( "transform", thumbScale );
        scaleParams.setParameter( "interpolation",
                Interpolation.getInstance( Interpolation.INTERP_BILINEAR ) );
       
        RenderedOp scaledImage = JAI.create( "affine", scaleParams );
        return scaledImage;       
    }   
View Full Code Here

        }
    }

    protected PlanarImage crop(PlanarImage image, float x, float y, float width, float height) {
      // Create a ParameterBlock with information for the cropping.
      ParameterBlockJAI pb = new ParameterBlockJAI("crop")
      pb.addSource(image);
      pb.setParameter("x", x);
      pb.setParameter("y", y);
      pb.setParameter("width", width);
      pb.setParameter("height", height);

      // Create the output image by cropping the input image.
      return JAI.create("crop", pb);
      // A cropped image will have its origin set to the (x,y) coordinates,
      // and with the display method we use it will cause bands on the top
View Full Code Here

TOP

Related Classes of javax.media.jai.ParameterBlockJAI

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.