History

avfilter/vf_lut3d: add planar rgb support

Paul B Mahol committed 8 years ago

Commit 901dc111 parent 9b563f61 file · +112 −4Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_lut3d.c+112−4
@@ -198,6 +198,83 @@ static inline struct rgbvec interp_tetrahedral(const LUT3DContext *lut3d, · 197 unmodified lines
198 return c;198 return c;
199}199}
200 200
201#define DEFINE_INTERP_FUNC_PLANAR(name, nbits, depth) \
202static int interp_##nbits##_##name##_p##depth(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
203{ \
204 int x, y; \
205 const LUT3DContext *lut3d = ctx->priv; \
206 const ThreadData *td = arg; \
207 const AVFrame *in = td->in; \
208 const AVFrame *out = td->out; \
209 const int direct = out == in; \
210 const int slice_start = (in->height * jobnr ) / nb_jobs; \
211 const int slice_end = (in->height * (jobnr+1)) / nb_jobs; \
212 uint8_t *grow = out->data[0] + slice_start * out->linesize[0]; \
213 uint8_t *brow = out->data[1] + slice_start * out->linesize[1]; \
214 uint8_t *rrow = out->data[2] + slice_start * out->linesize[2]; \
215 uint8_t *arow = out->data[2] + slice_start * out->linesize[2]; \
216 const uint8_t *srcgrow = in->data[0] + slice_start * in->linesize[0]; \
217 const uint8_t *srcbrow = in->data[1] + slice_start * in->linesize[1]; \
218 const uint8_t *srcrrow = in->data[2] + slice_start * in->linesize[2]; \
219 const uint8_t *srcarow = in->data[3] + slice_start * in->linesize[3]; \
220 const float scale = (1. / ((1<<depth) - 1)) * (lut3d->lutsize - 1); \
221 \
222 for (y = slice_start; y < slice_end; y++) { \
223 uint##nbits##_t *dstg = (uint##nbits##_t *)grow; \
224 uint##nbits##_t *dstb = (uint##nbits##_t *)brow; \
225 uint##nbits##_t *dstr = (uint##nbits##_t *)rrow; \
226 uint##nbits##_t *dsta = (uint##nbits##_t *)arow; \
227 const uint##nbits##_t *srcg = (const uint##nbits##_t *)srcgrow; \
228 const uint##nbits##_t *srcb = (const uint##nbits##_t *)srcbrow; \
229 const uint##nbits##_t *srcr = (const uint##nbits##_t *)srcrrow; \
230 const uint##nbits##_t *srca = (const uint##nbits##_t *)srcarow; \
231 for (x = 0; x < in->width; x++) { \
232 const struct rgbvec scaled_rgb = {srcr[x] * scale, \
233 srcg[x] * scale, \
234 srcb[x] * scale}; \
235 struct rgbvec vec = interp_##name(lut3d, &scaled_rgb); \
236 dstr[x] = av_clip_uintp2(vec.r * (float)((1<<depth) - 1), depth); \
237 dstg[x] = av_clip_uintp2(vec.g * (float)((1<<depth) - 1), depth); \
238 dstb[x] = av_clip_uintp2(vec.b * (float)((1<<depth) - 1), depth); \
239 if (!direct && in->linesize[3]) \
240 dsta[x] = srca[x]; \
241 } \
242 grow += out->linesize[0]; \
243 brow += out->linesize[1]; \
244 rrow += out->linesize[2]; \
245 arow += out->linesize[3]; \
246 srcgrow += in->linesize[0]; \
247 srcbrow += in->linesize[1]; \
248 srcrrow += in->linesize[2]; \
249 srcarow += in->linesize[3]; \
250 } \
251 return 0; \
252}
253
254DEFINE_INTERP_FUNC_PLANAR(nearest, 8, 8)
255DEFINE_INTERP_FUNC_PLANAR(trilinear, 8, 8)
256DEFINE_INTERP_FUNC_PLANAR(tetrahedral, 8, 8)
257
258DEFINE_INTERP_FUNC_PLANAR(nearest, 16, 9)
259DEFINE_INTERP_FUNC_PLANAR(trilinear, 16, 9)
260DEFINE_INTERP_FUNC_PLANAR(tetrahedral, 16, 9)
261
262DEFINE_INTERP_FUNC_PLANAR(nearest, 16, 10)
263DEFINE_INTERP_FUNC_PLANAR(trilinear, 16, 10)
264DEFINE_INTERP_FUNC_PLANAR(tetrahedral, 16, 10)
265
266DEFINE_INTERP_FUNC_PLANAR(nearest, 16, 12)
267DEFINE_INTERP_FUNC_PLANAR(trilinear, 16, 12)
268DEFINE_INTERP_FUNC_PLANAR(tetrahedral, 16, 12)
269
270DEFINE_INTERP_FUNC_PLANAR(nearest, 16, 14)
271DEFINE_INTERP_FUNC_PLANAR(trilinear, 16, 14)
272DEFINE_INTERP_FUNC_PLANAR(tetrahedral, 16, 14)
273
274DEFINE_INTERP_FUNC_PLANAR(nearest, 16, 16)
275DEFINE_INTERP_FUNC_PLANAR(trilinear, 16, 16)
276DEFINE_INTERP_FUNC_PLANAR(tetrahedral, 16, 16)
277
201#define DEFINE_INTERP_FUNC(name, nbits) \278#define DEFINE_INTERP_FUNC(name, nbits) \
202static int interp_##nbits##_##name(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \279static int interp_##nbits##_##name(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
203{ \280{ \
@@ -470,6 +547,12 @@ static int query_formats(AVFilterContext *ctx) · 266 unmodified lines
470 AV_PIX_FMT_RGB0, AV_PIX_FMT_BGR0,547 AV_PIX_FMT_RGB0, AV_PIX_FMT_BGR0,
471 AV_PIX_FMT_RGB48, AV_PIX_FMT_BGR48,548 AV_PIX_FMT_RGB48, AV_PIX_FMT_BGR48,
472 AV_PIX_FMT_RGBA64, AV_PIX_FMT_BGRA64,549 AV_PIX_FMT_RGBA64, AV_PIX_FMT_BGRA64,
550 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
551 AV_PIX_FMT_GBRP9,
552 AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10,
553 AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12,
554 AV_PIX_FMT_GBRP14,
555 AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16,
473 AV_PIX_FMT_NONE556 AV_PIX_FMT_NONE
474 };557 };
475 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);558 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
@@ -480,24 +563,49 @@ static int query_formats(AVFilterContext *ctx) · 4 unmodified lines
480 563
481static int config_input(AVFilterLink *inlink)564static int config_input(AVFilterLink *inlink)
482{565{
483 int is16bit = 0;566 int depth, is16bit = 0, planar = 0;
484 LUT3DContext *lut3d = inlink->dst->priv;567 LUT3DContext *lut3d = inlink->dst->priv;
485 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);568 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
486 569
570 depth = desc->comp[0].depth;
571
487 switch (inlink->format) {572 switch (inlink->format) {
488 case AV_PIX_FMT_RGB48:573 case AV_PIX_FMT_RGB48:
489 case AV_PIX_FMT_BGR48:574 case AV_PIX_FMT_BGR48:
490 case AV_PIX_FMT_RGBA64:575 case AV_PIX_FMT_RGBA64:
491 case AV_PIX_FMT_BGRA64:576 case AV_PIX_FMT_BGRA64:
492 is16bit = 1;577 is16bit = 1;
578 break;
579 case AV_PIX_FMT_GBRP9:
580 case AV_PIX_FMT_GBRP10:
581 case AV_PIX_FMT_GBRP12:
582 case AV_PIX_FMT_GBRP14:
583 case AV_PIX_FMT_GBRP16:
584 case AV_PIX_FMT_GBRAP10:
585 case AV_PIX_FMT_GBRAP12:
586 case AV_PIX_FMT_GBRAP16:
587 is16bit = 1;
588 case AV_PIX_FMT_GBRP:
589 case AV_PIX_FMT_GBRAP:
590 planar = 1;
591 break;
493 }592 }
494 593
495 ff_fill_rgba_map(lut3d->rgba_map, inlink->format);594 ff_fill_rgba_map(lut3d->rgba_map, inlink->format);
496 lut3d->step = av_get_padded_bits_per_pixel(desc) >> (3 + is16bit);595 lut3d->step = av_get_padded_bits_per_pixel(desc) >> (3 + is16bit);
497 596
498#define SET_FUNC(name) do { \597#define SET_FUNC(name) do { \
499 if (is16bit) lut3d->interp = interp_16_##name; \598 if (planar) { \
500 else lut3d->interp = interp_8_##name; \599 switch (depth) { \
600 case 8: lut3d->interp = interp_8_##name##_p8; break; \
601 case 9: lut3d->interp = interp_16_##name##_p9; break; \
602 case 10: lut3d->interp = interp_16_##name##_p10; break; \
603 case 12: lut3d->interp = interp_16_##name##_p12; break; \
604 case 14: lut3d->interp = interp_16_##name##_p14; break; \
605 case 16: lut3d->interp = interp_16_##name##_p16; break; \
606 } \
607 } else if (is16bit) { lut3d->interp = interp_16_##name; \
608 } else { lut3d->interp = interp_8_##name; } \
501} while (0)609} while (0)
502 610
503 switch (lut3d->interpolation) {611 switch (lut3d->interpolation) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t