pixel-formats: Add hsub and vsub helpers

We already had these with effective width and height, but they're useful
externally as well. Pull them out to a helper.

Signed-off-by: Daniel Stone <daniels@collabora.com>
This commit is contained in:
Daniel Stone 2022-04-28 01:00:34 +01:00 committed by Pekka Paalanen
parent e08df66bd3
commit 4161948da9
2 changed files with 54 additions and 10 deletions

View File

@ -654,16 +654,34 @@ pixel_format_get_info_by_opaque_substitute(uint32_t format)
return NULL;
}
WL_EXPORT unsigned int
pixel_format_hsub(const struct pixel_format_info *info,
unsigned int plane)
{
/* We don't support any formats where the first plane is subsampled. */
if (plane == 0 || info->hsub == 0)
return 1;
return info->hsub;
}
WL_EXPORT unsigned int
pixel_format_vsub(const struct pixel_format_info *info,
unsigned int plane)
{
/* We don't support any formats where the first plane is subsampled. */
if (plane == 0 || info->vsub == 0)
return 1;
return info->vsub;
}
WL_EXPORT unsigned int
pixel_format_width_for_plane(const struct pixel_format_info *info,
unsigned int plane,
unsigned int width)
{
/* We don't support any formats where the first plane is subsampled. */
if (plane == 0 || !info->hsub)
return width;
return width / info->hsub;
return width / pixel_format_hsub(info, plane);
}
WL_EXPORT unsigned int
@ -671,11 +689,7 @@ pixel_format_height_for_plane(const struct pixel_format_info *info,
unsigned int plane,
unsigned int height)
{
/* We don't support any formats where the first plane is subsampled. */
if (plane == 0 || !info->vsub)
return height;
return height / info->vsub;
return height / pixel_format_vsub(info, plane);
}
#ifdef HAVE_HUMAN_FORMAT_MODIFIER

View File

@ -248,6 +248,36 @@ pixel_format_get_opaque_substitute(const struct pixel_format_info *format);
const struct pixel_format_info *
pixel_format_get_info_by_opaque_substitute(uint32_t format);
/**
* Return the horizontal subsampling factor for a given plane
*
* When horizontal subsampling is effective, a sampler bound to a secondary
* plane must bind the sampler with a smaller effective width. This function
* returns the subsampling factor to use for the given plane.
*
* @param format Pixel format info structure
* @param plane Zero-indexed plane number
* @returns Horizontal subsampling factor for the given plane
*/
unsigned int
pixel_format_hsub(const struct pixel_format_info *format,
unsigned int plane);
/**
* Return the vertical subsampling factor for a given plane
*
* When vertical subsampling is effective, a sampler bound to a secondary
* plane must bind the sampler with a smaller effective height. This function
* returns the subsampling factor to use for the given plane.
*
* @param format Pixel format info structure
* @param plane Zero-indexed plane number
* @returns Vertical subsampling factor for the given plane
*/
unsigned int
pixel_format_vsub(const struct pixel_format_info *format,
unsigned int plane);
/**
* Return the effective sampling width for a given plane
*