Skip to content

Commit

Permalink
Skip test for big-endian .xcf loading (#259)
Browse files Browse the repository at this point in the history
* tests: Test image loading in a predictable order

This makes it easier to compare different architectures' ability to load
the various file formats.

Signed-off-by: Simon McVittie <smcv@collabora.com>

* ext.image: Make comments and variable naming less confusing

Somewhat confusingly, SDL uses ABGR8888 to represent a format where each
32-bit unit can be interpreted as 0xAABBGGRR in native endianness,
whereas it uses ARGB32 to represent a format where 8-bit units can be
interpreted as AA, RR, GG, BB in that order. Stick to the same
terminology as SDL here, and be clearer about what we mean.

No functional change intended.

Signed-off-by: Simon McVittie <smcv@collabora.com>

* tests: Skip pixel comparison when loading XCF files on big-endian

This isn't working for me. On x86 I get the desired rendering, but on
s390x, for example the pixels in the first row that should have been
green and red come out as transparent black.

There are no big-endian architectures that are relevant for gaming this
decade, and XCF is not a widespread format for game use, so it seems
reasonable to ignore this.

Signed-off-by: Simon McVittie <smcv@collabora.com>

---------

Signed-off-by: Simon McVittie <smcv@collabora.com>
  • Loading branch information
smcv committed Feb 13, 2023
1 parent 8c39f40 commit d08494f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions sdl2/ext/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,18 @@ def _get_mode_properties(mode):


def _ensure_argb32(sf, fname):
# Check if image already ARGB32 and return if True
ARGB32 = pixels.SDL_PIXELFORMAT_ARGB8888
if sf.contents.format.contents.format == ARGB32:
# Return if it's already SDL_PIXELFORMAT_ABGR8888.
# As per SDL documentation, this is the format where each 32-bit word
# (in machine-native endianness) has alpha in the most significant
# 8 bits and red in the least significant, so the 32-bit word
# 0xff0066cc is equivalent to HTML #cc6600.
ARGB8888 = pixels.SDL_PIXELFORMAT_ARGB8888
if sf.contents.format.contents.format == ARGB8888:
return sf

# Convert the image to ARGB32. Note that this frees the original surface.
out_fmt = pixels.SDL_AllocFormat(ARGB32)
# Convert the image to the desired format. Note that this frees the
# original surface.
out_fmt = pixels.SDL_AllocFormat(ARGB8888)
converted = surface.SDL_ConvertSurface(sf, out_fmt, 0)
surface.SDL_FreeSurface(sf)
if not converted:
Expand Down
4 changes: 2 additions & 2 deletions sdl2/test/sdl2ext_image_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

# Skip ICO and CUR tests on big-endian, since they don't seem to work yet
if sys.byteorder == "big":
skip_color_check += ['ico', 'cur']
skip_color_check += ['ico', 'cur', 'xcf']

# SDL 2.0.10 has a bug that messes up converting surfaces with transparency
if sdl2.dll.version == 2010:
Expand Down Expand Up @@ -140,7 +140,7 @@ def test_load_img(with_sdl):
# Test loading all test images, with and without ARGB conversion
resources = os.listdir(resource_path)
test_imgs = [f for f in resources if f[:11] == "surfacetest"]
for img in test_imgs:
for img in sorted(test_imgs):
img_path = os.path.join(resource_path, img)
fmt = img.split(".")[-1]
if fmt in skip_formats:
Expand Down

0 comments on commit d08494f

Please sign in to comment.