Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Copyright (c) 2013 Paul B Mahol | ||
3 | * | ||
4 | * This file is part of FFmpeg. | ||
5 | * | ||
6 | * FFmpeg is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * FFmpeg is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with FFmpeg; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | #include "libavutil/common.h" | ||
22 | #include "libavutil/intfloat.h" | ||
23 | #include "avfilter.h" | ||
24 | #include "video.h" | ||
25 | #include "blend.h" | ||
26 | |||
27 | #undef PIXEL | ||
28 | #undef MAX | ||
29 | #undef HALF | ||
30 | #undef CLIP | ||
31 | |||
32 | #if DEPTH == 8 | ||
33 | #define PIXEL uint8_t | ||
34 | #define MAX 255 | ||
35 | #define HALF 128 | ||
36 | #define CLIP(x) (av_clip_uint8(x)) | ||
37 | #elif DEPTH == 32 | ||
38 | #define PIXEL float | ||
39 | #define MAX 1.f | ||
40 | #define HALF 0.5f | ||
41 | #define CLIP(x) (x) | ||
42 | #else | ||
43 | #define PIXEL uint16_t | ||
44 | #define MAX ((1 << DEPTH) - 1) | ||
45 | #define HALF (1 << (DEPTH - 1)) | ||
46 | #define CLIP(x) ((int)av_clip_uintp2(x, DEPTH)) | ||
47 | #endif | ||
48 | |||
49 | #undef MULTIPLY | ||
50 | #undef SCREEN | ||
51 | #undef BURN | ||
52 | #undef DODGE | ||
53 | #undef GEOMETRIC | ||
54 | #undef INT2FLOAT | ||
55 | #undef FLOAT2INT | ||
56 | #undef MDIV | ||
57 | #undef LRINTF | ||
58 | |||
59 | #if DEPTH < 32 | ||
60 | #define MULTIPLY(x, a, b) ((x) * (((a) * (b)) / MAX)) | ||
61 | #define SCREEN(x, a, b) (MAX - (x) * ((MAX - (a)) * (MAX - (b)) / MAX)) | ||
62 | #define BURN(a, b) (((a) == 0) ? (a) : FFMAX(0, MAX - ((MAX - (b)) << DEPTH) / (a))) | ||
63 | #define DODGE(a, b) (((a) == MAX) ? (a) : FFMIN(MAX, (((b) << DEPTH) / (MAX - (a))))) | ||
64 | #define GEOMETRIC(a, b) (lrintf(sqrtf((unsigned)A * B))) | ||
65 | #define INT2FLOAT(x) (x) | ||
66 | #define FLOAT2INT(x) (x) | ||
67 | #define MDIV (0.125f * (1 << DEPTH)) | ||
68 | #define LRINTF(x) lrintf(x) | ||
69 | #else | ||
70 | #define MULTIPLY(x, a, b) ((x) * (((a) * (b)) / 1.0)) | ||
71 | #define SCREEN(x, a, b) (1.0 - (x) * ((1.0 - (a)) * (1.0 - (b)) / 1.0)) | ||
72 | #define BURN(a, b) (((a) <= 0.0) ? (a) : FFMAX(0.0, 1.0 - (1.0 - (b)) / (a))) | ||
73 | #define DODGE(a, b) (((a) >= 1.0) ? (a) : FFMIN(1.0, ((b) / (1.0 - (a))))) | ||
74 | #define GEOMETRIC(a, b) (sqrtf(fmaxf(A, 0) * fmaxf(B, 0))) | ||
75 | #define INT2FLOAT(x) av_int2float(x) | ||
76 | #define FLOAT2INT(x) av_float2int(x) | ||
77 | #define MDIV 0.125f | ||
78 | #define LRINTF(x) (x) | ||
79 | #endif | ||
80 | |||
81 | #define A top[j] | ||
82 | #define B bottom[j] | ||
83 | |||
84 | #define fn2(a, b) blend_##a##_##b##bit | ||
85 | #define fn1(name, depth) fn2(name, depth) | ||
86 | #define fn0(name) fn1(name, DEPTH) | ||
87 | |||
88 | #define fn(NAME, EXPR) \ | ||
89 | static void fn0(NAME)(const uint8_t *_top, ptrdiff_t top_linesize, \ | ||
90 | const uint8_t *_bottom, ptrdiff_t bottom_linesize, \ | ||
91 | uint8_t *_dst, ptrdiff_t dst_linesize, \ | ||
92 | ptrdiff_t width, ptrdiff_t height, \ | ||
93 | FilterParams *param, SliceParams *sliceparam) \ | ||
94 | { \ | ||
95 | const PIXEL *top = (const PIXEL *)_top; \ | ||
96 | const PIXEL *bottom = (const PIXEL *)_bottom; \ | ||
97 | PIXEL *dst = (PIXEL *)_dst; \ | ||
98 | const float opacity = param->opacity; \ | ||
99 | \ | ||
100 | dst_linesize /= sizeof(PIXEL); \ | ||
101 | top_linesize /= sizeof(PIXEL); \ | ||
102 | bottom_linesize /= sizeof(PIXEL); \ | ||
103 | \ | ||
104 | for (int i = 0; i < height; i++) { \ | ||
105 | for (int j = 0; j < width; j++) { \ | ||
106 | dst[j] = top[j] + ((EXPR)-top[j]) * opacity; \ | ||
107 | } \ | ||
108 | dst += dst_linesize; \ | ||
109 | top += top_linesize; \ | ||
110 | bottom += bottom_linesize; \ | ||
111 | } \ | ||
112 | } | ||
113 | |||
114 |
4/6✓ Branch 0 taken 589824 times.
✓ Branch 1 taken 3072 times.
✓ Branch 2 taken 3072 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1185816 | fn(addition, FFMIN(MAX, A + B)) |
115 |
4/4✓ Branch 0 taken 589824 times.
✓ Branch 1 taken 3072 times.
✓ Branch 2 taken 3072 times.
✓ Branch 3 taken 12 times.
|
1185816 | fn(grainmerge, CLIP(A + B - HALF)) |
116 |
4/4✓ Branch 0 taken 589824 times.
✓ Branch 1 taken 3072 times.
✓ Branch 2 taken 3072 times.
✓ Branch 3 taken 12 times.
|
1185816 | fn(average, (A + B) / 2) |
117 |
4/6✓ Branch 0 taken 786432 times.
✓ Branch 1 taken 4608 times.
✓ Branch 2 taken 4608 times.
✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1582116 | fn(subtract, FFMAX(0, A - B)) |
118 |
4/4✓ Branch 0 taken 393216 times.
✓ Branch 1 taken 1536 times.
✓ Branch 2 taken 1536 times.
✓ Branch 3 taken 6 times.
|
789516 | fn(multiply, MULTIPLY(1, A, B)) |
119 | ✗ | fn(multiply128,CLIP((A - HALF) * B / MDIV + HALF)) | |
120 |
4/6✓ Branch 0 taken 589824 times.
✓ Branch 1 taken 3072 times.
✓ Branch 2 taken 3072 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1185816 | fn(negation, MAX - FFABS(MAX - A - B)) |
121 |
4/6✓ Branch 0 taken 589824 times.
✓ Branch 1 taken 3072 times.
✓ Branch 2 taken 3072 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1185816 | fn(extremity, FFABS(MAX - A - B)) |
122 |
4/4✓ Branch 0 taken 589824 times.
✓ Branch 1 taken 3072 times.
✓ Branch 2 taken 3072 times.
✓ Branch 3 taken 12 times.
|
1185816 | fn(difference, FFABS(A - B)) |
123 |
4/4✓ Branch 0 taken 8040960 times.
✓ Branch 1 taken 31296 times.
✓ Branch 2 taken 31296 times.
✓ Branch 3 taken 1335 times.
|
16147182 | fn(grainextract, CLIP(HALF + A - B)) |
124 |
4/4✓ Branch 0 taken 393216 times.
✓ Branch 1 taken 1536 times.
✓ Branch 2 taken 1536 times.
✓ Branch 3 taken 6 times.
|
789516 | fn(screen, SCREEN(1, A, B)) |
125 | ✗ | fn(overlay, (A < HALF) ? MULTIPLY(2, A, B) : SCREEN(2, A, B)) | |
126 | ✗ | fn(hardlight, (B < HALF) ? MULTIPLY(2, B, A) : SCREEN(2, B, A)) | |
127 |
6/6✓ Branch 0 taken 195319 times.
✓ Branch 1 taken 197897 times.
✓ Branch 2 taken 393216 times.
✓ Branch 3 taken 1536 times.
✓ Branch 4 taken 1536 times.
✓ Branch 5 taken 6 times.
|
789516 | fn(hardmix, (A < (MAX - B)) ? 0: MAX) |
128 | ✗ | fn(heat, (A == 0) ? 0 : MAX - FFMIN(((MAX - B) * (MAX - B)) / A, MAX)) | |
129 | ✗ | fn(freeze, (B == 0) ? 0 : MAX - FFMIN(((MAX - A) * (MAX - A)) / B, MAX)) | |
130 |
4/6✓ Branch 0 taken 589824 times.
✓ Branch 1 taken 3072 times.
✓ Branch 2 taken 3072 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1185816 | fn(darken, FFMIN(A, B)) |
131 |
4/6✓ Branch 0 taken 589824 times.
✓ Branch 1 taken 3072 times.
✓ Branch 2 taken 3072 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1185816 | fn(lighten, FFMAX(A, B)) |
132 | ✗ | fn(divide, CLIP(B == 0 ? MAX : MAX * A / B)) | |
133 | ✗ | fn(dodge, DODGE(A, B)) | |
134 | ✗ | fn(burn, BURN(A, B)) | |
135 | ✗ | fn(softlight, CLIP(A * A / MAX + (2 * (B * ((A * (MAX - A)) / MAX) / MAX)))) | |
136 | ✗ | fn(exclusion, A + B - 2 * A * B / MAX) | |
137 | ✗ | fn(pinlight, (B < HALF) ? FFMIN(A, 2 * B) : FFMAX(A, 2 * (B - HALF))) | |
138 |
4/8✓ Branch 0 taken 589824 times.
✓ Branch 1 taken 3072 times.
✓ Branch 2 taken 3072 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
1185816 | fn(phoenix, FFMIN(A, B) - FFMAX(A, B) + MAX) |
139 | ✗ | fn(reflect, (B == MAX) ? B : FFMIN(MAX, (A * A / (MAX - B)))) | |
140 | ✗ | fn(glow, (A == MAX) ? A : FFMIN(MAX, (B * B / (MAX - A)))) | |
141 |
4/7✓ Branch 0 taken 589824 times.
✓ Branch 1 taken 3072 times.
✓ Branch 2 taken 3072 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
1185816 | fn(and, INT2FLOAT(FLOAT2INT(A) & FLOAT2INT(B))) |
142 |
4/7✓ Branch 0 taken 589824 times.
✓ Branch 1 taken 3072 times.
✓ Branch 2 taken 3072 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
1185816 | fn(or, INT2FLOAT(FLOAT2INT(A) | FLOAT2INT(B))) |
143 |
4/7✓ Branch 0 taken 393216 times.
✓ Branch 1 taken 1536 times.
✓ Branch 2 taken 1536 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
789516 | fn(xor, INT2FLOAT(FLOAT2INT(A) ^ FLOAT2INT(B))) |
144 | ✗ | fn(vividlight, (A < HALF) ? BURN(2 * A, B) : DODGE(2 * (A - HALF), B)) | |
145 | ✗ | fn(linearlight,CLIP((B < HALF) ? B + 2 * A - MAX : B + 2 * (A - HALF))) | |
146 | ✗ | fn(softdifference,CLIP((A > B) ? (B == MAX) ? 0 : (A - B) * MAX / (MAX - B) : (B == 0) ? 0 : (B - A) * MAX / B)) | |
147 | ✗ | fn(geometric, GEOMETRIC(A, B)) | |
148 | ✗ | fn(harmonic, A == 0 && B == 0 ? 0 : 2LL * A * B / (A + B)) | |
149 | ✗ | fn(bleach, (MAX - B) + (MAX - A) - MAX) | |
150 | ✗ | fn(stain, 2 * MAX - A - B) | |
151 | ✗ | fn(interpolate,LRINTF(MAX * (2 - cosf(A * M_PI / MAX) - cosf(B * M_PI / MAX)) * 0.25f)) | |
152 | ✗ | fn(hardoverlay,A == MAX ? MAX : FFMIN(MAX, MAX * B / (2 * MAX - 2 * A) * (A > HALF) + 2 * A * B / MAX * (A <= HALF))) | |
153 |