summaryrefslogtreecommitdiff
path: root/libjava/classpath/gnu/javax/imageio/bmp/BMPFileHeader.java
diff options
context:
space:
mode:
authorMark Wielaard <mark@gcc.gnu.org>2006-05-18 17:29:21 +0000
committerMark Wielaard <mark@gcc.gnu.org>2006-05-18 17:29:21 +0000
commit4f9533c7722fa07511a94d005227961f4a4dec23 (patch)
tree9f9c470de62ee62fba1331a396450d728d2b1fad /libjava/classpath/gnu/javax/imageio/bmp/BMPFileHeader.java
parenteaec4980e139903ae9b274d1abcf3a13946603a8 (diff)
Imported GNU Classpath 0.90
Imported GNU Classpath 0.90 * scripts/makemake.tcl: LocaleData.java moved to gnu/java/locale. * sources.am: Regenerated. * gcj/javaprims.h: Regenerated. * Makefile.in: Regenerated. * gcj/Makefile.in: Regenerated. * include/Makefile.in: Regenerated. * testsuite/Makefile.in: Regenerated. * gnu/java/lang/VMInstrumentationImpl.java: New override. * gnu/java/net/local/LocalSocketImpl.java: Likewise. * gnu/classpath/jdwp/VMMethod.java: Likewise. * gnu/classpath/jdwp/VMVirtualMachine.java: Update to latest interface. * java/lang/Thread.java: Add UncaughtExceptionHandler. * java/lang/reflect/Method.java: Implements GenericDeclaration and isSynthetic(), * java/lang/reflect/Field.java: Likewise. * java/lang/reflect/Constructor.java * java/lang/Class.java: Implements Type, GenericDeclaration, getSimpleName() and getEnclosing*() methods. * java/lang/Class.h: Add new public methods. * java/lang/Math.java: Add signum(), ulp() and log10(). * java/lang/natMath.cc (log10): New function. * java/security/VMSecureRandom.java: New override. * java/util/logging/Logger.java: Updated to latest classpath version. * java/util/logging/LogManager.java: New override. From-SVN: r113887
Diffstat (limited to 'libjava/classpath/gnu/javax/imageio/bmp/BMPFileHeader.java')
-rw-r--r--libjava/classpath/gnu/javax/imageio/bmp/BMPFileHeader.java39
1 files changed, 32 insertions, 7 deletions
diff --git a/libjava/classpath/gnu/javax/imageio/bmp/BMPFileHeader.java b/libjava/classpath/gnu/javax/imageio/bmp/BMPFileHeader.java
index 246e0eacfeb..4ba32d3c30a 100644
--- a/libjava/classpath/gnu/javax/imageio/bmp/BMPFileHeader.java
+++ b/libjava/classpath/gnu/javax/imageio/bmp/BMPFileHeader.java
@@ -37,27 +37,32 @@ exception statement from your version. */
package gnu.javax.imageio.bmp;
+import java.awt.image.RenderedImage;
import java.io.IOException;
-import javax.imageio.stream.ImageInputStream;
-import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import javax.imageio.IIOImage;
+import javax.imageio.stream.ImageInputStream;
+import javax.imageio.stream.ImageOutputStream;
+
public class BMPFileHeader {
/** Header signature, always 'BM' */
private final static short bfType = 0x424d;
/** Bitmap file size, in bytes. */
- private long bfSize;
+ protected long bfSize;
/** Offset from the beginning of the file to the bitmap data */
- private long bfOffBits;
+ protected long bfOffBits;
/** BITMAPFILEHEADER is 14 bytes */
public static final int SIZE = 14;
-
+ private static final int BITMAPINFOHEADER_SIZE = 40;
+
/**
* Creates the header from an input stream, which is not closed.
+ *
* @throws IOException if an I/O error occured.
* @throws BMPException if the header was invalid
*/
@@ -82,17 +87,37 @@ public class BMPFileHeader {
bfOffBits = ((long)buf.getInt(10) & (0xFFFFFFFF));
}
+
+ /**
+ * Creates the header from an output stream, which is not closed.
+ *
+ * @param out - the image output stream
+ * @param im - the image
+ * @throws IOException if an I/O error occured.
+ */
+ public BMPFileHeader(ImageOutputStream out, IIOImage im) throws IOException
+ {
+ RenderedImage img = im.getRenderedImage();
+ int w = img.getWidth();
+ int h = img.getHeight();
+
+ bfOffBits = SIZE + BITMAPINFOHEADER_SIZE;
+ bfSize = ((w * h) * 3) + ((4 - ((w * 3) % 4)) * h) + bfOffBits;
+
+ write(out);
+ }
/**
* Writes the header to an output stream, which is not closed or flushed.
+ *
* @throws IOException if an I/O error occured.
*/
- public void write(OutputStream out) throws IOException {
+ public void write(ImageOutputStream out) throws IOException {
ByteBuffer buf = ByteBuffer.allocate(SIZE);
buf.putShort(0, bfType); // ID
buf.putInt(2, (int)(bfSize & (0xFFFFFFFF))); // size
buf.putInt(6, 0); // 4 reserved bytes set to zero
- buf.putInt(2, (int)(bfOffBits & (0xFFFFFFFF))); // size
+ buf.putInt(7, (int)(bfOffBits & (0xFFFFFFFF))); // size
out.write(buf.array());
}