diff mbox series

[FFmpeg-devel,1/5] checkasm/sw_rgb: test rgb24 to yuv

Message ID tencent_1989B5246A0E016968927CC6AEC23A15C10A@qq.com
State New
Headers show
Series [FFmpeg-devel,1/5] checkasm/sw_rgb: test rgb24 to yuv | 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

Zhao Zhili June 4, 2024, 1:55 p.m. UTC
From: Zhao Zhili <zhilizhao@tencent.com>

---
 tests/checkasm/sw_rgb.c | 103 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)

Comments

James Almer June 4, 2024, 1:58 p.m. UTC | #1
On 6/4/2024 10:55 AM, Zhao Zhili wrote:
> From: Zhao Zhili <zhilizhao@tencent.com>
> 
> ---
>   tests/checkasm/sw_rgb.c | 103 ++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 103 insertions(+)
> 
> diff --git a/tests/checkasm/sw_rgb.c b/tests/checkasm/sw_rgb.c
> index 7cd815e5be..cc9b957461 100644
> --- a/tests/checkasm/sw_rgb.c
> +++ b/tests/checkasm/sw_rgb.c
> @@ -24,6 +24,8 @@
>   #include "libavutil/mem_internal.h"
>   
>   #include "libswscale/rgb2rgb.h"
> +#include "libswscale/swscale.h"
> +#include "libswscale/swscale_internal.h"
>   
>   #include "checkasm.h"
>   
> @@ -179,8 +181,89 @@ static void check_interleave_bytes(void)
>       }
>   }
>   
> +#define MAX_LINE_SIZE 1920
> +
> +static void check_rgb_to_y(struct SwsContext *ctx)
> +{
> +    static const int input_sizes[] = {8, 128, 1280, 1080, MAX_LINE_SIZE};
> +
> +    LOCAL_ALIGNED_32(uint8_t, src, [MAX_LINE_SIZE * 3]);
> +    LOCAL_ALIGNED_32(uint8_t, dst0_y, [MAX_LINE_SIZE * 2]);
> +    LOCAL_ALIGNED_32(uint8_t, dst1_y, [MAX_LINE_SIZE * 2]);
> +
> +    declare_func(void, uint8_t *dst, const uint8_t *src,
> +                 const uint8_t *unused1, const uint8_t *unused2, int width,
> +                 uint32_t *rgb2yuv, void *opq);
> +
> +    randomize_buffers(src, MAX_LINE_SIZE * 3);
> +
> +    for (int i = 0; i < FF_ARRAY_ELEMS(input_sizes); i++) {
> +        int w = input_sizes[i];
> +
> +        if (check_func(ctx->lumToYV12, "rgb24_to_y_%d", w)) {
> +            memset(dst0_y, 0xFA, MAX_LINE_SIZE * 2);
> +            memset(dst1_y, 0xFA, MAX_LINE_SIZE * 2);
> +
> +            call_ref(dst0_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
> +            call_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
> +
> +            if (memcmp(dst0_y, dst1_y, w * 2))
> +                fail();
> +
> +            bench_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
> +        }
> +    }
> +}
> +
> +static void check_rgb_to_uv(struct SwsContext *ctx)
> +{
> +    static const int input_sizes[] = {8, 128, 1280, 1080, MAX_LINE_SIZE};
> +
> +    LOCAL_ALIGNED_32(uint8_t, src, [MAX_LINE_SIZE * 3]);
> +    LOCAL_ALIGNED_32(uint8_t, dst0_u, [MAX_LINE_SIZE * 2]);
> +    LOCAL_ALIGNED_32(uint8_t, dst0_v, [MAX_LINE_SIZE * 2]);
> +    LOCAL_ALIGNED_32(uint8_t, dst1_u, [MAX_LINE_SIZE * 2]);
> +    LOCAL_ALIGNED_32(uint8_t, dst1_v, [MAX_LINE_SIZE * 2]);
> +
> +    declare_func(void, uint8_t *dstU, uint8_t *dstV,
> +                 const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
> +                 int width, uint32_t *pal, void *opq);
> +
> +    randomize_buffers(src, MAX_LINE_SIZE * 3);
> +
> +    for (int i = 0; i < 2; i++) {
> +        ctx->chrSrcHSubSample = i ? 1 : 0;
> +        ctx->srcFormat = AV_PIX_FMT_RGB24;
> +        ctx->dstFormat = i ? AV_PIX_FMT_YUV420P : AV_PIX_FMT_YUV444P;
> +        ff_sws_init_scale(ctx);
> +
> +        for (int j = 0; j < FF_ARRAY_ELEMS(input_sizes); j++) {
> +            int w = input_sizes[j] >> i;
> +
> +            if (check_func(ctx->chrToYV12, "rgb24_to_uv%s_%d", i ? "_half" : "", w)) {
> +                memset(dst0_u, 0xFF, MAX_LINE_SIZE * 2);
> +                memset(dst0_v, 0xFF, MAX_LINE_SIZE * 2);
> +                memset(dst1_u, 0xFF, MAX_LINE_SIZE * 2);
> +                memset(dst1_v, 0xFF, MAX_LINE_SIZE * 2);
> +
> +                call_ref(dst0_u, dst0_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
> +                call_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
> +
> +                if (memcmp(dst0_u, dst1_u, w * 2) || memcmp(dst0_v, dst1_v, w * 2))
> +                    fail();
> +
> +                bench_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
> +            }
> +        }
> +    }
> +}
> +
>   void checkasm_check_sw_rgb(void)
>   {
> +    struct SwsContext *ctx;
> +    int *inv_table, *table;
> +    int in_full, out_full, brightness, contrast, saturation;
> +
>       ff_sws_rgb2rgb_init();
>   
>       check_shuffle_bytes(shuffle_bytes_2103, "shuffle_bytes_2103");
> @@ -203,4 +286,24 @@ void checkasm_check_sw_rgb(void)
>   
>       check_interleave_bytes();
>       report("interleave_bytes");
> +
> +    ctx = sws_getContext(MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_RGB24,
> +                         MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_YUV420P,
> +                         SWS_ACCURATE_RND | SWS_BITEXACT, NULL, NULL, NULL);
> +    if (!ctx)
> +        fail();
> +
> +    sws_getColorspaceDetails(ctx, &inv_table, &in_full,
> +                             &table, &out_full,
> +                             &brightness, &contrast, &saturation);
> +    sws_setColorspaceDetails(ctx, inv_table, in_full,
> +                             table, out_full,
> +                             brightness, contrast, saturation);

Isn't this pointless? It looks like you're setting the context with 
values taken from the same context.

> +    check_rgb_to_y(ctx);
> +    report("rgb_to_y");
> +
> +    check_rgb_to_uv(ctx);
> +    report("rgb_to_uv");
> +
> +    sws_freeContext(ctx);
>   }
Zhao Zhili June 4, 2024, 2:06 p.m. UTC | #2
> On Jun 4, 2024, at 21:58, James Almer <jamrial@gmail.com> wrote:
> 
> On 6/4/2024 10:55 AM, Zhao Zhili wrote:
>> From: Zhao Zhili <zhilizhao@tencent.com>
>> ---
>>  tests/checkasm/sw_rgb.c | 103 ++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 103 insertions(+)
>> diff --git a/tests/checkasm/sw_rgb.c b/tests/checkasm/sw_rgb.c
>> index 7cd815e5be..cc9b957461 100644
>> --- a/tests/checkasm/sw_rgb.c
>> +++ b/tests/checkasm/sw_rgb.c
>> @@ -24,6 +24,8 @@
>>  #include "libavutil/mem_internal.h"
>>    #include "libswscale/rgb2rgb.h"
>> +#include "libswscale/swscale.h"
>> +#include "libswscale/swscale_internal.h"
>>    #include "checkasm.h"
>>  @@ -179,8 +181,89 @@ static void check_interleave_bytes(void)
>>      }
>>  }
>>  +#define MAX_LINE_SIZE 1920
>> +
>> +static void check_rgb_to_y(struct SwsContext *ctx)
>> +{
>> +    static const int input_sizes[] = {8, 128, 1280, 1080, MAX_LINE_SIZE};
>> +
>> +    LOCAL_ALIGNED_32(uint8_t, src, [MAX_LINE_SIZE * 3]);
>> +    LOCAL_ALIGNED_32(uint8_t, dst0_y, [MAX_LINE_SIZE * 2]);
>> +    LOCAL_ALIGNED_32(uint8_t, dst1_y, [MAX_LINE_SIZE * 2]);
>> +
>> +    declare_func(void, uint8_t *dst, const uint8_t *src,
>> +                 const uint8_t *unused1, const uint8_t *unused2, int width,
>> +                 uint32_t *rgb2yuv, void *opq);
>> +
>> +    randomize_buffers(src, MAX_LINE_SIZE * 3);
>> +
>> +    for (int i = 0; i < FF_ARRAY_ELEMS(input_sizes); i++) {
>> +        int w = input_sizes[i];
>> +
>> +        if (check_func(ctx->lumToYV12, "rgb24_to_y_%d", w)) {
>> +            memset(dst0_y, 0xFA, MAX_LINE_SIZE * 2);
>> +            memset(dst1_y, 0xFA, MAX_LINE_SIZE * 2);
>> +
>> +            call_ref(dst0_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
>> +            call_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
>> +
>> +            if (memcmp(dst0_y, dst1_y, w * 2))
>> +                fail();
>> +
>> +            bench_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
>> +        }
>> +    }
>> +}
>> +
>> +static void check_rgb_to_uv(struct SwsContext *ctx)
>> +{
>> +    static const int input_sizes[] = {8, 128, 1280, 1080, MAX_LINE_SIZE};
>> +
>> +    LOCAL_ALIGNED_32(uint8_t, src, [MAX_LINE_SIZE * 3]);
>> +    LOCAL_ALIGNED_32(uint8_t, dst0_u, [MAX_LINE_SIZE * 2]);
>> +    LOCAL_ALIGNED_32(uint8_t, dst0_v, [MAX_LINE_SIZE * 2]);
>> +    LOCAL_ALIGNED_32(uint8_t, dst1_u, [MAX_LINE_SIZE * 2]);
>> +    LOCAL_ALIGNED_32(uint8_t, dst1_v, [MAX_LINE_SIZE * 2]);
>> +
>> +    declare_func(void, uint8_t *dstU, uint8_t *dstV,
>> +                 const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
>> +                 int width, uint32_t *pal, void *opq);
>> +
>> +    randomize_buffers(src, MAX_LINE_SIZE * 3);
>> +
>> +    for (int i = 0; i < 2; i++) {
>> +        ctx->chrSrcHSubSample = i ? 1 : 0;
>> +        ctx->srcFormat = AV_PIX_FMT_RGB24;
>> +        ctx->dstFormat = i ? AV_PIX_FMT_YUV420P : AV_PIX_FMT_YUV444P;
>> +        ff_sws_init_scale(ctx);
>> +
>> +        for (int j = 0; j < FF_ARRAY_ELEMS(input_sizes); j++) {
>> +            int w = input_sizes[j] >> i;
>> +
>> +            if (check_func(ctx->chrToYV12, "rgb24_to_uv%s_%d", i ? "_half" : "", w)) {
>> +                memset(dst0_u, 0xFF, MAX_LINE_SIZE * 2);
>> +                memset(dst0_v, 0xFF, MAX_LINE_SIZE * 2);
>> +                memset(dst1_u, 0xFF, MAX_LINE_SIZE * 2);
>> +                memset(dst1_v, 0xFF, MAX_LINE_SIZE * 2);
>> +
>> +                call_ref(dst0_u, dst0_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
>> +                call_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
>> +
>> +                if (memcmp(dst0_u, dst1_u, w * 2) || memcmp(dst0_v, dst1_v, w * 2))
>> +                    fail();
>> +
>> +                bench_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
>> +            }
>> +        }
>> +    }
>> +}
>> +
>>  void checkasm_check_sw_rgb(void)
>>  {
>> +    struct SwsContext *ctx;
>> +    int *inv_table, *table;
>> +    int in_full, out_full, brightness, contrast, saturation;
>> +
>>      ff_sws_rgb2rgb_init();
>>        check_shuffle_bytes(shuffle_bytes_2103, "shuffle_bytes_2103");
>> @@ -203,4 +286,24 @@ void checkasm_check_sw_rgb(void)
>>        check_interleave_bytes();
>>      report("interleave_bytes");
>> +
>> +    ctx = sws_getContext(MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_RGB24,
>> +                         MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_YUV420P,
>> +                         SWS_ACCURATE_RND | SWS_BITEXACT, NULL, NULL, NULL);
>> +    if (!ctx)
>> +        fail();
>> +
>> +    sws_getColorspaceDetails(ctx, &inv_table, &in_full,
>> +                             &table, &out_full,
>> +                             &brightness, &contrast, &saturation);
>> +    sws_setColorspaceDetails(ctx, inv_table, in_full,
>> +                             table, out_full,
>> +                             brightness, contrast, saturation);
> 
> Isn't this pointless? It looks like you're setting the context with values taken from the same context.

Yes, will remove in next version.

> 
>> +    check_rgb_to_y(ctx);
>> +    report("rgb_to_y");
>> +
>> +    check_rgb_to_uv(ctx);
>> +    report("rgb_to_uv");
>> +
>> +    sws_freeContext(ctx);
>>  }
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org <mailto:ffmpeg-devel-request@ffmpeg.org> with subject "unsubscribe".
James Almer June 5, 2024, 3:37 p.m. UTC | #3
On 6/4/2024 11:06 AM, Zhao Zhili wrote:
> 
> 
>> On Jun 4, 2024, at 21:58, James Almer <jamrial@gmail.com> wrote:
>>
>> On 6/4/2024 10:55 AM, Zhao Zhili wrote:
>>> From: Zhao Zhili <zhilizhao@tencent.com>
>>> ---
>>>   tests/checkasm/sw_rgb.c | 103 ++++++++++++++++++++++++++++++++++++++++
>>>   1 file changed, 103 insertions(+)
>>> diff --git a/tests/checkasm/sw_rgb.c b/tests/checkasm/sw_rgb.c
>>> index 7cd815e5be..cc9b957461 100644
>>> --- a/tests/checkasm/sw_rgb.c
>>> +++ b/tests/checkasm/sw_rgb.c
>>> @@ -24,6 +24,8 @@
>>>   #include "libavutil/mem_internal.h"
>>>     #include "libswscale/rgb2rgb.h"
>>> +#include "libswscale/swscale.h"
>>> +#include "libswscale/swscale_internal.h"
>>>     #include "checkasm.h"
>>>   @@ -179,8 +181,89 @@ static void check_interleave_bytes(void)
>>>       }
>>>   }
>>>   +#define MAX_LINE_SIZE 1920
>>> +
>>> +static void check_rgb_to_y(struct SwsContext *ctx)
>>> +{
>>> +    static const int input_sizes[] = {8, 128, 1280, 1080, MAX_LINE_SIZE};
>>> +
>>> +    LOCAL_ALIGNED_32(uint8_t, src, [MAX_LINE_SIZE * 3]);
>>> +    LOCAL_ALIGNED_32(uint8_t, dst0_y, [MAX_LINE_SIZE * 2]);
>>> +    LOCAL_ALIGNED_32(uint8_t, dst1_y, [MAX_LINE_SIZE * 2]);
>>> +
>>> +    declare_func(void, uint8_t *dst, const uint8_t *src,
>>> +                 const uint8_t *unused1, const uint8_t *unused2, int width,
>>> +                 uint32_t *rgb2yuv, void *opq);
>>> +
>>> +    randomize_buffers(src, MAX_LINE_SIZE * 3);
>>> +
>>> +    for (int i = 0; i < FF_ARRAY_ELEMS(input_sizes); i++) {
>>> +        int w = input_sizes[i];
>>> +
>>> +        if (check_func(ctx->lumToYV12, "rgb24_to_y_%d", w)) {
>>> +            memset(dst0_y, 0xFA, MAX_LINE_SIZE * 2);
>>> +            memset(dst1_y, 0xFA, MAX_LINE_SIZE * 2);
>>> +
>>> +            call_ref(dst0_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
>>> +            call_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
>>> +
>>> +            if (memcmp(dst0_y, dst1_y, w * 2))
>>> +                fail();
>>> +
>>> +            bench_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
>>> +        }
>>> +    }
>>> +}
>>> +
>>> +static void check_rgb_to_uv(struct SwsContext *ctx)
>>> +{
>>> +    static const int input_sizes[] = {8, 128, 1280, 1080, MAX_LINE_SIZE};
>>> +
>>> +    LOCAL_ALIGNED_32(uint8_t, src, [MAX_LINE_SIZE * 3]);
>>> +    LOCAL_ALIGNED_32(uint8_t, dst0_u, [MAX_LINE_SIZE * 2]);
>>> +    LOCAL_ALIGNED_32(uint8_t, dst0_v, [MAX_LINE_SIZE * 2]);
>>> +    LOCAL_ALIGNED_32(uint8_t, dst1_u, [MAX_LINE_SIZE * 2]);
>>> +    LOCAL_ALIGNED_32(uint8_t, dst1_v, [MAX_LINE_SIZE * 2]);
>>> +
>>> +    declare_func(void, uint8_t *dstU, uint8_t *dstV,
>>> +                 const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
>>> +                 int width, uint32_t *pal, void *opq);
>>> +
>>> +    randomize_buffers(src, MAX_LINE_SIZE * 3);
>>> +
>>> +    for (int i = 0; i < 2; i++) {
>>> +        ctx->chrSrcHSubSample = i ? 1 : 0;
>>> +        ctx->srcFormat = AV_PIX_FMT_RGB24;
>>> +        ctx->dstFormat = i ? AV_PIX_FMT_YUV420P : AV_PIX_FMT_YUV444P;
>>> +        ff_sws_init_scale(ctx);
>>> +
>>> +        for (int j = 0; j < FF_ARRAY_ELEMS(input_sizes); j++) {
>>> +            int w = input_sizes[j] >> i;
>>> +
>>> +            if (check_func(ctx->chrToYV12, "rgb24_to_uv%s_%d", i ? "_half" : "", w)) {
>>> +                memset(dst0_u, 0xFF, MAX_LINE_SIZE * 2);
>>> +                memset(dst0_v, 0xFF, MAX_LINE_SIZE * 2);
>>> +                memset(dst1_u, 0xFF, MAX_LINE_SIZE * 2);
>>> +                memset(dst1_v, 0xFF, MAX_LINE_SIZE * 2);
>>> +
>>> +                call_ref(dst0_u, dst0_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
>>> +                call_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
>>> +
>>> +                if (memcmp(dst0_u, dst1_u, w * 2) || memcmp(dst0_v, dst1_v, w * 2))
>>> +                    fail();
>>> +
>>> +                bench_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
>>> +            }
>>> +        }
>>> +    }
>>> +}
>>> +
>>>   void checkasm_check_sw_rgb(void)
>>>   {
>>> +    struct SwsContext *ctx;
>>> +    int *inv_table, *table;
>>> +    int in_full, out_full, brightness, contrast, saturation;
>>> +
>>>       ff_sws_rgb2rgb_init();
>>>         check_shuffle_bytes(shuffle_bytes_2103, "shuffle_bytes_2103");
>>> @@ -203,4 +286,24 @@ void checkasm_check_sw_rgb(void)
>>>         check_interleave_bytes();
>>>       report("interleave_bytes");
>>> +
>>> +    ctx = sws_getContext(MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_RGB24,
>>> +                         MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_YUV420P,
>>> +                         SWS_ACCURATE_RND | SWS_BITEXACT, NULL, NULL, NULL);
>>> +    if (!ctx)
>>> +        fail();
>>> +
>>> +    sws_getColorspaceDetails(ctx, &inv_table, &in_full,
>>> +                             &table, &out_full,
>>> +                             &brightness, &contrast, &saturation);
>>> +    sws_setColorspaceDetails(ctx, inv_table, in_full,
>>> +                             table, out_full,
>>> +                             brightness, contrast, saturation);
>>
>> Isn't this pointless? It looks like you're setting the context with values taken from the same context.
> 
> Yes, will remove in next version.

Will you send a new version with other changes, or just this? If the 
latter, i can amend it and push it now.
Rémi Denis-Courmont June 5, 2024, 3:39 p.m. UTC | #4
Le tiistaina 4. kesäkuuta 2024, 16.55.00 EEST Zhao Zhili a écrit :
> From: Zhao Zhili <zhilizhao@tencent.com>
> 
> ---
>  tests/checkasm/sw_rgb.c | 103 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 103 insertions(+)
> 
> diff --git a/tests/checkasm/sw_rgb.c b/tests/checkasm/sw_rgb.c
> index 7cd815e5be..cc9b957461 100644
> --- a/tests/checkasm/sw_rgb.c
> +++ b/tests/checkasm/sw_rgb.c
> @@ -24,6 +24,8 @@
>  #include "libavutil/mem_internal.h"
> 
>  #include "libswscale/rgb2rgb.h"
> +#include "libswscale/swscale.h"
> +#include "libswscale/swscale_internal.h"
> 
>  #include "checkasm.h"
> 
> @@ -179,8 +181,89 @@ static void check_interleave_bytes(void)
>      }
>  }
> 
> +#define MAX_LINE_SIZE 1920
> +
> +static void check_rgb_to_y(struct SwsContext *ctx)
> +{
> +    static const int input_sizes[] = {8, 128, 1280, 1080, MAX_LINE_SIZE};
> +
> +    LOCAL_ALIGNED_32(uint8_t, src, [MAX_LINE_SIZE * 3]);
> +    LOCAL_ALIGNED_32(uint8_t, dst0_y, [MAX_LINE_SIZE * 2]);
> +    LOCAL_ALIGNED_32(uint8_t, dst1_y, [MAX_LINE_SIZE * 2]);
> +
> +    declare_func(void, uint8_t *dst, const uint8_t *src,
> +                 const uint8_t *unused1, const uint8_t *unused2, int width,
> +                 uint32_t *rgb2yuv, void *opq);
> +
> +    randomize_buffers(src, MAX_LINE_SIZE * 3);
> +
> +    for (int i = 0; i < FF_ARRAY_ELEMS(input_sizes); i++) {
> +        int w = input_sizes[i];
> +
> +        if (check_func(ctx->lumToYV12, "rgb24_to_y_%d", w)) {
> +            memset(dst0_y, 0xFA, MAX_LINE_SIZE * 2);
> +            memset(dst1_y, 0xFA, MAX_LINE_SIZE * 2);
> +
> +            call_ref(dst0_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table,
> NULL); +            call_new(dst1_y, src, NULL, NULL, w,
> ctx->input_rgb2yuv_table, NULL); +
> +            if (memcmp(dst0_y, dst1_y, w * 2))
> +                fail();
> +
> +            bench_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table,
> NULL); +        }
> +    }
> +}
> +
> +static void check_rgb_to_uv(struct SwsContext *ctx)
> +{
> +    static const int input_sizes[] = {8, 128, 1280, 1080, MAX_LINE_SIZE};
> +
> +    LOCAL_ALIGNED_32(uint8_t, src, [MAX_LINE_SIZE * 3]);
> +    LOCAL_ALIGNED_32(uint8_t, dst0_u, [MAX_LINE_SIZE * 2]);
> +    LOCAL_ALIGNED_32(uint8_t, dst0_v, [MAX_LINE_SIZE * 2]);
> +    LOCAL_ALIGNED_32(uint8_t, dst1_u, [MAX_LINE_SIZE * 2]);
> +    LOCAL_ALIGNED_32(uint8_t, dst1_v, [MAX_LINE_SIZE * 2]);
> +
> +    declare_func(void, uint8_t *dstU, uint8_t *dstV,
> +                 const uint8_t *src1, const uint8_t *src2, const uint8_t
> *src3, +                 int width, uint32_t *pal, void *opq);
> +
> +    randomize_buffers(src, MAX_LINE_SIZE * 3);
> +
> +    for (int i = 0; i < 2; i++) {
> +        ctx->chrSrcHSubSample = i ? 1 : 0;
> +        ctx->srcFormat = AV_PIX_FMT_RGB24;
> +        ctx->dstFormat = i ? AV_PIX_FMT_YUV420P : AV_PIX_FMT_YUV444P;
> +        ff_sws_init_scale(ctx);

Given the loop is there, wouldn't it be trivial to also test BGR24 ? (maybe 
skipping benchmarks)

> +
> +        for (int j = 0; j < FF_ARRAY_ELEMS(input_sizes); j++) {
> +            int w = input_sizes[j] >> i;
> +
> +            if (check_func(ctx->chrToYV12, "rgb24_to_uv%s_%d", i ? "_half"
> : "", w)) { +                memset(dst0_u, 0xFF, MAX_LINE_SIZE * 2);
> +                memset(dst0_v, 0xFF, MAX_LINE_SIZE * 2);
> +                memset(dst1_u, 0xFF, MAX_LINE_SIZE * 2);
> +                memset(dst1_v, 0xFF, MAX_LINE_SIZE * 2);
> +
> +                call_ref(dst0_u, dst0_v, NULL, src, src, w,
> ctx->input_rgb2yuv_table, NULL); +                call_new(dst1_u, dst1_v,
> NULL, src, src, w, ctx->input_rgb2yuv_table, NULL); +
> +                if (memcmp(dst0_u, dst1_u, w * 2) || memcmp(dst0_v, dst1_v,
> w * 2)) +                    fail();
> +
> +                bench_new(dst1_u, dst1_v, NULL, src, src, w,
> ctx->input_rgb2yuv_table, NULL); +            }
> +        }
> +    }
> +}
> +
>  void checkasm_check_sw_rgb(void)
>  {
> +    struct SwsContext *ctx;
> +    int *inv_table, *table;
> +    int in_full, out_full, brightness, contrast, saturation;
> +
>      ff_sws_rgb2rgb_init();
> 
>      check_shuffle_bytes(shuffle_bytes_2103, "shuffle_bytes_2103");
> @@ -203,4 +286,24 @@ void checkasm_check_sw_rgb(void)
> 
>      check_interleave_bytes();
>      report("interleave_bytes");
> +
> +    ctx = sws_getContext(MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_RGB24,
> +                         MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_YUV420P,
> +                         SWS_ACCURATE_RND | SWS_BITEXACT, NULL, NULL,
> NULL); +    if (!ctx)
> +        fail();
> +
> +    sws_getColorspaceDetails(ctx, &inv_table, &in_full,
> +                             &table, &out_full,
> +                             &brightness, &contrast, &saturation);
> +    sws_setColorspaceDetails(ctx, inv_table, in_full,
> +                             table, out_full,
> +                             brightness, contrast, saturation);
> +    check_rgb_to_y(ctx);
> +    report("rgb_to_y");
> +
> +    check_rgb_to_uv(ctx);
> +    report("rgb_to_uv");
> +
> +    sws_freeContext(ctx);
>  }
diff mbox series

