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
19689 19689
19690@item bgopacity, b19690@item bgopacity, b
19691Set background opacity.19691Set background opacity.
19692
19693@item tint0, t0
19694@item tint1, t1
19695Set tint for output.
19696Only used with lowpass filter and when display is not overlay and input
19697pixel formats are not RGB.
19692@end table19698@end table
19693 19699
19694@section weave, doubleweave19700@section weave, doubleweave
libavfilter/vf_waveform.c+125−31
@@ -112,6 +112,8 @@ typedef struct WaveformContext { · 111 unmodified lines
112 GraticuleLines *glines;112 GraticuleLines *glines;
113 int nb_glines;113 int nb_glines;
114 int rgb;114 int rgb;
115 float ftint[2];
116 int tint[2];
115 117
116 int (*waveform_slice)(AVFilterContext *ctx, void *arg,118 int (*waveform_slice)(AVFilterContext *ctx, void *arg,
117 int jobnr, int nb_jobs);119 int jobnr, int nb_jobs);
@@ -179,6 +181,10 @@ static const AVOption waveform_options[] = { · 61 unmodified lines
179 { "ire", NULL, 0, AV_OPT_TYPE_CONST, {.i64=IRE}, 0, 0, FLAGS, "scale" },181 { "ire", NULL, 0, AV_OPT_TYPE_CONST, {.i64=IRE}, 0, 0, FLAGS, "scale" },
180 { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },182 { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },
181 { "b", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, FLAGS },183 { "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},
182 { NULL }188 { NULL }
183};189};
184 190
@@ -678,10 +684,11 @@ static av_always_inline void lowpass16(WaveformContext *s, · 493 unmodified lines
678 int jobnr, int nb_jobs)684 int jobnr, int nb_jobs)
679{685{
680 const int plane = s->desc->comp[component].plane;686 const int plane = s->desc->comp[component].plane;
687 const int dplane = (s->rgb || s->display == OVERLAY) ? plane : 0;
681 const int shift_w = s->shift_w[component];688 const int shift_w = s->shift_w[component];
682 const int shift_h = s->shift_h[component];689 const int shift_h = s->shift_h[component];
683 const int src_linesize = in->linesize[plane] / 2;690 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;
685 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);692 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
686 const int limit = s->max - 1;693 const int limit = s->max - 1;
687 const int max = limit - intensity;694 const int max = limit - intensity;
@@ -693,7 +700,7 @@ static av_always_inline void lowpass16(WaveformContext *s, · 5 unmodified lines
693 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;700 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
694 const int step = column ? 1 << shift_w : 1 << shift_h;701 const int step = column ? 1 << shift_w : 1 << shift_h;
695 const uint16_t *src_data = (const uint16_t *)in->data[plane] + sliceh_start * src_linesize;702 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;
697 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);704 uint16_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
698 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);705 uint16_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
699 const uint16_t *p;706 const uint16_t *p;
@@ -730,6 +737,56 @@ static av_always_inline void lowpass16(WaveformContext *s, · 30 unmodified lines
730 src_data += src_linesize;737 src_data += src_linesize;
731 dst_data += dst_linesize * step;738 dst_data += dst_linesize * step;
732 }739 }
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 }
733}790}
734 791
735#define LOWPASS16_FUNC(name, column, mirror) \792#define LOWPASS16_FUNC(name, column, mirror) \
@@ -765,10 +822,11 @@ static av_always_inline void lowpass(WaveformContext *s, · 29 unmodified lines
765 int jobnr, int nb_jobs)822 int jobnr, int nb_jobs)
766{823{
767 const int plane = s->desc->comp[component].plane;824 const int plane = s->desc->comp[component].plane;
825 const int dplane = (s->rgb || s->display == OVERLAY) ? plane : 0;
768 const int shift_w = s->shift_w[component];826 const int shift_w = s->shift_w[component];
769 const int shift_h = s->shift_h[component];827 const int shift_h = s->shift_h[component];
770 const int src_linesize = in->linesize[plane];828 const int src_linesize = in->linesize[plane];
771 const int dst_linesize = out->linesize[plane];829 const int dst_linesize = out->linesize[dplane];
772 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);830 const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
773 const int max = 255 - intensity;831 const int max = 255 - intensity;
774 const int src_h = AV_CEIL_RSHIFT(in->height, shift_h);832 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
779 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;837 const int slicew_end = column ? (src_w * (jobnr+1)) / nb_jobs : src_w;
780 const int step = column ? 1 << shift_w : 1 << shift_h;838 const int step = column ? 1 << shift_w : 1 << shift_h;
781 const uint8_t *src_data = in->data[plane] + sliceh_start * src_linesize;839 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;
783 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);841 uint8_t * const dst_bottom_line = dst_data + dst_linesize * (s->size - 1);
784 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);842 uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
785 const uint8_t *p;843 const uint8_t *p;
@@ -794,48 +852,76 @@ static av_always_inline void lowpass(WaveformContext *s, · 8 unmodified lines
794 852
795 for (p = src_data + slicew_start; p < src_data_end; p++) {853 for (p = src_data + slicew_start; p < src_data_end; p++) {
796 uint8_t *target;854 uint8_t *target;
855 int i = 0;
856
797 if (column) {857 if (column) {
798 target = dst + dst_signed_linesize * *p;858 do {
799 dst += step;859 target = dst++ + dst_signed_linesize * *p;
800 update(target, max, intensity);860 update(target, max, intensity);
861 } while (++i < step);
801 } else {862 } else {
802 uint8_t *row = dst_data;863 uint8_t *row = dst_data;
803 if (mirror)864 do {
804 target = row - *p - 1;865 if (mirror)
805 else866 target = row - *p - 1;
806 target = row + *p;867 else
807 update(target, max, intensity);868 target = row + *p;
808 row += dst_linesize;869 update(target, max, intensity);
870 row += dst_linesize;
871 } while (++i < step);
809 }872 }
810 }873 }
811 src_data += src_linesize;874 src_data += src_linesize;
812 dst_data += dst_linesize * step;875 dst_data += dst_linesize * step;
813 }876 }
814 877
815 if (column && step > 1) {878 if (s->display != OVERLAY && column && !s->rgb) {
879 const int bg = s->bg_color[0];
816 const int dst_h = 256;880 const int dst_h = 256;
817 uint8_t *dst;881 const int t0 = s->tint[0];
818 int x, z;882 const int t1 = s->tint[1];
819 883 uint8_t *dst0, *dst1;
820 dst = out->data[plane] + offset_y * dst_linesize + offset_x;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;
821 for (y = 0; y < dst_h; y++) {890 for (y = 0; y < dst_h; y++) {
822 for (x = slicew_start * step; x < slicew_end * step; x+=step) {891 for (x = slicew_start * step; x < slicew_end * step; x++) {
823 for (z = 1; z < step; z++) {892 if (src[x] != bg) {
824 dst[x + z] = dst[x];893 dst0[x] = t0;
894 dst1[x] = t1;
825 }895 }
826 }896 }
827 dst += dst_linesize;897
898 src += dst_linesize;
899 dst0 += dst_linesize;
900 dst1 += dst_linesize;
828 }901 }
829 } else if (step > 1) {902 } else if (s->display != OVERLAY && !s->rgb) {
903 const int bg = s->bg_color[0];
830 const int dst_w = 256;904 const int dst_w = 256;
831 uint8_t *dst;905 const int t0 = s->tint[0];
832 int z;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 }
833 921
834 dst = out->data[plane] + (offset_y + sliceh_start * step) * dst_linesize + offset_x;922 src += dst_linesize;
835 for (y = sliceh_start * step; y < sliceh_end * step; y+=step) {923 dst0 += dst_linesize;
836 for (z = 1; z < step; z++)924 dst1 += dst_linesize;
837 memcpy(dst + dst_linesize * z, dst, dst_w);
838 dst += dst_linesize * step;
839 }925 }
840 }926 }
841}927}
@@ -3198,6 +3284,9 @@ static int config_input(AVFilterLink *inlink) · 2356 unmodified lines
3198 3284
3199 s->size = s->size << (s->bits - 8);3285 s->size = s->size << (s->bits - 8);
3200 3286
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
3201 switch (inlink->format) {3290 switch (inlink->format) {
3202 case AV_PIX_FMT_GBRAP:3291 case AV_PIX_FMT_GBRAP:
3203 case AV_PIX_FMT_GBRP:3292 case AV_PIX_FMT_GBRP:
@@ -3334,10 +3423,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 130 unmodified lines
3334 td.offset_x = offset_x;3423 td.offset_x = offset_x;
3335 ctx->internal->execute(ctx, s->waveform_slice, &td, NULL, ff_filter_get_nb_threads(ctx));3424 ctx->internal->execute(ctx, s->waveform_slice, &td, NULL, ff_filter_get_nb_threads(ctx));
3336 switch (s->filter) {3425 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;
3337 case ACOLOR:3432 case ACOLOR:
3338 case CHROMA:3433 case CHROMA:
3339 case COLOR:3434 case COLOR:
3340 case LOWPASS:
3341 if (s->bits <= 8)3435 if (s->bits <= 8)
3342 envelope(s, out, plane, plane, s->mode ? offset_x : offset_y);3436 envelope(s, out, plane, plane, s->mode ? offset_x : offset_y);
3343 else3437 else
tests/ref/fate/filter-waveform_uv+50−50
@@ -3,53 +3,53 @@ · 2 unmodified lines
3#codec_id 0: rawvideo3#codec_id 0: rawvideo
4#dimensions 0: 352x5124#dimensions 0: 352x512
5#sar 0: 1/15#sar 0: 1/1
60, 0, 0, 1, 540672, 0x8a2521d660, 0, 0, 1, 540672, 0xe33821d6
70, 1, 1, 1, 540672, 0xb9a321d670, 1, 1, 1, 540672, 0x12c521d6
80, 2, 2, 1, 540672, 0x325421d680, 2, 2, 1, 540672, 0x8b6721d6
90, 3, 3, 1, 540672, 0xafee21d290, 3, 3, 1, 540672, 0x6fd321d6
100, 4, 4, 1, 540672, 0x172121d6100, 4, 4, 1, 540672, 0x703421d6
110, 5, 5, 1, 540672, 0x24d121d6110, 5, 5, 1, 540672, 0x7de421d6
120, 6, 6, 1, 540672, 0x7fec21d6120, 6, 6, 1, 540672, 0xd8ff21d6
130, 7, 7, 1, 540672, 0xa8a021d6130, 7, 7, 1, 540672, 0x01c221d6
140, 8, 8, 1, 540672, 0x29fd21d6140, 8, 8, 1, 540672, 0x831021d6
150, 9, 9, 1, 540672, 0x6dfe21d6150, 9, 9, 1, 540672, 0xc71121d6
160, 10, 10, 1, 540672, 0xe39821d6160, 10, 10, 1, 540672, 0x3cba21d6
170, 11, 11, 1, 540672, 0x83f521d6170, 11, 11, 1, 540672, 0xdd0821d6
180, 12, 12, 1, 540672, 0x57aa21d6180, 12, 12, 1, 540672, 0xb0bd21d6
190, 13, 13, 1, 540672, 0x67b221d6190, 13, 13, 1, 540672, 0xc0c521d6
200, 14, 14, 1, 540672, 0x535821d6200, 14, 14, 1, 540672, 0xac6b21d6
210, 15, 15, 1, 540672, 0xb8ac21d6210, 15, 15, 1, 540672, 0x11ce21d6
220, 16, 16, 1, 540672, 0x27f621d6220, 16, 16, 1, 540672, 0x810921d6
230, 17, 17, 1, 540672, 0x775221d6230, 17, 17, 1, 540672, 0xd06521d6
240, 18, 18, 1, 540672, 0x8e6621d6240, 18, 18, 1, 540672, 0xe77921d6
250, 19, 19, 1, 540672, 0x74c921d6250, 19, 19, 1, 540672, 0xcddc21d6
260, 20, 20, 1, 540672, 0x04cd21d6260, 20, 20, 1, 540672, 0x5de021d6
270, 21, 21, 1, 540672, 0xccd421d6270, 21, 21, 1, 540672, 0x25f621d6
280, 22, 22, 1, 540672, 0x317221d6280, 22, 22, 1, 540672, 0x8a8521d6
290, 23, 23, 1, 540672, 0xd79321d6290, 23, 23, 1, 540672, 0x30b521d6
300, 24, 24, 1, 540672, 0xa2ac21d6300, 24, 24, 1, 540672, 0xfbbf21d6
310, 25, 25, 1, 540672, 0x7f0a21d6310, 25, 25, 1, 540672, 0xd81d21d6
320, 26, 26, 1, 540672, 0x483521d6320, 26, 26, 1, 540672, 0xa14821d6
330, 27, 27, 1, 540672, 0xb65721d6330, 27, 27, 1, 540672, 0x0f7921d6
340, 28, 28, 1, 540672, 0xb77021d6340, 28, 28, 1, 540672, 0x109221d6
350, 29, 29, 1, 540672, 0x9fd521d6350, 29, 29, 1, 540672, 0xf8e821d6
360, 30, 30, 1, 540672, 0xb72121d6360, 30, 30, 1, 540672, 0x104321d6
370, 31, 31, 1, 540672, 0x540221d6370, 31, 31, 1, 540672, 0xad1521d6
380, 32, 32, 1, 540672, 0xa34121d6380, 32, 32, 1, 540672, 0xfc5421d6
390, 33, 33, 1, 540672, 0xe01421d6390, 33, 33, 1, 540672, 0x393621d6
400, 34, 34, 1, 540672, 0x6fc721d6400, 34, 34, 1, 540672, 0xc8da21d6
410, 35, 35, 1, 540672, 0x7fa621d6410, 35, 35, 1, 540672, 0xd8b921d6
420, 36, 36, 1, 540672, 0xc48c21d6420, 36, 36, 1, 540672, 0x1dae21d6
430, 37, 37, 1, 540672, 0x40f021d6430, 37, 37, 1, 540672, 0x9a0321d6
440, 38, 38, 1, 540672, 0xdf3f21d6440, 38, 38, 1, 540672, 0x386121d6
450, 39, 39, 1, 540672, 0xb04321d6450, 39, 39, 1, 540672, 0x096521d6
460, 40, 40, 1, 540672, 0x222821d6460, 40, 40, 1, 540672, 0x7b3b21d6
470, 41, 41, 1, 540672, 0x2a5521d6470, 41, 41, 1, 540672, 0x836821d6
480, 42, 42, 1, 540672, 0x6a4621be480, 42, 42, 1, 540672, 0x97bd21d6
490, 43, 43, 1, 540672, 0xed7f21d6490, 43, 43, 1, 540672, 0x46a121d6
500, 44, 44, 1, 540672, 0xb16521d6500, 44, 44, 1, 540672, 0x0a8721d6
510, 45, 45, 1, 540672, 0x9f5621d6510, 45, 45, 1, 540672, 0xf86921d6
520, 46, 46, 1, 540672, 0x204321d6520, 46, 46, 1, 540672, 0x795621d6
530, 47, 47, 1, 540672, 0xc26e21d6530, 47, 47, 1, 540672, 0x1b9021d6
540, 48, 48, 1, 540672, 0x3e8321d6540, 48, 48, 1, 540672, 0x979621d6
550, 49, 49, 1, 540672, 0xaaee21d6550, 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