diff --git a/include/pixels.h b/include/pixels.h new file mode 100644 index 0000000..6663b03 --- /dev/null +++ b/include/pixels.h @@ -0,0 +1,9 @@ +#pragma once + +#include +#include +#include +#include + +enum wl_shm_format fourcc_to_wl_shm(uint32_t in); +bool fourcc_to_pixman_fmt(pixman_format_code_t* dst, uint32_t src); diff --git a/src/buffer.c b/src/buffer.c index 8c6b0c9..25b1514 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -11,43 +11,10 @@ #include "shm.h" #include "sys/queue.h" #include "buffer.h" +#include "pixels.h" extern struct wl_shm* wl_shm; -static enum wl_shm_format fourcc_to_wl_shm(uint32_t in) -{ - assert(!(in & DRM_FORMAT_BIG_ENDIAN)); - - switch (in) { - case DRM_FORMAT_ARGB8888: return WL_SHM_FORMAT_ARGB8888; - case DRM_FORMAT_XRGB8888: return WL_SHM_FORMAT_XRGB8888; - } - - return in; -} - -static bool fourcc_to_pixman_fmt(pixman_format_code_t* dst, uint32_t src) -{ - assert(!(src & DRM_FORMAT_BIG_ENDIAN)); - - /* TODO: Add more, perhaps with the help of - * https://github.com/afrantzis/pixel-format-guide - */ - switch (src) { - case DRM_FORMAT_ARGB8888: *dst = PIXMAN_a8r8g8b8; break; - case DRM_FORMAT_XRGB8888: *dst = PIXMAN_x8r8g8b8; break; - case DRM_FORMAT_ABGR8888: *dst = PIXMAN_a8b8g8r8; break; - case DRM_FORMAT_XBGR8888: *dst = PIXMAN_x8b8g8r8; break; - case DRM_FORMAT_RGBA8888: *dst = PIXMAN_r8g8b8a8; break; - case DRM_FORMAT_RGBX8888: *dst = PIXMAN_r8g8b8x8; break; - case DRM_FORMAT_BGRA8888: *dst = PIXMAN_b8g8r8a8; break; - case DRM_FORMAT_BGRX8888: *dst = PIXMAN_b8g8r8x8; break; - default: return false; - } - - return true; -} - struct wv_buffer* wv_buffer_create(int width, int height, int stride, uint32_t fourcc) { diff --git a/src/pixels.c b/src/pixels.c new file mode 100644 index 0000000..e93d947 --- /dev/null +++ b/src/pixels.c @@ -0,0 +1,42 @@ +#include "pixels.h" + +#include +#include +#include +#include +#include + +enum wl_shm_format fourcc_to_wl_shm(uint32_t in) +{ + assert(!(in & DRM_FORMAT_BIG_ENDIAN)); + + switch (in) { + case DRM_FORMAT_ARGB8888: return WL_SHM_FORMAT_ARGB8888; + case DRM_FORMAT_XRGB8888: return WL_SHM_FORMAT_XRGB8888; + } + + return in; +} + +bool fourcc_to_pixman_fmt(pixman_format_code_t* dst, uint32_t src) +{ + assert(!(src & DRM_FORMAT_BIG_ENDIAN)); + + /* TODO: Add more, perhaps with the help of + * https://github.com/afrantzis/pixel-format-guide + */ + switch (src) { + case DRM_FORMAT_ARGB8888: *dst = PIXMAN_a8r8g8b8; break; + case DRM_FORMAT_XRGB8888: *dst = PIXMAN_x8r8g8b8; break; + case DRM_FORMAT_ABGR8888: *dst = PIXMAN_a8b8g8r8; break; + case DRM_FORMAT_XBGR8888: *dst = PIXMAN_x8b8g8r8; break; + case DRM_FORMAT_RGBA8888: *dst = PIXMAN_r8g8b8a8; break; + case DRM_FORMAT_RGBX8888: *dst = PIXMAN_r8g8b8x8; break; + case DRM_FORMAT_BGRA8888: *dst = PIXMAN_b8g8r8a8; break; + case DRM_FORMAT_BGRX8888: *dst = PIXMAN_b8g8r8x8; break; + default: return false; + } + + return true; +} +