Browse code

avfilter/vf_remap: >8 bit support

Paul B Mahol authored on 2016/08/10 17:02:05
Showing 1 changed files
... ...
@@ -75,6 +75,14 @@ static int query_formats(AVFilterContext *ctx)
75 75
         AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24,
76 76
         AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR, AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA,
77 77
         AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
78
+        AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV444P12,
79
+        AV_PIX_FMT_YUV444P14, AV_PIX_FMT_YUV444P16,
80
+        AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P16,
81
+        AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12,
82
+        AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
83
+        AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP16,
84
+        AV_PIX_FMT_RGB48, AV_PIX_FMT_BGR48,
85
+        AV_PIX_FMT_RGBA64, AV_PIX_FMT_BGRA64,
78 86
         AV_PIX_FMT_NONE
79 87
     };
80 88
     static const enum AVPixelFormat map_fmts[] = {
... ...
@@ -141,6 +149,37 @@ static void remap_planar(RemapContext *s, const AVFrame *in,
141 141
     }
142 142
 }
143 143
 
144
+static void remap_planar16(RemapContext *s, const AVFrame *in,
145
+                           const AVFrame *xin, const AVFrame *yin,
146
+                           AVFrame *out)
147
+{
148
+    const int xlinesize = xin->linesize[0] / 2;
149
+    const int ylinesize = yin->linesize[0] / 2;
150
+    int x , y, plane;
151
+
152
+    for (plane = 0; plane < s->nb_planes ; plane++) {
153
+        uint16_t *dst        = (uint16_t *)out->data[plane];
154
+        const int dlinesize  = out->linesize[plane] / 2;
155
+        const uint16_t *src  = (const uint16_t *)in->data[plane];
156
+        const int slinesize  = in->linesize[plane] / 2;
157
+        const uint16_t *xmap = (const uint16_t *)xin->data[0];
158
+        const uint16_t *ymap = (const uint16_t *)yin->data[0];
159
+
160
+        for (y = 0; y < out->height; y++) {
161
+            for (x = 0; x < out->width; x++) {
162
+                if (ymap[x] < in->height && xmap[x] < in->width) {
163
+                    dst[x] = src[ymap[x] * slinesize + xmap[x]];
164
+                } else {
165
+                    dst[x] = 0;
166
+                }
167
+            }
168
+            dst  += dlinesize;
169
+            xmap += xlinesize;
170
+            ymap += ylinesize;
171
+        }
172
+    }
173
+}
174
+
144 175
 /**
145 176
  * remap_packed algorithm expects pixels with both padded bits (step) and
146 177
  * number of components correctly set.
... ...
@@ -178,6 +217,37 @@ static void remap_packed(RemapContext *s, const AVFrame *in,
178 178
     }
179 179
 }
180 180
 
181
+static void remap_packed16(RemapContext *s, const AVFrame *in,
182
+                           const AVFrame *xin, const AVFrame *yin,
183
+                           AVFrame *out)
184
+{
185
+    uint16_t *dst = (uint16_t *)out->data[0];
186
+    const uint16_t *src  = (const uint16_t *)in->data[0];
187
+    const int dlinesize = out->linesize[0] / 2;
188
+    const int slinesize = in->linesize[0] / 2;
189
+    const int xlinesize = xin->linesize[0] / 2;
190
+    const int ylinesize = yin->linesize[0] / 2;
191
+    const uint16_t *xmap = (const uint16_t *)xin->data[0];
192
+    const uint16_t *ymap = (const uint16_t *)yin->data[0];
193
+    const int step = s->step / 2;
194
+    int c, x, y;
195
+
196
+    for (y = 0; y < out->height; y++) {
197
+        for (x = 0; x < out->width; x++) {
198
+            for (c = 0; c < s->nb_components; c++) {
199
+                if (ymap[x] < in->height && xmap[x] < in->width) {
200
+                    dst[x * step + c] = src[ymap[x] * slinesize + xmap[x] * step + c];
201
+                } else {
202
+                    dst[x * step + c] = 0;
203
+                }
204
+            }
205
+        }
206
+        dst  += dlinesize;
207
+        xmap += xlinesize;
208
+        ymap += ylinesize;
209
+    }
210
+}
211
+
181 212
 static int config_input(AVFilterLink *inlink)
182 213
 {
183 214
     AVFilterContext *ctx = inlink->dst;
... ...
@@ -187,10 +257,18 @@ static int config_input(AVFilterLink *inlink)
187 187
     s->nb_planes = av_pix_fmt_count_planes(inlink->format);
188 188
     s->nb_components = desc->nb_components;
189 189
 
190
-    if (s->nb_planes > 1 || s->nb_components == 1) {
191
-        s->remap = remap_planar;
190
+    if (desc->comp[0].depth == 8) {
191
+        if (s->nb_planes > 1 || s->nb_components == 1) {
192
+            s->remap = remap_planar;
193
+        } else {
194
+            s->remap = remap_packed;
195
+        }
192 196
     } else {
193
-        s->remap = remap_packed;
197
+        if (s->nb_planes > 1 || s->nb_components == 1) {
198
+            s->remap = remap_planar16;
199
+        } else {
200
+            s->remap = remap_packed16;
201
+        }
194 202
     }
195 203
 
196 204
     s->step = av_get_padded_bits_per_pixel(desc) >> 3;