avformat/network: add union for avoiding strict aliassing violations with sockaddr*
[ffmpeg.git] / libavfilter / vf_stereo3d.c
index ec3ab47..2140120 100644 (file)
@@ -25,6 +25,7 @@
 #include "libavutil/parseutils.h"
 #include "libavutil/pixdesc.h"
 #include "avfilter.h"
+#include "drawutils.h"
 #include "formats.h"
 #include "internal.h"
 #include "video.h"
@@ -133,9 +134,11 @@ typedef struct Stereo3DContext {
     StereoComponent in, out;
     int width, height;
     int row_step;
-    int ana_matrix[3][6];
+    const int *ana_matrix[3];
     int nb_planes;
     int linesize[4];
+    int pheight[4];
+    int hsub, vsub;
     int pixstep[4];
     AVFrame *prev;
     double ts_unit;
@@ -185,12 +188,16 @@ static const AVOption stereo3d_options[] = {
     { "sbs2r", "side by side half width right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_RL},  0, 0, FLAGS, "out" },
     { "sbsl",  "side by side left first",             0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_LR},    0, 0, FLAGS, "out" },
     { "sbsr",  "side by side right first",            0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_RL},    0, 0, FLAGS, "out" },
-    {NULL},
+    { NULL }
 };
 
 AVFILTER_DEFINE_CLASS(stereo3d);
 
-static const enum AVPixelFormat anaglyph_pix_fmts[] = { AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE };
+static const enum AVPixelFormat anaglyph_pix_fmts[] = {
+    AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24,
+    AV_PIX_FMT_NONE
+};
+
 static const enum AVPixelFormat other_pix_fmts[] = {
     AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24,
     AV_PIX_FMT_RGB48BE, AV_PIX_FMT_BGR48BE,
@@ -207,14 +214,39 @@ static const enum AVPixelFormat other_pix_fmts[] = {
     AV_PIX_FMT_GBRP12BE, AV_PIX_FMT_GBRP12LE,
     AV_PIX_FMT_GBRP14BE, AV_PIX_FMT_GBRP14LE,
     AV_PIX_FMT_GBRP16BE, AV_PIX_FMT_GBRP16LE,
+    AV_PIX_FMT_YUV410P,
+    AV_PIX_FMT_YUV411P,
+    AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVA420P,
+    AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVA422P,
+    AV_PIX_FMT_YUV440P,
     AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVA444P,
+    AV_PIX_FMT_YUVJ411P,
+    AV_PIX_FMT_YUVJ420P,
+    AV_PIX_FMT_YUVJ422P,
+    AV_PIX_FMT_YUVJ440P,
     AV_PIX_FMT_YUVJ444P,
+    AV_PIX_FMT_YUV420P9LE,  AV_PIX_FMT_YUVA420P9LE,
+    AV_PIX_FMT_YUV420P9BE,  AV_PIX_FMT_YUVA420P9BE,
+    AV_PIX_FMT_YUV422P9LE,  AV_PIX_FMT_YUVA422P9LE,
+    AV_PIX_FMT_YUV422P9BE,  AV_PIX_FMT_YUVA422P9BE,
     AV_PIX_FMT_YUV444P9LE,  AV_PIX_FMT_YUVA444P9LE,
     AV_PIX_FMT_YUV444P9BE,  AV_PIX_FMT_YUVA444P9BE,
+    AV_PIX_FMT_YUV420P10LE, AV_PIX_FMT_YUVA420P10LE,
+    AV_PIX_FMT_YUV420P10BE, AV_PIX_FMT_YUVA420P10BE,
+    AV_PIX_FMT_YUV422P10LE, AV_PIX_FMT_YUVA422P10LE,
+    AV_PIX_FMT_YUV422P10BE, AV_PIX_FMT_YUVA422P10BE,
     AV_PIX_FMT_YUV444P10LE, AV_PIX_FMT_YUVA444P10LE,
     AV_PIX_FMT_YUV444P10BE, AV_PIX_FMT_YUVA444P10BE,
+    AV_PIX_FMT_YUV420P12BE,  AV_PIX_FMT_YUV420P12LE,
+    AV_PIX_FMT_YUV422P12BE,  AV_PIX_FMT_YUV422P12LE,
     AV_PIX_FMT_YUV444P12BE,  AV_PIX_FMT_YUV444P12LE,
+    AV_PIX_FMT_YUV420P14BE,  AV_PIX_FMT_YUV420P14LE,
+    AV_PIX_FMT_YUV422P14BE,  AV_PIX_FMT_YUV422P14LE,
     AV_PIX_FMT_YUV444P14BE,  AV_PIX_FMT_YUV444P14LE,
+    AV_PIX_FMT_YUV420P16LE, AV_PIX_FMT_YUVA420P16LE,
+    AV_PIX_FMT_YUV420P16BE, AV_PIX_FMT_YUVA420P16BE,
+    AV_PIX_FMT_YUV422P16LE, AV_PIX_FMT_YUVA422P16LE,
+    AV_PIX_FMT_YUV422P16BE, AV_PIX_FMT_YUVA422P16BE,
     AV_PIX_FMT_YUV444P16LE, AV_PIX_FMT_YUVA444P16LE,
     AV_PIX_FMT_YUV444P16BE, AV_PIX_FMT_YUVA444P16BE,
     AV_PIX_FMT_NONE
@@ -361,9 +393,15 @@ static int config_output(AVFilterLink *outlink)
     case ANAGLYPH_YB_GRAY:
     case ANAGLYPH_YB_HALF:
     case ANAGLYPH_YB_COLOR:
-    case ANAGLYPH_YB_DUBOIS:
-        memcpy(s->ana_matrix, ana_coeff[s->out.format], sizeof(s->ana_matrix));
+    case ANAGLYPH_YB_DUBOIS: {
+        uint8_t rgba_map[4];
+
+        ff_fill_rgba_map(rgba_map, outlink->format);
+        s->ana_matrix[rgba_map[0]] = &ana_coeff[s->out.format][0][0];
+        s->ana_matrix[rgba_map[1]] = &ana_coeff[s->out.format][1][0];
+        s->ana_matrix[rgba_map[2]] = &ana_coeff[s->out.format][2][0];
         break;
+    }
     case SIDE_BY_SIDE_2_LR:
         aspect.den      *= 2;
     case SIDE_BY_SIDE_LR:
@@ -426,11 +464,15 @@ static int config_output(AVFilterLink *outlink)
     s->nb_planes = av_pix_fmt_count_planes(outlink->format);
     av_image_fill_max_pixsteps(s->pixstep, NULL, desc);
     s->ts_unit = av_q2d(av_inv_q(av_mul_q(outlink->frame_rate, outlink->time_base)));
+    s->pheight[1] = s->pheight[2] = FF_CEIL_RSHIFT(s->height, desc->log2_chroma_h);
+    s->pheight[0] = s->pheight[3] = s->height;
+    s->hsub = desc->log2_chroma_w;
+    s->vsub = desc->log2_chroma_h;
 
     return 0;
 }
 
-static inline uint8_t ana_convert(const int *coeff, uint8_t *left, uint8_t *right)
+static inline uint8_t ana_convert(const int *coeff, const uint8_t *left, const uint8_t *right)
 {
     int sum;
 
@@ -488,10 +530,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
     }
 
     for (i = 0; i < 4; i++) {
-        in_off_left[i]   = (s->in.row_left   + s->in.off_lstep)  * ileft->linesize[i]  + s->in.off_left   * s->pixstep[i];
-        in_off_right[i]  = (s->in.row_right  + s->in.off_rstep)  * iright->linesize[i] + s->in.off_right  * s->pixstep[i];
-        out_off_left[i]  = (s->out.row_left  + s->out.off_lstep) * oleft->linesize[i]  + s->out.off_left  * s->pixstep[i];
-        out_off_right[i] = (s->out.row_right + s->out.off_rstep) * oright->linesize[i] + s->out.off_right * s->pixstep[i];
+        int hsub = i == 1 || i == 2 ? s->hsub : 0;
+        int vsub = i == 1 || i == 2 ? s->vsub : 0;
+        in_off_left[i]   = (FF_CEIL_RSHIFT(s->in.row_left,   vsub) + s->in.off_lstep)  * ileft->linesize[i]  + FF_CEIL_RSHIFT(s->in.off_left   * s->pixstep[i], hsub);
+        in_off_right[i]  = (FF_CEIL_RSHIFT(s->in.row_right,  vsub) + s->in.off_rstep)  * iright->linesize[i] + FF_CEIL_RSHIFT(s->in.off_right  * s->pixstep[i], hsub);
+        out_off_left[i]  = (FF_CEIL_RSHIFT(s->out.row_left,  vsub) + s->out.off_lstep) * oleft->linesize[i]  + FF_CEIL_RSHIFT(s->out.off_left  * s->pixstep[i], hsub);
+        out_off_right[i] = (FF_CEIL_RSHIFT(s->out.row_right, vsub) + s->out.off_rstep) * oright->linesize[i] + FF_CEIL_RSHIFT(s->out.off_right * s->pixstep[i], hsub);
     }
 
     switch (s->out.format) {
@@ -512,12 +556,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
                                 oleft->linesize[i] * s->row_step,
                                 ileft->data[i] + in_off_left[i],
                                 ileft->linesize[i] * s->row_step,
-                                s->linesize[i], s->height);
+                                s->linesize[i], s->pheight[i]);
             av_image_copy_plane(oright->data[i] + out_off_right[i],
                                 oright->linesize[i] * s->row_step,
                                 iright->data[i] + in_off_right[i],
                                 iright->linesize[i] * s->row_step,
-                                s->linesize[i], s->height);
+                                s->linesize[i], s->pheight[i]);
         }
         break;
     case MONO_L:
