summaryrefslogtreecommitdiff
path: root/libavutil/imgutils.h
diff options
context:
space:
mode:
authorwm4 <nfxjfg@googlemail.com>2017-07-22 23:05:14 +0200
committerwm4 <nfxjfg@googlemail.com>2017-08-08 13:37:37 +0200
commit463b81de2b252691d75417643597c42684bf830d (patch)
tree9fffe9f41caf458bae6492803686e2e2bed418ec /libavutil/imgutils.h
parentcaa12027baf1180453846c58da08fc87accc0ff6 (diff)
imgutils: add function to clear an image to black
Black isn't always just memset(ptr, 0, size). Limited YUV in particular requires relatively non-obvious values, and filling a frame with repeating 0 bytes is disallowed in some contexts. With component sizes larger than 8 or packed YUV, this can become relatively complicated. So having a generic function for this seems helpful. In order to handle the complex cases in a generic way without destroying performance, this code attempts to compute a black pixel, and then uses that value to clear the image data quickly by using a function like memset. Common cases like yuv410p10 or rgba can't be handled with a simple memset, so there is some code to fill memory with 2/4/8 byte patterns. For the remaining cases, a generic slow fallback is used. Signed-off-by: Anton Khirnov <anton@khirnov.net> Merged from Libav commit 45df7adc1d9b7.
Diffstat (limited to 'libavutil/imgutils.h')
-rw-r--r--libavutil/imgutils.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/libavutil/imgutils.h b/libavutil/imgutils.h
index ea083b10f1..2ab90ac033 100644
--- a/libavutil/imgutils.h
+++ b/libavutil/imgutils.h
@@ -239,6 +239,33 @@ int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enu
int av_image_check_sar(unsigned int w, unsigned int h, AVRational sar);
/**
+ * Overwrite the image data with black. 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, the alpha is cleared to opaque.
+ *
+ * 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 range the color range of the image (important for colorspaces such as YUV)
+ * @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_black(uint8_t *dst_data[4], const ptrdiff_t dst_linesize[4],
+ enum AVPixelFormat pix_fmt, enum AVColorRange range,
+ int width, int height);
+
+/**
* @}
*/