diff mbox series

[FFmpeg-devel] avutil/pixfmt: fix AV_PIX_FMT_RGB8 description

Message ID 20240108145336.380094-1-jeff@jeffreyknockel.com
State New
Headers show
Series [FFmpeg-devel] avutil/pixfmt: fix AV_PIX_FMT_RGB8 description | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Jeffrey Knockel Jan. 8, 2024, 2:53 p.m. UTC
Previously the description was partially mistaken, explaining the format
as RGB 3:3:2, (msb)2R 3G 3B(lsb).  While the RGB 3:3:2 part is correct,
the latter part should be: (msb)3R 3G 2B(lsb). The corresponding bit
masks are red: 0xE0, green: 0x1C, blue: 0x03.

Signed-off-by: Jeffrey Knockel <jeff@jeffreyknockel.com>
---
 libavutil/pixfmt.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stefano Sabatini Jan. 14, 2024, 11:32 a.m. UTC | #1
On date Monday 2024-01-08 09:53:37 -0500, Jeffrey Knockel wrote:
> Previously the description was partially mistaken, explaining the format
> as RGB 3:3:2, (msb)2R 3G 3B(lsb).  While the RGB 3:3:2 part is correct,
> the latter part should be: (msb)3R 3G 2B(lsb). The corresponding bit
> masks are red: 0xE0, green: 0x1C, blue: 0x03.
> 
> Signed-off-by: Jeffrey Knockel <jeff@jeffreyknockel.com>
> ---
>  libavutil/pixfmt.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h
> index 58f9ad28bd..9c87571f49 100644
> --- a/libavutil/pixfmt.h
> +++ b/libavutil/pixfmt.h
> @@ -83,7 +83,7 @@ enum AVPixelFormat {
>      AV_PIX_FMT_BGR8,      ///< packed RGB 3:3:2,  8bpp, (msb)2B 3G 3R(lsb)
>      AV_PIX_FMT_BGR4,      ///< packed RGB 1:2:1 bitstream,  4bpp, (msb)1B 2G 1R(lsb), a byte contains two pixels, the first pixel in the byte is the one composed by the 4 msb bits
>      AV_PIX_FMT_BGR4_BYTE, ///< packed RGB 1:2:1,  8bpp, (msb)1B 2G 1R(lsb)

> -    AV_PIX_FMT_RGB8,      ///< packed RGB 3:3:2,  8bpp, (msb)2R 3G 3B(lsb)
> +    AV_PIX_FMT_RGB8,      ///< packed RGB 3:3:2,  8bpp, (msb)3R 3G 2B(lsb)

This is not consistent with pixdesc definition:
    [AV_PIX_FMT_RGB8] = {
        .name = "rgb8",
        .nb_components = 3,
        .log2_chroma_w = 0,
        .log2_chroma_h = 0,
        .comp = {
            { 0, 1, 0, 6, 2 },        /* R */
            { 0, 1, 0, 3, 3 },        /* G */
            { 0, 1, 0, 0, 3 },        /* B */
        },
        .flags = AV_PIX_FMT_FLAG_RGB,
    },

so either the documentation or the pixdesc description is wrong.

Do you confirm "(msb)3R 3G 2B(lsb)" is the correct definition?

In this case pixdesc should be fixed accordingly.

Thanks.
Jeffrey Knockel Jan. 14, 2024, 3:14 p.m. UTC | #2
On 1/14/24 6:32 AM, Stefano Sabatini wrote:
> On date Monday 2024-01-08 09:53:37 -0500, Jeffrey Knockel wrote:
>> Previously the description was partially mistaken, explaining the format
>> as RGB 3:3:2, (msb)2R 3G 3B(lsb).  While the RGB 3:3:2 part is correct,
>> the latter part should be: (msb)3R 3G 2B(lsb). The corresponding bit
>> masks are red: 0xE0, green: 0x1C, blue: 0x03.
>>
>> Signed-off-by: Jeffrey Knockel <jeff@jeffreyknockel.com>
>> ---
>>  libavutil/pixfmt.h | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h
>> index 58f9ad28bd..9c87571f49 100644
>> --- a/libavutil/pixfmt.h
>> +++ b/libavutil/pixfmt.h
>> @@ -83,7 +83,7 @@ enum AVPixelFormat {
>>      AV_PIX_FMT_BGR8,      ///< packed RGB 3:3:2,  8bpp, (msb)2B 3G 3R(lsb)
>>      AV_PIX_FMT_BGR4,      ///< packed RGB 1:2:1 bitstream,  4bpp, (msb)1B 2G 1R(lsb), a byte contains two pixels, the first pixel in the byte is the one composed by the 4 msb bits
>>      AV_PIX_FMT_BGR4_BYTE, ///< packed RGB 1:2:1,  8bpp, (msb)1B 2G 1R(lsb)
> 
>> -    AV_PIX_FMT_RGB8,      ///< packed RGB 3:3:2,  8bpp, (msb)2R 3G 3B(lsb)
>> +    AV_PIX_FMT_RGB8,      ///< packed RGB 3:3:2,  8bpp, (msb)3R 3G 2B(lsb)
> 
> This is not consistent with pixdesc definition:
>     [AV_PIX_FMT_RGB8] = {
>         .name = "rgb8",
>         .nb_components = 3,
>         .log2_chroma_w = 0,
>         .log2_chroma_h = 0,
>         .comp = {
>             { 0, 1, 0, 6, 2 },        /* R */
>             { 0, 1, 0, 3, 3 },        /* G */
>             { 0, 1, 0, 0, 3 },        /* B */
>         },
>         .flags = AV_PIX_FMT_FLAG_RGB,
>     },
> 
> so either the documentation or the pixdesc description is wrong.
> 
> Do you confirm "(msb)3R 3G 2B(lsb)" is the correct definition?

Yes, I created three solid-colored RGBA raw samples filled with either #ff0000ff, #00ff00ff, or #0000ffff, and converted them using `ffmpeg ... -pix_fmt rgba ... -pix_fmt rgb8 ...` and inspected the output.  I also tested with `ffmpeg ... -pix_fmt rgba ... -pix_fmt yuv420p ...` followed by `ffmpeg ... -pix_fmt yuv420p ... -pix_fmt rgb8 ...`.  In these tests the outputs were consistent with "(msb)3R 3G 2B(lsb)".

> In this case pixdesc should be fixed accordingly.

Got it, will send an updated patch!

Thanks,
Jeff
diff mbox series

Patch

diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h
index 58f9ad28bd..9c87571f49 100644
--- a/libavutil/pixfmt.h
+++ b/libavutil/pixfmt.h
@@ -83,7 +83,7 @@  enum AVPixelFormat {
     AV_PIX_FMT_BGR8,      ///< packed RGB 3:3:2,  8bpp, (msb)2B 3G 3R(lsb)
     AV_PIX_FMT_BGR4,      ///< packed RGB 1:2:1 bitstream,  4bpp, (msb)1B 2G 1R(lsb), a byte contains two pixels, the first pixel in the byte is the one composed by the 4 msb bits
     AV_PIX_FMT_BGR4_BYTE, ///< packed RGB 1:2:1,  8bpp, (msb)1B 2G 1R(lsb)
-    AV_PIX_FMT_RGB8,      ///< packed RGB 3:3:2,  8bpp, (msb)2R 3G 3B(lsb)
+    AV_PIX_FMT_RGB8,      ///< packed RGB 3:3:2,  8bpp, (msb)3R 3G 2B(lsb)
     AV_PIX_FMT_RGB4,      ///< packed RGB 1:2:1 bitstream,  4bpp, (msb)1R 2G 1B(lsb), a byte contains two pixels, the first pixel in the byte is the one composed by the 4 msb bits
     AV_PIX_FMT_RGB4_BYTE, ///< packed RGB 1:2:1,  8bpp, (msb)1R 2G 1B(lsb)
     AV_PIX_FMT_NV12,      ///< planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (first byte U and the following byte V)