diff mbox series

[FFmpeg-devel,6/7] avutil/imgutils: add new function av_image_fill_color()

Message ID 20231203002726.29683-6-cus@passwd.hu
State New
Headers show
Series [FFmpeg-devel,1/7] avutil/tests/imgutils: factorize basic tests to new function | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Marton Balint Dec. 3, 2023, 12:27 a.m. UTC
Signed-off-by: Marton Balint <cus@passwd.hu>
---
 doc/APIchanges       |  3 +++
 libavutil/imgutils.c |  4 ++--
 libavutil/imgutils.h | 30 ++++++++++++++++++++++++++++++
 libavutil/version.h  |  2 +-
 4 files changed, 36 insertions(+), 3 deletions(-)

Comments

Stefano Sabatini Dec. 4, 2023, 1:07 a.m. UTC | #1
On date Sunday 2023-12-03 01:27:25 +0100, Marton Balint wrote:
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
>  doc/APIchanges       |  3 +++
>  libavutil/imgutils.c |  4 ++--
>  libavutil/imgutils.h | 30 ++++++++++++++++++++++++++++++
>  libavutil/version.h  |  2 +-
>  4 files changed, 36 insertions(+), 3 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 4a2dc1c44f..b6ac8e08e2 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
>  
>  API changes, most recent first:
>  
> +2023-12-xx - xxxxxxxxxxx - lavu 58.33.100 - imguils.h

imguils typo

