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 2016/06/09 23:03:01 UTC
svn commit: r1747603 -
/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/icns/IcnsRoundTripTest.java
Author: ggregory
Date: Thu Jun 9 23:03:01 2016
New Revision: 1747603
URL: http://svn.apache.org/viewvc?rev=1747603&view=rev
Log:
Use try-with-resources.
Modified:
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/icns/IcnsRoundTripTest.java
Modified: commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/icns/IcnsRoundTripTest.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/icns/IcnsRoundTripTest.java?rev=1747603&r1=1747602&r2=1747603&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/icns/IcnsRoundTripTest.java (original)
+++ commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/icns/IcnsRoundTripTest.java Thu Jun 9 23:03:01 2016
@@ -58,369 +58,357 @@ public class IcnsRoundTripTest extends I
public void test1BPPIconMaskVersus8BPPMask() throws Exception {
final int foreground = 0xff000000;
final int background = 0xff000000;
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final BinaryOutputStream bos = new BinaryOutputStream(baos,
- ByteOrder.BIG_ENDIAN);
- bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
- bos.write4Bytes(4 + 4 + 4 + 4 + 2 * 16 * 16 / 8 + 4 + 4 + 16 * 16);
- bos.write4Bytes(IcnsType.ICNS_16x16_1BIT_IMAGE_AND_MASK.getType());
- bos.write4Bytes(4 + 4 + 2 * 16 * 16 / 8);
- // 1 BPP image - all black
- for (int y = 0; y < 16; y++) {
- bos.write(0xff);
- bos.write(0xff);
- }
- // 1 BPP mask - all opaque
- for (int y = 0; y < 16; y++) {
- bos.write(0xff);
- bos.write(0xff);
- }
- // 8 BPP alpha mask - partially transparent
- bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_MASK.getType());
- bos.write4Bytes(4 + 4 + 16 * 16);
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x++) {
- if (IMAGE[y][x] != 0) {
- bos.write(0xff);
- } else {
- bos.write(0x00);
+ try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ final BinaryOutputStream bos = new BinaryOutputStream(baos, ByteOrder.BIG_ENDIAN)) {
+ bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
+ bos.write4Bytes(4 + 4 + 4 + 4 + 2 * 16 * 16 / 8 + 4 + 4 + 16 * 16);
+ bos.write4Bytes(IcnsType.ICNS_16x16_1BIT_IMAGE_AND_MASK.getType());
+ bos.write4Bytes(4 + 4 + 2 * 16 * 16 / 8);
+ // 1 BPP image - all black
+ for (int y = 0; y < 16; y++) {
+ bos.write(0xff);
+ bos.write(0xff);
+ }
+ // 1 BPP mask - all opaque
+ for (int y = 0; y < 16; y++) {
+ bos.write(0xff);
+ bos.write(0xff);
+ }
+ // 8 BPP alpha mask - partially transparent
+ bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_MASK.getType());
+ bos.write4Bytes(4 + 4 + 16 * 16);
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x++) {
+ if (IMAGE[y][x] != 0) {
+ bos.write(0xff);
+ } else {
+ bos.write(0x00);
+ }
}
}
+ bos.flush();
+ writeAndReadImageData("1bpp-image-mask-versus-8bpp-mask", baos.toByteArray(), foreground, background);
+ bos.close();
}
- bos.flush();
- writeAndReadImageData("1bpp-image-mask-versus-8bpp-mask",
- baos.toByteArray(), foreground, background);
- bos.close();
}
@Test
public void test8BPPIcon8BPPMask() throws Exception {
final int foreground = 0xff000000;
final int background = 0x00cccccc;
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final BinaryOutputStream bos = new BinaryOutputStream(baos,
- ByteOrder.BIG_ENDIAN);
- bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
- bos.write4Bytes(4 + 4 + 4 + 4 + 16 * 16 + 4 + 4 + 16 * 16);
- bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_IMAGE.getType());
- bos.write4Bytes(4 + 4 + 16 * 16);
- // 8 BPP image
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x++) {
- if (IMAGE[y][x] != 0) {
- bos.write(0xff);
- } else {
- bos.write(43);
+ try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ final BinaryOutputStream bos = new BinaryOutputStream(baos, ByteOrder.BIG_ENDIAN)) {
+ bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
+ bos.write4Bytes(4 + 4 + 4 + 4 + 16 * 16 + 4 + 4 + 16 * 16);
+ bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_IMAGE.getType());
+ bos.write4Bytes(4 + 4 + 16 * 16);
+ // 8 BPP image
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x++) {
+ if (IMAGE[y][x] != 0) {
+ bos.write(0xff);
+ } else {
+ bos.write(43);
+ }
}
}
- }
- // 8 BPP alpha mask
- bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_MASK.getType());
- bos.write4Bytes(4 + 4 + 16 * 16);
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x++) {
- if (IMAGE[y][x] != 0) {
- bos.write(0xff);
- } else {
- bos.write(0x00);
+ // 8 BPP alpha mask
+ bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_MASK.getType());
+ bos.write4Bytes(4 + 4 + 16 * 16);
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x++) {
+ if (IMAGE[y][x] != 0) {
+ bos.write(0xff);
+ } else {
+ bos.write(0x00);
+ }
}
}
- }
- bos.flush();
- writeAndReadImageData("8bpp-image-8bpp-mask", baos.toByteArray(),
- foreground, background);
- bos.close();
- }
+ bos.flush();
+ writeAndReadImageData("8bpp-image-8bpp-mask", baos.toByteArray(), foreground, background);
+ bos.close();
+ }}
@Test
public void test8BPPIcon8BPPMaskVersus1BPPMask() throws Exception {
final int foreground = 0xff000000;
final int background = 0x00cccccc;
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final BinaryOutputStream bos = new BinaryOutputStream(baos,
- ByteOrder.BIG_ENDIAN);
- bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
- bos.write4Bytes(4 + 4 + 4 + 4 + 16 * 16 + 4 + 4 + 16 * 16 + 4 + 4 + 2
- * 16 * 16 / 8);
- bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_IMAGE.getType());
- bos.write4Bytes(4 + 4 + 16 * 16);
- // 8 BPP image
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x++) {
- if (IMAGE[y][x] != 0) {
- bos.write(0xff);
- } else {
- bos.write(43);
+ try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ final BinaryOutputStream bos = new BinaryOutputStream(baos, ByteOrder.BIG_ENDIAN)) {
+ bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
+ bos.write4Bytes(4 + 4 + 4 + 4 + 16 * 16 + 4 + 4 + 16 * 16 + 4 + 4 + 2 * 16 * 16 / 8);
+ bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_IMAGE.getType());
+ bos.write4Bytes(4 + 4 + 16 * 16);
+ // 8 BPP image
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x++) {
+ if (IMAGE[y][x] != 0) {
+ bos.write(0xff);
+ } else {
+ bos.write(43);
+ }
}
}
- }
- // 8 BPP alpha mask, some transparent
- bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_MASK.getType());
- bos.write4Bytes(4 + 4 + 16 * 16);
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x++) {
- if (IMAGE[y][x] != 0) {
- bos.write(0xff);
- } else {
- bos.write(0x00);
+ // 8 BPP alpha mask, some transparent
+ bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_MASK.getType());
+ bos.write4Bytes(4 + 4 + 16 * 16);
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x++) {
+ if (IMAGE[y][x] != 0) {
+ bos.write(0xff);
+ } else {
+ bos.write(0x00);
+ }
}
}
- }
- // 1 BPP mask
- bos.write4Bytes(IcnsType.ICNS_16x16_1BIT_IMAGE_AND_MASK.getType());
- bos.write4Bytes(4 + 4 + 2 * 16 * 16 / 8);
- // 1 bit image
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x += 8) {
- int eightBits = 0;
- for (int pos = 0; pos < 8; pos++) {
- if (IMAGE[y][x + pos] != 0) {
- eightBits |= (1 << (7 - pos));
+ // 1 BPP mask
+ bos.write4Bytes(IcnsType.ICNS_16x16_1BIT_IMAGE_AND_MASK.getType());
+ bos.write4Bytes(4 + 4 + 2 * 16 * 16 / 8);
+ // 1 bit image
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x += 8) {
+ int eightBits = 0;
+ for (int pos = 0; pos < 8; pos++) {
+ if (IMAGE[y][x + pos] != 0) {
+ eightBits |= (1 << (7 - pos));
+ }
}
+ bos.write(eightBits);
}
- bos.write(eightBits);
}
+ // 1 bit mask, all opaque
+ for (int y = 0; y < 16; y++) {
+ bos.write(0xff);
+ bos.write(0xff);
+ }
+ bos.flush();
+ writeAndReadImageData("8bpp-image-8bpp-mask-vs-1bpp-mask", baos.toByteArray(), foreground, background);
+ bos.close();
}
- // 1 bit mask, all opaque
- for (int y = 0; y < 16; y++) {
- bos.write(0xff);
- bos.write(0xff);
- }
- bos.flush();
- writeAndReadImageData("8bpp-image-8bpp-mask-vs-1bpp-mask",
- baos.toByteArray(), foreground, background);
- bos.close();
}
@Test
public void test8BPPIcon1BPPMaskVersus8BPPMask() throws Exception {
final int foreground = 0xff000000;
final int background = 0x00cccccc;
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final BinaryOutputStream bos = new BinaryOutputStream(baos,
- ByteOrder.BIG_ENDIAN);
- bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
- bos.write4Bytes(4 + 4 + 4 + 4 + 16 * 16 + 4 + 4 + 16 * 16 + 4 + 4 + 2
- * 16 * 16 / 8);
- bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_IMAGE.getType());
- bos.write4Bytes(4 + 4 + 16 * 16);
- // 8 BPP image
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x++) {
- if (IMAGE[y][x] != 0) {
- bos.write(0xff);
- } else {
- bos.write(43);
+ try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ final BinaryOutputStream bos = new BinaryOutputStream(baos, ByteOrder.BIG_ENDIAN)) {
+ bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
+ bos.write4Bytes(4 + 4 + 4 + 4 + 16 * 16 + 4 + 4 + 16 * 16 + 4 + 4 + 2 * 16 * 16 / 8);
+ bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_IMAGE.getType());
+ bos.write4Bytes(4 + 4 + 16 * 16);
+ // 8 BPP image
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x++) {
+ if (IMAGE[y][x] != 0) {
+ bos.write(0xff);
+ } else {
+ bos.write(43);
+ }
}
}
- }
- // 1 BPP mask
- bos.write4Bytes(IcnsType.ICNS_16x16_1BIT_IMAGE_AND_MASK.getType());
- bos.write4Bytes(4 + 4 + 2 * 16 * 16 / 8);
- // 1 bit image
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x += 8) {
- int eightBits = 0;
- for (int pos = 0; pos < 8; pos++) {
- if (IMAGE[y][x + pos] != 0) {
- eightBits |= (1 << (7 - pos));
+ // 1 BPP mask
+ bos.write4Bytes(IcnsType.ICNS_16x16_1BIT_IMAGE_AND_MASK.getType());
+ bos.write4Bytes(4 + 4 + 2 * 16 * 16 / 8);
+ // 1 bit image
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x += 8) {
+ int eightBits = 0;
+ for (int pos = 0; pos < 8; pos++) {
+ if (IMAGE[y][x + pos] != 0) {
+ eightBits |= (1 << (7 - pos));
+ }
}
+ bos.write(eightBits);
}
- bos.write(eightBits);
}
- }
- // 1 bit mask, all opaque
- for (int y = 0; y < 16; y++) {
- bos.write(0xff);
- bos.write(0xff);
- }
- // 8 BPP alpha mask, some transparent
- bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_MASK.getType());
- bos.write4Bytes(4 + 4 + 16 * 16);
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x++) {
- if (IMAGE[y][x] != 0) {
- bos.write(0xff);
- } else {
- bos.write(0x00);
+ // 1 bit mask, all opaque
+ for (int y = 0; y < 16; y++) {
+ bos.write(0xff);
+ bos.write(0xff);
+ }
+ // 8 BPP alpha mask, some transparent
+ bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_MASK.getType());
+ bos.write4Bytes(4 + 4 + 16 * 16);
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x++) {
+ if (IMAGE[y][x] != 0) {
+ bos.write(0xff);
+ } else {
+ bos.write(0x00);
+ }
}
}
+ bos.flush();
+ writeAndReadImageData("8bpp-image-1bpp-mask-vs-8bpp-mask", baos.toByteArray(), foreground, background);
+ bos.close();
}
- bos.flush();
- writeAndReadImageData("8bpp-image-1bpp-mask-vs-8bpp-mask",
- baos.toByteArray(), foreground, background);
- bos.close();
}
@Test
public void test8BPPIconNoMask() throws Exception {
final int foreground = 0xff000000;
final int background = 0xffcccccc;
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final BinaryOutputStream bos = new BinaryOutputStream(baos,
- ByteOrder.BIG_ENDIAN);
- bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
- bos.write4Bytes(4 + 4 + 4 + 4 + 16 * 16);
- bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_IMAGE.getType());
- bos.write4Bytes(4 + 4 + 16 * 16);
- // 8 BPP image
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x++) {
- if (IMAGE[y][x] != 0) {
- bos.write(0xff);
- } else {
- bos.write(43);
+ try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ final BinaryOutputStream bos = new BinaryOutputStream(baos, ByteOrder.BIG_ENDIAN)) {
+ bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
+ bos.write4Bytes(4 + 4 + 4 + 4 + 16 * 16);
+ bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_IMAGE.getType());
+ bos.write4Bytes(4 + 4 + 16 * 16);
+ // 8 BPP image
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x++) {
+ if (IMAGE[y][x] != 0) {
+ bos.write(0xff);
+ } else {
+ bos.write(43);
+ }
}
}
- }
- bos.flush();
- writeAndReadImageData("8bpp-image-no-mask", baos.toByteArray(),
- foreground, background);
- bos.close();
- }
+ bos.flush();
+ writeAndReadImageData("8bpp-image-no-mask", baos.toByteArray(), foreground, background);
+ bos.close();
+ }}
@Test
public void test32BPPMaskedIcon() throws Exception {
final int foreground = 0xff000000;
final int background = 0x000000ff;
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final BinaryOutputStream bos = new BinaryOutputStream(baos,
- ByteOrder.BIG_ENDIAN);
- bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
- bos.write4Bytes(4 + 4 + 4 + 4 + 4 * 16 * 16 + 4 + 4 + 2 * 16 * 16 / 8);
- bos.write4Bytes(IcnsType.ICNS_16x16_32BIT_IMAGE.getType());
- bos.write4Bytes(4 + 4 + 4 * 16 * 16);
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x++) {
- // argb, a ignored
- bos.write(0);
- final int pixel;
- if (IMAGE[y][x] != 0) {
- pixel = foreground;
- } else {
- pixel = background;
- }
- bos.write(0xff & (pixel >> 16));
- bos.write(0xff & (pixel >> 8));
- bos.write(0xff & pixel);
+ try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ final BinaryOutputStream bos = new BinaryOutputStream(baos, ByteOrder.BIG_ENDIAN)) {
+ bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
+ bos.write4Bytes(4 + 4 + 4 + 4 + 4 * 16 * 16 + 4 + 4 + 2 * 16 * 16 / 8);
+ bos.write4Bytes(IcnsType.ICNS_16x16_32BIT_IMAGE.getType());
+ bos.write4Bytes(4 + 4 + 4 * 16 * 16);
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x++) {
+ // argb, a ignored
+ bos.write(0);
+ final int pixel;
+ if (IMAGE[y][x] != 0) {
+ pixel = foreground;
+ } else {
+ pixel = background;
+ }
+ bos.write(0xff & (pixel >> 16));
+ bos.write(0xff & (pixel >> 8));
+ bos.write(0xff & pixel);
+ }
}
- }
- bos.write4Bytes(IcnsType.ICNS_16x16_1BIT_IMAGE_AND_MASK.getType());
- bos.write4Bytes(4 + 4 + 2 * 16 * 16 / 8);
- // 1 bit image
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x += 8) {
- int eightBits = 0;
- for (int pos = 0; pos < 8; pos++) {
- if (IMAGE[y][x + pos] != 0) {
- eightBits |= (1 << (7 - pos));
+ bos.write4Bytes(IcnsType.ICNS_16x16_1BIT_IMAGE_AND_MASK.getType());
+ bos.write4Bytes(4 + 4 + 2 * 16 * 16 / 8);
+ // 1 bit image
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x += 8) {
+ int eightBits = 0;
+ for (int pos = 0; pos < 8; pos++) {
+ if (IMAGE[y][x + pos] != 0) {
+ eightBits |= (1 << (7 - pos));
+ }
}
+ bos.write(eightBits);
}
- bos.write(eightBits);
}
- }
- // 1 bit mask
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x += 8) {
- int eightBits = 0;
- for (int pos = 0; pos < 8; pos++) {
- if (IMAGE[y][x + pos] != 0) {
- eightBits |= (1 << (7 - pos));
+ // 1 bit mask
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x += 8) {
+ int eightBits = 0;
+ for (int pos = 0; pos < 8; pos++) {
+ if (IMAGE[y][x + pos] != 0) {
+ eightBits |= (1 << (7 - pos));
+ }
}
+ bos.write(eightBits);
}
- bos.write(eightBits);
}
+ bos.flush();
+ writeAndReadImageData("32bpp-image-1bpp-mask", baos.toByteArray(), foreground, background);
+ bos.close();
}
- bos.flush();
- writeAndReadImageData("32bpp-image-1bpp-mask", baos.toByteArray(),
- foreground, background);
- bos.close();
}
@Test
public void test32BPPHalfMaskedIcon() throws Exception {
final int foreground = 0xff000000;
final int background = 0xff0000ff;
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final BinaryOutputStream bos = new BinaryOutputStream(baos,
- ByteOrder.BIG_ENDIAN);
- bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
- bos.write4Bytes(4 + 4 + 4 + 4 + 4 * 16 * 16 + 4 + 4 + 16 * 16 / 8);
- bos.write4Bytes(IcnsType.ICNS_16x16_32BIT_IMAGE.getType());
- bos.write4Bytes(4 + 4 + 4 * 16 * 16);
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x++) {
- // argb, a ignored
- bos.write(0);
- final int pixel;
- if (IMAGE[y][x] != 0) {
- pixel = foreground;
- } else {
- pixel = background;
- }
- bos.write(0xff & (pixel >> 16));
- bos.write(0xff & (pixel >> 8));
- bos.write(0xff & pixel);
+ try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ final BinaryOutputStream bos = new BinaryOutputStream(baos, ByteOrder.BIG_ENDIAN)) {
+ bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
+ bos.write4Bytes(4 + 4 + 4 + 4 + 4 * 16 * 16 + 4 + 4 + 16 * 16 / 8);
+ bos.write4Bytes(IcnsType.ICNS_16x16_32BIT_IMAGE.getType());
+ bos.write4Bytes(4 + 4 + 4 * 16 * 16);
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x++) {
+ // argb, a ignored
+ bos.write(0);
+ final int pixel;
+ if (IMAGE[y][x] != 0) {
+ pixel = foreground;
+ } else {
+ pixel = background;
+ }
+ bos.write(0xff & (pixel >> 16));
+ bos.write(0xff & (pixel >> 8));
+ bos.write(0xff & pixel);
+ }
}
- }
- bos.write4Bytes(IcnsType.ICNS_16x16_1BIT_IMAGE_AND_MASK.getType());
- bos.write4Bytes(4 + 4 + 16 * 16 / 8);
- // 1 bit image
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x += 8) {
- int eightBits = 0;
- for (int pos = 0; pos < 8; pos++) {
- if (IMAGE[y][x + pos] != 0) {
- eightBits |= (1 << (7 - pos));
+ bos.write4Bytes(IcnsType.ICNS_16x16_1BIT_IMAGE_AND_MASK.getType());
+ bos.write4Bytes(4 + 4 + 16 * 16 / 8);
+ // 1 bit image
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x += 8) {
+ int eightBits = 0;
+ for (int pos = 0; pos < 8; pos++) {
+ if (IMAGE[y][x + pos] != 0) {
+ eightBits |= (1 << (7 - pos));
+ }
}
+ bos.write(eightBits);
}
- bos.write(eightBits);
}
- }
- // Missing 1 bit mask!!!
- bos.flush();
+ // Missing 1 bit mask!!!
+ bos.flush();
- boolean threw = false;
- try {
- writeAndReadImageData("32bpp-half-masked-CORRUPT",
- baos.toByteArray(), foreground, background);
- } catch (final ImageReadException imageReadException) {
- threw = true;
+ boolean threw = false;
+ try {
+ writeAndReadImageData("32bpp-half-masked-CORRUPT", baos.toByteArray(), foreground, background);
+ } catch (final ImageReadException imageReadException) {
+ threw = true;
+ }
+ assertTrue("ICNS file with corrupt mask didn't fail to parse", threw);
+ bos.close();
}
- assertTrue("ICNS file with corrupt mask didn't fail to parse", threw);
- bos.close();
}
@Test
public void test32BPPMaskMissingIcon() throws Exception {
final int foreground = 0xff000000;
final int background = 0xff0000ff;
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final BinaryOutputStream bos = new BinaryOutputStream(baos,
- ByteOrder.BIG_ENDIAN);
- bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
- bos.write4Bytes(4 + 4 + 4 + 4 + 4 * 16 * 16);
- bos.write4Bytes(IcnsType.ICNS_16x16_32BIT_IMAGE.getType());
- bos.write4Bytes(4 + 4 + 4 * 16 * 16);
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x++) {
- // argb, a ignored
- bos.write(0);
- final int pixel;
- if (IMAGE[y][x] != 0) {
- pixel = foreground;
- } else {
- pixel = background;
- }
- bos.write(0xff & (pixel >> 16));
- bos.write(0xff & (pixel >> 8));
- bos.write(0xff & pixel);
+ try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ final BinaryOutputStream bos = new BinaryOutputStream(baos, ByteOrder.BIG_ENDIAN)) {
+ bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
+ bos.write4Bytes(4 + 4 + 4 + 4 + 4 * 16 * 16);
+ bos.write4Bytes(IcnsType.ICNS_16x16_32BIT_IMAGE.getType());
+ bos.write4Bytes(4 + 4 + 4 * 16 * 16);
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x++) {
+ // argb, a ignored
+ bos.write(0);
+ final int pixel;
+ if (IMAGE[y][x] != 0) {
+ pixel = foreground;
+ } else {
+ pixel = background;
+ }
+ bos.write(0xff & (pixel >> 16));
+ bos.write(0xff & (pixel >> 8));
+ bos.write(0xff & pixel);
+ }
}
+ bos.flush();
+ writeAndReadImageData("32bpp-mask-missing", baos.toByteArray(), foreground, background);
+ bos.close();
}
- bos.flush();
- writeAndReadImageData("32bpp-mask-missing", baos.toByteArray(),
- foreground, background);
- bos.close();
}
private void writeAndReadImageData(final String description, final byte[] rawData,