Mercurial > projects > dwt-mac
diff dwt/internal/image/OS2BMPFileFormat.d @ 34:5123b17c98ef
Ported dwt.events.*, dwt.graphics.GC, Region, dwt.internal.image.*
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sun, 14 Sep 2008 01:45:57 +0200 |
parents | e831403a80a9 |
children | d8635bb48c7c |
line wrap: on
line diff
--- a/dwt/internal/image/OS2BMPFileFormat.d Fri Sep 12 13:53:21 2008 +0200 +++ b/dwt/internal/image/OS2BMPFileFormat.d Sun Sep 14 01:45:57 2008 +0200 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,26 +7,29 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit <benoit@tionex.de> *******************************************************************************/ -module dwt.internal.image; - - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; +module dwt.internal.image.OS2BMPFileFormat; import dwt.DWT; import dwt.graphics.ImageData; import dwt.graphics.ImageLoader; import dwt.graphics.PaletteData; import dwt.graphics.RGB; +import dwt.internal.image.LEDataInputStream; +import dwt.internal.image.FileFormat; +import dwt.dwthelper.ByteArrayOutputStream; +import dwt.dwthelper.utils; -public final class OS2BMPFileFormat : FileFormat { +import tango.core.Exception; + +final class OS2BMPFileFormat : FileFormat { static final int BMPFileHeaderSize = 14; static final int BMPHeaderFixedSize = 12; int width, height, bitCount; -bool isFileFormat(LEDataInputStream stream) { +override bool isFileFormat(LEDataInputStream stream) { try { byte[] header = new byte[18]; stream.read(header); @@ -70,7 +73,7 @@ DWT.error(DWT.ERROR_INVALID_IMAGE); return header; } -ImageData[] loadFromByteStream() { +override ImageData[] loadFromByteStream() { int[] fileHeader = loadFileHeader(); byte[] infoHeader = new byte[BMPHeaderFixedSize]; try { @@ -92,7 +95,7 @@ } byte[] data = loadData(infoHeader); int type = DWT.IMAGE_OS2_BMP; - return new ImageData[] { + return [ ImageData.internal_new( width, height, @@ -110,7 +113,7 @@ 0, 0, 0) - }; + ]; } PaletteData loadPalette(byte[] infoHeader) { if (bitCount <= 8) { @@ -157,10 +160,10 @@ return bytes; } /** - * Unload the given image's data into the given byte stream. + * Unload the given image's data into the given byte stream. * Answer the number of bytes written. */ -int unloadData(ImageData image, OutputStream out) { +int unloadData(ImageData image, OutputStream ostr) { int bmpBpl = 0; try { int bpl = (image.width * image.depth + 7) / 8; @@ -183,7 +186,7 @@ bufOffset += bmpBpl; dataIndex -= imageBpl; } - out.write(buf, 0, bufOffset); + ostr.write(buf, 0, bufOffset); } } else { for (int y = 0; y < image.height; y += linesPerBuf) { @@ -195,7 +198,7 @@ bufOffset += bmpBpl; dataIndex -= imageBpl; } - out.write(buf, 0, bufOffset); + ostr.write(buf, 0, bufOffset); } } } catch (IOException e) { @@ -207,7 +210,7 @@ * Unload a DeviceIndependentImage using Windows .BMP format into the given * byte stream. */ -void unloadIntoByteStream(ImageLoader loader) { +override void unloadIntoByteStream(ImageLoader loader) { ImageData image = loader.data[0]; byte[] rgbs; int numCols; @@ -240,10 +243,10 @@ // 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); - byte[] data = out.toByteArray(); - + ByteArrayOutputStream ostr = new ByteArrayOutputStream(); + unloadData(image, ostr); + byte[] data = ostr.toByteArray(); + // Calculate file size fileHeader[1] = fileHeader[4] + data.length; @@ -266,7 +269,7 @@ } catch (IOException e) { DWT.error(DWT.ERROR_IO, e); } - + // Unload palette if (numCols > 0) { try {