Img implements ImgBase<Pixel> { public int getValue(final int x, final int y){ return this.data[y*this.width + x]; } Img(int width, int height);  Img(Dimension dimension);  Img(BufferedImage bimg);  Img(int width, int height, int[] data);  Img(Dimension dim, int[] data); int getWidth(); int getHeight(); int numValues(); int[] getData(); int getValue(final int x, final int y); int getValue(int x, int y, final int boundaryMode); int interpolateARGB(final double xNormalized, final double yNormalized); Pixel getPixel(); Pixel getPixel(int x, int y); Img copyArea(int x, int y, int w, int h, Img dest, int destX, int destY); void setValue(final int x, final int y, final int value); Img fill(final int value); @Override Img copy(); @Override BufferedImage toBufferedImage(BufferedImage bimg); @Override BufferedImage getRemoteBufferedImage(); @Override boolean supportsRemoteBufferedImage(); static Img createRemoteImg(BufferedImage bimg); @Override int getSpliteratorMinimumSplitSize(); void setSpliteratorMinimumSplitSize(int size); static final int boundary_mode_zero; static final int boundary_mode_repeat_edge; static final int boundary_mode_repeat_image; static final int boundary_mode_mirror; }
@Test public void boundaryModes_test(){ Img img = new Img(4, 4, new int[] { 0,1,2,3, 4,5,6,7, 8,9,9,9, 9,9,9,9 }); for(int mode: new int[]{Img.boundary_mode_zero, Img.boundary_mode_mirror, Img.boundary_mode_repeat_edge, Img.boundary_mode_repeat_image}){ assertEquals(0, img.getValue(0, 0, mode)); assertEquals(3, img.getValue(3, 0, mode)); assertEquals(9, img.getValue(0, 3, mode)); assertEquals(9, img.getValue(3, 3, mode)); } assertEquals(0, img.getValue(-1, 0, Img.boundary_mode_zero)); assertEquals(0, img.getValue(4, 0, Img.boundary_mode_zero)); assertEquals(0, img.getValue(0, -1, Img.boundary_mode_zero)); assertEquals(0, img.getValue(0, 4, Img.boundary_mode_zero)); assertEquals(0xff112233, img.getValue(-1, 0, 0xff112233)); assertEquals(0xff112233, img.getValue(4, 0, 0xff112233)); assertEquals(0xff112233, img.getValue(0, -1, 0xff112233)); assertEquals(0xff112233, img.getValue(0, 4, 0xff112233)); assertEquals(0, img.getValue(-2, 0, Img.boundary_mode_repeat_edge)); assertEquals(3, img.getValue(3, -2, Img.boundary_mode_repeat_edge)); assertEquals(9, img.getValue(-10, 10, Img.boundary_mode_repeat_edge)); assertEquals(3, img.getValue(10, -10, Img.boundary_mode_repeat_edge)); for(int y = 0; y < 4; y++) for(int x = 0; x < 4; x++){ assertEquals(img.getValue(x, y), img.getValue(x+4, y, Img.boundary_mode_repeat_image)); assertEquals(img.getValue(x, y), img.getValue(x, y+4, Img.boundary_mode_repeat_image)); assertEquals(img.getValue(x, y), img.getValue(x-4, y, Img.boundary_mode_repeat_image)); assertEquals(img.getValue(x, y), img.getValue(x, y-4, Img.boundary_mode_repeat_image)); assertEquals(img.getValue(x, y), img.getValue(x+8, y+8, Img.boundary_mode_repeat_image)); assertEquals(img.getValue(x, y), img.getValue(x-8, y-8, Img.boundary_mode_repeat_image)); } for(int y = 0; y < 4; y++) for(int x = 0; x < 4; x++){ assertEquals(img.getValue(x, y), img.getValue(x+8, y+8, Img.boundary_mode_mirror)); assertEquals(img.getValue(x, y), img.getValue(7-x, 7-y, Img.boundary_mode_mirror)); assertEquals(img.getValue(x, y), img.getValue(-8+x, -8+y, Img.boundary_mode_mirror)); assertEquals(img.getValue(x, y), img.getValue(-1-x, -1-y, Img.boundary_mode_mirror)); } }
@Test public void graphics_test(){ Img img = new Img(400, 400); img.paint(g->{ g.setColor(new Color(0xffff0000)); g.drawLine(0, 0, 400, 400); }); img.forEach(px->{ if(px.getX() == px.getY()){ assertEquals(0xffff0000, px.getValue()); } else { assertEquals(0, px.getValue()); } }); }