diff --git a/libweston/pixel-formats.c b/libweston/pixel-formats.c index 16b95e20..8d3d49a3 100644 --- a/libweston/pixel-formats.c +++ b/libweston/pixel-formats.c @@ -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 diff --git a/libweston/pixel-formats.h b/libweston/pixel-formats.h index 6e8aafde..c14a3ed4 100644 --- a/libweston/pixel-formats.h +++ b/libweston/pixel-formats.h @@ -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 *