Package com.volantis.map.ics.imageprocessor.tool

Examples of com.volantis.map.ics.imageprocessor.tool.ToolException


        try {
            result = JAI.create("composite", pb);
        } catch (Exception e) {
            LOGGER.error("jai-operation-failure", new String[]{ "composite", e.toString() });
            throw new ToolException(e);
        }
        return result;
    }
View Full Code Here


                ImageConvertorFactory.getInstance().
                getImageConvertor(ImageRule.TRUECOLOUR);
            watermark = cnv.convert(watermark, params);
            params.setObject(ParameterNames.WATERMARK_IMAGE, watermark);
        } catch (Exception e) {
            throw new ToolException(
                EXCEPTION_LOCALIZER.format("loading-watermark-failure"));
        }
       
        //We use image to transform watermark (scale, add transparent border).
        //To improve performance we suppose all the frames have the same size.
        //So the parameters for watermark transformation is retrieved from the
        // first frams.
        RenderedOp image = ops[0];

        //Scale the watermark to fit into the source image.
        float xFactor = (float) image.getWidth() / watermark.getWidth();
        float yFactor = (float) image.getHeight() / watermark.getHeight();
        float factor;
        int leftPad = 0;
        int bottomPad = 0;

        // Get the smallest factor to guarantee that watermark will fit
        // into image entirely.
        if (xFactor > yFactor) {
            factor = yFactor;
            leftPad = (int) ((xFactor - yFactor) * watermark.getWidth() / 2.0);
        } else {
            factor = xFactor;
            bottomPad = (int) ((yFactor - xFactor) * watermark.getHeight()/ 2.0);
        }

        ParameterBlockJAI scalePb = new ParameterBlockJAI("scale");
        scalePb.addSource(watermark);
        // X scale factor
        scalePb.setParameter("xScale", new Float(factor));
        // Y scale factor
        scalePb.setParameter("yScale", new Float(factor));
        // Interpolation method (should really use something better then
        // NN here)
        scalePb.setParameter("interpolation",
                Interpolation.getInstance(Interpolation.INTERP_NEAREST));

        try {
            watermark = JAI.create("scale",
                                   scalePb,
                                   null);
        } catch (Exception e) {
            LOGGER.error("jai-operation-failure"new String[]{ "scale", e.toString() });
            throw new ToolException(e);
        }

        if (leftPad != 0 || bottomPad != 0) {
            ParameterBlockJAI boarderPb = new ParameterBlockJAI("border");
            boarderPb.addSource(watermark);

            if (leftPad != 0) {
                Integer padding = leftPad;
                boarderPb.setParameter("leftPad", padding);
                boarderPb.setParameter("rightPad", padding);
            } else { // means bottomPad != 0
                Integer padding = bottomPad;
                boarderPb.setParameter("bottomPad", padding);
                boarderPb.setParameter("topPad", padding);
            }
            //Transparent border.
            boarderPb.setParameter("type", new BorderExtenderConstant(new double[]{1}));
            try {
                watermark = JAI.create("border", boarderPb);
            } catch (Exception e) {
                LOGGER.error("jai-operation-failure", new String[]{ "border", e.toString() });
                throw new ToolException(e);
            }

            // perform nearest neighbour interpolation as these should only be integer
            // translations
            watermark = TranslateDescriptor.create(watermark,
View Full Code Here

                (image.getColorModel() instanceof IndexColorModel) &&
                (dfr.startsWith("cg") || dfr.startsWith("gg"))) {
                useOptimizedGifPath = true;
            }
        } catch (MissingParameterException e) {
            throw new ToolException(e);
        }

        try {

            // don't do anything if the optimized Indexed image path is to be
            // used.
            if (useOptimizedGifPath) {
                result = image;
            } else {
                result = cnv.convert(image, params);
            }
        } catch (ImageConvertorException e) {
            LOGGER.error("processing-error", e.toString());
            throw new ToolException(e);
        }

        return result;
    }
