Example usage for java.awt RenderingHints KEY_RENDERING

List of usage examples for java.awt RenderingHints KEY_RENDERING

Introduction

In this page you can find the example usage for java.awt RenderingHints KEY_RENDERING.

Prototype

Key KEY_RENDERING

To view the source code for java.awt RenderingHints KEY_RENDERING.

Click Source Link

Document

Rendering hint key.

Usage

From source file:com.fluidops.iwb.deepzoom.ImageLoader.java

private void generateIDCard(URI uri, Map<URI, Set<Value>> facets, String url, File file) {
    int width = 200;
    int height = 200;

    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    Graphics2D ig2 = bi.createGraphics();
    ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    ig2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    /* Special ID card handling for certain entity types */

    /*  TODO: special images based on type
    if(facets.containsKey(RDF.TYPE)) {/*  w  w w .  j ava  2s .  c o  m*/
    Set<Value> facet = facets.get(RDF.TYPE);
            
    for(Value v : facet)
    {
        if(v.equals(Vocabulary.DCAT_DATASET))
        {
            
            Image img = null;
            try
            {
                img = ImageIO.read( new File( "webapps/ROOT/images/rdf.jpg" ) );
            }
            catch (MalformedURLException e)
            {
                logger.error(e.getMessage(), e);
            }
            catch (IOException e)
            {
                logger.error("Could not get image");
            }
            
            ig2.drawImage( img, 0, 0, null );        
            break;
        }
    }
    } */

    String label = EndpointImpl.api().getDataManager().getLabel(uri);
    Font font = new Font(Font.SANS_SERIF, Font.BOLD, 20);
    ig2.setFont(font);

    FontMetrics fontMetrics = ig2.getFontMetrics();
    int labelwidth = fontMetrics.stringWidth(label);
    if (labelwidth >= width) {
        int fontsize = 20 * width / labelwidth;
        font = new Font(Font.SANS_SERIF, Font.BOLD, fontsize);
        ig2.setFont(font);
        fontMetrics = ig2.getFontMetrics();
    }

    int x = (width - fontMetrics.stringWidth(label)) / 2;
    int y = (fontMetrics.getAscent() + (height - (fontMetrics.getAscent() + fontMetrics.getDescent())) / 2);

    ig2.setPaint(Color.black);

    ig2.drawString(label, x, y);

    BufferedOutputStream out;
    try {
        out = new BufferedOutputStream(new FileOutputStream(file));
        ImageIO.write(bi, "PNG", out);
        out.flush();
        out.close();

    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphPanel.java

/**
 * Paints the panel component/*from   w  w w  .jav  a  2 s .  c  om*/
 *
 * @param g The Graphics
 */
@Override
protected void paintComponent(java.awt.Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    DrawGraph(g2, graphEx.GetGraphNodes());
}

From source file:net.pms.util.GenericIcons.java

/**
 * Add the format(container) name of the media to the generic icon image.
 *
 * @param image BufferdImage to be the label added
 * @param label the media container name to be added as a label
 * @param renderer the renderer configuration
 *
 * @return the generic icon with the container label added and scaled in accordance with renderer setting
 */// w  w w  .j  ava 2s.  co m
private DLNAThumbnail addFormatLabelToImage(String label, ImageFormat imageFormat, IconType iconType)
        throws IOException {

    BufferedImage image;
    switch (iconType) {
    case AUDIO:
        image = genericAudioIcon;
        break;
    case IMAGE:
        image = genericImageIcon;
        break;
    case VIDEO:
        image = genericVideoIcon;
        break;
    default:
        image = genericUnknownIcon;
    }

    if (image != null) {
        // Make a copy
        ColorModel colorModel = image.getColorModel();
        image = new BufferedImage(colorModel, image.copyData(null), colorModel.isAlphaPremultiplied(), null);
    }

    ByteArrayOutputStream out = null;

    if (label != null && image != null) {
        out = new ByteArrayOutputStream();
        Graphics2D g = image.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

        try {
            int size = 40;
            Font font = new Font(Font.SANS_SERIF, Font.BOLD, size);
            FontMetrics metrics = g.getFontMetrics(font);
            while (size > 7 && metrics.stringWidth(label) > 135) {
                size--;
                font = new Font(Font.SANS_SERIF, Font.BOLD, size);
                metrics = g.getFontMetrics(font);
            }
            // Text center point 127x, 49y - calculate centering coordinates
            int x = 127 - metrics.stringWidth(label) / 2;
            int y = 46 + metrics.getAscent() / 2;
            g.drawImage(image, 0, 0, null);
            g.setColor(Color.WHITE);
            g.setFont(font);
            g.drawString(label, x, y);

            ImageIO.setUseCache(false);
            ImageIOTools.imageIOWrite(image, imageFormat.toString(), out);
        } finally {
            g.dispose();
        }
    }
    return out != null ? DLNAThumbnail.toThumbnail(out.toByteArray(), 0, 0, ScaleType.MAX, imageFormat, false)
            : null;
}

From source file:org.forumj.web.servlet.post.SetAvatar.java

private BufferedImage renderImage(ImageSize destSize, int imgType, Image image) {
    BufferedImage thumbsImage = new BufferedImage(destSize.getWidth(), destSize.getHeight(), imgType);
    Graphics2D graphics2D = thumbsImage.createGraphics();
    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics2D.drawImage(image, 0, 0, destSize.getWidth(), destSize.getHeight(), null);
    return thumbsImage;
}

From source file:com.kahlon.guard.controller.PersonImageManager.java

private BufferedImage resizeImageWithHint(BufferedImage originalImage, int type) {

    BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
    Graphics2D g = resizedImage.createGraphics();
    g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
    g.dispose();//from   w  ww. jav a  2  s  .  c om
    g.setComposite(AlphaComposite.Src);

    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    return resizedImage;
}

From source file:ch.entwine.weblounge.preview.jai.JAIPreviewGenerator.java

/**
 * Resizes the given image to what is defined by the image style and writes
 * the result to the output stream.//from w  w  w  . j a  va2  s .  c o m
 * 
 * @param is
 *          the input stream
 * @param os
 *          the output stream
 * @param format
 *          the image format
 * @param style
 *          the style
 * @throws IllegalArgumentException
 *           if the image is in an unsupported format
 * @throws IllegalArgumentException
 *           if the input stream is empty
 * @throws IOException
 *           if reading from or writing to the stream fails
 * @throws OutOfMemoryError
 *           if the image is too large to be processed in memory
 */
private void style(InputStream is, OutputStream os, String format, ImageStyle style)
        throws IllegalArgumentException, IOException, OutOfMemoryError {

    // Does the input stream contain any data?
    if (is.available() == 0)
        throw new IllegalArgumentException("Empty input stream was passed to image styling");

    // Do we need to do any work at all?
    if (style == null || ImageScalingMode.None.equals(style.getScalingMode())) {
        logger.trace("No scaling needed, performing a noop stream copy");
        IOUtils.copy(is, os);
        return;
    }

    SeekableStream seekableInputStream = null;
    RenderedOp image = null;
    try {
        // Load the image from the given input stream
        seekableInputStream = new FileCacheSeekableStream(is);
        image = JAI.create("stream", seekableInputStream);
        if (image == null)
            throw new IOException("Error reading image from input stream");

        // Get the original image size
        int imageWidth = image.getWidth();
        int imageHeight = image.getHeight();

        // Resizing
        float scale = ImageStyleUtils.getScale(imageWidth, imageHeight, style);

        RenderingHints scaleHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        scaleHints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
        scaleHints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        scaleHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

        int scaledWidth = Math.round(scale * image.getWidth());
        int scaledHeight = Math.round(scale * image.getHeight());
        int cropX = 0;
        int cropY = 0;

        // If either one of scaledWidth or scaledHeight is < 1.0, then
        // the scale needs to be adapted to scale to 1.0 exactly and accomplish
        // the rest by cropping.

        if (scaledWidth < 1.0f) {
            scale = 1.0f / imageWidth;
            scaledWidth = 1;
            cropY = imageHeight - scaledHeight;
            scaledHeight = Math.round(imageHeight * scale);
        } else if (scaledHeight < 1.0f) {
            scale = 1.0f / imageHeight;
            scaledHeight = 1;
            cropX = imageWidth - scaledWidth;
            scaledWidth = Math.round(imageWidth * scale);
        }

        if (scale > 1.0) {
            ParameterBlock scaleParams = new ParameterBlock();
            scaleParams.addSource(image);
            scaleParams.add(scale).add(scale).add(0.0f).add(0.0f);
            scaleParams.add(Interpolation.getInstance(Interpolation.INTERP_BICUBIC_2));
            image = JAI.create("scale", scaleParams, scaleHints);
        } else if (scale < 1.0) {
            ParameterBlock subsampleAverageParams = new ParameterBlock();
            subsampleAverageParams.addSource(image);
            subsampleAverageParams.add(Double.valueOf(scale));
            subsampleAverageParams.add(Double.valueOf(scale));
            image = JAI.create("subsampleaverage", subsampleAverageParams, scaleHints);
        }

        // Cropping
        cropX = (int) Math.max(cropX,
                (float) Math.ceil(ImageStyleUtils.getCropX(scaledWidth, scaledHeight, style)));
        cropY = (int) Math.max(cropY,
                (float) Math.ceil(ImageStyleUtils.getCropY(scaledWidth, scaledHeight, style)));

        if ((cropX > 0 && Math.floor(cropX / 2.0f) > 0) || (cropY > 0 && Math.floor(cropY / 2.0f) > 0)) {

            ParameterBlock cropTopLeftParams = new ParameterBlock();
            cropTopLeftParams.addSource(image);
            cropTopLeftParams.add(cropX > 0 ? ((float) Math.floor(cropX / 2.0f)) : 0.0f);
            cropTopLeftParams.add(cropY > 0 ? ((float) Math.floor(cropY / 2.0f)) : 0.0f);
            cropTopLeftParams.add(scaledWidth - Math.max(cropX, 0.0f)); // width
            cropTopLeftParams.add(scaledHeight - Math.max(cropY, 0.0f)); // height

            RenderingHints croppingHints = new RenderingHints(JAI.KEY_BORDER_EXTENDER,
                    BorderExtender.createInstance(BorderExtender.BORDER_COPY));

            image = JAI.create("crop", cropTopLeftParams, croppingHints);
        }

        // Write resized/cropped image encoded as JPEG to the output stream
        ParameterBlock encodeParams = new ParameterBlock();
        encodeParams.addSource(image);
        encodeParams.add(os);
        encodeParams.add("jpeg");
        JAI.create("encode", encodeParams);

    } catch (Throwable t) {
        if (t.getClass().getName().contains("ImageFormat")) {
            throw new IllegalArgumentException(t.getMessage());
        }
    } finally {
        IOUtils.closeQuietly(seekableInputStream);
        if (image != null)
            image.dispose();
    }
}

From source file:com.fengduo.bee.service.impl.file.FileServiceImpl.java

/**
 * ?//from  ww w. jav a2s .c  o m
 * 
 * @param source
 * @param targetW
 * @param targetH
 * @param ifScaling ?
 * @return
 */
public static BufferedImage resize(BufferedImage source, int targetW, int targetH, boolean ifScaling) {
    // targetWtargetH
    int type = source.getType();
    BufferedImage target = null;
    double sx = (double) targetW / source.getWidth();
    double sy = (double) targetH / source.getHeight();
    // targetWtargetH??,?if else???
    if (ifScaling) {
        if (sx > sy) {
            sx = sy;
            targetW = (int) (sx * source.getWidth());
        } else {
            sy = sx;
            targetH = (int) (sy * source.getHeight());
        }
    }
    if (type == BufferedImage.TYPE_CUSTOM) { // handmade
        ColorModel cm = source.getColorModel();
        WritableRaster raster = cm.createCompatibleWritableRaster(targetW, targetH);
        boolean alphaPremultiplied = cm.isAlphaPremultiplied();
        target = new BufferedImage(cm, raster, alphaPremultiplied, null);
    } else
        target = new BufferedImage(targetW, targetH, type);
    Graphics2D g = target.createGraphics();
    // smoother than exlax:
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.drawRenderedImage(source, AffineTransform.getScaleInstance(sx, sy));
    g.dispose();
    return target;
}

From source file:org.polymap.core.data.feature.FeatureRenderProcessor2.java

protected Image getMap(final Set<ILayer> layers, int width, int height, final ReferencedEnvelope bbox) {
    //        Logger wfsLog = Logging.getLogger( "org.geotools.data.wfs.protocol.http" );
    //        wfsLog.setLevel( Level.FINEST );

    // mapContext
    MapContext mapContext = mapContextRef.get(new Supplier<MapContext>() {
        public MapContext get() {
            log.debug("Creating new MapContext... ");
            // sort z-priority
            TreeMap<String, ILayer> sortedLayers = new TreeMap();
            for (ILayer layer : layers) {
                String uniqueOrderKey = String.valueOf(layer.getOrderKey()) + layer.id();
                sortedLayers.put(uniqueOrderKey, layer);
            }//from ww  w .j  a  va  2 s .com
            // add to mapContext
            MapContext result = new DefaultMapContext(bbox.getCoordinateReferenceSystem());
            for (ILayer layer : sortedLayers.values()) {
                try {
                    FeatureSource fs = PipelineFeatureSource.forLayer(layer, false);
                    log.debug("        FeatureSource: " + fs);
                    log.debug("            fs.getName(): " + fs.getName());

                    Style style = layer.getStyle().resolve(Style.class, null);
                    if (style == null) {
                        log.warn("            fs.getName(): " + fs.getName());
                        style = new DefaultStyles().findStyle(fs);
                    }
                    result.addLayer(fs, style);

                    // watch layer for style changes
                    LayerStyleListener listener = new LayerStyleListener(mapContextRef);
                    if (watchedLayers.putIfAbsent(layer, listener) == null) {
                        layer.addPropertyChangeListener(listener);
                    }
                } catch (IOException e) {
                    log.warn(e);
                    // FIXME set layer status and statusMessage
                } catch (PipelineIncubationException e) {
                    log.warn("No pipeline.", e);
                }
            }
            log.debug("created: " + result);
            return result;
        }
    });
    log.debug("using: " + mapContext);

    // render
    //        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    //        GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    //        VolatileImage result = gc.createCompatibleVolatileImage( width, height, Transparency.TRANSLUCENT );

    BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    result.setAccelerationPriority(1);

    final Graphics2D g = result.createGraphics();
    //        log.info( "IMAGE: accelerated=" + result.getCapabilities( g.getDeviceConfiguration() ).isAccelerated() );

    try {
        final StreamingRenderer renderer = new StreamingRenderer();

        // rendering hints
        RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING,
                RenderingHints.VALUE_RENDER_SPEED);
        hints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
        hints.add(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON));

        renderer.setJava2DHints(hints);
        //            g.setRenderingHints( hints );

        // error handler
        renderer.addRenderListener(new RenderListener() {
            int featureCount = 0;

            @Override
            public void featureRenderer(SimpleFeature feature) {
                //                  if (++featureCount == 100) {
                //                      log.info( "Switch off antialiasing!" );
                //                      RenderingHints off = new RenderingHints(
                //                              RenderingHints.KEY_ANTIALIASING,
                //                              RenderingHints.VALUE_ANTIALIAS_OFF );
                //                      renderer.setJava2DHints( off );
                //                      g.setRenderingHints( off );
                //                  }
            }

            @Override
            public void errorOccurred(Exception e) {
                log.error("Renderer error: ", e);
                drawErrorMsg(g, "Fehler bei der Darstellung.", e);
            }
        });

        // render params
        Map rendererParams = new HashMap();
        rendererParams.put("optimizedDataLoadingEnabled", Boolean.TRUE);
        renderer.setRendererHints(rendererParams);

        renderer.setContext(mapContext);
        Rectangle paintArea = new Rectangle(width, height);
        renderer.paint(g, paintArea, bbox);
        return result;
    } catch (Throwable e) {
        log.error("Renderer error: ", e);
        drawErrorMsg(g, null, e);
        return result;
    } finally {
        if (g != null) {
            g.dispose();
        }
    }
}

