[FFmpeg-devel] [PATCH 4/7] avutil/imgutils: add support for 32bit pixel format for av_image_fill_black()
Marton Balint
cus at passwd.hu
Sun Dec 3 02:27:23 EET 2023
Signed-off-by: Marton Balint <cus at passwd.hu>
---
libavutil/imgutils.c | 32 ++++++++++++++++++++++----------
tests/ref/fate/imgutils | 24 ++++++++++++------------
2 files changed, 34 insertions(+), 22 deletions(-)
diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c
index 5e401139c8..26bb2f2c6f 100644
--- a/libavutil/imgutils.c
+++ b/libavutil/imgutils.c
@@ -590,7 +590,7 @@ int av_image_fill_black(uint8_t * const dst_data[4], const ptrdiff_t dst_linesiz
uint8_t clear_block[4][MAX_BLOCK_SIZE] = {{0}}; // clear padding with 0
int clear_block_size[4] = {0};
ptrdiff_t plane_line_bytes[4] = {0};
- int rgb, xyz, pal, limited, alpha, bitstream;
+ int rgb, xyz, pal, limited, alpha, bitstream, fltp;
int plane, c;
if (!desc || nb_planes < 1 || nb_planes > 4 || desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
@@ -602,6 +602,7 @@ int av_image_fill_black(uint8_t * const dst_data[4], const ptrdiff_t dst_linesiz
limited = !rgb && !xyz && !pal && range != AVCOL_RANGE_JPEG;
alpha = !pal && !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA);
bitstream = !!(desc->flags & AV_PIX_FMT_FLAG_BITSTREAM);
+ fltp = !!(desc->flags & AV_PIX_FMT_FLAG_FLOAT);
for (c = 0; c < desc->nb_components; c++) {
const AVComponentDescriptor comp = desc->comp[c];
@@ -621,11 +622,11 @@ int av_image_fill_black(uint8_t * const dst_data[4], const ptrdiff_t dst_linesiz
int w = (bitstream ? 8 : 1) * clear_block_size[comp.plane] / comp.step;
uint8_t *c_data[4];
const int c_linesize[4] = {0};
- uint16_t src_array[MAX_BLOCK_SIZE];
- uint16_t src = 0;
+ uint32_t src_array[MAX_BLOCK_SIZE];
+ uint32_t src = 0;
int x;
- if (comp.depth > 16)
+ if (comp.depth > 32)
return AVERROR(EINVAL);
if (w < 1)
return AVERROR(EINVAL);
@@ -634,15 +635,26 @@ int av_image_fill_black(uint8_t * const dst_data[4], const ptrdiff_t dst_linesiz
src = 1;
} else if (c + 1 == desc->nb_components && alpha) {
// (Assume even limited YUV uses full range alpha.)
- src = (1 << comp.depth) - 1;
+ if (fltp && comp.depth != 16 && comp.depth != 32)
+ return AVERROR(EINVAL);
+ if (fltp)
+ src = (comp.depth == 16 ? 0x3C00 : 0x3F800000); // 1.0
+ else
+ src = (comp.depth == 32 ? 0 : (1 << comp.depth)) - 1;
} else if (c == 0 && limited && comp.depth > 1) {
- if (comp.depth < 8)
+ if (comp.depth < 8 || fltp && comp.depth != 16 && comp.depth != 32)
return AVERROR(EINVAL);
- src = 16 << (comp.depth - 8);
+ if (fltp)
+ src = (comp.depth == 16 ? 0x3000 : 0x3D800000); // 0.0625
+ else
+ src = 16 << (comp.depth - 8);
} else if ((c == 1 || c == 2) && !rgb && !xyz) {
- if (comp.depth < 8)
+ if (comp.depth < 8 || fltp && comp.depth != 16 && comp.depth != 32)
return AVERROR(EINVAL);
- src = 128 << (comp.depth - 8);
+ if (fltp)
+ src = (comp.depth == 16 ? 0x3800 : 0x3F000000); // 0.5
+ else
+ src = 128 << (comp.depth - 8);
}
for (x = 0; x < w; x++)
@@ -651,7 +663,7 @@ int av_image_fill_black(uint8_t * const dst_data[4], const ptrdiff_t dst_linesiz
for (x = 0; x < 4; x++)
c_data[x] = &clear_block[x][0];
- av_write_image_line(src_array, c_data, c_linesize, desc, 0, 0, c, w);
+ av_write_image_line2(src_array, c_data, c_linesize, desc, 0, 0, c, w, 4);
}
for (plane = 0; plane < nb_planes; plane++) {
diff --git a/tests/ref/fate/imgutils b/tests/ref/fate/imgutils
index 79ef5cdfc0..b589c49473 100644
--- a/tests/ref/fate/imgutils
+++ b/tests/ref/fate/imgutils
@@ -435,14 +435,14 @@ p016le total_size: 9216, black_unknown_crc: 0xfff85b60, black_tv_cr
p016be total_size: 9216, black_unknown_crc: 0x4d4d9903, black_tv_crc: 0x4d4d9903, black_pc_crc: 0x69c6fe01
gray9be total_size: 6144, black_unknown_crc: 0xa913cdc7, black_tv_crc: 0xa913cdc7, black_pc_crc: 0x00000000
gray9le total_size: 6144, black_unknown_crc: 0x05a944de, black_tv_crc: 0x05a944de, black_pc_crc: 0x00000000
-gbrpf32be total_size: 36864, black_unknown_crc: ----------, black_tv_crc: ----------, black_pc_crc: ----------
-gbrpf32le total_size: 36864, black_unknown_crc: ----------, black_tv_crc: ----------, black_pc_crc: ----------
-gbrapf32be total_size: 49152, black_unknown_crc: ----------, black_tv_crc: ----------, black_pc_crc: ----------
-gbrapf32le total_size: 49152, black_unknown_crc: ----------, black_tv_crc: ----------, black_pc_crc: ----------
+gbrpf32be total_size: 36864, black_unknown_crc: 0x00000000, black_tv_crc: 0x00000000, black_pc_crc: 0x00000000
+gbrpf32le total_size: 36864, black_unknown_crc: 0x00000000, black_tv_crc: 0x00000000, black_pc_crc: 0x00000000
+gbrapf32be total_size: 49152, black_unknown_crc: 0xda9c5af9, black_tv_crc: 0xda9c5af9, black_pc_crc: 0xda9c5af9
+gbrapf32le total_size: 49152, black_unknown_crc: 0xd2f28790, black_tv_crc: 0xd2f28790, black_pc_crc: 0xd2f28790
gray14be total_size: 6144, black_unknown_crc: 0x9bd1ea2b, black_tv_crc: 0x9bd1ea2b, black_pc_crc: 0x00000000
gray14le total_size: 6144, black_unknown_crc: 0xb5289bc0, black_tv_crc: 0xb5289bc0, black_pc_crc: 0x00000000
-grayf32be total_size: 12288, black_unknown_crc: ----------, black_tv_crc: ----------, black_pc_crc: ----------
-grayf32le total_size: 12288, black_unknown_crc: ----------, black_tv_crc: ----------, black_pc_crc: ----------
+grayf32be total_size: 12288, black_unknown_crc: 0x4bafcc11, black_tv_crc: 0x4bafcc11, black_pc_crc: 0x00000000
+grayf32le total_size: 12288, black_unknown_crc: 0xca17685c, black_tv_crc: 0xca17685c, black_pc_crc: 0x00000000
yuva422p12be total_size: 18432, black_unknown_crc: 0xa7067ca1, black_tv_crc: 0xa7067ca1, black_pc_crc: 0xaa881b51
yuva422p12le total_size: 18432, black_unknown_crc: 0xb6bdf055, black_tv_crc: 0xb6bdf055, black_pc_crc: 0x55b03edf
yuva444p12be total_size: 24576, black_unknown_crc: 0x488f478f, black_tv_crc: 0x488f478f, black_pc_crc: 0xc6fb24d1
@@ -464,8 +464,8 @@ p216le total_size: 12288, black_unknown_crc: 0x6582d6cf, black_tv_cr
p416be total_size: 18432, black_unknown_crc: 0x26991800, black_tv_crc: 0x26991800, black_pc_crc: 0xfe7f6700
p416le total_size: 18432, black_unknown_crc: 0x4028ac30, black_tv_crc: 0x4028ac30, black_pc_crc: 0xab7c7698
vuya total_size: 12288, black_unknown_crc: 0x60db2d2c, black_tv_crc: 0x60db2d2c, black_pc_crc: 0x2dae630a
-rgbaf16be total_size: 24576, black_unknown_crc: 0x0ab5caf6, black_tv_crc: 0x0ab5caf6, black_pc_crc: 0x0ab5caf6
-rgbaf16le total_size: 24576, black_unknown_crc: 0x0ab5caf6, black_tv_crc: 0x0ab5caf6, black_pc_crc: 0x0ab5caf6
+rgbaf16be total_size: 24576, black_unknown_crc: 0x76fd69af, black_tv_crc: 0x76fd69af, black_pc_crc: 0x76fd69af
+rgbaf16le total_size: 24576, black_unknown_crc: 0x21283f40, black_tv_crc: 0x21283f40, black_pc_crc: 0x21283f40
vuyx total_size: 12288, black_unknown_crc: 0x9181c808, black_tv_crc: 0x9181c808, black_pc_crc: 0xdcf4862e
p012le total_size: 9216, black_unknown_crc: 0xfff85b60, black_tv_crc: 0xfff85b60, black_pc_crc: 0xc03cff93
p012be total_size: 9216, black_unknown_crc: 0x4d4d9903, black_tv_crc: 0x4d4d9903, black_pc_crc: 0x69c6fe01
@@ -475,10 +475,10 @@ xv30be total_size: 12288, black_unknown_crc: 0x1c42115f, black_tv_cr
xv30le total_size: 12288, black_unknown_crc: 0x4bb0b075, black_tv_crc: 0x4bb0b075, black_pc_crc: 0x02d585cf
xv36be total_size: 24576, black_unknown_crc: 0x6ba828bd, black_tv_crc: 0x6ba828bd, black_pc_crc: 0x5f450f41
xv36le total_size: 24576, black_unknown_crc: 0xc3794950, black_tv_crc: 0xc3794950, black_pc_crc: 0x40874939
-rgbf32be total_size: 36864, black_unknown_crc: ----------, black_tv_crc: ----------, black_pc_crc: ----------
-rgbf32le total_size: 36864, black_unknown_crc: ----------, black_tv_crc: ----------, black_pc_crc: ----------
-rgbaf32be total_size: 49152, black_unknown_crc: ----------, black_tv_crc: ----------, black_pc_crc: ----------
-rgbaf32le total_size: 49152, black_unknown_crc: ----------, black_tv_crc: ----------, black_pc_crc: ----------
+rgbf32be total_size: 36864, black_unknown_crc: 0x00000000, black_tv_crc: 0x00000000, black_pc_crc: 0x00000000
+rgbf32le total_size: 36864, black_unknown_crc: 0x00000000, black_tv_crc: 0x00000000, black_pc_crc: 0x00000000
+rgbaf32be total_size: 49152, black_unknown_crc: 0x5eae6680, black_tv_crc: 0x5eae6680, black_pc_crc: 0x5eae6680
+rgbaf32le total_size: 49152, black_unknown_crc: 0x11d73f6d, black_tv_crc: 0x11d73f6d, black_pc_crc: 0x11d73f6d
p212be total_size: 12288, black_unknown_crc: 0x0bbe5df7, black_tv_crc: 0x0bbe5df7, black_pc_crc: 0x16a51378
p212le total_size: 12288, black_unknown_crc: 0x6582d6cf, black_tv_crc: 0x6582d6cf, black_pc_crc: 0xc9dc3ddf
p412be total_size: 18432, black_unknown_crc: 0x26991800, black_tv_crc: 0x26991800, black_pc_crc: 0xfe7f6700
--
2.35.3
More information about the ffmpeg-devel
mailing list