outputStream.writeInt(compressedData.length);
outputStream.writeInt(data.length);
void unloadIntoByteStream(ImageData image) {	byte[] rgbs;	int numCols;	if (!((image.depth == 1) || (image.depth == 4) || (image.depth == 8) ||		  (image.depth == 16) || (image.depth == 24) || (image.depth == 32)))			SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);	int comp = this.compression;	if (!((comp == 0) || ((comp == 1) && (image.depth == 8)) ||		  ((comp == 2) && (image.depth == 4))))			SWT.error(SWT.ERROR_INVALID_IMAGE);	PaletteData pal = image.palette;	if ((image.depth == 16) || (image.depth == 24) || (image.depth == 32)) {		if (!pal.isDirect)			SWT.error(SWT.ERROR_INVALID_IMAGE);		numCols = 0;		rgbs = null;	} else {		if (pal.isDirect)			SWT.error(SWT.ERROR_INVALID_IMAGE);		numCols = pal.colors.length;		rgbs = paletteToBytes(pal);	}	// Fill in file header, except for bfsize, which is done later.	int headersSize = 54;	int[] fileHeader = new int[5];	fileHeader[0] = 0x4D42;	// Signature	fileHeader[1] = 0; // File size - filled in later	fileHeader[2] = 0; // Reserved 1	fileHeader[3] = 0; // Reserved 2	fileHeader[4] = headersSize; // Offset to data	if (rgbs != null) {		fileHeader[4] += rgbs.length;	}	// Prepare data. This is done first so we don't have to try to rewind	// the stream and fill in the details later.	ByteArrayOutputStream out = new ByteArrayOutputStream();	unloadData(image, out, comp);	byte[] compressedData = out.toByteArray();		// Calculate file size	fileHeader[1] = fileHeader[4] + compressedData.length;	// Write the headers	try {		outputStream.writeShort(fileHeader[0]);		outputStream.writeInt(fileHeader[1]);		outputStream.writeShort(fileHeader[2]);		outputStream.writeShort(fileHeader[3]);		outputStream.writeInt(fileHeader[4]);	} catch (IOException e) {		SWT.error(SWT.ERROR_IO, e);	}	try {		outputStream.writeInt(WinBMPFileFormat.BMPHeaderFixedSize);		outputStream.writeInt(image.width);		outputStream.writeInt(image.height);		outputStream.writeShort(1);		outputStream.writeShort((short)image.depth);		outputStream.writeInt(comp);		outputStream.writeInt(compressedData.length);		outputStream.writeInt(pelsPerMeter.x);		outputStream.writeInt(pelsPerMeter.y);		outputStream.writeInt(numCols);		outputStream.writeInt(importantColors);	} catch (IOException e) {		SWT.error(SWT.ERROR_IO, e);	}		// Unload palette	if (numCols > 0) {		try {			outputStream.write(rgbs);		} catch (IOException e) {			SWT.error(SWT.ERROR_IO, e);		}	}	// Unload the data	try {		outputStream.write(compressedData);	} catch (IOException e) {		SWT.error(SWT.ERROR_IO, e);	}}