From source file:org.apache.fop.render.bitmap.AbstractBitmapDocumentHandler.java

/** {@inheritDoc} */
public IFPainter startPageContent() throws IFException {
    int bitmapWidth;
    int bitmapHeight;
    double scale;
    Point2D offset = null;/*from  w  w w .j  av a 2 s  .c o  m*/
    if (targetBitmapSize != null) {
        //Fit the generated page proportionally into the given rectangle (in pixels)
        double scale2w = 1000 * targetBitmapSize.width / this.currentPageDimensions.getWidth();
        double scale2h = 1000 * targetBitmapSize.height / this.currentPageDimensions.getHeight();
        bitmapWidth = targetBitmapSize.width;
        bitmapHeight = targetBitmapSize.height;

        //Centering the page in the given bitmap
        offset = new Point2D.Double();
        if (scale2w < scale2h) {
            scale = scale2w;
            double h = this.currentPageDimensions.height * scale / 1000;
            offset.setLocation(0, (bitmapHeight - h) / 2.0);
        } else {
            scale = scale2h;
            double w = this.currentPageDimensions.width * scale / 1000;
            offset.setLocation((bitmapWidth - w) / 2.0, 0);
        }
    } else {
        //Normal case: just scale according to the target resolution
        scale = scaleFactor * getUserAgent().getTargetResolution()
                / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION;
        bitmapWidth = (int) ((this.currentPageDimensions.width * scale / 1000f) + 0.5f);
        bitmapHeight = (int) ((this.currentPageDimensions.height * scale / 1000f) + 0.5f);
    }

    //Set up bitmap to paint on
    this.currentImage = createBufferedImage(bitmapWidth, bitmapHeight);
    Graphics2D graphics2D = this.currentImage.createGraphics();

    // draw page background
    if (!getSettings().hasTransparentPageBackground()) {
        graphics2D.setBackground(getSettings().getPageBackgroundColor());
        graphics2D.setPaint(getSettings().getPageBackgroundColor());
        graphics2D.fillRect(0, 0, bitmapWidth, bitmapHeight);
    }

    //Set rendering hints
    graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
            RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    if (getSettings().isAntiAliasingEnabled() && this.currentImage.getColorModel().getPixelSize() > 1) {
        graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    } else {
        graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
        graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    }
    if (getSettings().isQualityRenderingEnabled()) {
        graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    } else {
        graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    }
    graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);

    //Set up initial coordinate system for the page
    if (offset != null) {
        graphics2D.translate(offset.getX(), offset.getY());
    }
    graphics2D.scale(scale / 1000f, scale / 1000f);

    return new Java2DPainter(graphics2D, getContext(), getFontInfo());
}