> +  Add av_image_fill_color()
> +
>  2023-11-08 - b82957a66a7 - lavu 58.32.100 - channel_layout.h
>    Add AV_CH_LAYOUT_7POINT2POINT3 and AV_CHANNEL_LAYOUT_7POINT2POINT3.
>    Add AV_CH_LAYOUT_9POINT1POINT4_BACK and AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK.
> diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c
> index 959e6850ac..c09848a317 100644
> --- a/libavutil/imgutils.c
> +++ b/libavutil/imgutils.c
> @@ -579,7 +579,7 @@ static void memset_bytes(uint8_t *dst, size_t dst_size, uint8_t *clear,
>  // if it's a subsampled packed format).
>  #define MAX_BLOCK_SIZE 32
>  
> -static int image_fill_color(uint8_t * const dst_data[4], const ptrdiff_t dst_linesize[4],
> +int av_image_fill_color(uint8_t * const dst_data[4], const ptrdiff_t dst_linesize[4],
>                          enum AVPixelFormat pix_fmt, const uint32_t color[4],
>                          int width, int height)
>  {
> @@ -712,5 +712,5 @@ int av_image_fill_black(uint8_t * const dst_data[4], const ptrdiff_t dst_linesiz
>          color[c] = src;
>      }
>  
> -    return image_fill_color(dst_data, dst_linesize, pix_fmt, color, width, height);
> +    return av_image_fill_color(dst_data, dst_linesize, pix_fmt, color, width, height);
>  }
> diff --git a/libavutil/imgutils.h b/libavutil/imgutils.h
> index fa3bb101b1..e047b3a693 100644
> --- a/libavutil/imgutils.h
> +++ b/libavutil/imgutils.h
> @@ -339,6 +339,36 @@ int av_image_fill_black(uint8_t * const dst_data[4], const ptrdiff_t dst_linesiz
>                          enum AVPixelFormat pix_fmt, enum AVColorRange range,
>                          int width, int height);
>  
> +/**
> + * Overwrite the image data with a color. This is suitable for filling a
> + * sub-rectangle of an image, meaning the padding between the right most pixel
> + * and the left most pixel on the next line will not be overwritten. For some
> + * formats, the image size might be rounded up due to inherent alignment.
> + *
> + * If the pixel format has alpha, it is also replaced. Color component values
> + * are interpreted as native integers (or intfloats) regardless of actual pixel
> + * format endianness.
> + *
> + * This can return an error if the pixel format is not supported. Normally, all
> + * non-hwaccel pixel formats should be supported.
> + *
> + * Passing NULL for dst_data is allowed. Then the function returns whether the
> + * operation would have succeeded. (It can return an error if the pix_fmt is
> + * not supported.)
> + *
> + * @param dst_data      data pointers to destination image
> + * @param dst_linesize  linesizes for the destination image
> + * @param pix_fmt       the pixel format of the image
> + * @param color         the color components to be used for the fill
> + * @param width         the width of the image in pixels
> + * @param height        the height of the image in pixels

> + * @return 0 if the image data was cleared, a negative AVERROR code otherwise

was filled

> + */
> +int av_image_fill_color(uint8_t * const dst_data[4], const ptrdiff_t dst_linesize[4],
> +                        enum AVPixelFormat pix_fmt, const uint32_t color[4],
> +                        int width, int height);

LGTM otherwise.
diff mbox series

Patch

diff --git a/doc/APIchanges b/doc/APIchanges
index 4a2dc1c44f..b6ac8e08e2 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@  The last version increases of all libraries were on 2023-02-09
 
 API changes, most recent first:
 
+2023-12-xx - xxxxxxxxxxx - lavu 58.33.100 - imguils.h
+  Add av_image_fill_color()
+
 2023-11-08 - b82957a66a7 - lavu 58.32.100 - channel_layout.h
   Add AV_CH_LAYOUT_7POINT2POINT3 and AV_CHANNEL_LAYOUT_7POINT2POINT3.
   Add AV_CH_LAYOUT_9POINT1POINT4_BACK and AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK.
diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c
index 959e6850ac..c09848a317 100644
--- a/libavutil/imgutils.c
+++ b/libavutil/imgutils.c
@@ -579,7 +579,7 @@  static void memset_bytes(uint8_t *dst, size_t dst_size, uint8_t *clear,
 // if it's a subsampled packed format).
 #define MAX_BLOCK_SIZE 32
 
-static int image_fill_color(uint8_t * const dst_data[4], const ptrdiff_t dst_linesize[4],
+int av_image_fill_color(uint8_t * const dst_data[4], const ptrdiff_t dst_linesize[4],
                         enum AVPixelFormat pix_fmt, const uint32_t color[4],
                         int width, int height)
 {
@@ -712,5 +712,5 @@  int av_image_fill_black(uint8_t * const dst_data[4], const ptrdiff_t dst_linesiz
         color[c] = src;
     }
 
-    return image_fill_color(dst_data, dst_linesize, pix_fmt, color, width, height);
+    return av_image_fill_color(dst_data, dst_linesize, pix_fmt, color, width, height);
 }
diff --git a/libavutil/imgutils.h b/libavutil/imgutils.h
index fa3bb101b1..e047b3a693 100644
--- a/libavutil/imgutils.h
+++ b/libavutil/imgutils.h
@@ -339,6 +339,36 @@  int av_image_fill_black(uint8_t * const dst_data[4], const ptrdiff_t dst_linesiz
                         enum AVPixelFormat pix_fmt, enum AVColorRange range,
                         int width, int height);
 
+/**
+ * Overwrite the image data with a color. This is suitable for filling a
+ * sub-rectangle of an image, meaning the padding between the right most pixel
+ * and the left most pixel on the next line will not be overwritten. For some
+ * formats, the image size might be rounded up due to inherent alignment.
+ *
+ * If the pixel format has alpha, it is also replaced. Color component values
+ * are interpreted as native integers (or intfloats) regardless of actual pixel
+ * format endianness.
+ *
+ * This can return an error if the pixel format is not supported. Normally, all
+ * non-hwaccel pixel formats should be supported.
+ *
+ * Passing NULL for dst_data is allowed. Then the function returns whether the
+ * operation would have succeeded. (It can return an error if the pix_fmt is
+ * not supported.)
+ *
+ * @param dst_data      data pointers to destination image
+ * @param dst_linesize  linesizes for the destination image
+ * @param pix_fmt       the pixel format of the image
+ * @param color         the color components to be used for the fill
+ * @param width         the width of the image in pixels
+ * @param height        the height of the image in pixels
+ * @return 0 if the image data was cleared, a negative AVERROR code otherwise
+ */
+int av_image_fill_color(uint8_t * const dst_data[4], const ptrdiff_t dst_linesize[4],
+                        enum AVPixelFormat pix_fmt, const uint32_t color[4],
+                        int width, int height);
+
+
 /**
  * @}
  */
diff --git a/libavutil/version.h b/libavutil/version.h
index c5fa7c3692..0684996bf2 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@ 
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  58
-#define LIBAVUTIL_VERSION_MINOR  32
+#define LIBAVUTIL_VERSION_MINOR  33
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \