From 96886e21d57f26260cb54fccdcea4dcbb5c9c1f2 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 5 Sep 2021 00:20:05 +0000 Subject: [PATCH] Add a API function to get the pixel size of nvnc_fb --- include/neatvnc.h | 1 + include/pixels.h | 2 ++ src/fb.c | 7 +++++++ src/pixels.c | 30 ++++++++++++++++++++++++++++-- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/include/neatvnc.h b/include/neatvnc.h index 6b3f9f7..d10e5c9 100644 --- a/include/neatvnc.h +++ b/include/neatvnc.h @@ -97,6 +97,7 @@ uint16_t nvnc_fb_get_width(const struct nvnc_fb* fb); uint16_t nvnc_fb_get_height(const struct nvnc_fb* fb); uint32_t nvnc_fb_get_fourcc_format(const struct nvnc_fb* fb); int32_t nvnc_fb_get_stride(const struct nvnc_fb* fb); +int nvnc_fb_get_pixel_size(const struct nvnc_fb* fb); struct nvnc_fb_pool* nvnc_fb_pool_new(uint16_t width, uint16_t height, uint32_t fourcc_format, uint16_t stride); diff --git a/include/pixels.h b/include/pixels.h index 5b50989..3ebd1d9 100644 --- a/include/pixels.h +++ b/include/pixels.h @@ -29,3 +29,5 @@ void pixel32_to_cpixel(uint8_t* restrict dst, int rfb_pixfmt_from_fourcc(struct rfb_pixel_format *dst, uint32_t src); uint32_t rfb_pixfmt_to_fourcc(const struct rfb_pixel_format* fmt); + +int pixel_size_from_fourcc(uint32_t fourcc); diff --git a/src/fb.c b/src/fb.c index 32ba580..789d6b9 100644 --- a/src/fb.c +++ b/src/fb.c @@ -15,6 +15,7 @@ */ #include "fb.h" +#include "pixels.h" #include "neatvnc.h" #include @@ -99,6 +100,12 @@ int32_t nvnc_fb_get_stride(const struct nvnc_fb* fb) return fb->stride; } +EXPORT +int nvnc_fb_get_pixel_size(const struct nvnc_fb* fb) +{ + return pixel_size_from_fourcc(fb->fourcc_format); +} + static void nvnc__fb_free(struct nvnc_fb* fb) { nvnc_cleanup_fn cleanup = fb->common.cleanup_fn; diff --git a/src/pixels.c b/src/pixels.c index 5f00bd1..9b25909 100644 --- a/src/pixels.c +++ b/src/pixels.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 - 2020 Andri Yngvason + * Copyright (c) 2019 - 2021 Andri Yngvason * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -220,4 +220,30 @@ bpp_16: dst->true_colour_flag = 1; return 0; -}; +} + +int pixel_size_from_fourcc(uint32_t fourcc) +{ + switch (fourcc & ~DRM_FORMAT_BIG_ENDIAN) { + case DRM_FORMAT_RGBA8888: + case DRM_FORMAT_RGBX8888: + case DRM_FORMAT_BGRA8888: + case DRM_FORMAT_BGRX8888: + case DRM_FORMAT_ARGB8888: + case DRM_FORMAT_XRGB8888: + case DRM_FORMAT_ABGR8888: + case DRM_FORMAT_XBGR8888: + return 4; + case DRM_FORMAT_RGBA4444: + case DRM_FORMAT_RGBX4444: + case DRM_FORMAT_BGRA4444: + case DRM_FORMAT_BGRX4444: + case DRM_FORMAT_ARGB4444: + case DRM_FORMAT_XRGB4444: + case DRM_FORMAT_ABGR4444: + case DRM_FORMAT_XBGR4444: + return 2; + } + + return 0; +}