Skip to content

Commit 3de58dd

Browse files
hansonrhansonr
authored andcommitted
Test update
1 parent bc577fd commit 3de58dd

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

sources/net.sf.j2s.java.core/src/test/Test_Image.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.awt.Color;
44
import java.awt.Graphics;
5+
import java.awt.Graphics2D;
56
import java.awt.GraphicsEnvironment;
67
import java.awt.Image;
78
import java.awt.Toolkit;
@@ -39,8 +40,8 @@ public class Test_Image extends Test_ {
3940
public static void main(String[] args) {
4041

4142
// testSource();
42-
// testPacked();
43-
testGray();
43+
testPacked();
44+
// testGray();
4445
// testRead();
4546
// testWrite();
4647

@@ -264,15 +265,40 @@ private static void testPacked() {
264265
DataBuffer databuffer = new DataBufferByte(packedData, len);
265266
WritableRaster raster = Raster.createPackedRaster(databuffer, nx, ny, 1, null);
266267
// default colors are red and blue
267-
ColorModel colorModel = new IndexColorModel(1, 2, new byte[] {(byte) 255, (byte) 0}, new byte[] {(byte) 0, (byte) 0}, new byte[] {(byte) 0, (byte) 255});
268+
ColorModel colorModel = new IndexColorModel(1, 2,
269+
new byte[] {(byte) 255, (byte) 0},
270+
new byte[] {(byte) 0, (byte) 0},
271+
new byte[] {(byte) 0, (byte) 255});
268272
BufferedImage image = new BufferedImage(colorModel, raster, false, null);
269-
273+
274+
dumpImage(image, nx, ny);
275+
DataBuffer buf = image.getRaster().getDataBuffer();
276+
byte[] data = ((DataBufferByte) buf).getData();
277+
System.out.println(Arrays.toString(data));
278+
Graphics2D g = image.createGraphics();
279+
g.setColor(new Color(0,0,255));
280+
g.fillRect(0, 0, 100, 100);
281+
g.dispose();
282+
image.flush();
283+
System.out.println(Arrays.toString(data));
284+
dumpImage(image, nx, ny);
285+
}
286+
287+
private static void dumpImage(BufferedImage image, int nx, int ny) {
288+
System.out.println("----------------");
270289
int n = nx * ny;
271290
int[] pixels = new int[n * 4];
272291
for (int i = 0, pt = 0; i < n; i++, pt+=4) {
292+
273293
image.getColorModel().getComponents(i, pixels, pt);
274-
System.out.println(pixels[pt] + " " + pixels[pt+1] + " " + pixels[pt+2] + " " + pixels[pt+3]);
294+
System.out.println(i + " " + nx + " " + ny + ": " + pixels[pt] + " " + pixels[pt+1] + " " + pixels[pt+2] + " " + pixels[pt+3]);
275295
}
296+
System.out.println("===========");
297+
for (int i = 0; i < nx; i++) {
298+
for (int j = 0; j < ny; j++) {
299+
System.out.println(Integer.toHexString(image.getRGB(i, j)));
300+
}
301+
}
276302
}
277303

278304
}

0 commit comments

Comments
 (0)