[Image-SIG] Support for writing tga images of different orientations
Alexey Borzenkov
snaury at gmail.com
Fri Jun 22 20:35:35 CEST 2007
Hi everyone,
Another patch (against my tga saving patch) that I'm not sure anyone
needs or appreciates:
Index: PIL/TgaImagePlugin.py
===================================================================
--- PIL/TgaImagePlugin.py (revision 284)
+++ PIL/TgaImagePlugin.py (revision 331)
@@ -100,6 +100,8 @@
else:
raise SyntaxError, "unknown TGA orientation"
+ self.info["orientation"] = orientation
+
if imagetype & 8:
self.info["compression"] = "tga_rle"
@@ -163,6 +165,15 @@
else:
colormapfirst, colormaplength, colormapentry = 0, 0, 0
+ if im.mode == "RGBA":
+ flags = 8
+ else:
+ flags = 0
+
+ orientation = im.info.get("orientation", -1)
+ if orientation > 0:
+ flags = flags | 0x20
+
fp.write("\000" +
chr(colormaptype) +
chr(imagetype) +
@@ -174,12 +185,12 @@
o16(im.size[0]) +
o16(im.size[1]) +
chr(bits) +
- chr(0x20))
+ chr(flags))
if colormaptype:
fp.write(im.im.getpalette("RGB", "BGR"))
- ImageFile._save(im, fp, [("raw", (0,0)+im.size, 0, (rawmode, 0, 1))])
+ ImageFile._save(im, fp, [("raw", (0,0)+im.size, 0, (rawmode, 0,
orientation))])
#
# --------------------------------------------------------------------
More information about the Image-SIG
mailing list