Java Code Examples for java.awt.image.BufferedImage.isAlphaPremultiplied()

The following are Jave code examples for showing how to use isAlphaPremultiplied() of the java.awt.image.BufferedImage class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: VASSAL-src   File: GeneralFilter.java   View Source Code Vote up 6 votes
/**
 * Filters the entire source image.
 *
 * This is a convenience function which calls
 * {@link zoom(WritableRaster, Rectangle, BufferedImage, Filter)},
 * setting the destination rectangle as the bounds of the destination
 * tile.
 *
 * @param dst the destination rectangle
 * @param src the soure image
 * @param filter the filter to apply
 * @throws ClassCastException if <code>src</code> does not store its data
 * in a {@link DataBufferInt}
 */
public static BufferedImage zoom(
  Rectangle dst, BufferedImage src, final Filter filter) {

  final WritableRaster dstR =
    src.getColorModel().createCompatibleWritableRaster(dst.width, dst.height);
  zoom(dstR, dstR.getBounds(), src, filter);

  // FIXME: check whether this affects hardware acceleration
  return new BufferedImage(
    src.getColorModel(),
    dstR,
    src.isAlphaPremultiplied(),
    null
  );
}
 
Example 2
Project: Image-Stegano   File: ImageUtility.java   View Source Code Vote up 6 votes
/**
 * we don't want to alter original image (actually converted image)
 * since we need this each time for reference
 * @param coverImage original carrier/cover image
 * @return a copy of supplied image
 */
public BufferedImage copyImage(BufferedImage coverImage) {
    ColorModel colorModel = coverImage.getColorModel();
    boolean isAlphaPremultiplied = coverImage.isAlphaPremultiplied();
    WritableRaster raster = coverImage.copyData(null);
    BufferedImage newImage = new BufferedImage(colorModel, raster,
            isAlphaPremultiplied, null);
    return newImage;
}
 
Example 3
Project: Image-Stegano   File: ColourMap.java   View Source Code Vote up 5 votes
public BufferedImage changeColourMap(BufferedImage userSpaceImage, 
        IndexColorModel customIndexColorModel) {
    ColorModel originalCM = userSpaceImage.getColorModel();
    if (originalCM instanceof IndexColorModel) {
        boolean isAlphaPremultiplied = userSpaceImage.isAlphaPremultiplied();
        WritableRaster raster = userSpaceImage.copyData(null);
        BufferedImage newImage = new BufferedImage(customIndexColorModel, 
                raster, isAlphaPremultiplied, null);
        return newImage;
    } else {
        return null;
    }
}
 
Example 4
Project: VASSAL-src   File: GeneralFilter.java   View Source Code Vote up 4 votes
/**
 * Filters a portion of the source image.
 *
 * @param dstR the destination tile to calculate
 * @param dst_fr the bounds of the whole destination image
 * @param srcI the source image
 * @param filter the filter to apply
 * @throws ClassCastException if <code>srcI</code> does not store its data
 * in a {@link DataBufferInt}
 */
public static void zoom(
  WritableRaster dstR,
  Rectangle dst_fr,
  BufferedImage srcI,
  final Filter filter)
{
  final int dst_data[] = ((DataBufferInt) dstR.getDataBuffer()).getData();

  final int src_type;
  if (srcI.getTransparency() == BufferedImage.OPAQUE) {
    src_type = OPAQUE;
  }
  else if (srcI.isAlphaPremultiplied()) {
    src_type = TRANS_PREMULT;
  }
  else {
    src_type = TRANS_UNPREMULT;
  }

  final int dx0 = dstR.getMinX();
  final int dy0 = dstR.getMinY();
  final int dx1 = dx0 + dstR.getWidth() - 1;
  final int dy1 = dy0 + dstR.getHeight() - 1;
  final int dw = dstR.getWidth();
  final int dh = dstR.getHeight();

  final int dstWidth = dst_fr.width;
  final int dstHeight = dst_fr.height;

  final int srcWidth = srcI.getWidth();
  final int srcHeight = srcI.getHeight();

  // We want dstX0 * xscale = srcX0, except when that would make
  // xscale = 0; similarly for yscale.
  final float xscale =
    srcWidth == 1 ? dstWidth : (float)(dstWidth-1) / (srcWidth-1);
  final float yscale =
    srcHeight == 1 ? dstHeight : (float)(dstHeight-1) / (srcHeight-1);

  final float fwidth = filter.getSamplingRadius();

  final int sx0 = Math.max(0, (int) Math.floor((dx0-fwidth)/xscale));
  final int sy0 = Math.max(0, (int) Math.floor((dy0-fwidth)/yscale));
  final int sx1 = Math.min(srcWidth-1, (int) Math.ceil((dx1+fwidth)/xscale));
  final int sy1 = Math.min(srcHeight-1, (int) Math.ceil((dy1+fwidth)/yscale));
  final int sw = sx1 - sx0 + 1;
  final int sh = sy1 - sy0 + 1;

  final int src_data[] =
    ((DataBufferInt) srcI.getRaster().getDataBuffer()).getData();

  resample(
    src_data, false,
    sx0, sy0, sx1, sy1, sw, sh, src_type, srcWidth, srcHeight,
    dst_data, dx0, dy0, dx1, dy1, dw, dh, dstWidth, dstHeight,
    xscale, yscale, filter
  );
}