diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2026-10-12 20:31:10 +0200 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2026-10-12 20:31:10 +0200 |
| commit | e06434fd89345fdc4e931f6fa3904626d75097db (patch) | |
| tree | 75287102b1e1ec85db4cdb7d634da4b5fee6f9a7 /doc | |
| parent | c6f5cca39dad3f395e8b479f6106feb10e710695 (diff) | |
Fix Byte Order for Surface Pixels
I went down a deep rabbithole to understand the pixel order, and
it turns out that the Emscripten library code is setting the wrong
`format` value for what it actually uses, which threw me off.
We now set the correct pixel format tag, and handle pixel byte
ordering correctly on the host.
Some other minor fixes.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/journal.md | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/doc/journal.md b/doc/journal.md index 7bfce6a..a0d18b5 100644 --- a/doc/journal.md +++ b/doc/journal.md @@ -1,3 +1,18 @@ +# 12.10.2026 + +Looking at the exported Emscripted glue code, it encodes the pixel format as `0x86462004` which is `SDL_PIXELFORMAT_RGBA8888` - an endian-independent pixel format. For example, the PICO-8 baby blue is encoded as: + +``` +[0x29, 0xad, 0xff, 0xff] +#ffffad29 r=29 g=ad b=ff a=ff +``` + +However, this contradicts my understanding of SDL pixel formats. From the docs: + +> Names with a bit count per component, such as ARGB8888 [...], are "packed" into an appropriately-sized integer in the platform's native endianness. For example, ARGB8888 is a sequence of 32-bit integers; in each integer, the most significant bits are alpha, and the least significant bits are blue. On a little-endian CPU such as x86, the least significant bits of each integer are arranged first in memory, but on a big-endian CPU such as s390x, the most significant bits are arranged first. Use these names if the property of a format that is important to you is the meaning of each bit position within a native-endianness integer. + +Which suggests, given the mask and pixel order, should be `ABGR8888` instead. Use the correct value `0x86762004` instead of just copying what the Emscripten glue code does, we can revert it in case it causes issues with the actual PICO-8 engine once we get there. + # 02.10.2026 I figured out that PICO-8 is built with Emscripten using the [SDL 1.3 built-in](https://github.com/emscripten-core/emscripten/tree/main/system/include/SDL). We can use the headers to understand memory layout of the various pieces used by PICO-8. I noticed that: |
