Swapped channels in SDL

27 views
Skip to first unread message

Piotr Grochowski

unread,
Nov 4, 2022, 3:55:46 PM11/4/22
to emscripten-discuss
SDL2 library in emscripten swaps red and blue channels which makes it false color.

//C:\dm\bin\dmc colortest.cpp -o -I C:\dm\stlport\stlport -I C:\Users\Admin\Downloads\SDL2-devel-2.0.22-VC\SDL2-2.0.22\include C:\Users\Admin\Downloads\SDL2-devel-2.0.22-VC\SDL2-2.0.22\lib\x86\sdl.lib -L/exet:nt/su:windows:4.0
//emcc colortest.cpp -O3 -sUSE_SDL=2 -sASYNCIFY -sALLOW_MEMORY_GROWTH -o colortest.html
#define SDL_MAIN_HANDLED
#include <SDL.h>
int main(int argc, char *argv[]){
    const int width=128; const int height=64;
    SDL_Window* window = SDL_CreateWindow("color test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, 0);
    SDL_Surface* screenSurface = SDL_GetWindowSurface(window);
    unsigned* bitmapdata = (unsigned*)screenSurface->pixels;
    for(int i=0;i<width*height;i++)bitmapdata[i]=(i>>5&1?0xFF0000:0)|(i>>6&1?0x00FF00:0)|(i>>12&1?0x0000FF:0);
    while (1){
    SDL_Event event_;
    while (SDL_PollEvent(&event_)) if(event_.type==SDL_QUIT)exit(0);
    SDL_UpdateWindowSurface(window); SDL_Delay(1);
    }
    return 0;
}

https://i.imgur.com/EMQhoF5.png

How do I ensure the video image is always drawn correctly when  represented in 0x00RRGGBB (note: little endian byte order is BGR)?

Sam Clegg

unread,
Nov 4, 2022, 5:18:16 PM11/4/22
to emscripte...@googlegroups.com
I was able to reproduce this locally too.  Would you mind opening a bug on the emscripten tracker?

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/b6b2f368-7ef3-4ec6-89a4-3ef7862108b8n%40googlegroups.com.

Piotr Grochowski

unread,
Nov 4, 2022, 5:53:24 PM11/4/22
to emscripten-discuss
How come you are telling me to create a topic for this when you’re replying to the topic I already made?

Sam Clegg

unread,
Nov 4, 2022, 6:41:58 PM11/4/22
to emscripte...@googlegroups.com
On Fri, Nov 4, 2022 at 2:53 PM Piotr Grochowski <anydesksu...@gmail.com> wrote:
How come you are telling me to create a topic for this when you’re replying to the topic I already made?

This is a thread on the mailing list.  Since this seems like a bug, I was suggesting we open a bug at https://github.com/emscripten-core/emscripten/issues.  

Piotr Grochowski

unread,
Nov 5, 2022, 1:29:50 AM11/5/22
to emscripten-discuss
No thanks, I was suspended many times on GitHub so I am a gitphobe.
Reply all
Reply to author
Forward
0 new messages