-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibGfx: Respect order of image data in TGAImageDecoderPlugin
Previously, the order of data was incorrectly based on x_origin and y_origin, which are meant for where on the screen the image should be placed (TarGA is an image format meant for graphic cards), instead of Image descriptor bits 4 and 5, which specify the direction. This fixes a problem where tga files generated with magick would render up-side-down. The test images where created in GIMP, 4 simple 2x2 images exported as .tga, no compression, origin: Bottom Left square-bottom-left.tga: Red, Green Blue, Magenta square-bottom-right.tga: Green, Red Magenta, Blue square-top-left.tga: Blue, Magenta Red, Green square-top-right.tga: Magenta, Blue Green, Red then this script was ran: ```python def update_tga_descriptor(file_path, top_to_bottom, left_to_right): with open(file_path, 'r+b') as f: header = f.read(18) descriptor = header[17] descriptor &= ~(1 << 4); descriptor &= ~(1 << 5); if left_to_right: descriptor |= 1 << 4; if top_to_bottom: descriptor |= 1 << 5; header = header[:17] + bytes([descriptor]) f.seek(0) f.write(header) update_tga_descriptor('square-bottom-left.tga', False, False) update_tga_descriptor('square-bottom-right.tga', False, True) update_tga_descriptor('square-top-left.tga', True, False) update_tga_descriptor('square-top-right.tga', True, True) ```
- Loading branch information
1 parent
76301a6
commit 66bdb3b
Showing
6 changed files
with
30 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters