Extract pixel format conversion into own file

pull/55/head
Andri Yngvason 2020-06-20 21:41:53 +00:00
parent a6e1ba25ea
commit e65cae43c2
3 changed files with 52 additions and 34 deletions

9
include/pixels.h 100644
View File

@ -0,0 +1,9 @@
#pragma once
#include <pixman.h>
#include <wayland-client.h>
#include <libdrm/drm_fourcc.h>
#include <stdbool.h>
enum wl_shm_format fourcc_to_wl_shm(uint32_t in);
bool fourcc_to_pixman_fmt(pixman_format_code_t* dst, uint32_t src);

View File

@ -11,43 +11,10 @@
#include "shm.h" #include "shm.h"
#include "sys/queue.h" #include "sys/queue.h"
#include "buffer.h" #include "buffer.h"
#include "pixels.h"
extern struct wl_shm* wl_shm; 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, struct wv_buffer* wv_buffer_create(int width, int height, int stride,
uint32_t fourcc) uint32_t fourcc)
{ {

42
src/pixels.c 100644
View File

@ -0,0 +1,42 @@
#include "pixels.h"
#include <pixman.h>
#include <wayland-client.h>
#include <assert.h>
#include <libdrm/drm_fourcc.h>
#include <stdbool.h>
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;
}