--- a/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPImageWriter.java Mon Jun 08 13:56:45 2009 -0700
+++ b/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPImageWriter.java Thu Jun 11 13:47:42 2009 +0400
@@ -506,6 +506,19 @@
writeFileHeader(fileSize, offset);
+ /* According to MSDN description, the top-down image layout
+ * is allowed only if compression type is BI_RGB or BI_BITFIELDS.
+ * Images with any other compression type must be wrote in the
+ * bottom-up layout.
+ */
+ if (compressionType == BMPConstants.BI_RGB ||
+ compressionType == BMPConstants.BI_BITFIELDS)
+ {
+ isTopDown = bmpParam.isTopDown();
+ } else {
+ isTopDown = false;
+ }
+
writeInfoHeader(headerSize, bitsPerPixel);
// compression
@@ -588,8 +601,6 @@
return;
}
- isTopDown = bmpParam.isTopDown();
-
int maxBandOffset = bandOffsets[0];
for (int i = 1; i < bandOffsets.length; i++)
if (bandOffsets[i] > maxBandOffset)
@@ -1299,7 +1310,7 @@
stream.writeInt(w);
// height
- stream.writeInt(h);
+ stream.writeInt(isTopDown ? -h : h);
// number of planes
stream.writeShort(1);