Browse Source

Adds handling of negative height value for bmp files. (#644)

* Adds handling of negative height value for bmp files.

* Simplifies negative height check, and moves it down to include checking the OS/2 16-bit version.

* Adds int16 conversion to OS/2 height.
Joshua Banton 3 years ago
parent
commit
9a3feab9cc
1 changed files with 7 additions and 2 deletions
  1. 7 2
      imagemeta/bmp.go

+ 7 - 2
imagemeta/bmp.go

@@ -29,11 +29,16 @@ func DecodeBmpMeta(r io.Reader) (Meta, error) {
 
 	if infoSize >= 40 {
 		width = int(binary.LittleEndian.Uint32(tmp[18:22]))
-		height = int(binary.LittleEndian.Uint32(tmp[22:26]))
+		height = int(int32(binary.LittleEndian.Uint32(tmp[22:26])))
 	} else {
 		// CORE
 		width = int(binary.LittleEndian.Uint16(tmp[18:20]))
-		height = int(binary.LittleEndian.Uint16(tmp[20:22]))
+		height = int(int16(binary.LittleEndian.Uint16(tmp[20:22])))
+	}
+
+	// height can be negative in Windows bitmaps
+	if height < 0 {
+		height = -height
 	}
 
 	return &meta{