From source file:springapp.web.controller.theme.ProcessThemeController.java

public ModelAndView handleRequest(HttpServletRequest httpServletRequest,
        HttpServletResponse httpServletResponse) throws Exception {
    HttpSession session = httpServletRequest.getSession();

    String templateIdString = httpServletRequest.getParameter(ApplicationConstants.TEMPLATE_ID);
    byte templateId = 0;

    int oldColor = 0;
    int newColor = 0;
    int oldHeaderColor = 0;
    int newHeaderColor = 0;
    int oldBgColor = 0;
    int newBgColor = 0;
    int oldFontColor = 0;
    int newFontColor = 0;
    int oldHeaderFontColor = 0;
    int newHeaderFontColor = 0;
    int oldBorderColor = 0;
    int newBorderColor = 0;
    int oldTransp = 0;
    int newTransp = 0;
    byte sizeHeaderFontDiff = 11;
    byte sizeFontDiff = 11;

    ThemeParametersHolder themeParametersHolder = null;
    String toolsetName = httpServletRequest.getParameter(ApplicationConstants.TOOLSET_NAME);

    String versionString = httpServletRequest.getParameter(ApplicationConstants.VERSION);
    String version = (null == versionString) ? ApplicationConstants.DEFAULT_EXTJS_VERSION : versionString;
    String familyHeaderFont = httpServletRequest.getParameter(ApplicationConstants.FAMILY_HEADER_FONT);
    String familyFont = httpServletRequest.getParameter(ApplicationConstants.FAMILY_FONT);
    String weightHeaderFont = httpServletRequest.getParameter(ApplicationConstants.WEIGHT_HEADER_FONT);
    String weightFont = httpServletRequest.getParameter(ApplicationConstants.WEIGHT_FONT);
    try {//from  ww  w.j av a 2  s . co m
        templateId = null != templateIdString ? Byte.parseByte(templateIdString) : 0;

        String oldColorString = (0 == templateId) ? "#DFE8F6" : "#F1F1F1";
        String newColorString = httpServletRequest.getParameter(ApplicationConstants.NEW_COLOR);

        String oldHeaderColorString = (0 == templateId) ? "#CDDEF3" : "#D7D7D7";
        String newHeaderColorString = httpServletRequest.getParameter(ApplicationConstants.NEW_HEADER_COLOR);

        String oldBgColorString = "#FFFFFF";
        String newBgColorString = httpServletRequest.getParameter(ApplicationConstants.NEW_BG_COLOR);

        String oldFontColorString = "#000000";
        String newFontColorString = httpServletRequest.getParameter(ApplicationConstants.NEW_FONT_COLOR);

        String oldHeaderFontColorString = (0 == templateId) ? "#15428B" : "#222222";
        String newHeaderFontColorString = httpServletRequest
                .getParameter(ApplicationConstants.NEW_HEADER_FONT_COLOR);

        String sizeHeaderFontString = httpServletRequest.getParameter(ApplicationConstants.SIZE_HEADER_FONT);

        String sizeFontString = httpServletRequest.getParameter(ApplicationConstants.SIZE_FONT);

        String oldBorderColorString = (0 == templateId) ? "#99BBE8" : "#D0D0D0";
        String newBorderColorString = httpServletRequest.getParameter(ApplicationConstants.NEW_BORDER_COLOR);

        String oldTranspString = "255";
        String newTranspString = httpServletRequest.getParameter(ApplicationConstants.NEW_TRANSP);

        themeParametersHolder = new ThemeParametersHolder(templateIdString, newColorString,
                newHeaderColorString, newBgColorString, newFontColorString, newHeaderFontColorString,
                familyHeaderFont, weightHeaderFont, sizeHeaderFontString, familyFont, weightFont,
                sizeFontString, newBorderColorString, newTranspString, toolsetName, version);

        oldColor = null != oldColorString ? Integer.parseInt(oldColorString.replaceFirst("#", ""), 16) : 0;
        newColor = null != newColorString ? Integer.parseInt(newColorString.replaceFirst("#", ""), 16) : 0;
        oldHeaderColor = null != oldHeaderColorString
                ? Integer.parseInt(oldHeaderColorString.replaceFirst("#", ""), 16)
                : 0;
        newHeaderColor = null != newHeaderColorString
                ? Integer.parseInt(newHeaderColorString.replaceFirst("#", ""), 16)
                : 0;
        oldBgColor = null != oldBgColorString ? Integer.parseInt(oldBgColorString.replaceFirst("#", ""), 16)
                : 0;
        newBgColor = null != newBgColorString ? Integer.parseInt(newBgColorString.replaceFirst("#", ""), 16)
                : 0;
        oldFontColor = null != oldFontColorString
                ? Integer.parseInt(oldFontColorString.replaceFirst("#", ""), 16)
                : 0;
        newFontColor = null != newFontColorString
                ? Integer.parseInt(newFontColorString.replaceFirst("#", ""), 16)
                : 0;
        oldHeaderFontColor = null != oldHeaderFontColorString
                ? Integer.parseInt(oldHeaderFontColorString.replaceFirst("#", ""), 16)
                : 0;
        newHeaderFontColor = null != newHeaderFontColorString
                ? Integer.parseInt(newHeaderFontColorString.replaceFirst("#", ""), 16)
                : 0;

        oldBorderColor = null != oldBorderColorString
                ? Integer.parseInt(oldBorderColorString.replaceFirst("#", ""), 16)
                : 0;
        newBorderColor = null != newBorderColorString
                ? Integer.parseInt(newBorderColorString.replaceFirst("#", ""), 16)
                : 0;

        oldTransp = null != oldTranspString ? Integer.parseInt(oldTranspString) : 0;
        newTransp = null != newTranspString ? Integer.parseInt(newTranspString) : 0;

        sizeHeaderFontDiff = (byte) ((null != sizeHeaderFontString ? Byte.parseByte(sizeHeaderFontString) : 11)
                - 11);
        sizeFontDiff = (byte) ((null != sizeFontString ? Byte.parseByte(sizeFontString) : 11) - 11);
    } catch (Exception e) {
        logger.error(e);
    }

    int oldR = (oldColor >> 16) & 0xff;
    int oldG = (oldColor >> 8) & 0xff;
    int oldB = oldColor & 0xff;

    int newR = (newColor >> 16) & 0xff;
    int newG = (newColor >> 8) & 0xff;
    int newB = newColor & 0xff;

    int oldHeaderR = (oldHeaderColor >> 16) & 0xff;
    int oldHeaderG = (oldHeaderColor >> 8) & 0xff;
    int oldHeaderB = oldHeaderColor & 0xff;

    int newHeaderR = (newHeaderColor >> 16) & 0xff;
    int newHeaderG = (newHeaderColor >> 8) & 0xff;
    int newHeaderB = newHeaderColor & 0xff;

    int oldBgR = (oldBgColor >> 16) & 0xff;
    int oldBgG = (oldBgColor >> 8) & 0xff;
    int oldBgB = oldBgColor & 0xff;

    int newBgR = (newBgColor >> 16) & 0xff;
    int newBgG = (newBgColor >> 8) & 0xff;
    int newBgB = newBgColor & 0xff;

    int oldFontR = (oldFontColor >> 16) & 0xff;
    int oldFontG = (oldFontColor >> 8) & 0xff;
    int oldFontB = oldFontColor & 0xff;

    int newFontR = (newFontColor >> 16) & 0xff;
    int newFontG = (newFontColor >> 8) & 0xff;
    int newFontB = newFontColor & 0xff;

    int oldHeaderFontR = (oldHeaderFontColor >> 16) & 0xff;
    int oldHeaderFontG = (oldHeaderFontColor >> 8) & 0xff;
    int oldHeaderFontB = oldHeaderFontColor & 0xff;

    int newHeaderFontR = (newHeaderFontColor >> 16) & 0xff;
    int newHeaderFontG = (newHeaderFontColor >> 8) & 0xff;
    int newHeaderFontB = newHeaderFontColor & 0xff;

    int oldBorderR = (oldBorderColor >> 16) & 0xff;
    int oldBorderG = (oldBorderColor >> 8) & 0xff;
    int oldBorderB = oldBorderColor & 0xff;

    int newBorderR = (newBorderColor >> 16) & 0xff;
    int newBorderG = (newBorderColor >> 8) & 0xff;
    int newBorderB = newBorderColor & 0xff;

    ServletContext servletContext = session.getServletContext();
    WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);

    ResourcesProcessorFactory resourcesProcessorFactory = (ResourcesProcessorFactory) context
            .getBean("processorFactory");

    ResourcesHolder schemaHolder;
    ResourcesProcessor processor;
    /*        schemaHolder = getResourcesHolderForProcessing(templateId, "");
            processor = resourcesProcessorFactory.getResourcesProcessor(schemaHolder, context);*/

    //operation definition
    //hints
    HashMap hints = new HashMap();
    hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    hints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
    hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    hints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);

    RenderingHints renderingHints = new RenderingHints(hints);

    int rDiff = newR - oldR;
    int gDiff = newG - oldG;
    int bDiff = newB - oldB;
    int rHeaderDiff = newHeaderR - oldHeaderR;
    int gHeaderDiff = newHeaderG - oldHeaderG;
    int bHeaderDiff = newHeaderB - oldHeaderB;
    int rBgDiff = newBgR - oldBgR;
    int gBgDiff = newBgG - oldBgG;
    int bBgDiff = newBgB - oldBgB;
    int rFontDiff = newFontR - oldFontR;
    int gFontDiff = newFontG - oldFontG;
    int bFontDiff = newFontB - oldFontB;
    int rHeaderFontDiff = newHeaderFontR - oldHeaderFontR;
    int gHeaderFontDiff = newHeaderFontG - oldHeaderFontG;
    int bHeaderFontDiff = newHeaderFontB - oldHeaderFontB;

    int rBorderDiff = newBorderR - oldBorderR;
    int gBorderDiff = newBorderG - oldBorderG;
    int bBorderDiff = newBorderB - oldBorderB;

    float transparencyDiff = newTransp - oldTransp;

    float[] offsets = { rDiff, gDiff, bDiff, 0f };
    float[] offsetsHeader = { rHeaderDiff, gHeaderDiff, bHeaderDiff, 0f };
    float[] offsetsBg = { rBgDiff, gBgDiff, bBgDiff, 0f };
    float[] offsetsFont = { rFontDiff, gFontDiff, bFontDiff, 0f };
    float[] offsetsHeaderFont = { rHeaderFontDiff, gHeaderFontDiff, bHeaderFontDiff, 0f };
    float[] offsetsBorder = { rBorderDiff, gBorderDiff, bBorderDiff, 0f };
    float[] offsetsTranceparency = (0 == transparencyDiff) ? null : new float[] { 0, 0, 0, transparencyDiff };
    float[] offsetsShadowTransparency = { 0, 0, 0, transparencyDiff / 5 };

    float liteDivider = 2.5f;
    float[] liteoffsets = { rDiff / liteDivider, gDiff / liteDivider, bDiff / liteDivider, 0f };
    float[] scaleFactors = { 1.0f, 1.0f, 1.0f, 1.0f };
    ExtJSRescaleOp brightenOp = new ExtJSRescaleOp(scaleFactors, // 1  ,1   ,1
            offsets, renderingHints);

    ExtJSRescaleOp headerOp = new ExtJSRescaleOp(scaleFactors, // 1  ,1   ,1
            offsetsHeader, renderingHints);

    ExtJSRescaleOp liteOp = new ExtJSRescaleOp(scaleFactors, // 1  ,1   ,1
            liteoffsets, renderingHints);

    ExtJSRescaleOp bgOp = new ExtJSRescaleOp(scaleFactors, // 1  ,1   ,1
            offsetsBg, renderingHints);

    ExtJSRescaleOp fontOp = new ExtJSRescaleOp(scaleFactors, // 1  ,1   ,1
            offsetsFont, renderingHints);

    ExtJSRescaleOp headerFontOp = new ExtJSRescaleOp(scaleFactors, // 1  ,1   ,1
            offsetsHeaderFont, renderingHints);

    ExtJSRescaleOp borderOp = new ExtJSRescaleOp(scaleFactors, // 1  ,1   ,1
            offsetsBorder, renderingHints);

    ExtJSRescaleOp transparencyOp = (0 == transparencyDiff) ? null
            : new ExtJSRescaleOp(scaleFactors, // 1  ,1   ,1
                    offsetsTranceparency, renderingHints);

    ExtJSRescaleOp shadowTransparencyOp = null/*new ExtJSRescaleOp(
                                              scaleFactors,// 1  ,1   ,1
                                              offsetsShadowTransparency,
                                              renderingHints)*/;

    /*
            ShiftOp shiftOp = new ShiftOp(new float[]{1, 1, 1, 1}
        , offsets, renderingHints, true);
            
            int csRGB = ColorSpace.CS_sRGB;
            int csGRAY = ColorSpace.CS_GRAY;
            ColorSpace srcCS = ColorSpace.getInstance(csRGB);
            
            ColorSpace destCS = ColorSpace.getInstance(csGRAY);
    */
    //operation with inversion of color #for heading font color
    ForegroundShiftOp foregroundOp = new ForegroundShiftOp(newR, newG, newB);

    AffineTransformOp affineTransformOp = null/*new AffineTransformOp(
                                              AffineTransform.getScaleInstance(2,2), AffineTransformOp.TYPE_BICUBIC)*/;
    //end operation  definition

    //get toolset holder
    ResourceHolderPool holderToolsetPool = this.holderToolsetPool;
    ResourcesHolder toolsetSchemaHolder = holderToolsetPool.checkOut();
    //
    //get drawable holder
    ResourceHolderPool holderDrawablePool = this.holderDrawablePool;
    ResourcesHolder drawableSchemaHolder = holderDrawablePool.checkOut();
    //
    /*        process(processor, templateId, schemaHolder, brightenOp, foregroundOp, liteOp, bgOp,
        fontOp, transparencyOp, session, borderOp, affineTransformOp, headerFontOp,
        shadowTransparencyOp, headerOp, toolsetSchemaHolder,
        toolsetName, familyHeaderFont, weightHeaderFont, sizeHeaderFontDiff,
        familyFont, weightFont, sizeFontDiff,
        drawableSchemaHolder, "3.2"*//*version*//*);
                                                 if (!"3.2".equals(version)){*/
    schemaHolder = getResourcesHolderForProcessing(templateId, version);
    processor = resourcesProcessorFactory.getResourcesProcessor(schemaHolder, context);
    process(processor, themeParametersHolder, templateId, schemaHolder, brightenOp, foregroundOp, liteOp, bgOp,
            fontOp, transparencyOp, session, borderOp, affineTransformOp, headerFontOp, shadowTransparencyOp,
            headerOp, toolsetSchemaHolder, toolsetName, familyHeaderFont, weightHeaderFont, sizeHeaderFontDiff,
            familyFont, weightFont, sizeFontDiff, drawableSchemaHolder, version);

    /*        }*/

    logger.info("ProcessThemeController ! IP=" + httpServletRequest.getRemoteAddr());

    return new ModelAndView("json/success");
}