You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/05/24 18:20:34 UTC
[commons-imaging] 01/02: Sort members
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-imaging.git
commit 5255076665a13d37b7be186e5c9d08ffa76c1481
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed May 24 14:20:12 2023 -0400
Sort members
---
.../commons/imaging/formats/png/PngWriterTest.java | 78 +++++++++++-----------
1 file changed, 39 insertions(+), 39 deletions(-)
diff --git a/src/test/java/org/apache/commons/imaging/formats/png/PngWriterTest.java b/src/test/java/org/apache/commons/imaging/formats/png/PngWriterTest.java
index 7bee866b..66b8d6f7 100644
--- a/src/test/java/org/apache/commons/imaging/formats/png/PngWriterTest.java
+++ b/src/test/java/org/apache/commons/imaging/formats/png/PngWriterTest.java
@@ -37,42 +37,9 @@ import org.junit.jupiter.api.Test;
*/
public class PngWriterTest extends PngBaseTest {
- @Test
- public void testPaletteFactory() throws IOException {
- final File imageFile = getValidPngImages().get(0);
-
- final BufferedImage image = Imaging.getBufferedImage(imageFile);
- final PngImagingParameters params = new PngImagingParameters();
- params.setForceIndexedColor(true);
-
- final byte[] bytes = getImageBytes(image, params);
- final int numColors = countColors(bytes);
- assertTrue(numColors > 1);
-
- final PaletteFactory factory = new PaletteFactory() {
- @Override
- public Palette makeQuantizedRgbPalette(final BufferedImage src, final int max) {
- // Force a stupid palette containing nothing but black (all zero's).
- return new SimplePalette(new int[max]);
- }
- };
- final byte[] palettedBytes = getImageBytesWithPalette(image, params, factory);
-
- assertEquals(1, countColors(palettedBytes));
- }
-
- @Test
- public void testNullParameters() throws IOException {
- final File imageFile = getValidPngImages().get(0);
-
- final BufferedImage image = Imaging.getBufferedImage(imageFile);
-
- try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
- new PngWriter().writeImage(image, os, null, null);
- byte[] bytes = os.toByteArray();
- final int numColors = countColors(bytes);
- assertTrue(numColors > 1);
- }
+ private static int countColors(final byte[] bytes) throws IOException {
+ final BufferedImage imageParsed = Imaging.getBufferedImage(bytes);
+ return new PaletteFactory().makeExactRgbPaletteSimple(imageParsed, Integer.MAX_VALUE).length();
}
private static byte[] getImageBytes(final BufferedImage image, final PngImagingParameters params) throws IOException {
@@ -100,8 +67,41 @@ public class PngWriterTest extends PngBaseTest {
return result;
}
- private static int countColors(final byte[] bytes) throws IOException {
- final BufferedImage imageParsed = Imaging.getBufferedImage(bytes);
- return new PaletteFactory().makeExactRgbPaletteSimple(imageParsed, Integer.MAX_VALUE).length();
+ @Test
+ public void testNullParameters() throws IOException {
+ final File imageFile = getValidPngImages().get(0);
+
+ final BufferedImage image = Imaging.getBufferedImage(imageFile);
+
+ try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
+ new PngWriter().writeImage(image, os, null, null);
+ byte[] bytes = os.toByteArray();
+ final int numColors = countColors(bytes);
+ assertTrue(numColors > 1);
+ }
+ }
+
+ @Test
+ public void testPaletteFactory() throws IOException {
+ final File imageFile = getValidPngImages().get(0);
+
+ final BufferedImage image = Imaging.getBufferedImage(imageFile);
+ final PngImagingParameters params = new PngImagingParameters();
+ params.setForceIndexedColor(true);
+
+ final byte[] bytes = getImageBytes(image, params);
+ final int numColors = countColors(bytes);
+ assertTrue(numColors > 1);
+
+ final PaletteFactory factory = new PaletteFactory() {
+ @Override
+ public Palette makeQuantizedRgbPalette(final BufferedImage src, final int max) {
+ // Force a stupid palette containing nothing but black (all zero's).
+ return new SimplePalette(new int[max]);
+ }
+ };
+ final byte[] palettedBytes = getImageBytesWithPalette(image, params, factory);
+
+ assertEquals(1, countColors(palettedBytes));
}
}