From: Stefano Sabatini <stefasab@gmail.com> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Cc: Marton Balint <cus@passwd.hu> Subject: Re: [FFmpeg-devel] [PATCH 5/7] avutil/imgutils: factorize a fill color function Date: Mon, 4 Dec 2023 02:04:51 +0100 Message-ID: <ZW0ls0WHBpQiehN+@mariano> (raw) In-Reply-To: <20231203002726.29683-5-cus@passwd.hu> On date Sunday 2023-12-03 01:27:24 +0100, Marton Balint wrote: > In preparation for making it public. > > Signed-off-by: Marton Balint <cus@passwd.hu> > --- > libavutil/imgutils.c | 101 +++++++++++++++++++++++++++---------------- > 1 file changed, 63 insertions(+), 38 deletions(-) > > diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c > index 26bb2f2c6f..959e6850ac 100644 > --- a/libavutil/imgutils.c > +++ b/libavutil/imgutils.c > @@ -579,30 +579,24 @@ 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 > > -int av_image_fill_black(uint8_t * const dst_data[4], const ptrdiff_t dst_linesize[4], > - enum AVPixelFormat pix_fmt, enum AVColorRange range, > +static int 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) > { > const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); > int nb_planes = av_pix_fmt_count_planes(pix_fmt); > - // A pixel or a group of pixels on each plane, with a value that represents black. > + // A pixel or a group of pixels on each plane, with a value that represents the color. > // Consider e.g. AV_PIX_FMT_UYVY422 for non-trivial cases. > 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, fltp; > + int bitstream; > int plane, c; > > if (!desc || nb_planes < 1 || nb_planes > 4 || desc->flags & AV_PIX_FMT_FLAG_HWACCEL) > return AVERROR(EINVAL); > > - rgb = !!(desc->flags & AV_PIX_FMT_FLAG_RGB); > - xyz = !!(desc->flags & AV_PIX_FMT_FLAG_XYZ); > - pal = !!(desc->flags & AV_PIX_FMT_FLAG_PAL); > - 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]; > @@ -623,7 +617,6 @@ int av_image_fill_black(uint8_t * const dst_data[4], const ptrdiff_t dst_linesiz > uint8_t *c_data[4]; > const int c_linesize[4] = {0}; > uint32_t src_array[MAX_BLOCK_SIZE]; > - uint32_t src = 0; > int x; > > if (comp.depth > 32) > @@ -631,34 +624,8 @@ int av_image_fill_black(uint8_t * const dst_data[4], const ptrdiff_t dst_linesiz > if (w < 1) > return AVERROR(EINVAL); > > - if (pix_fmt == AV_PIX_FMT_MONOWHITE) { > - src = 1; > - } else if (c + 1 == desc->nb_components && alpha) { > - // (Assume even limited YUV uses full range alpha.) > - 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 || fltp && comp.depth != 16 && comp.depth != 32) > - return AVERROR(EINVAL); > - 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 || fltp && comp.depth != 16 && comp.depth != 32) > - return AVERROR(EINVAL); > - if (fltp) > - src = (comp.depth == 16 ? 0x3800 : 0x3F000000); // 0.5 > - else > - src = 128 << (comp.depth - 8); > - } > - > for (x = 0; x < w; x++) > - src_array[x] = src; > + src_array[x] = color[c]; > > for (x = 0; x < 4; x++) > c_data[x] = &clear_block[x][0]; > @@ -689,3 +656,61 @@ int av_image_fill_black(uint8_t * const dst_data[4], const ptrdiff_t dst_linesiz > > return 0; > } > + > +int av_image_fill_black(uint8_t * const dst_data[4], const ptrdiff_t dst_linesize[4], > + enum AVPixelFormat pix_fmt, enum AVColorRange range, > + int width, int height) > +{ > + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); > + int nb_planes = av_pix_fmt_count_planes(pix_fmt); > + int rgb, xyz, pal, limited, alpha, fltp; > + uint32_t color[4] = {0}; > + > + if (!desc || nb_planes < 1 || nb_planes > 4 || desc->flags & AV_PIX_FMT_FLAG_HWACCEL) > + return AVERROR(EINVAL); > + > + rgb = !!(desc->flags & AV_PIX_FMT_FLAG_RGB); > + xyz = !!(desc->flags & AV_PIX_FMT_FLAG_XYZ); > + pal = !!(desc->flags & AV_PIX_FMT_FLAG_PAL); > + limited = !rgb && !xyz && !pal && range != AVCOL_RANGE_JPEG; > + alpha = !pal && !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA); > + fltp = !!(desc->flags & AV_PIX_FMT_FLAG_FLOAT); > + > + for (int c = 0; c < desc->nb_components; c++) { > + const AVComponentDescriptor comp = desc->comp[c]; > + uint32_t src = 0; might be renamed in this context, color (color_component)? [...] LGTM otherwise. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2023-12-04 1:05 UTC|newest] Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-12-03 0:27 [FFmpeg-devel] [PATCH 1/7] avutil/tests/imgutils: factorize basic tests to new function Marton Balint 2023-12-03 0:27 ` [FFmpeg-devel] [PATCH 2/7] avutil/tests/imgutils: add tests for av_image_fill_black() Marton Balint 2023-12-03 23:47 ` Stefano Sabatini 2023-12-03 0:27 ` [FFmpeg-devel] [PATCH 3/7] avutil/imgutils: fix av_image_fill_black() for some pixel formats Marton Balint 2023-12-04 0:23 ` Stefano Sabatini 2023-12-03 0:27 ` [FFmpeg-devel] [PATCH 4/7] avutil/imgutils: add support for 32bit pixel format for av_image_fill_black() Marton Balint 2023-12-04 0:52 ` Stefano Sabatini 2023-12-03 0:27 ` [FFmpeg-devel] [PATCH 5/7] avutil/imgutils: factorize a fill color function Marton Balint 2023-12-04 1:04 ` Stefano Sabatini [this message] 2023-12-03 0:27 ` [FFmpeg-devel] [PATCH 6/7] avutil/imgutils: add new function av_image_fill_color() Marton Balint 2023-12-04 1:07 ` Stefano Sabatini 2023-12-03 0:27 ` [FFmpeg-devel] [PATCH 7/7] avcodec: add AV_CODEC_FLAG_CLEAR Marton Balint 2023-12-03 21:31 ` [FFmpeg-devel] [PATCH 1/7] avutil/tests/imgutils: factorize basic tests to new function Stefano Sabatini 2023-12-06 8:22 ` [FFmpeg-devel] [PATCH v2 " Marton Balint 2023-12-06 8:22 ` [FFmpeg-devel] [PATCH v2 2/7] avutil/tests/imgutils: add tests for av_image_fill_black() Marton Balint 2023-12-06 22:46 ` Stefano Sabatini 2023-12-06 8:22 ` [FFmpeg-devel] [PATCH v2 3/7] avutil/imgutils: fix av_image_fill_black() for some pixel formats Marton Balint 2023-12-06 22:47 ` Stefano Sabatini 2023-12-06 8:22 ` [FFmpeg-devel] [PATCH v2 4/7] avutil/imgutils: add support for 32bit pixel format for av_image_fill_black() Marton Balint 2023-12-06 22:48 ` Stefano Sabatini 2023-12-06 8:22 ` [FFmpeg-devel] [PATCH v2 5/7] avutil/imgutils: factorize a fill color function Marton Balint 2023-12-06 22:52 ` Stefano Sabatini 2023-12-06 8:22 ` [FFmpeg-devel] [PATCH v2 6/7] avutil/imgutils: add new function av_image_fill_color() Marton Balint 2023-12-06 22:53 ` Stefano Sabatini 2023-12-07 16:15 ` Anton Khirnov 2023-12-09 19:25 ` [FFmpeg-devel] [PATCH v3 " Marton Balint 2023-12-11 23:05 ` Stefano Sabatini 2023-12-12 18:45 ` Marton Balint 2023-12-06 8:22 ` [FFmpeg-devel] [PATCH v2 7/7] avcodec: add AV_CODEC_FLAG_CLEAR Marton Balint 2023-12-06 22:57 ` Stefano Sabatini 2023-12-07 1:44 ` Ronald S. Bultje 2023-12-07 16:19 ` Anton Khirnov 2023-12-07 22:47 ` Marton Balint 2023-12-08 5:12 ` Rémi Denis-Courmont 2023-12-07 2:37 ` Vittorio Giovara 2023-12-07 16:30 ` Anton Khirnov 2023-12-07 23:11 ` Marton Balint 2023-12-11 20:49 ` Mark Thompson 2023-12-12 11:23 ` Anton Khirnov 2023-12-12 18:37 ` Marton Balint 2023-12-13 8:59 ` Anton Khirnov 2023-12-13 17:09 ` Marton Balint 2023-12-14 8:03 ` Anton Khirnov 2023-12-12 22:18 ` Michael Niedermayer 2023-12-06 22:43 ` [FFmpeg-devel] [PATCH v2 1/7] avutil/tests/imgutils: factorize basic tests to new function Stefano Sabatini
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=ZW0ls0WHBpQiehN+@mariano \ --to=stefasab@gmail.com \ --cc=cus@passwd.hu \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git