Showing the changes to libavfilter (1 of 2 files). Show all
Unified · Split
| @@ -79,10 +79,11 @@ static const AVOption gradients_options[] = { · 78 unmodified lines | ||
| 79 | 79 | {"duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS }, |
| 80 | 80 | {"d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS }, |
| 81 | 81 | {"speed", "set gradients rotation speed", OFFSET(speed), AV_OPT_TYPE_FLOAT,{.dbl=0.01}, 0.00001, 1, FLAGS }, |
| 82 | − {"type", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "type" }, | |
| 83 | − {"t", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "type" }, | |
| 82 | + {"type", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, FLAGS, "type" }, | |
| 83 | + {"t", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, FLAGS, "type" }, | |
| 84 | 84 | {"linear", "set gradient type", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "type" }, |
| 85 | 85 | {"radial", "set gradient type", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "type" }, |
| 86 | + {"circular", "set gradient type", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "type" }, | |
| 86 | 87 | {NULL}, |
| 87 | 88 | }; |
| 88 | 89 | |
| @@ -115,10 +116,10 @@ static uint64_t lerp_color16(uint8_t c0[4], uint8_t c1[4], float x) · 26 unmodified lines | ||
| 115 | 116 | (llrintf((c0[3] * y + c1[3] * x) * 256)) << 48; |
| 116 | 117 | } |
| 117 | 118 | |
| 118 | −static uint32_t lerp_colors(uint8_t arr[3][4], int nb_colors, float step) | |
| 119 | +static uint32_t lerp_colors(uint8_t arr[3][4], int nb_colors, int nb_wrap_colors, float step) | |
| 119 | 120 | { |
| 120 | 121 | float scl; |
| 121 | − int i; | |
| 122 | + int i, j; | |
| 122 | 123 | |
| 123 | 124 | if (nb_colors == 1 || step <= 0.0) { |
| 124 | 125 | return arr[0][0] | (arr[0][1] << 8) | (arr[0][2] << 16) | (arr[0][3] << 24); |
| @@ -127,16 +128,21 @@ static uint32_t lerp_colors(uint8_t arr[3][4], int nb_colors, float step) · 2 unmodified lines | ||
| 127 | 128 | return arr[i][0] | (arr[i][1] << 8) | (arr[i][2] << 16) | (arr[i][3] << 24); |
| 128 | 129 | } |
| 129 | 130 | |
| 130 | − scl = step * (nb_colors - 1); | |
| 131 | + scl = step * (nb_wrap_colors - 1); | |
| 131 | 132 | i = floorf(scl); |
| 133 | + j = i + 1; | |
| 134 | + if (i >= nb_colors - 1) { | |
| 135 | + i = nb_colors - 1; | |
| 136 | + j = 0; | |
| 137 | + } | |
| 132 | 138 | |
| 133 | − return lerp_color(arr[i], arr[i + 1], scl - i); | |
| 139 | + return lerp_color(arr[i], arr[j], scl - i); | |
| 134 | 140 | } |
| 135 | 141 | |
| 136 | −static uint64_t lerp_colors16(uint8_t arr[3][4], int nb_colors, float step) | |
| 142 | +static uint64_t lerp_colors16(uint8_t arr[3][4], int nb_colors, int nb_wrap_colors, float step) | |
| 137 | 143 | { |
| 138 | 144 | float scl; |
| 139 | − int i; | |
| 145 | + int i, j; | |
| 140 | 146 | |
| 141 | 147 | if (nb_colors == 1 || step <= 0.0) { |
| 142 | 148 | return ((uint64_t)arr[0][0] << 8) | ((uint64_t)arr[0][1] << 24) | ((uint64_t)arr[0][2] << 40) | ((uint64_t)arr[0][3] << 56); |
| @@ -145,17 +151,23 @@ static uint64_t lerp_colors16(uint8_t arr[3][4], int nb_colors, float step) · 2 unmodified lines | ||
| 145 | 151 | return ((uint64_t)arr[i][0] << 8) | ((uint64_t)arr[i][1] << 24) | ((uint64_t)arr[i][2] << 40) | ((uint64_t)arr[i][3] << 56); |
| 146 | 152 | } |
| 147 | 153 | |
| 148 | − scl = step * (nb_colors - 1); | |
| 154 | + scl = step * (nb_wrap_colors - 1); | |
| 149 | 155 | i = floorf(scl); |
| 156 | + j = i + 1; | |
| 157 | + if (i >= nb_colors - 1) { | |
| 158 | + i = nb_colors - 1; | |
| 159 | + j = 0; | |
| 160 | + } | |
| 150 | 161 | |
| 151 | − return lerp_color16(arr[i], arr[i + 1], scl - i); | |
| 162 | + return lerp_color16(arr[i], arr[j], scl - i); | |
| 152 | 163 | } |
| 153 | 164 | |
| 154 | −static void lerp_colors32(float arr[3][4], int nb_colors, float step, | |
| 165 | +static void lerp_colors32(float arr[3][4], int nb_colors, | |
| 166 | + int nb_wrap_colors, float step, | |
| 155 | 167 | float *r, float *g, float *b, float *a) |
| 156 | 168 | { |
| 157 | 169 | float scl, x; |
| 158 | − int i; | |
| 170 | + int i, j; | |
| 159 | 171 | |
| 160 | 172 | if (nb_colors == 1 || step <= 0.0) { |
| 161 | 173 | *r = arr[0][0]; |
| @@ -172,31 +184,55 @@ static void lerp_colors32(float arr[3][4], int nb_colors, float step, · 10 unmodified lines | ||
| 172 | 184 | return; |
| 173 | 185 | } |
| 174 | 186 | |
| 175 | − scl = step * (nb_colors - 1); | |
| 187 | + scl = step * (nb_wrap_colors - 1); | |
| 176 | 188 | i = floorf(scl); |
| 177 | 189 | x = scl - i; |
| 190 | + j = i + 1; | |
| 191 | + if (i >= nb_colors - 1) { | |
| 192 | + i = nb_colors - 1; | |
| 193 | + j = 0; | |
| 194 | + } | |
| 178 | 195 | |
| 179 | − *r = lerpf(arr[i][0], arr[i + 1][0], x); | |
| 180 | − *g = lerpf(arr[i][1], arr[i + 1][1], x); | |
| 181 | − *b = lerpf(arr[i][2], arr[i + 1][2], x); | |
| 182 | − *a = lerpf(arr[i][3], arr[i + 1][3], x); | |
| 196 | + *r = lerpf(arr[i][0], arr[j][0], x); | |
| 197 | + *g = lerpf(arr[i][1], arr[j][1], x); | |
| 198 | + *b = lerpf(arr[i][2], arr[j][2], x); | |
| 199 | + *a = lerpf(arr[i][3], arr[j][3], x); | |
| 183 | 200 | } |
| 184 | 201 | |
| 185 | 202 | static float project(float origin_x, float origin_y, |
| 186 | 203 | float dest_x, float dest_y, |
| 187 | − int point_x, int point_y, int type) | |
| 204 | + float point_x, float point_y, int type) | |
| 188 | 205 | { |
| 189 | − // Rise and run of line. | |
| 206 | + float op_x = point_x - origin_x; | |
| 207 | + float op_y = point_y - origin_y; | |
| 190 | 208 | float od_x = dest_x - origin_x; |
| 191 | 209 | float od_y = dest_y - origin_y; |
| 210 | + float op_x_od; | |
| 211 | + float od_s_q; | |
| 192 | 212 | |
| 193 | − // Distance-squared of line. | |
| 194 | − float od_s_q = type ? sqrtf(od_x * od_x + od_y * od_y) : od_x * od_x + od_y * od_y; | |
| 213 | + switch (type) { | |
| 214 | + case 0: | |
| 215 | + od_s_q = od_x * od_x + od_y * od_y; | |
| 216 | + break; | |
| 217 | + case 1: | |
| 218 | + od_s_q = sqrtf(od_x * od_x + od_y * od_y); | |
| 219 | + break; | |
| 220 | + case 2: | |
| 221 | + od_s_q = M_PI * 2.f; | |
| 222 | + break; | |
| 223 | + } | |
| 195 | 224 | |
| 196 | − // Rise and run of projection. | |
| 197 | − float op_x = point_x - origin_x; | |
| 198 | − float op_y = point_y - origin_y; | |
| 199 | − float op_x_od = type ? sqrtf(op_x * op_x + op_y * op_y) : op_x * od_x + op_y * od_y; | |
| 225 | + switch (type) { | |
| 226 | + case 0: | |
| 227 | + op_x_od = op_x * od_x + op_y * od_y; | |
| 228 | + break; | |
| 229 | + case 1: | |
| 230 | + op_x_od = sqrtf(op_x * op_x + op_y * op_y); | |
| 231 | + break; | |
| 232 | + case 2: | |
| 233 | + op_x_od = atan2f(op_x, op_y) + M_PI; | |
| 234 | + break; | |
| 235 | + } | |
| 200 | 236 | |
| 201 | 237 | // Normalize and clamp range. |
| 202 | 238 | return av_clipf(op_x_od / od_s_q, 0.f, 1.f); |
| @@ -216,7 +252,7 @@ static int draw_gradients_slice(AVFilterContext *ctx, void *arg, int job, int nb · 13 unmodified lines | ||
| 216 | 252 | for (int y = start; y < end; y++) { |
| 217 | 253 | for (int x = 0; x < width; x++) { |
| 218 | 254 | float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, s->type); |
| 219 | − dst[x] = lerp_colors(s->color_rgba, s->nb_colors, factor); | |
| 255 | + dst[x] = lerp_colors(s->color_rgba, s->nb_colors, s->nb_colors + (s->type == 2), factor); | |
| 220 | 256 | } |
| 221 | 257 | |
| 222 | 258 | dst += linesize; |
| @@ -239,7 +275,7 @@ static int draw_gradients_slice16(AVFilterContext *ctx, void *arg, int job, int · 16 unmodified lines | ||
| 239 | 275 | for (int y = start; y < end; y++) { |
| 240 | 276 | for (int x = 0; x < width; x++) { |
| 241 | 277 | float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, s->type); |
| 242 | − dst[x] = lerp_colors16(s->color_rgba, s->nb_colors, factor); | |
| 278 | + dst[x] = lerp_colors16(s->color_rgba, s->nb_colors, s->nb_colors + s->type == 2, factor); | |
| 243 | 279 | } |
| 244 | 280 | |
| 245 | 281 | dst += linesize; |
| @@ -268,7 +304,7 @@ static int draw_gradients_slice32_planar(AVFilterContext *ctx, void *arg, int jo · 22 unmodified lines | ||
| 268 | 304 | for (int y = start; y < end; y++) { |
| 269 | 305 | for (int x = 0; x < width; x++) { |
| 270 | 306 | float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, s->type); |
| 271 | − lerp_colors32(s->color_rgbaf, s->nb_colors, factor, | |
| 307 | + lerp_colors32(s->color_rgbaf, s->nb_colors, s->nb_colors + s->type == 2 ,factor, | |
| 272 | 308 | &dst_r[x], &dst_g[x], &dst_b[x], &dst_a[x]); |
| 273 | 309 | } |
| 274 | 310 | |