@@ -527,7 +571,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
             av_image_copy_plane(out->data[i], out->linesize[i],
                                 iright->data[i] + in_off_left[i],
                                 iright->linesize[i],
-                                s->linesize[i], s->height);
+                                s->linesize[i], s->pheight[i]);
         }
         break;
     case ANAGLYPH_RB_GRAY:
@@ -544,15 +588,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
     case ANAGLYPH_YB_HALF:
     case ANAGLYPH_YB_COLOR:
     case ANAGLYPH_YB_DUBOIS: {
-        int i, x, y, il, ir, o;
-        uint8_t *lsrc = ileft->data[0];
-        uint8_t *rsrc = iright->data[0];
+        int x, y, il, ir, o;
+        const uint8_t *lsrc = ileft->data[0];
+        const uint8_t *rsrc = iright->data[0];
         uint8_t *dst = out->data[0];
         int out_width = s->out.width;
-        int *ana_matrix[3];
-
-        for (i = 0; i < 3; i++)
-            ana_matrix[i] = s->ana_matrix[i];
+        const int **ana_matrix = s->ana_matrix;
 
         for (y = 0; y < s->out.height; y++) {
             o   = out->linesize[0] * y;
@@ -595,9 +636,9 @@ static av_cold void uninit(AVFilterContext *ctx)
 
 static const AVFilterPad stereo3d_inputs[] = {
     {
-        .name             = "default",
-        .type             = AVMEDIA_TYPE_VIDEO,
-        .filter_frame     = filter_frame,
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_VIDEO,
+        .filter_frame = filter_frame,
     },
     { NULL }
 };
@@ -611,7 +652,7 @@ static const AVFilterPad stereo3d_outputs[] = {
     { NULL }
 };
 
-AVFilter avfilter_vf_stereo3d = {
+AVFilter ff_vf_stereo3d = {
     .name          = "stereo3d",
     .description   = NULL_IF_CONFIG_SMALL("Convert video stereoscopic 3D view."),
     .priv_size     = sizeof(Stereo3DContext),