Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SDL2 - difference between RGB888 and RGB24

Tags:

sdl-2

As best I understand, both the RGB888 and RGB24 formats put their red components first, followed by green and then blue, and both formats take a total of 24 bits per pixel (because 8+8+8 = 24). Given this information both identifiers appear to describe the exact same format but I can verify that some of my code works with one of the two formats but not the other. What's the difference between the two that makes them incompatible?

like image 303
Flaise Avatar asked Nov 27 '15 17:11

Flaise


People also ask

What is Rgb24?

Rgb24 is a sRGB format with 24 bits per pixel (BPP). Each color channel (red, green, and blue) is allocated 8 bits per pixel (BPP).

What format is RGB888?

RGB888. In TouchGFX, a color of 24 bpp color depth will have the color format RGB888. This means that 8 bits are used for each of the color components red, green and blue.

What is pixel format in SDL?

An SDL_PixelFormat describes the format of the pixel data stored at the pixels field of an SDL_Surface. Every surface stores an SDL_PixelFormat in the format field. If you wish to do pixel level modifications on a surface, then understanding how SDL stores its color information is essential.


1 Answers

They are different. If you look at SDL2/SDL_pixels.h you'll find:

SDL_PIXELFORMAT_RGB24 =
    SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_RGB, 0,
                           24, 3)

SDL_PIXELFORMAT_RGB888 =
    SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XRGB,
                           SDL_PACKEDLAYOUT_8888, 24, 4)

SDL_PIXELFORMAT_RGBX8888 =
    SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBX,
                           SDL_PACKEDLAYOUT_8888, 24, 4)

So RGB24 is a tightly packed three byte format (RRGGBB), while RGB888 is a four byte format with the first byte going ignored (XXRRGGBB). So the format is just confusingly named and XRGB8888 would be a more appropriate name.

Don't know why they called it RGB888 instead of XRGB8888, but they leave the leading X away on other formats as well.

like image 166
Grumbel Avatar answered Sep 29 '22 18:09

Grumbel