Files
serenity/Tests/LibGfx/test-inputs
Marcus Nilsson 66bdb3bf43 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)
```
2024-09-18 06:34:19 -04:00
..
2024-01-26 07:36:53 +01:00