throws ImageReadException, ImageWriteException, IOException
{
final int foreground = 0xff000000;
final int background = 0x00cccccc;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputStream bos = new BinaryOutputStream(baos,
BinaryOutputStream.BYTE_ORDER_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);
}
}
// 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);
}
}
// 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);
}