use of java.awt.image.ColorConvertOp in project jdk8u_jdk by JetBrains.
the class AlphaTest method main.
public static void main(String[] args) {
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorConvertOp op = new ColorConvertOp(cs, null);
// create source image filled with an opaque color
BufferedImage src = createSrc();
int srcAlpha = getAlpha(src);
System.out.printf("Src alpha: 0x%02x\n", srcAlpha);
// create clear (transparent black) destination image
BufferedImage dst = createDst();
int dstAlpha = getAlpha(dst);
System.out.printf("Dst alpha: 0x%02x\n", dstAlpha);
dst = op.filter(src, dst);
dstAlpha = getAlpha(dst);
// we expect that destination image is opaque
// i.e. alpha is transferred from source to
// the destination
System.out.printf("Result alpha: 0x%02x\n", dstAlpha);
if (srcAlpha != dstAlpha) {
throw new RuntimeException("Test failed!");
}
System.out.println("Test passed");
}
use of java.awt.image.ColorConvertOp in project jdk8u_jdk by JetBrains.
the class ColConvDCMTest method testSubImage.
static boolean testSubImage(int x0, int y0, int dx, int dy, int type, int rBits, int gBits, int bBits, int cs, BufferedImage gldImage, double accuracy) {
BufferedImage src = ImageFactory.createDCMImage(type, cs);
BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
BufferedImage dst = ImageFactory.createDstImage(BufferedImage.TYPE_INT_RGB);
BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);
ColorConvertOp op = new ColorConvertOp(null);
op.filter(subSrc, subDst);
ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits, bBits);
boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
if (!result) {
System.err.println(cmp.getStat());
}
return result;
}
use of java.awt.image.ColorConvertOp in project jdk8u_jdk by JetBrains.
the class ColCvtAlpha method main.
public static void main(String[] args) {
BufferedImage src = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);
// Set src pixel values
Color pelColor = new Color(100, 100, 100, 128);
for (int i = 0; i < 10; i++) {
src.setRGB(0, i, pelColor.getRGB());
}
ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] { 8, 8 }, true, src.getColorModel().isAlphaPremultiplied(), Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
SampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, 100, 100, 2, 200, new int[] { 0, 1 });
WritableRaster wr = Raster.createWritableRaster(sm, new Point(0, 0));
BufferedImage dst = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
dst = dst.getSubimage(0, 0, 1, 10);
ColorConvertOp op = new ColorConvertOp(null);
op.filter(src, dst);
for (int i = 0; i < 10; i++) {
if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
throw new RuntimeException("Incorrect destination alpha value.");
}
}
}
use of java.awt.image.ColorConvertOp in project jdk8u_jdk by JetBrains.
the class ColCvtIntARGB method main.
public static void main(String[] args) {
//
// Build a 1 pixel ARGB, non-premultiplied image
//
BufferedImage src = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
// Set src pixel value
Color pelColor = new Color(100, 100, 100, 128);
src.setRGB(0, 0, pelColor.getRGB());
//
// ColorConvertOp filter
//
ColorConvertOp op = new ColorConvertOp(null);
//
// Test ARGB -> ARGB_PRE
//
BufferedImage dst = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE);
op.filter(src, dst);
if (((dst.getRGB(0, 0) >> 24) & 0xff) != 128) {
throw new RuntimeException("Incorrect destination alpha value.");
}
//
// Test ARGB -> ARGB
//
dst = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
op.filter(src, dst);
if (((dst.getRGB(0, 0) >> 24) & 0xff) != 128) {
throw new RuntimeException("Incorrect destination alpha value.");
}
}
use of java.awt.image.ColorConvertOp in project jdk8u_jdk by JetBrains.
the class InvalidRenderIntentTest method main.
public static void main(String[] args) {
ICC_Profile pSRGB = ICC_Profile.getInstance(CS_sRGB);
byte[] raw_data = pSRGB.getData();
setRenderingIntent(0x1000000, raw_data);
ICC_Profile p = ICC_Profile.getInstance(raw_data);
ICC_ColorSpace cs = new ICC_ColorSpace(p);
// perfrom test color conversion
ColorConvertOp op = new ColorConvertOp(cs, ColorSpace.getInstance(CS_sRGB), null);
BufferedImage src = new BufferedImage(1, 1, TYPE_3BYTE_BGR);
BufferedImage dst = new BufferedImage(1, 1, TYPE_3BYTE_BGR);
try {
op.filter(src.getRaster(), dst.getRaster());
} catch (CMMException e) {
throw new RuntimeException("Test failed.", e);
}
System.out.println("Test passed.");
}
Aggregations