Example usage for java.awt RenderingHints RenderingHints

List of usage examples for java.awt RenderingHints RenderingHints

Introduction

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

Prototype

public RenderingHints(Map<Key, ?> init) 

Source Link

Document

Constructs a new object with keys and values initialized from the specified Map object which may be null.

Usage

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   www  . ja  va  2s  .com
        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");
}

From source file:com.salesmanager.core.util.ProductImageUtil.java

public BufferedImage blurImage(BufferedImage image) {
    float ninth = 1.0f / 9.0f;
    float[] blurKernel = { ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth };
    Map<Key, Object> map = new HashMap<Key, Object>();
    map.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    map.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    map.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    RenderingHints hints = new RenderingHints(map);
    BufferedImageOp op = new ConvolveOp(new Kernel(3, 3, blurKernel), ConvolveOp.EDGE_NO_OP, hints);
    return op.filter(image, null);
}

From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java

public void setRenderingHints(Map arg0) {
    renderingHints = new RenderingHints(arg0);
}

From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java

public void addRenderingHints(Map arg0) {
    renderingHints.add(new RenderingHints(arg0));
}

From source file:org.photovault.image.PhotovaultImage.java

protected RenderableOp getCropped(RenderableOp uncroppedImage) {
    float origWidth = uncroppedImage.getWidth();
    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);
    /* //from   ww  w. jav a2s  .  c o  m
     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);
    rotatedImage.setProperty("org.photovault.opname", "rotated_image");
    /*
     Due to rounding errors in JAI pipeline transformations we have a danger 
     that the crop border goes outside image area. To avoind this, create a
     slightly larger background and overlay the actual image in front of it.         
     */
    RenderableOp background = ScaleDescriptor.createRenderable(rotatedImage, 1.01f, 1.01f, 0.0f, 0.0f,
            Interpolation.getInstance(Interpolation.INTERP_BILINEAR), hints);
    RenderableOp overlayed = OverlayDescriptor.createRenderable(background, rotatedImage, hints);

    ParameterBlockJAI cropParams = new ParameterBlockJAI("crop");
    cropParams.addSource(overlayed);
    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). 
            // Make the crop rectangle slightly smaller so that the rounding 
            // error is avoided
            final float correction = 5E-3f;
            if (srcRect.getMinX() > cropRect.getMinX()) {
                cropX += correction;
            }
            if (srcRect.getMinY() > cropRect.getMinY()) {
                cropY += correction;
            }
            if (srcRect.getMaxX() < cropRect.getMaxX()) {
                cropW -= correction;
            }
            if (srcRect.getMaxY() < cropRect.getMaxY()) {
                cropH -= correction;
            }
            cropRect = new Rectangle2D.Float(cropX, cropY, cropW, cropH);
            if (!srcRect.contains(cropRect)) {
                // Hmm, now I am out of ideas...
                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);
    CropDescriptor cdesc = new CropDescriptor();
    StringBuffer msg = new StringBuffer();
    if (!cdesc.validateArguments("renderable", cropParams, msg)) {
        log.error("Error settings up crop operation: " + msg.toString());
    }

    croppedImage = JAI.createRenderable("crop", cropParams, hints);
    // Translate the image so that it begins in origo
    rotatedImage.setProperty("org.photovault.opname", "cropped_image");
    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);
    rotatedImage.setProperty("org.photovault.opname", "xlated_image");
    return xformCroppedImage;
}

From source file:DefaultGraphics2D.java

/**
 * Replaces the values of all preferences for the rendering algorithms with
 * the specified <code>hints</code>. The existing values for all rendering
 * hints are discarded and the new set of known hints and values are
 * initialized from the specified {@link Map} object. Hint categories include
 * controls for rendering quality and overall time/quality trade-off in the
 * rendering process. Refer to the <code>RenderingHints</code> class for
 * definitions of some common keys and values.
 * /*www  .  j a  v a2s.c o  m*/
 * @param hints
 *          the rendering hints to be set
 * @see RenderingHints
 */
public void setRenderingHints(Map hints) {
    this.hints = new RenderingHints(hints);
}