Package com.volantis.map.ics.imageprocessor.writer

Examples of com.volantis.map.ics.imageprocessor.writer.ImageWriter


        // if there is no destination rule in parameter block it means
        // that we should just pass the input into output.
        if (params.containsName(ParameterNames.DESTINATION_FORMAT_RULE)) {
           // ImageReader reader = null;
            ImageWriter writer = null;
            Pipeline pipeline = null;

            String rule = null;
            try {
                rule = params.getParameterValue(ParameterNames.DESTINATION_FORMAT_RULE);
                writer = theImageWriterFactory.
                    getWriter(rule, params);
            } catch (Exception e) {
                LOGGER.error("instantiating-error",
                        new String[] { "image writer", rule });
                throw new ImageProcessorException(e);
            }
            if (writer == null) {
                String msg = EXCEPTION_LOCALIZER.format("instantiating-error",
                        new String[] { "image writer", rule });
                throw new ImageProcessorException(msg);
            }

            try {
                // Build up processing pipeline.
                pipeline = new Pipeline();

                //Add cropping tool. when there are
                //all needed parameters, otherwise
                // tool will not be used
                if (params.containsName(ParameterNames.LEFT_X) &&
                    params.containsName(ParameterNames.RIGHT_X) &&
                    params.containsName(ParameterNames.BOTTOM_Y) &&
                    params.containsName(ParameterNames.TOP_Y)) {
                    Tool croppingTool =
                        theToolFactory.getTool("CroppingTool");
                    pipeline.addTool(croppingTool);
                }


                // We should guarantee that all other tools works
                // with RGB(A) images. However we have an optimized path for
                // writing Indexed images as GIFs. The RGB converter tool won't
                // do anything in that case unless watermarking is required in
                // which case we take the slow route.
                pipeline.addTool(theToolFactory.getTool("RGBConverterTool"));

                // Add clipping tool if it is needed.
                if (params.containsName(ParameterNames.PRESERVE_X_LEFT) ||
                    params.containsName(ParameterNames.PRESERVE_X_RIGHT)) {
                    Tool clippingTool =
                        theToolFactory.getTool("ClippingTool");
                    pipeline.addTool(clippingTool);
                }

                // Add resizing tool if it is needed.
                if (params.containsName(ParameterNames.IMAGE_WIDTH)) {
                    Tool resizingTool =
                        theToolFactory.getTool("ResizingTool");
                    pipeline.addTool(resizingTool);
                }

               
                //Add watermarking tool.
                if (params.containsName(ParameterNames.WATERMARK_URL)) {
                    Tool watermarkingTool =
                        theToolFactory.getTool("WatermarkingTool");
                    pipeline.addTool(watermarkingTool);
                }

                RenderedOp[] ops = null;
                ops = ImageReader.loadImage(inputData);

                // hack to get around incorrect behaviour associated with
                // the scale operation vbm.2004121009
                // if source has an indexed colour model and has a
                // transparency which is not OPAQUE and has an Alpha then
                // switch back to nearest neighbour interpolation for the
                // scaling.
                if (ops.length > 0)
                {
                    ColorModel colorModel = ops[0].getColorModel();
                    if (colorModel.hasAlpha() && colorModel.getTransparency()
                                                 != ColorModel.OPAQUE) {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug("Resetting scale mode to " +
                                         "SCALE_MODE_NEAREST");
                        }
                        params.setParameterValue(
                            ParameterNames.SCALE_MODE,
                            Integer.toString(ImageConstants.SCALE_MODE_NEAREST));
                    }
                }

                // Run the pipeline and process images.
                ops = pipeline.process(ops, params);

                // Write images into chosen format.
                    outputData.mark();
                outputData = writer.process(ops, params, outputData);
            } catch (Exception e) {
                LOGGER.error("processor-failure");
                throw new ImageProcessorException(e);
            }
        } else {
View Full Code Here

TOP

Related Classes of com.volantis.map.ics.imageprocessor.writer.ImageWriter

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.