Patch

diff --git a/tests/checkasm/sw_rgb.c b/tests/checkasm/sw_rgb.c
index 7cd815e5be..cc9b957461 100644
--- a/tests/checkasm/sw_rgb.c
+++ b/tests/checkasm/sw_rgb.c
@@ -24,6 +24,8 @@ 
 #include "libavutil/mem_internal.h"
 
 #include "libswscale/rgb2rgb.h"
+#include "libswscale/swscale.h"
+#include "libswscale/swscale_internal.h"
 
 #include "checkasm.h"
 
@@ -179,8 +181,89 @@  static void check_interleave_bytes(void)
     }
 }
 
+#define MAX_LINE_SIZE 1920
+
+static void check_rgb_to_y(struct SwsContext *ctx)
+{
+    static const int input_sizes[] = {8, 128, 1280, 1080, MAX_LINE_SIZE};
+
+    LOCAL_ALIGNED_32(uint8_t, src, [MAX_LINE_SIZE * 3]);
+    LOCAL_ALIGNED_32(uint8_t, dst0_y, [MAX_LINE_SIZE * 2]);
+    LOCAL_ALIGNED_32(uint8_t, dst1_y, [MAX_LINE_SIZE * 2]);
+
+    declare_func(void, uint8_t *dst, const uint8_t *src,
+                 const uint8_t *unused1, const uint8_t *unused2, int width,
+                 uint32_t *rgb2yuv, void *opq);
+
+    randomize_buffers(src, MAX_LINE_SIZE * 3);
+
+    for (int i = 0; i < FF_ARRAY_ELEMS(input_sizes); i++) {
+        int w = input_sizes[i];
+
+        if (check_func(ctx->lumToYV12, "rgb24_to_y_%d", w)) {
+            memset(dst0_y, 0xFA, MAX_LINE_SIZE * 2);
+            memset(dst1_y, 0xFA, MAX_LINE_SIZE * 2);
+
+            call_ref(dst0_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
+            call_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
+
+            if (memcmp(dst0_y, dst1_y, w * 2))
+                fail();
+
+            bench_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
+        }
+    }
+}
+
+static void check_rgb_to_uv(struct SwsContext *ctx)
+{
+    static const int input_sizes[] = {8, 128, 1280, 1080, MAX_LINE_SIZE};
+
+    LOCAL_ALIGNED_32(uint8_t, src, [MAX_LINE_SIZE * 3]);
+    LOCAL_ALIGNED_32(uint8_t, dst0_u, [MAX_LINE_SIZE * 2]);
+    LOCAL_ALIGNED_32(uint8_t, dst0_v, [MAX_LINE_SIZE * 2]);
+    LOCAL_ALIGNED_32(uint8_t, dst1_u, [MAX_LINE_SIZE * 2]);
+    LOCAL_ALIGNED_32(uint8_t, dst1_v, [MAX_LINE_SIZE * 2]);
+
+    declare_func(void, uint8_t *dstU, uint8_t *dstV,
+                 const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
+                 int width, uint32_t *pal, void *opq);
+
+    randomize_buffers(src, MAX_LINE_SIZE * 3);
+
+    for (int i = 0; i < 2; i++) {
+        ctx->chrSrcHSubSample = i ? 1 : 0;
+        ctx->srcFormat = AV_PIX_FMT_RGB24;
+        ctx->dstFormat = i ? AV_PIX_FMT_YUV420P : AV_PIX_FMT_YUV444P;
+        ff_sws_init_scale(ctx);
+
+        for (int j = 0; j < FF_ARRAY_ELEMS(input_sizes); j++) {
+            int w = input_sizes[j] >> i;
+
+            if (check_func(ctx->chrToYV12, "rgb24_to_uv%s_%d", i ? "_half" : "", w)) {
+                memset(dst0_u, 0xFF, MAX_LINE_SIZE * 2);
+                memset(dst0_v, 0xFF, MAX_LINE_SIZE * 2);
+                memset(dst1_u, 0xFF, MAX_LINE_SIZE * 2);
+                memset(dst1_v, 0xFF, MAX_LINE_SIZE * 2);
+
+                call_ref(dst0_u, dst0_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
+                call_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
+
+                if (memcmp(dst0_u, dst1_u, w * 2) || memcmp(dst0_v, dst1_v, w * 2))
+                    fail();
+
+                bench_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
+            }
+        }
+    }
+}
+
 void checkasm_check_sw_rgb(void)
 {
+    struct SwsContext *ctx;
+    int *inv_table, *table;
+    int in_full, out_full, brightness, contrast, saturation;
+
     ff_sws_rgb2rgb_init();
 
     check_shuffle_bytes(shuffle_bytes_2103, "shuffle_bytes_2103");
@@ -203,4 +286,24 @@  void checkasm_check_sw_rgb(void)
 
     check_interleave_bytes();
     report("interleave_bytes");
+
+    ctx = sws_getContext(MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_RGB24,
+                         MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_YUV420P,
+                         SWS_ACCURATE_RND | SWS_BITEXACT, NULL, NULL, NULL);
+    if (!ctx)
+        fail();
+
+    sws_getColorspaceDetails(ctx, &inv_table, &in_full,
+                             &table, &out_full,
+                             &brightness, &contrast, &saturation);
+    sws_setColorspaceDetails(ctx, inv_table, in_full,
+                             table, out_full,
+                             brightness, contrast, saturation);
+    check_rgb_to_y(ctx);
+    report("rgb_to_y");
+
+    check_rgb_to_uv(ctx);
+    report("rgb_to_uv");
+
+    sws_freeContext(ctx);
 }