use of java.awt.Color in project jdk8u_jdk by JetBrains.
the class MultiResolutionRenderingHintsTest method main.
public static void main(String[] args) throws Exception {
int length = COLORS.length;
BufferedImage[] resolutionVariants = new BufferedImage[length];
for (int i = 0; i < length; i++) {
resolutionVariants[i] = createRVImage(getSize(i), COLORS[i]);
}
BaseMultiResolutionImage mrImage = new BaseMultiResolutionImage(resolutionVariants);
// base
Color color = getImageColor(VALUE_RESOLUTION_VARIANT_BASE, mrImage, 2, 3);
if (!getColorForScale(1).equals(color)) {
throw new RuntimeException("Wrong base resolution variant!");
}
// dpi fit
color = getImageColor(VALUE_RESOLUTION_VARIANT_DPI_FIT, mrImage, 2, 3);
if (!getColorForScale(2).equals(color)) {
throw new RuntimeException("Resolution variant is not based on dpi!");
}
// size fit
color = getImageColor(VALUE_RESOLUTION_VARIANT_SIZE_FIT, mrImage, 2, 3);
if (!getColorForScale(6).equals(color)) {
throw new RuntimeException("Resolution variant is not based on" + " rendered size!");
}
// default
// depends on the policies of the platform
// just check that exception is not thrown
getImageColor(VALUE_RESOLUTION_VARIANT_DEFAULT, mrImage, 2, 3);
}
use of java.awt.Color in project jdk8u_jdk by JetBrains.
the class MlibOpsTest method createSrcImage.
private static BufferedImage createSrcImage() {
BufferedImage img = createImage();
Graphics2D g = img.createGraphics();
Color[] colors = { Color.red, Color.green, Color.blue };
float[] dist = { 0.0f, 0.5f, 1.0f };
Point2D center = new Point2D.Float(0.5f * w, 0.5f * h);
RadialGradientPaint p = new RadialGradientPaint(center, 0.5f * w, dist, colors);
g.setPaint(p);
g.fillRect(0, 0, w, h);
g.dispose();
return img;
}
use of java.awt.Color in project jdk8u_jdk by JetBrains.
the class ReadAsGrayTest method verify.
private static void verify(BufferedImage src, BufferedImage dst, ImageTypeSpecifier type) {
BufferedImage test = type.createBufferedImage(src.getWidth(), src.getHeight());
Graphics2D g = test.createGraphics();
g.drawImage(src, 0, 0, null);
g.dispose();
for (int i = 0; i < colors.length; i++) {
int x = i * dx + dx / 2;
int y = h / 2;
Color c_test = new Color(test.getRGB(x, y));
Color c_dst = new Color(dst.getRGB(x, y));
if (!compareWithTolerance(c_test, c_dst, 0.01f)) {
String msg = String.format("Invalid color: %x instead of %x", c_dst.getRGB(), c_test.getRGB());
throw new RuntimeException("Test failed: " + msg);
}
}
System.out.println("Verified.");
}
use of java.awt.Color in project jdk8u_jdk by JetBrains.
the class JPEGsNotAcceleratedTest method writeTestImage.
public static void writeTestImage(String fileName) {
BufferedImage bi = new BufferedImage(TEST_W, TEST_H, BufferedImage.TYPE_INT_RGB);
Graphics g = bi.getGraphics();
g.setColor(new Color(testRGB));
g.fillRect(0, 0, TEST_W, TEST_H);
try {
System.err.printf("Writing %s\n", fileName);
if (lowCompression) {
ImageWriter iw = (ImageWriter) ImageIO.getImageWritersBySuffix("jpeg").next();
if (iw == null) {
throw new RuntimeException("No available image writer for " + "jpeg " + " Test failed.");
}
File file = new File(fileName);
ImageOutputStream ios = ImageIO.createImageOutputStream(file);
iw.setOutput(ios);
ImageWriteParam param = iw.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionQuality(1);
IIOImage iioImg = new IIOImage(bi, null, null);
iw.write(null, iioImg, param);
} else {
ImageIO.write(bi, "jpeg", new File(fileName));
}
} catch (IOException e) {
System.err.println("Error " + e + " when writing file: " + fileName);
throw new RuntimeException(e);
}
}
use of java.awt.Color in project jdk8u_jdk by JetBrains.
the class WritingInterruptionTest method createTestImage.
private static BufferedImage createTestImage() {
int w = 1024;
int h = 768;
BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = img.createGraphics();
Color[] colors = { Color.red, Color.green, Color.blue };
float[] dist = { 0.0f, 0.5f, 1.0f };
Point2D center = new Point2D.Float(0.5f * w, 0.5f * h);
RadialGradientPaint p = new RadialGradientPaint(center, 0.5f * w, dist, colors);
g.setPaint(p);
g.fillRect(0, 0, w, h);
g.dispose();
return img;
}
Aggregations