SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); try {  ImageData imageData = loader.data[0];   writeSignature();   int width = imageData.width; int height = imageData.height; PaletteData palette = imageData.palette; byte colorType = PngIhdrChunk.COLOR_TYPE_RGB; byte bitDepth = 8; if (!palette.isDirect) { colorType = PngIhdrChunk.COLOR_TYPE_PALETTE; bitDepth = (byte) Math.min(imageData.depth, 8); } if (imageData.getTransparencyType() == SWT.TRANSPARENCY_ALPHA) { colorType = PngIhdrChunk.COLOR_TYPE_RGB_WITH_ALPHA; } byte compressionMethod = 0; byte filterMethod = 0; byte interlaceMethod = PngIhdrChunk.INTERLACE_METHOD_NONE; outputStream.write(new PngIhdrChunk(width, height, bitDepth, colorType, compressionMethod, filterMethod, interlaceMethod).getReference());   if (!palette.isDirect) { outputStream.write(new PngPlteChunk(palette).getReference()); }   if (imageData.transparentPixel != -1) { RGB transparentRGB = palette.getRGB(imageData.transparentPixel); outputStream.write(new PngTrnsChunk(transparentRGB).getReference()); }   compress(imageData); outputStream.write(new PngIdatChunk(headerByte1, headerByte2, data, adler).getReference());   outputStream.write(new PngIendChunk().getReference()); } catch (IOException e) { SWT.error(SWT.ERROR_IO, e); }
PngEncoder encoder = new PngEncoder(loader); encoder.encode(outputStream);
void unloadIntoByteStream(ImageLoader loader) {	/* We do not currently support writing png. */	SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);	try {		/* PNG only supports single image (use MNG for multi-image). */		ImageData imageData = loader.data[0];			/* Step 1: Write PNG signature. */		writeSignature();				/* Step 2: Write IHDR chunk. */		int width = imageData.width;		int height = imageData.height;		PaletteData palette = imageData.palette;		byte colorType = PngIhdrChunk.COLOR_TYPE_RGB;		byte bitDepth = 8;		if (!palette.isDirect) {			colorType = PngIhdrChunk.COLOR_TYPE_PALETTE;			bitDepth = (byte) Math.min(imageData.depth, 8);		}		if (imageData.getTransparencyType() == SWT.TRANSPARENCY_ALPHA) {			colorType = PngIhdrChunk.COLOR_TYPE_RGB_WITH_ALPHA;		}		byte compressionMethod = 0; // must be zero		byte filterMethod = 0; // must be zero		byte interlaceMethod = PngIhdrChunk.INTERLACE_METHOD_NONE;		outputStream.write(new PngIhdrChunk(width, height, bitDepth, colorType, compressionMethod, filterMethod, interlaceMethod).getReference());				/* Step 3: Write PLTE (palette) chunk, if any. */		if (!palette.isDirect) {			outputStream.write(new PngPlteChunk(palette).getReference());		}				/* Step 4: Write tRNS (transparency) chunk, if any. */		if (imageData.transparentPixel != -1) {			RGB transparentRGB = palette.getRGB(imageData.transparentPixel);			outputStream.write(new PngTrnsChunk(transparentRGB).getReference());		}				/* Step 5: Write IDAT chunk. */		compress(imageData);		outputStream.write(new PngIdatChunk(headerByte1, headerByte2, data, adler).getReference());				/* Step 6: Write IEND chunk. */		outputStream.write(new PngIendChunk().getReference());	} catch (IOException e) {		SWT.error(SWT.ERROR_IO, e);	}}