1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.roundtrip;
18
19 import java.awt.image.BufferedImage;
20
21 final class TestImages {
22
23 static BufferedImage createArgbBitmapImage(final int width, final int height) {
24 final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
25 for (int x = 0; x < width; x++) {
26 for (int y = 0; y < height; y++) {
27
28 final int modulator = y + 2;
29 final int argb = (x + y) % modulator == 0 ? 0xff000000 : 0xffffffff;
30 result.setRGB(x, y, argb);
31 }
32 }
33 return result;
34 }
35
36 static BufferedImage createArgbGrayscaleImage(final int width, final int height) {
37 final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
38 for (int x = 0; x < width; x++) {
39 for (int y = 0; y < height; y++) {
40 final int value = 256 * (x + y) / (width + height);
41 final int argb = 0xff << 24 | value << 16 | value << 8 | value << 0;
42
43 result.setRGB(x, y, argb);
44 }
45 }
46 return result;
47 }
48
49 static BufferedImage createBitmapBitmapImage(final int width, final int height) {
50 final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
51 for (int x = 0; x < width; x++) {
52 for (int y = 0; y < height; y++) {
53
54 final int modulator = y + 2;
55 final int argb = (x + y) % modulator == 0 ? 0xff000000 : 0xffffffff;
56 result.setRGB(x, y, argb);
57 }
58 }
59 return result;
60 }
61
62 static BufferedImage createFullColorImage(final int width, final int height) {
63 final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
64 for (int x = 0; x < width; x++) {
65 for (int y = 0; y < height; y++) {
66 final int red = x * 255 / width;
67 final int green = y * 255 / height;
68 final int blue = (x + y) * 255 / (width + height);
69 final int argb = 0xff << 24 | red << 16 | green << 8 | blue << 0;
70 result.setRGB(x, y, argb);
71 }
72 }
73 return result;
74 }
75
76 static BufferedImage createGrayscaleGrayscaleImage(final int width, final int height) {
77 final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
78 for (int x = 0; x < width; x++) {
79 for (int y = 0; y < height; y++) {
80 final int value = 256 * (x + y) / (width + height);
81 final int argb = 0xff << 24 | value << 16 | value << 8 | value << 0;
82
83 result.setRGB(x, y, argb);
84 }
85 }
86 return result;
87 }
88
89 static BufferedImage createLimitedColorImage(final int width, final int height) {
90 final int[] colors = { 0xffffffff, 0xff000000, 0xfff00000, 0xff0000ff, 0xff123456, 0xfffefeff, 0xff7f817f, };
91
92 final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
93 for (int x = 0; x < width; x++) {
94 for (int y = 0; y < height; y++) {
95 final int argb = colors[(x + y) % colors.length];
96 result.setRGB(x, y, argb);
97 }
98 }
99 return result;
100 }
101
102 private TestImages() {
103 }
104 }