From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 1211F48418 for ; Mon, 4 Dec 2023 01:05:03 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 10BA468CCBE; Mon, 4 Dec 2023 03:05:01 +0200 (EET) Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 72C8568BDA0 for ; Mon, 4 Dec 2023 03:04:54 +0200 (EET) Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a1a52aecc67so226285466b.2 for ; Sun, 03 Dec 2023 17:04:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701651893; x=1702256693; darn=ffmpeg.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=lfHo3SVDRxjMLhJUY6jfPyQD5vRhur1gF+S/aFHoTK4=; b=Av1k2yVP3LDmJDaiaazFAHWp2gtlb8TGCHDDqP6Sz4kd5fy+Yy29rgMVcwJDIIH7gg 0IZ9qj7NyRiJFfsIPe1qHZUGNOrIq4yd04Ozi9ccSPSiep3RcwJtnw/eUvXJhHy04P+q FeIsQTE6/MlP5HJ8AmqZj0A60gW972f6SJ8/TBmPss+O+gGHMey2J/dHDk2RSFrTRpv+ iRO3QsN1t3KiWgRuv6PDfJ+lAyvN7SkZ9FdeY+tjOYaW3aysoaN/EG7YXDBedeQse3pl nMkgvSdhw9SmJHe1dSRM2grZgiYatY8NagazkbXY8FLOT8X6acOUA7kgnjVHE2c347LO HL5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701651893; x=1702256693; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lfHo3SVDRxjMLhJUY6jfPyQD5vRhur1gF+S/aFHoTK4=; b=iu4KoN9zs/TaewbKvhALToyfJgRxGXXV6EHgDmJdlddgIi1o/4uZjIK6I9Bek3PRXh mEUeh1t2tpGCwyCkNfmmhPE4ex11djMqH36B7O151MmqB1n/odow+KyezjQzB3GMYONE cmQprLkQ+Grf5EnCIJKTcy8xYwTIkq8qZL5e+CRqTufXamonvbXhQX9+4eYORkiK4yLd ppQYqEl6jYiWvlXMGePev1qIy1UzOB7cLgJBQ5os+BeSmqlvAWIH5FkG8/m46gaCFJTT ohjFtFDhl0zv+bCi7hUJ0z6QwwDZEMjtKdtSvWUH5EF03oVzKzsUWFItbx/nmTDCv1X6 TZIw== X-Gm-Message-State: AOJu0YzSdBkyW+PDCcr3vssw8UbtkiHDTlXeEO8eRv3Vu8oEEuhS7IJG HfhJEeB7wedT/SZ4mJA5+ERocGtonZs= X-Google-Smtp-Source: AGHT+IF3zzk88Tdft1Oekui9isCdy2NbAieJ8+peH2+6yyWy167bpi9cgEyx9q9daGJxwS5qMjFJMw== X-Received: by 2002:a17:906:2dc7:b0:a04:a0c4:ccef with SMTP id h7-20020a1709062dc700b00a04a0c4ccefmr2345544eji.15.1701651893277; Sun, 03 Dec 2023 17:04:53 -0800 (PST) Received: from mariano (dynamic-adsl-84-220-189-10.clienti.tiscali.it. [84.220.189.10]) by smtp.gmail.com with ESMTPSA id b6-20020a170906d10600b009ade1a4f795sm4634180ejz.168.2023.12.03.17.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 17:04:52 -0800 (PST) Received: by mariano (Postfix, from userid 1000) id BBF5ABFCDA; Mon, 4 Dec 2023 02:04:51 +0100 (CET) Date: Mon, 4 Dec 2023 02:04:51 +0100 From: Stefano Sabatini To: FFmpeg development discussions and patches Message-ID: Mail-Followup-To: FFmpeg development discussions and patches , Marton Balint References: <20231203002726.29683-1-cus@passwd.hu> <20231203002726.29683-5-cus@passwd.hu> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20231203002726.29683-5-cus@passwd.hu> User-Agent: Mutt/2.1.4 (2021-12-11) Subject: Re: [FFmpeg-devel] [PATCH 5/7] avutil/imgutils: factorize a fill color function X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On date Sunday 2023-12-03 01:27:24 +0100, Marton Balint wrote: > In preparation for making it public. > > Signed-off-by: Marton Balint > --- > 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".