pixels: Add function to get rfb pixel format name
parent
0e0fe5b73a
commit
c876b91541
|
@ -40,3 +40,4 @@ bool extract_alpha_mask(uint8_t* dst, const void* src, uint32_t format,
|
|||
size_t len);
|
||||
|
||||
const char* drm_format_to_string(uint32_t fmt);
|
||||
const char* rfb_pixfmt_to_string(const struct rfb_pixel_format* fmt);
|
||||
|
|
31
src/pixels.c
31
src/pixels.c
|
@ -470,3 +470,34 @@ const char* drm_format_to_string(uint32_t fmt)
|
|||
}
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
// Not exact, but close enough for debugging
|
||||
const char* rfb_pixfmt_to_string(const struct rfb_pixel_format* fmt)
|
||||
{
|
||||
if (!(fmt->red_max == fmt->green_max && fmt->red_max == fmt->blue_max))
|
||||
goto failure;
|
||||
|
||||
uint32_t profile = (fmt->red_shift << 16) | (fmt->green_shift << 8)
|
||||
| (fmt->blue_shift);
|
||||
|
||||
switch (profile) {
|
||||
#define CASE(r, g, b) case ((r << 16) | (g << 8) | b)
|
||||
CASE(22, 10, 2): return "RGBX1010102";
|
||||
CASE(2, 12, 22): return "BGRX1010102";
|
||||
CASE(20, 10, 0): return "XRGB2101010";
|
||||
CASE(0, 10, 20): return "XBGR2101010";
|
||||
CASE(24, 16, 8): return "RGBX8888";
|
||||
CASE(8, 16, 24): return "BGRX8888";
|
||||
CASE(16, 8, 0): return "XRGB8888";
|
||||
CASE(0, 8, 16): return "XBGR8888";
|
||||
CASE(12, 8, 4): return "RGBX4444";
|
||||
CASE(4, 8, 12): return "BGRX4444";
|
||||
CASE(8, 4, 0): return "XRGB4444";
|
||||
CASE(0, 4, 8): return "XBGR4444";
|
||||
CASE(11, 5, 0): return "RGB565";
|
||||
#undef CASE
|
||||
}
|
||||
|
||||
failure:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
|
|
@ -144,11 +144,39 @@ static bool test_drm_format_to_string(void)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool test_rfb_pixfmt_to_string(void)
|
||||
{
|
||||
struct rfb_pixel_format rgbx8888;
|
||||
struct rfb_pixel_format bgrx8888;
|
||||
struct rfb_pixel_format xrgb8888;
|
||||
struct rfb_pixel_format xbgr8888;
|
||||
|
||||
rfb_pixfmt_from_fourcc(&rgbx8888, DRM_FORMAT_RGBX8888);
|
||||
rfb_pixfmt_from_fourcc(&bgrx8888, DRM_FORMAT_BGRX8888);
|
||||
rfb_pixfmt_from_fourcc(&xrgb8888, DRM_FORMAT_XRGB8888);
|
||||
rfb_pixfmt_from_fourcc(&xbgr8888, DRM_FORMAT_XBGR8888);
|
||||
|
||||
if (strcmp(rfb_pixfmt_to_string(&rgbx8888), "RGBX8888") != 0)
|
||||
return false;
|
||||
|
||||
if (strcmp(rfb_pixfmt_to_string(&bgrx8888), "BGRX8888") != 0)
|
||||
return false;
|
||||
|
||||
if (strcmp(rfb_pixfmt_to_string(&xrgb8888), "XRGB8888") != 0)
|
||||
return false;
|
||||
|
||||
if (strcmp(rfb_pixfmt_to_string(&xbgr8888), "XBGR8888") != 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
bool ok = test_pixel32_to_cpixel_4bpp() &&
|
||||
test_fourcc_to_pixman_fmt() &&
|
||||
test_extract_alpha_mask_rgba8888() &&
|
||||
test_drm_format_to_string();
|
||||
test_drm_format_to_string() &&
|
||||
test_rfb_pixfmt_to_string();
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue