We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3964

Summary: [PATCH] YUV to RGB in video/SDL_yuv.c is broken for any output format of type ABGR8888 or BGR888
Product: SDL Reporter: raist66676
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2 CC: raist66676
Version: HG 2.0   
Hardware: All   
OS: All   
Attachments: proposed patch to fix bug 3964 by fixing the typos in src/video/SDL_yuv.c

Description raist66676 2017-11-17 06:05:25 UTC
Here is the bug in latest SDL 2.0.8 development repo. It is obvious and simple to fix by correcting typos on six lines of code.

In “src/video/SDL_yuv.c,” on lines 217, 249, 280, 321, 353, and 384 the wrong conversion functions are called for SDL_PIXELFORMAT_ABGR8888 and SDL_PIXELFORMAT_BGR888. Instead of ABGR functions, BGRA functions are called. These are typos.

One example in context:
(…)
line 312:
case SDL_PIXELFORMAT_BGRX8888:
case SDL_PIXELFORMAT_BGRA8888:
yuv420_bgra_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
return SDL_TRUE;
case SDL_PIXELFORMAT_RGB888:
case SDL_PIXELFORMAT_ARGB8888:
yuv420_argb_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
return SDL_TRUE;
case SDL_PIXELFORMAT_BGR888:
case SDL_PIXELFORMAT_ABGR8888:
yuv420_bgra_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
return SDL_TRUE;

Notice the second to last line, line 321 has a typo. it should read
line321:
yuv420_abgr_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);

Similarly for line 353, it should read
line353:
yuv422_abgr_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);

Similarly for line 383, it should read
line383:
yuvnv12_abgr_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);

And the same typo is also present in the SSE function calls:
line217 should read:
yuv420_abgr_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
line249 should read:
yuv422_abgr_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
line 280 should read:
yuvnv12_abgr_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);

In summary, in six places in src/video/SDL_yuv.c, “bgra” should be switched to “abgr”.

It is clear from the context that it is a bug: Why would BGRA and ABGR pixel formats use the same conversion function?

But of course I also double-checked it using a program that displayed the wrong colors when linked to latest 2.0.8 HG but worked fine in previous versions. And indeed, these changes fixed the output. SDL was simply calling the wrong conversion function due to these typos.
Comment 1 raist66676 2017-11-17 18:45:25 UTC
Created attachment 3088 [details]
proposed patch to fix bug 3964 by fixing the typos in src/video/SDL_yuv.c
Comment 2 Sam Lantinga 2017-11-17 19:03:02 UTC
Good catch, thanks!
https://hg.libsdl.org/SDL/rev/88462f00ffac