Java Code Examples for java.awt.RenderingHints.VALUE_COLOR_RENDER_QUALITY

The following are Jave code examples for showing how to use VALUE_COLOR_RENDER_QUALITY of the java.awt.RenderingHints class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: OpenJSharp   File: ColorConvertOp.java   Source Code and License Vote up 6 votes
/**
 * Copy a source raster to a destination raster, performing a colorspace
 * conversion between the two.  The conversion will respect the
 * KEY_COLOR_RENDERING rendering hint if one is present.
 * 
 * @param src The source raster.
 * @param scs The colorspace of the source raster.
 * @dst The destination raster.
 * @dcs The colorspace of the destination raster.
 */
private void copyraster(Raster src, ColorSpace scs, WritableRaster dst, ColorSpace dcs)
{
  float[] sbuf = new float[src.getNumBands()];
  
  if (hints != null
      && hints.get(RenderingHints.KEY_COLOR_RENDERING) ==
               RenderingHints.VALUE_COLOR_RENDER_QUALITY)
  {
    // use cie for accuracy
    for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++)
      for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++)
        dst.setPixel(x, y,
       dcs.fromCIEXYZ(scs.toCIEXYZ(src.getPixel(x, y, sbuf))));
  }
  else
  {
    // use rgb - it's probably faster
    for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++)
      for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++)
        dst.setPixel(x, y,
       dcs.fromRGB(scs.toRGB(src.getPixel(x, y, sbuf))));
  }
}