pixels: Add function to convert drm format to string

pull/63/head
Andri Yngvason 2022-02-12 12:30:12 +00:00
parent 4dcf8ec25b
commit 0e0fe5b73a
3 changed files with 54 additions and 1 deletions

View File

@ -38,3 +38,5 @@ bool fourcc_to_pixman_fmt(pixman_format_code_t* dst, uint32_t src);
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);

View File

@ -22,6 +22,8 @@
#define POPCOUNT(x) __builtin_popcount(x)
#define UDIV_UP(a, b) (((a) + (b) - 1) / (b))
#define XSTR(s) STR(s)
#define STR(s) #s
void pixel32_to_cpixel(uint8_t* restrict dst,
const struct rfb_pixel_format* dst_fmt,
@ -434,3 +436,37 @@ bool extract_alpha_mask(uint8_t* dst, const void* src, uint32_t format,
return false;
}
const char* drm_format_to_string(uint32_t fmt)
{
switch (fmt) {
#define X(x) case DRM_FORMAT_ ## x: return XSTR(x);
X(RGBA1010102) \
X(RGBX1010102) \
X(BGRA1010102) \
X(BGRX1010102) \
X(ARGB2101010) \
X(XRGB2101010) \
X(ABGR2101010) \
X(XBGR2101010) \
X(RGBA8888) \
X(RGBX8888) \
X(BGRA8888) \
X(BGRX8888) \
X(ARGB8888) \
X(XRGB8888) \
X(ABGR8888) \
X(XBGR8888) \
X(RGBA4444) \
X(RGBX4444) \
X(BGRA4444) \
X(BGRX4444) \
X(ARGB4444) \
X(XRGB4444) \
X(ABGR4444) \
X(XBGR4444) \
X(RGB565)
#undef X
}
return "UNKNOWN";
}

View File

@ -130,10 +130,25 @@ static bool test_extract_alpha_mask_rgba8888(void)
return true;
}
static bool test_drm_format_to_string(void)
{
if (strcmp(drm_format_to_string(DRM_FORMAT_RGBA8888), "RGBA8888") != 0)
return false;
if (strcmp(drm_format_to_string(DRM_FORMAT_RGBX8888), "RGBX8888") != 0)
return false;
if (strcmp(drm_format_to_string(DRM_FORMAT_RGB565), "RGB565") != 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_extract_alpha_mask_rgba8888() &&
test_drm_format_to_string();
return ok ? 0 : 1;
}