From ba57d91da4e26899a76100b3b32ae790d0d9bffa Mon Sep 17 00:00:00 2001 From: Yassine Oudjana Date: Thu, 24 Feb 2022 09:00:23 +0400 Subject: [PATCH] mode: Add a function to get padding bytes per line (MR 13) Add a function to get extra padding bytes needed to make bytes per width a multiple of 8. --- src/mode.c | 13 +++++++++++++ src/mode.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/src/mode.c b/src/mode.c index 8db36e3..d4f9f7e 100644 --- a/src/mode.c +++ b/src/mode.c @@ -208,6 +208,19 @@ mp_pixel_format_width_to_bytes(MPPixelFormat pixel_format, uint32_t width) return (bits_per_width + 8 - remainder) / 8; } +uint32_t +mp_pixel_format_width_to_padding(MPPixelFormat pixel_format, uint32_t width) +{ + uint64_t bytes_per_width = + mp_pixel_format_width_to_bytes(pixel_format, width); + + uint64_t remainder = bytes_per_width % 8; + if (remainder == 0) + return remainder; + + return 8 - remainder; +} + uint32_t mp_pixel_format_width_to_colors(MPPixelFormat pixel_format, uint32_t width) { diff --git a/src/mode.h b/src/mode.h index f3e5a5b..6cdfb7a 100644 --- a/src/mode.h +++ b/src/mode.h @@ -33,6 +33,8 @@ uint32_t mp_pixel_format_pixel_depth(MPPixelFormat pixel_format); const char *mp_pixel_format_cfa(MPPixelFormat pixel_format); const char *mp_pixel_format_cfa_pattern(MPPixelFormat pixel_format); uint32_t mp_pixel_format_width_to_bytes(MPPixelFormat pixel_format, uint32_t width); +uint32_t mp_pixel_format_width_to_padding(MPPixelFormat pixel_format, + uint32_t width); uint32_t mp_pixel_format_width_to_colors(MPPixelFormat pixel_format, uint32_t width); uint32_t mp_pixel_format_height_to_colors(MPPixelFormat pixel_format, uint32_t height);