modetest: simplify planar YUV handling

In preparation to adding more planar YUV formats, introduce X, Y
subsampling ratios and use them to calculate plane offsets and buffer
size.

Reviewed-by: Marijn Suijten <marijn.suijten@somainline.org>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
This commit is contained in:
Dmitry Baryshkov 2024-09-08 07:37:15 +03:00
parent bea14386bc
commit 38c043dca2

View file

@ -116,9 +116,10 @@ bo_create(int fd, unsigned int format,
unsigned int handles[4], unsigned int pitches[4],
unsigned int offsets[4], enum util_fill_pattern pattern)
{
unsigned int virtual_height;
unsigned int virtual_height, xsub, ysub;
struct bo *bo;
unsigned int bpp;
bool is_planar;
void *planes[3] = { 0, };
void *virtual;
int ret;
@ -223,26 +224,38 @@ bo_create(int fd, unsigned int format,
case DRM_FORMAT_NV15:
case DRM_FORMAT_YUV420:
case DRM_FORMAT_YVU420:
virtual_height = height * 3 / 2;
is_planar = true;
xsub = 2;
ysub = 2;
break;
case DRM_FORMAT_NV16:
case DRM_FORMAT_NV61:
case DRM_FORMAT_NV20:
virtual_height = height * 2;
is_planar = true;
xsub = 2;
ysub = 1;
break;
case DRM_FORMAT_NV24:
case DRM_FORMAT_NV42:
case DRM_FORMAT_NV30:
virtual_height = height * 3;
is_planar = true;
xsub = 1;
ysub = 1;
break;
default:
virtual_height = height;
is_planar = false;
xsub = 1;
ysub = 1;
break;
}
virtual_height = height;
if (is_planar)
virtual_height += height * 2 / xsub / ysub;
bo = bo_create_dumb(fd, width, virtual_height, bpp);
if (!bo)
return NULL;
@ -275,25 +288,14 @@ bo_create(int fd, unsigned int format,
case DRM_FORMAT_NV16:
case DRM_FORMAT_NV61:
case DRM_FORMAT_NV15:
case DRM_FORMAT_NV20:
offsets[0] = 0;
handles[0] = bo->handle;
pitches[0] = bo->pitch;
pitches[1] = pitches[0];
offsets[1] = pitches[0] * height;
handles[1] = bo->handle;
planes[0] = virtual;
planes[1] = virtual + offsets[1];
break;
case DRM_FORMAT_NV24:
case DRM_FORMAT_NV42:
case DRM_FORMAT_NV20:
case DRM_FORMAT_NV30:
offsets[0] = 0;
handles[0] = bo->handle;
pitches[0] = bo->pitch;
pitches[1] = pitches[0] * 2;
pitches[1] = pitches[0] * 2 / xsub;
offsets[1] = pitches[0] * height;
handles[1] = bo->handle;
@ -306,11 +308,11 @@ bo_create(int fd, unsigned int format,
offsets[0] = 0;
handles[0] = bo->handle;
pitches[0] = bo->pitch;
pitches[1] = pitches[0] / 2;
pitches[1] = pitches[0] / xsub;
offsets[1] = pitches[0] * height;
handles[1] = bo->handle;
pitches[2] = pitches[1];
offsets[2] = offsets[1] + pitches[1] * height / 2;
offsets[2] = offsets[1] + pitches[1] * height / ysub;
handles[2] = bo->handle;
planes[0] = virtual;