@Override public void parseFromRaw(ChunkRaw c) { if (imgInfo.greyscale) { gray = PngHelperInternal.readInt2fromBytes(c.data, 0); } else if (imgInfo.indexed) { int nentries = c.data.length; paletteAlpha = new int[nentries]; for (int n = 0; n < nentries; n++) { paletteAlpha[n] = (int) (c.data[n] & 0xff); } } else { red = PngHelperInternal.readInt2fromBytes(c.data, 0); green = PngHelperInternal.readInt2fromBytes(c.data, 2); blue = PngHelperInternal.readInt2fromBytes(c.data, 4); } }
@Override public ChunkRaw createRawChunk() { ChunkRaw c = null; if (imgInfo.greyscale) { c = createEmptyChunk(2, true); PngHelperInternal.writeInt2tobytes(gray, c.data, 0); } else if (imgInfo.indexed) { c = createEmptyChunk(paletteAlpha.length, true); for (int n = 0; n < c.len; n++) { c.data[n] = (byte) paletteAlpha[n]; } } else { c = createEmptyChunk(6, true); PngHelperInternal.writeInt2tobytes(red, c.data, 0); PngHelperInternal.writeInt2tobytes(green, c.data, 0); PngHelperInternal.writeInt2tobytes(blue, c.data, 0); } return c; }