View Full Code Here

            if (params.containsName(ParameterNames.PRESERVE_X_RIGHT)) {
                preserveXRight = params.getInteger(ParameterNames.PRESERVE_X_RIGHT);
            }
        } catch (MissingParameterException e) {
            LOGGER.error("loading-param-failure", "newWidth, preserveXLeft, preserveXRight");
            throw new ToolException(e);
        }
        if (newWidth > -1 && oldWidth > newWidth) {
            // should try to crop the image.
            ClipXY clipper = new ClipXY(firstImage.getWidth(), preserveXLeft, preserveXRight,
                                        firstImage.getHeight(), ImageConstants.NO_CLIP_LEFT,
View Full Code Here

            try {
                clippedImage = JAI.create("crop", cropParams);
            } catch (Exception e) {
                LOGGER.error("jai-operation-failure", "crop");
                throw new ToolException(e);
            }

            if (clipper.getX().getClipOffset() != 0 ||
                clipper.getY().getClipOffset() != 0) {
                // Move the image origin to 0,0
                // (this should not be necessary, but there is a bug
                // in the GIF writter and an exception is thrown if the
                // image has differen origin).
                ParameterBlock pb = new ParameterBlock();
                // The source image.
                pb.addSource(clippedImage);
                // The x translation.
                pb.add((float) -clipper.getX()
                                .getClipOffset());
                // The y translation.
                pb.add((float) -clipper.getY()
                                .getClipOffset());
                // The interpolation.
                pb.add(new InterpolationNearest());
                // Create the translate operation.
                try {
                    clippedImage = JAI.create("translate", pb, null);
                } catch (Exception e) {
                    LOGGER.error("jai-operation-failure", "translate");
                    throw new ToolException(e);
                }
            }
        }
        return clippedImage;
    }
View Full Code Here

            if (params.containsName(ParameterNames.RIGHT_X)) {
                rightX = params.getFloat(ParameterNames.RIGHT_X);
            }
        } catch (MissingParameterException e) {
            LOGGER.error("loading-param-failure", "newWidth, preserveXLeft, preserveXRight");
            throw new ToolException(e);
        }

        // normalize points
        topY = topY < 0.0f ? 0.0f : topY;
        leftX = leftX < 0.0f ? 0.0f : leftX;
        rightX = rightX > 1.0f ? 1.0f : rightX;
        bottomY = bottomY > 1.0f ? 1.0f : bottomY;

        float newX = (float) Math.floor(leftX * oldWidth);
        float newY = (float) Math.floor(topY * oldHeight);
        float newWidth = (float) Math.floor((rightX - leftX) * oldWidth);
        float newHeight = (float) Math.floor((bottomY - topY) * oldHeight);

        try {
            /*
             * cropping
             */
            ParameterBlock cropParams = new ParameterBlock();
            cropParams.addSource(clippedImage);
            cropParams.add(newX);
            cropParams.add(newY);
            cropParams.add(newWidth);
            cropParams.add(newHeight);

            clippedImage = JAI.create("crop", cropParams);

            /*
             * image must be shifted after crop operation
             */
            ParameterBlock translateParams = new ParameterBlock();
            translateParams.addSource(clippedImage);
            translateParams.add(-1 * newX);
            translateParams.add(-1 * newY);

            clippedImage = JAI.create("translate", translateParams);

        } catch (Exception e) {
            LOGGER.error("jai-operation-failure", "crop");
            throw new ToolException(e);
        }
        return clippedImage;
    }
View Full Code Here

                }
            }
        } catch (MissingParameterException e) {
            LOGGER.error("loading-param-failure",
                "newWidth, scaleMode, canScaleLarger");
            throw new ToolException(e);
        }

        return super.process(images, params);
    }
View Full Code Here

                    scaledImage = JAI.create("scale",
                        createParams,
                        RENDERING_HINTS);
                } catch (Exception e) {
                    LOGGER.error("jai-operation-failure", "scale");
                    throw new ToolException(e);
                }

                // If the scaling enlarges the image we must crop off the
                // border extension. Reducing the size of the image
                // automatically gets rid of the border extension.
                if (factor > 1.0) {
                    ParameterBlock cropParams = new ParameterBlock();
                    cropParams.addSource(scaledImage);
                    cropParams.add((float) scaledImage.getMinX());
                    cropParams.add((float) scaledImage.getMinY());
                    cropParams.add((float) scaledImage.getWidth());
                    cropParams.add((float) scaledImage.getHeight());
                    RenderedOp cropped = null;
                    try {
                        cropped = JAI.create("crop", cropParams);
                    } catch (Exception e) {
                        LOGGER.error("jai-operation-failure", "crop");
                        throw new ToolException(e);
                    }
                    scaledImage = cropped;
                }
            } else {
                scaledImage = null;
View Full Code Here

TOP

Related Classes of com.volantis.map.ics.imageprocessor.tool.ToolException

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.