diff mbox series

[FFmpeg-devel,1/2] avfilter/vsrc_testsrc: add planar support to rgbtestsrc

Message ID 20210116145547.31834-1-onemda@gmail.com
State Accepted
Commit 79f2bca59ceae1429bd3a252f09d8e49c853c5f1
Headers show
Series [FFmpeg-devel,1/2] avfilter/vsrc_testsrc: add planar support to rgbtestsrc
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Paul B Mahol Jan. 16, 2021, 2:55 p.m. UTC
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavfilter/vsrc_testsrc.c | 33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)

Comments

James Almer Jan. 17, 2021, 2:45 p.m. UTC | #1
On 1/16/2021 11:55 AM, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>   libavfilter/vsrc_testsrc.c | 33 ++++++++++++++++++++++++++++++---
>   1 file changed, 30 insertions(+), 3 deletions(-)
> 
> diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c
> index 7001f9ba16..c047fe8e86 100644
> --- a/libavfilter/vsrc_testsrc.c
> +++ b/libavfilter/vsrc_testsrc.c
> @@ -77,6 +77,7 @@ typedef struct TestSourceContext {
>   
>       /* only used by rgbtest */
>       uint8_t rgba_map[4];
> +    int depth;
>   
>       /* only used by haldclut */
>       int level;
> @@ -970,12 +971,15 @@ AVFILTER_DEFINE_CLASS(rgbtestsrc);
>   #define B 2
>   #define A 3
>   
> -static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
> +static void rgbtest_put_pixel(uint8_t *dstp[4], int dst_linesizep[4],
>                                 int x, int y, unsigned r, unsigned g, unsigned b, enum AVPixelFormat fmt,
>                                 uint8_t rgba_map[4])
>   {
> +    uint8_t *dst = dstp[0];
> +    int dst_linesize = dst_linesizep[0];
>       uint32_t v;
>       uint8_t *p;
> +    uint16_t *p16;
>   
>       switch (fmt) {
>       case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
> @@ -998,6 +1002,25 @@ static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
>           p = dst + 4*x + y*dst_linesize;
>           AV_WL32(p, v);
>           break;
> +    case AV_PIX_FMT_GBRP:
> +        p = dstp[0] + x + y * dst_linesizep[0];
> +        p[0] = g;
> +        p = dstp[1] + x + y * dst_linesizep[1];
> +        p[0] = b;
> +        p = dstp[2] + x + y * dst_linesizep[2];
> +        p[0] = r;

Missing a break;?

> +    case AV_PIX_FMT_GBRP9:
> +    case AV_PIX_FMT_GBRP10:
> +    case AV_PIX_FMT_GBRP12:
> +    case AV_PIX_FMT_GBRP14:
> +    case AV_PIX_FMT_GBRP16:
> +        p16 = (uint16_t *)(dstp[0] + x*2 + y * dst_linesizep[0]);
> +        p16[0] = g;
> +        p16 = (uint16_t *)(dstp[1] + x*2 + y * dst_linesizep[1]);
> +        p16[0] = b;
> +        p16 = (uint16_t *)(dstp[2] + x*2 + y * dst_linesizep[2]);
> +        p16[0] = r;
> +        break;
>       }
>   }
>   
> @@ -1008,14 +1031,14 @@ static void rgbtest_fill_picture(AVFilterContext *ctx, AVFrame *frame)
>   
>       for (y = 0; y < h; y++) {
>            for (x = 0; x < w; x++) {
> -             int c = 256*x/w;
> +             int c = (1 << FFMAX(test->depth, 8))*x/w;
>                int r = 0, g = 0, b = 0;
>   
>                if      (3*y < h  ) r = c;
>                else if (3*y < 2*h) g = c;
>                else                b = c;
>   
> -             rgbtest_put_pixel(frame->data[0], frame->linesize[0], x, y, r, g, b,
> +             rgbtest_put_pixel(frame->data, frame->linesize, x, y, r, g, b,
>                                  ctx->outputs[0]->format, test->rgba_map);
>            }
>        }
> @@ -1038,6 +1061,8 @@ static int rgbtest_query_formats(AVFilterContext *ctx)
>           AV_PIX_FMT_RGB444, AV_PIX_FMT_BGR444,
>           AV_PIX_FMT_RGB565, AV_PIX_FMT_BGR565,
>           AV_PIX_FMT_RGB555, AV_PIX_FMT_BGR555,
> +        AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
> +        AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
>           AV_PIX_FMT_NONE
>       };
>   
> @@ -1050,7 +1075,9 @@ static int rgbtest_query_formats(AVFilterContext *ctx)
>   static int rgbtest_config_props(AVFilterLink *outlink)
>   {
>       TestSourceContext *test = outlink->src->priv;
> +    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
>   
> +    test->depth = desc->comp[0].depth;
>       ff_fill_rgba_map(test->rgba_map, outlink->format);
>       return config_props(outlink);
>   }
>
diff mbox series

Patch

diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c
index 7001f9ba16..c047fe8e86 100644
--- a/libavfilter/vsrc_testsrc.c
+++ b/libavfilter/vsrc_testsrc.c
@@ -77,6 +77,7 @@  typedef struct TestSourceContext {
 
     /* only used by rgbtest */
     uint8_t rgba_map[4];
+    int depth;
 
     /* only used by haldclut */
     int level;
@@ -970,12 +971,15 @@  AVFILTER_DEFINE_CLASS(rgbtestsrc);
 #define B 2
 #define A 3
 
-static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
+static void rgbtest_put_pixel(uint8_t *dstp[4], int dst_linesizep[4],
                               int x, int y, unsigned r, unsigned g, unsigned b, enum AVPixelFormat fmt,
                               uint8_t rgba_map[4])
 {
+    uint8_t *dst = dstp[0];
+    int dst_linesize = dst_linesizep[0];
     uint32_t v;
     uint8_t *p;
+    uint16_t *p16;
 
     switch (fmt) {
     case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
@@ -998,6 +1002,25 @@  static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
         p = dst + 4*x + y*dst_linesize;
         AV_WL32(p, v);
         break;
+    case AV_PIX_FMT_GBRP:
+        p = dstp[0] + x + y * dst_linesizep[0];
+        p[0] = g;
+        p = dstp[1] + x + y * dst_linesizep[1];
+        p[0] = b;
+        p = dstp[2] + x + y * dst_linesizep[2];
+        p[0] = r;
+    case AV_PIX_FMT_GBRP9:
+    case AV_PIX_FMT_GBRP10:
+    case AV_PIX_FMT_GBRP12:
+    case AV_PIX_FMT_GBRP14:
+    case AV_PIX_FMT_GBRP16:
+        p16 = (uint16_t *)(dstp[0] + x*2 + y * dst_linesizep[0]);
+        p16[0] = g;
+        p16 = (uint16_t *)(dstp[1] + x*2 + y * dst_linesizep[1]);
+        p16[0] = b;
+        p16 = (uint16_t *)(dstp[2] + x*2 + y * dst_linesizep[2]);
+        p16[0] = r;
+        break;
     }
 }
 
@@ -1008,14 +1031,14 @@  static void rgbtest_fill_picture(AVFilterContext *ctx, AVFrame *frame)
 
     for (y = 0; y < h; y++) {
          for (x = 0; x < w; x++) {
-             int c = 256*x/w;
+             int c = (1 << FFMAX(test->depth, 8))*x/w;
              int r = 0, g = 0, b = 0;
 
              if      (3*y < h  ) r = c;
              else if (3*y < 2*h) g = c;
              else                b = c;
 
-             rgbtest_put_pixel(frame->data[0], frame->linesize[0], x, y, r, g, b,
+             rgbtest_put_pixel(frame->data, frame->linesize, x, y, r, g, b,
                                ctx->outputs[0]->format, test->rgba_map);
          }
      }
@@ -1038,6 +1061,8 @@  static int rgbtest_query_formats(AVFilterContext *ctx)
         AV_PIX_FMT_RGB444, AV_PIX_FMT_BGR444,
         AV_PIX_FMT_RGB565, AV_PIX_FMT_BGR565,
         AV_PIX_FMT_RGB555, AV_PIX_FMT_BGR555,
+        AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
+        AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
         AV_PIX_FMT_NONE
     };
 
@@ -1050,7 +1075,9 @@  static int rgbtest_query_formats(AVFilterContext *ctx)
 static int rgbtest_config_props(AVFilterLink *outlink)
 {
     TestSourceContext *test = outlink->src->priv;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
 
+    test->depth = desc->comp[0].depth;
     ff_fill_rgba_map(test->rgba_map, outlink->format);
     return config_props(outlink);
 }