ImagePoolImpl implements ImagePool { @NotNull public ImagePool.Image copyOf(@Nullable BufferedImage origin) { if (origin == null) { return ImagePool.NULL_POOLED_IMAGE; } int w = origin.getWidth(); int h = origin.getHeight(); int type = origin.getType(); ImageImpl image = create(w, h, type, null); image.drawFrom(origin); return image; } ImagePoolImpl(@NotNull int[] bucketSizes, @NotNull BiFunction<Integer, Integer, Function<Integer, Integer>> bucketSizingPolicy); @NotNull ImagePool.Image create(final int w, final int h, final int type); @NotNull ImagePool.Image copyOf(@Nullable BufferedImage origin); @Nullable @Override Stats getStats(); void dispose();  }
@Test public void testImageCopy() throws IOException { BufferedImage original = getSampleImage(); ImagePoolImpl.ImageImpl image = (ImagePoolImpl.ImageImpl)myPool.copyOf(original); assertNotEquals(original, image.myBuffer); BufferedImage copy = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB); image.drawImageTo(copy); ImageDiffUtil.assertImageSimilar("pooledimage", original, copy, 0.0); copy = image.getCopy(); assertNotEquals(copy, image.myBuffer); ImageDiffUtil.assertImageSimilar("pooledimage", original, copy, 0.0); copy = image.getCopy(0, 0, 25, 50); assertNotEquals(copy, image.myBuffer); assertEquals(25, copy.getWidth()); assertEquals(50, copy.getHeight()); ImageDiffUtil.assertImageSimilar("pooledimage", original.getSubimage(0, 0, 25, 50), copy, 0.0); copy = image.getCopy(10, 10, 25, 25); assertNotEquals(copy, image.myBuffer); assertEquals(25, copy.getWidth()); assertEquals(25, copy.getHeight()); ImageDiffUtil.assertImageSimilar("pooledimage", original.getSubimage(10, 10, 25, 25), copy, 0.0); try { copy = image.getCopy(0, 0, 25, 150); fail("IndexOutOfBoundsException expected for height out of bounds"); } catch (IndexOutOfBoundsException ignored) { } }
@Test public void testNullImage() throws IOException { ImagePool.Image image = myPool.copyOf(null); assertNotNull(image); assertEquals(0, image.getWidth()); assertEquals(0, image.getHeight()); assertNull(image.getCopy()); BufferedImage original = getSampleImage(); BufferedImage buffer = getSampleImage(); ImageDiffUtil.assertImageSimilar("sample", original, buffer, 0.0); image.drawImageTo(buffer); ImageDiffUtil.assertImageSimilar("sample", original, buffer, 0.0); }