History

avfilter/vf_waveform: implement tint options

Paul B Mahol committed 6 years ago

Commit 6399eed1 parent b3216f13 files · +181 −81Browse files

Unified · Split

3 files
  1. doc/filters.texi +6 −0
  2. libavfilter/vf_waveform.c +125 −31
  3. tests/ref/fate/filter-waveform_uv +50 −50
doc/filters.texi+6−0
@@ -19689,6 +19689,12 @@ Default is digital. · 19688 unmodified lines
1968919689
1969019690 @item bgopacity, b
1969119691 Set background opacity.
19692+
19693+@item tint0, t0
19694+@item tint1, t1
19695+Set tint for output.
19696+Only used with lowpass filter and when display is not overlay and input
19697+pixel formats are not RGB.
1969219698 @end table
1969319699
1969419700 @section weave, doubleweave
libavfilter/vf_waveform.c+125−31
@@ -112,6 +112,8 @@ typedef struct WaveformContext { · 111 unmodified lines
112112 GraticuleLines *glines;
113113 int nb_glines;
114114 int rgb;
115+ float ftint[2];
116+ int tint[2];
115117
116118 int (*waveform_slice)(AVFilterContext *ctx, void *arg,
117119 int jobnr, int nb_jobs);
@@ -179,6 +181,10 @@ static const AVOption waveform_options[] = { · 61 unmodified lines
179181 { "ire", NULL, 0, AV_OPT_TYPE_CONST, {.i64=IRE}, 0, 0, FLAGS, "scale" },
180182 { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
181183 { "b", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
184+ { "tint0", "set 1st tint", OFFSET(ftint[0]), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, FLAGS},
185+ { "t0", "set 1st tint", OFFSET(ftint[0]), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, FLAGS},
186+ { "tint1", "set 2nd tint", OFFSET(ftint[1]), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, FLAGS},
187+ { "t1", "set 2nd tint", OFFSET(ftint[1]), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, FLAGS},
182188 { NULL }
183189 };
184190
@@ -678,10 +684,11 @@ static av_always_inline void lowpass16(WaveformContext *s, · 493 unmodified lines
678684 int jobnr, int nb_jobs)
679685 {
680686 const int plane = s->desc->comp[component].plane;
687+ const int dplane = (s->rgb || s->display == OVERLAY) ? plane : 0;
681688 const int shift_w = s->shift_w[component];
682689 const int shift_h = s->shift_h[component];
683690 const int src_linesize = in->linesize[plane] / 2;
684− const int dst_linesize = out->linesize[plane] / 2;
691+ const int dst_linesize = out->linesize[dplane] / 2;
685692 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
686693 const int limit = s->max - 1;
687694 const int max = limit - intensity;
@@ -693,7 +700,7 @@ static av_always_inline void lowpass16(WaveformContext *s, · 5 unmodified lines
693700 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
694701 const int step = column ? 1 << shift_w : 1 << shift_h;
695702 const uint16_t *src_data = (const uint16_t *)in->data[plane] + sliceh_start * src_linesize;
696− uint16_t *dst_data = (uint16_t *)out->data[plane] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
703+ uint16_t *dst_data = (uint16_t *)out->data[dplane] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
697704 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
698705 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
699706 const uint16_t *p;
@@ -730,6 +737,56 @@ static av_always_inline void lowpass16(WaveformContext *s, · 30 unmodified lines
730737 src_data += src_linesize;
731738 dst_data += dst_linesize * step;
732739 }
740+
741+ if (s->display != OVERLAY && column && !s->rgb) {
742+ const int mult = s->max / 256;
743+ const int bg = s->bg_color[0] * mult;
744+ const int t0 = s->tint[0];
745+ const int t1 = s->tint[1];
746+ uint16_t *dst0, *dst1;
747+ const uint16_t *src;
748+ int x;
749+
750+ src = (const uint16_t *)(out->data[0]) + offset_y * dst_linesize + offset_x;
751+ dst0 = (uint16_t *)(out->data[1]) + offset_y * dst_linesize + offset_x;
752+ dst1 = (uint16_t *)(out->data[2]) + offset_y * dst_linesize + offset_x;
753+ for (y = 0; y < s->max; y++) {
754+ for (x = slicew_start * step; x < slicew_end * step; x++) {
755+ if (src[x] != bg) {
756+ dst0[x] = t0;
757+ dst1[x] = t1;
758+ }
759+ }
760+
761+ src += dst_linesize;
762+ dst0 += dst_linesize;
763+ dst1 += dst_linesize;
764+ }
765+ } else if (s->display != OVERLAY && !s->rgb) {
766+ const int mult = s->max / 256;
767+ const int bg = s->bg_color[0] * mult;
768+ const int t0 = s->tint[0];
769+ const int t1 = s->tint[1];
770+ uint16_t *dst0, *dst1;
771+ const uint16_t *src;
772+ int x;
773+
774+ src = (const uint16_t *)out->data[0] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
775+ dst0 = (uint16_t *)(out->data[1]) + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
776+ dst1 = (uint16_t *)(out->data[2]) + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
777+ for (y = sliceh_start * step; y < sliceh_end * step; y++) {
778+ for (x = 0; x < s->max; x++) {
779+ if (src[x] != bg) {
780+ dst0[x] = t0;
781+ dst1[x] = t1;
782+ }
783+ }
784+
785+ src += dst_linesize;
786+ dst0 += dst_linesize;
787+ dst1 += dst_linesize;
788+ }
789+ }
733790 }
734791
735792 #define LOWPASS16_FUNC(name, column, mirror) \
@@ -765,10 +822,11 @@ static av_always_inline void lowpass(WaveformContext *s, · 29 unmodified lines
765822 int jobnr, int nb_jobs)
766823 {
767824 const int plane = s->desc->comp[component].plane;
825+ const int dplane = (s->rgb || s->display == OVERLAY) ? plane : 0;
768826 const int shift_w = s->shift_w[component];
769827 const int shift_h = s->shift_h[component];
770828 const int src_linesize = in->linesize[plane];
771− const int dst_linesize = out->linesize[plane];
829+ const int dst_linesize = out->linesize[dplane];
772830 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
773831 const int max = 255 - intensity;
774832 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);
@@ -779,7 +837,7 @@ static av_always_inline void lowpass(WaveformContext *s, · 4 unmodified lines
779837 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
780838 const int step = column ? 1 << shift_w : 1 << shift_h;
781839 const uint8_t *src_data = in->data[plane] + sliceh_start * src_linesize;
782− uint8_t *dst_data = out->data[plane] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
840+ uint8_t *dst_data = out->data[dplane] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
783841 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
784842 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
785843 const uint8_t *p;
@@ -794,48 +852,76 @@ static av_always_inline void lowpass(WaveformContext *s, · 8 unmodified lines
794852
795853 for (p = src_data + slicew_start; p < src_data_end; p++) {
796854 uint8_t *target;
855+ int i = 0;
856+
797857 if (column) {
798− target = dst + dst_signed_linesize * *p;
799− dst += step;
800− update(target, max, intensity);
858+ do {
859+ target = dst++ + dst_signed_linesize * *p;
860+ update(target, max, intensity);
861+ } while (++i < step);
801862 } else {
802863 uint8_t *row = dst_data;
803− if (mirror)
804− target = row - *p - 1;
805− else
806− target = row + *p;
807− update(target, max, intensity);
808− row += dst_linesize;
864+ do {
865+ if (mirror)
866+ target = row - *p - 1;
867+ else
868+ target = row + *p;
869+ update(target, max, intensity);
870+ row += dst_linesize;
871+ } while (++i < step);
809872 }
810873 }
811874 src_data += src_linesize;
812875 dst_data += dst_linesize * step;
813876 }
814877
815− if (column && step > 1) {
878+ if (s->display != OVERLAY && column && !s->rgb) {
879+ const int bg = s->bg_color[0];
816880 const int dst_h = 256;
817− uint8_t *dst;
818− int x, z;
819−
820− dst = out->data[plane] + offset_y * dst_linesize + offset_x;
881+ const int t0 = s->tint[0];
882+ const int t1 = s->tint[1];
883+ uint8_t *dst0, *dst1;
884+ const uint8_t *src;
885+ int x;
886+
887+ src = out->data[0] + offset_y * dst_linesize + offset_x;
888+ dst0 = out->data[1] + offset_y * dst_linesize + offset_x;
889+ dst1 = out->data[2] + offset_y * dst_linesize + offset_x;
821890 for (y = 0; y < dst_h; y++) {
822− for (x = slicew_start * step; x < slicew_end * step; x+=step) {
823− for (z = 1; z < step; z++) {
824− dst[x + z] = dst[x];
891+ for (x = slicew_start * step; x < slicew_end * step; x++) {
892+ if (src[x] != bg) {
893+ dst0[x] = t0;
894+ dst1[x] = t1;
825895 }
826896 }
827− dst += dst_linesize;
897+
898+ src += dst_linesize;
899+ dst0 += dst_linesize;
900+ dst1 += dst_linesize;
828901 }
829− } else if (step > 1) {
902+ } else if (s->display != OVERLAY && !s->rgb) {
903+ const int bg = s->bg_color[0];
830904 const int dst_w = 256;
831− uint8_t *dst;
832− int z;
905+ const int t0 = s->tint[0];
906+ const int t1 = s->tint[1];
907+ uint8_t *dst0, *dst1;
908+ const uint8_t *src;
909+ int x;
910+
911+ src = out->data[0] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
912+ dst0 = out->data[1] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
913+ dst1 = out->data[2] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
914+ for (y = sliceh_start * step; y < sliceh_end * step; y++) {
915+ for (x = 0; x < dst_w; x++) {
916+ if (src[x] != bg) {
917+ dst0[x] = t0;
918+ dst1[x] = t1;
919+ }
920+ }
833921
834− dst = out->data[plane] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;
835− for (y = sliceh_start * step; y < sliceh_end * step; y+=step) {
836− for (z = 1; z < step; z++)
837− memcpy(dst + dst_linesize * z, dst, dst_w);
838− dst += dst_linesize * step;
922+ src += dst_linesize;
923+ dst0 += dst_linesize;
924+ dst1 += dst_linesize;
839925 }
840926 }
841927 }
@@ -3198,6 +3284,9 @@ static int config_input(AVFilterLink *inlink) · 2356 unmodified lines
31983284
31993285 s->size = s->size << (s->bits - 8);
32003286
3287+ s->tint[0] = .5f * (s->ftint[0] + 1.f) * (s->size - 1);
3288+ s->tint[1] = .5f * (s->ftint[1] + 1.f) * (s->size - 1);
3289+
32013290 switch (inlink->format) {
32023291 case AV_PIX_FMT_GBRAP:
32033292 case AV_PIX_FMT_GBRP:
@@ -3334,10 +3423,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 130 unmodified lines
33343423 td.offset_x = offset_x;
33353424 ctx->internal->execute(ctx, s->waveform_slice, &td, NULL, ff_filter_get_nb_threads(ctx));
33363425 switch (s->filter) {
3426+ case LOWPASS:
3427+ if (s->bits <= 8)
3428+ envelope(s, out, plane, s->rgb || s->display == OVERLAY ? plane : 0, s->mode ? offset_x : offset_y);
3429+ else
3430+ envelope16(s, out, plane, s->rgb || s->display == OVERLAY ? plane : 0, s->mode ? offset_x : offset_y);
3431+ break;
33373432 case ACOLOR:
33383433 case CHROMA:
33393434 case COLOR:
3340− case LOWPASS:
33413435 if (s->bits <= 8)
33423436 envelope(s, out, plane, plane, s->mode ? offset_x : offset_y);
33433437 else
tests/ref/fate/filter-waveform_uv+50−50
@@ -3,53 +3,53 @@ · 2 unmodified lines
33 #codec_id 0: rawvideo
44 #dimensions 0: 352x512
55 #sar 0: 1/1
6−0, 0, 0, 1, 540672, 0x8a2521d6
7−0, 1, 1, 1, 540672, 0xb9a321d6
8−0, 2, 2, 1, 540672, 0x325421d6
9−0, 3, 3, 1, 540672, 0xafee21d2
10−0, 4, 4, 1, 540672, 0x172121d6
11−0, 5, 5, 1, 540672, 0x24d121d6
12−0, 6, 6, 1, 540672, 0x7fec21d6
13−0, 7, 7, 1, 540672, 0xa8a021d6
14−0, 8, 8, 1, 540672, 0x29fd21d6
15−0, 9, 9, 1, 540672, 0x6dfe21d6
16−0, 10, 10, 1, 540672, 0xe39821d6
17−0, 11, 11, 1, 540672, 0x83f521d6
18−0, 12, 12, 1, 540672, 0x57aa21d6
19−0, 13, 13, 1, 540672, 0x67b221d6
20−0, 14, 14, 1, 540672, 0x535821d6
21−0, 15, 15, 1, 540672, 0xb8ac21d6
22−0, 16, 16, 1, 540672, 0x27f621d6
23−0, 17, 17, 1, 540672, 0x775221d6
24−0, 18, 18, 1, 540672, 0x8e6621d6
25−0, 19, 19, 1, 540672, 0x74c921d6
26−0, 20, 20, 1, 540672, 0x04cd21d6
27−0, 21, 21, 1, 540672, 0xccd421d6
28−0, 22, 22, 1, 540672, 0x317221d6
29−0, 23, 23, 1, 540672, 0xd79321d6
30−0, 24, 24, 1, 540672, 0xa2ac21d6
31−0, 25, 25, 1, 540672, 0x7f0a21d6
32−0, 26, 26, 1, 540672, 0x483521d6
33−0, 27, 27, 1, 540672, 0xb65721d6
34−0, 28, 28, 1, 540672, 0xb77021d6
35−0, 29, 29, 1, 540672, 0x9fd521d6
36−0, 30, 30, 1, 540672, 0xb72121d6
37−0, 31, 31, 1, 540672, 0x540221d6
38−0, 32, 32, 1, 540672, 0xa34121d6
39−0, 33, 33, 1, 540672, 0xe01421d6
40−0, 34, 34, 1, 540672, 0x6fc721d6
41−0, 35, 35, 1, 540672, 0x7fa621d6
42−0, 36, 36, 1, 540672, 0xc48c21d6
43−0, 37, 37, 1, 540672, 0x40f021d6
44−0, 38, 38, 1, 540672, 0xdf3f21d6
45−0, 39, 39, 1, 540672, 0xb04321d6
46−0, 40, 40, 1, 540672, 0x222821d6
47−0, 41, 41, 1, 540672, 0x2a5521d6
48−0, 42, 42, 1, 540672, 0x6a4621be
49−0, 43, 43, 1, 540672, 0xed7f21d6
50−0, 44, 44, 1, 540672, 0xb16521d6
51−0, 45, 45, 1, 540672, 0x9f5621d6
52−0, 46, 46, 1, 540672, 0x204321d6
53−0, 47, 47, 1, 540672, 0xc26e21d6
54−0, 48, 48, 1, 540672, 0x3e8321d6
55−0, 49, 49, 1, 540672, 0xaaee21d6
6+0, 0, 0, 1, 540672, 0xe33821d6
7+0, 1, 1, 1, 540672, 0x12c521d6
8+0, 2, 2, 1, 540672, 0x8b6721d6
9+0, 3, 3, 1, 540672, 0x6fd321d6
10+0, 4, 4, 1, 540672, 0x703421d6
11+0, 5, 5, 1, 540672, 0x7de421d6
12+0, 6, 6, 1, 540672, 0xd8ff21d6
13+0, 7, 7, 1, 540672, 0x01c221d6
14+0, 8, 8, 1, 540672, 0x831021d6
15+0, 9, 9, 1, 540672, 0xc71121d6
16+0, 10, 10, 1, 540672, 0x3cba21d6
17+0, 11, 11, 1, 540672, 0xdd0821d6
18+0, 12, 12, 1, 540672, 0xb0bd21d6
19+0, 13, 13, 1, 540672, 0xc0c521d6
20+0, 14, 14, 1, 540672, 0xac6b21d6
21+0, 15, 15, 1, 540672, 0x11ce21d6
22+0, 16, 16, 1, 540672, 0x810921d6
23+0, 17, 17, 1, 540672, 0xd06521d6
24+0, 18, 18, 1, 540672, 0xe77921d6
25+0, 19, 19, 1, 540672, 0xcddc21d6
26+0, 20, 20, 1, 540672, 0x5de021d6
27+0, 21, 21, 1, 540672, 0x25f621d6
28+0, 22, 22, 1, 540672, 0x8a8521d6
29+0, 23, 23, 1, 540672, 0x30b521d6
30+0, 24, 24, 1, 540672, 0xfbbf21d6
31+0, 25, 25, 1, 540672, 0xd81d21d6
32+0, 26, 26, 1, 540672, 0xa14821d6
33+0, 27, 27, 1, 540672, 0x0f7921d6
34+0, 28, 28, 1, 540672, 0x109221d6
35+0, 29, 29, 1, 540672, 0xf8e821d6
36+0, 30, 30, 1, 540672, 0x104321d6
37+0, 31, 31, 1, 540672, 0xad1521d6
38+0, 32, 32, 1, 540672, 0xfc5421d6
39+0, 33, 33, 1, 540672, 0x393621d6
40+0, 34, 34, 1, 540672, 0xc8da21d6
41+0, 35, 35, 1, 540672, 0xd8b921d6
42+0, 36, 36, 1, 540672, 0x1dae21d6
43+0, 37, 37, 1, 540672, 0x9a0321d6
44+0, 38, 38, 1, 540672, 0x386121d6
45+0, 39, 39, 1, 540672, 0x096521d6
46+0, 40, 40, 1, 540672, 0x7b3b21d6
47+0, 41, 41, 1, 540672, 0x836821d6
48+0, 42, 42, 1, 540672, 0x97bd21d6
49+0, 43, 43, 1, 540672, 0x46a121d6
50+0, 44, 44, 1, 540672, 0x0a8721d6
51+0, 45, 45, 1, 540672, 0xf86921d6
52+0, 46, 46, 1, 540672, 0x795621d6
53+0, 47, 47, 1, 540672, 0x1b9021d6
54+0, 48, 48, 1, 540672, 0x979621d6
55+0, 49, 49, 1, 540672, 0x041021d6

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