Skip to content

Commit

Permalink
get pixel size from fourcc to calculate pixel stride
Browse files Browse the repository at this point in the history
  • Loading branch information
MazTheMan authored and any1 committed Sep 29, 2023
1 parent 8ed08d6 commit ec885cf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/pixels.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@

enum wl_shm_format fourcc_to_wl_shm(uint32_t in);
uint32_t fourcc_from_wl_shm(enum wl_shm_format in);
int pixel_size_from_fourcc(uint32_t fourcc);
5 changes: 3 additions & 2 deletions src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ struct wv_buffer* wv_buffer_create_shm(int width,
if (!self->wl_buffer)
goto shm_failure;

// TODO: Get the pixel size from the format instead of assuming it's 4.
int bpp = pixel_size_from_fourcc(fourcc);
assert(bpp > 0);
self->nvnc_fb = nvnc_fb_from_buffer(self->pixels, width, height, fourcc,
stride / 4);
stride / bpp);
if (!self->nvnc_fb) {
goto nvnc_fb_failure;
}
Expand Down
37 changes: 37 additions & 0 deletions src/pixels.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,40 @@ uint32_t fourcc_from_wl_shm(enum wl_shm_format in)

return in;
}

int pixel_size_from_fourcc(uint32_t fourcc)
{
switch (fourcc & ~DRM_FORMAT_BIG_ENDIAN) {
case DRM_FORMAT_RGBA1010102:
case DRM_FORMAT_RGBX1010102:
case DRM_FORMAT_BGRA1010102:
case DRM_FORMAT_BGRX1010102:
case DRM_FORMAT_ARGB2101010:
case DRM_FORMAT_XRGB2101010:
case DRM_FORMAT_ABGR2101010:
case DRM_FORMAT_XBGR2101010:
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_BGR888:
case DRM_FORMAT_RGB888:
return 3;
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;
}

0 comments on commit ec885cf

Please sign in to comment.