Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -19,6 +19,7 @@ · 18 unmodified lines | ||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | #include "libavutil/imgutils.h" |
| 22 | +#include "libavutil/intfloat.h" | |
| 22 | 23 | #include "libavutil/eval.h" |
| 23 | 24 | #include "libavutil/opt.h" |
| 24 | 25 | #include "libavutil/pixfmt.h" |
| @@ -138,6 +139,9 @@ COPY(bottom, 8) · 113 unmodified lines | ||
| 138 | 139 | COPY(top, 16) |
| 139 | 140 | COPY(bottom, 16) |
| 140 | 141 | |
| 142 | +COPY(top, 32) | |
| 143 | +COPY(bottom, 32) | |
| 144 | + | |
| 141 | 145 | #undef COPY |
| 142 | 146 | |
| 143 | 147 | static void blend_normal_8bit(const uint8_t *top, ptrdiff_t top_linesize, |
| @@ -184,6 +188,31 @@ static void blend_normal_16bit(const uint8_t *_top, ptrdiff_t top_linesize, · 40 unmodified lines | ||
| 184 | 188 | } |
| 185 | 189 | } |
| 186 | 190 | |
| 191 | +static void blend_normal_32bit(const uint8_t *_top, ptrdiff_t top_linesize, | |
| 192 | + const uint8_t *_bottom, ptrdiff_t bottom_linesize, | |
| 193 | + uint8_t *_dst, ptrdiff_t dst_linesize, | |
| 194 | + ptrdiff_t width, ptrdiff_t height, | |
| 195 | + FilterParams *param, double *values, int starty) | |
| 196 | +{ | |
| 197 | + const float *top = (float*)_top; | |
| 198 | + const float *bottom = (float*)_bottom; | |
| 199 | + float *dst = (float*)_dst; | |
| 200 | + const double opacity = param->opacity; | |
| 201 | + int i, j; | |
| 202 | + dst_linesize /= 4; | |
| 203 | + top_linesize /= 4; | |
| 204 | + bottom_linesize /= 4; | |
| 205 | + | |
| 206 | + for (i = 0; i < height; i++) { | |
| 207 | + for (j = 0; j < width; j++) { | |
| 208 | + dst[j] = top[j] * opacity + bottom[j] * (1. - opacity); | |
| 209 | + } | |
| 210 | + dst += dst_linesize; | |
| 211 | + top += top_linesize; | |
| 212 | + bottom += bottom_linesize; | |
| 213 | + } | |
| 214 | +} | |
| 215 | + | |
| 187 | 216 | #define DEFINE_BLEND8(name, expr) \ |
| 188 | 217 | static void blend_## name##_8bit(const uint8_t *top, ptrdiff_t top_linesize, \ |
| 189 | 218 | const uint8_t *bottom, ptrdiff_t bottom_linesize, \ |
| @@ -230,6 +259,32 @@ static void blend_## name##_##depth##bit(const uint8_t *_top, ptrdiff_t top_line · 40 unmodified lines | ||
| 230 | 259 | } \ |
| 231 | 260 | } |
| 232 | 261 | |
| 262 | +#define DEFINE_BLEND32(name, expr, depth) \ | |
| 263 | +static void blend_## name##_##depth##bit(const uint8_t *_top, ptrdiff_t top_linesize,\ | |
| 264 | + const uint8_t *_bottom, ptrdiff_t bottom_linesize, \ | |
| 265 | + uint8_t *_dst, ptrdiff_t dst_linesize, \ | |
| 266 | + ptrdiff_t width, ptrdiff_t height, \ | |
| 267 | + FilterParams *param, double *values, int starty) \ | |
| 268 | +{ \ | |
| 269 | + const float *top = (const float*)_top; \ | |
| 270 | + const float *bottom = (const float*)_bottom; \ | |
| 271 | + float *dst = (float*)_dst; \ | |
| 272 | + double opacity = param->opacity; \ | |
| 273 | + int i, j; \ | |
| 274 | + dst_linesize /= 4; \ | |
| 275 | + top_linesize /= 4; \ | |
| 276 | + bottom_linesize /= 4; \ | |
| 277 | + \ | |
| 278 | + for (i = 0; i < height; i++) { \ | |
| 279 | + for (j = 0; j < width; j++) { \ | |
| 280 | + dst[j] = top[j] + ((expr) - top[j]) * opacity; \ | |
| 281 | + } \ | |
| 282 | + dst += dst_linesize; \ | |
| 283 | + top += top_linesize; \ | |
| 284 | + bottom += bottom_linesize; \ | |
| 285 | + } \ | |
| 286 | +} | |
| 287 | + | |
| 233 | 288 | #define A top[j] |
| 234 | 289 | #define B bottom[j] |
| 235 | 290 | |
| @@ -443,6 +498,49 @@ DEFINE_BLEND16(xor, A ^ B, 9) · 207 unmodified lines | ||
| 443 | 498 | DEFINE_BLEND16(vividlight, (A < 256) ? BURN(2 * A, B) : DODGE(2 * (A - 256), B), 9) |
| 444 | 499 | DEFINE_BLEND16(linearlight,(int)av_clip_uintp2((B < 256) ? B + 2 * A - 511 : B + 2 * (A - 256), 9), 9) |
| 445 | 500 | |
| 501 | +#undef MULTIPLY | |
| 502 | +#undef SCREEN | |
| 503 | +#undef BURN | |
| 504 | +#undef DODGE | |
| 505 | + | |
| 506 | +#define MULTIPLY(x, a, b) ((x) * (((a) * (b)) / 1.0)) | |
| 507 | +#define SCREEN(x, a, b) (1.0 - (x) * ((1.0 - (a)) * (1.0 - (b)) / 1.0)) | |
| 508 | +#define BURN(a, b) (((a) <= 0.0) ? (a) : FFMAX(0.0, 1.0 - (1.0 - (b)) / (a))) | |
| 509 | +#define DODGE(a, b) (((a) >= 1.0) ? (a) : FFMIN(1.0, ((b) / (1.0 - (a))))) | |
| 510 | + | |
| 511 | +DEFINE_BLEND32(addition, A + B, 32) | |
| 512 | +DEFINE_BLEND32(grainmerge, A + B - 0.5, 32) | |
| 513 | +DEFINE_BLEND32(average, (A + B) / 2, 32) | |
| 514 | +DEFINE_BLEND32(subtract, A - B, 32) | |
| 515 | +DEFINE_BLEND32(multiply, A * B, 32) | |
| 516 | +DEFINE_BLEND32(multiply128, (A - 0.5) * B / 0.125 + 0.5, 32) | |
| 517 | +DEFINE_BLEND32(negation, 1.0 - FFABS(1.0 - A - B), 32) | |
| 518 | +DEFINE_BLEND32(extremity, FFABS(1.0 - A - B), 32) | |
| 519 | +DEFINE_BLEND32(difference, FFABS(A - B), 32) | |
| 520 | +DEFINE_BLEND32(grainextract, 0.5 + A - B, 32) | |
| 521 | +DEFINE_BLEND32(screen, SCREEN(1, A, B), 32) | |
| 522 | +DEFINE_BLEND32(overlay, (A < 0.5) ? MULTIPLY(2, A, B) : SCREEN(2, A, B), 32) | |
| 523 | +DEFINE_BLEND32(hardlight, (B < 0.5) ? MULTIPLY(2, B, A) : SCREEN(2, B, A), 32) | |
| 524 | +DEFINE_BLEND32(hardmix, (A < (1.0 - B)) ? 0: 1.0, 32) | |
| 525 | +DEFINE_BLEND32(heat, (A == 0) ? 0 : 1.0 - FFMIN(((1.0 - B) * (1.0 - B)) / A, 1.0), 32) | |
| 526 | +DEFINE_BLEND32(freeze, (B == 0) ? 0 : 1.0 - FFMIN(((1.0 - A) * (1.0 - A)) / B, 1.0), 32) | |
| 527 | +DEFINE_BLEND32(darken, FFMIN(A, B), 32) | |
| 528 | +DEFINE_BLEND32(lighten, FFMAX(A, B), 32) | |
| 529 | +DEFINE_BLEND32(divide, B == 0 ? 1.0 : 1.0 * A / B, 32) | |
| 530 | +DEFINE_BLEND32(dodge, DODGE(A, B), 32) | |
| 531 | +DEFINE_BLEND32(burn, BURN(A, B), 32) | |
| 532 | +DEFINE_BLEND32(softlight, (A > 0.5) ? B + (1.0 - B) * (A - 0.5) / 0.5 * (0.5 - fabs(B - 0.5) / 1.0): B - B * ((0.5 - A) / 0.5) * (0.5 - fabs(B - 0.5)/1.0), 32) | |
| 533 | +DEFINE_BLEND32(exclusion, A + B - 2 * A * B / 1.0, 32) | |
| 534 | +DEFINE_BLEND32(pinlight, (B < 0.5) ? FFMIN(A, 2 * B) : FFMAX(A, 2 * (B - 0.5)), 32) | |
| 535 | +DEFINE_BLEND32(phoenix, FFMIN(A, B) - FFMAX(A, B) + 1.0, 32) | |
| 536 | +DEFINE_BLEND32(reflect, (B == 1.0) ? B : FFMIN(1.0, (A * A / (1.0 - B))), 32) | |
| 537 | +DEFINE_BLEND32(glow, (A == 1.0) ? A : FFMIN(1.0, (B * B / (1.0 - A))), 32) | |
| 538 | +DEFINE_BLEND32(and, av_int2float(av_float2int(A) & av_float2int(B)), 32) | |
| 539 | +DEFINE_BLEND32(or, av_int2float(av_float2int(A) | av_float2int(B)), 32) | |
| 540 | +DEFINE_BLEND32(xor, av_int2float(av_float2int(A) ^ av_float2int(B)), 32) | |
| 541 | +DEFINE_BLEND32(vividlight, (A < 0.5) ? BURN(2 * A, B) : DODGE(2 * (A - 0.5), B), 32) | |
| 542 | +DEFINE_BLEND32(linearlight,(B < 0.5) ? B + 2 * A - 1.0 : B + 2 * (A - 0.5), 32) | |
| 543 | + | |
| 446 | 544 | #define DEFINE_BLEND_EXPR(type, name, div) \ |
| 447 | 545 | static void blend_expr_## name(const uint8_t *_top, ptrdiff_t top_linesize, \ |
| 448 | 546 | const uint8_t *_bottom, ptrdiff_t bottom_linesize, \ |
| @@ -475,6 +573,7 @@ static void blend_expr_## name(const uint8_t *_top, ptrdiff_t top_linesize, · 26 unmodified lines | ||
| 475 | 573 | |
| 476 | 574 | DEFINE_BLEND_EXPR(uint8_t, 8bit, 1) |
| 477 | 575 | DEFINE_BLEND_EXPR(uint16_t, 16bit, 2) |
| 576 | +DEFINE_BLEND_EXPR(float, 32bit, 4) | |
| 478 | 577 | |
| 479 | 578 | static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) |
| 480 | 579 | { |
| @@ -580,6 +679,7 @@ static int query_formats(AVFilterContext *ctx) · 99 unmodified lines | ||
| 580 | 679 | AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16, |
| 581 | 680 | AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16, |
| 582 | 681 | AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16, AV_PIX_FMT_GRAY16, |
| 682 | + AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32, AV_PIX_FMT_GRAYF32, | |
| 583 | 683 | AV_PIX_FMT_NONE |
| 584 | 684 | }; |
| 585 | 685 | |
| @@ -645,6 +745,7 @@ DEFINE_INIT_BLEND_FUNC(9, 16) · 59 unmodified lines | ||
| 645 | 745 | DEFINE_INIT_BLEND_FUNC(10, 16) |
| 646 | 746 | DEFINE_INIT_BLEND_FUNC(12, 16) |
| 647 | 747 | DEFINE_INIT_BLEND_FUNC(16, 16) |
| 748 | +DEFINE_INIT_BLEND_FUNC(32, 32) | |
| 648 | 749 | |
| 649 | 750 | void ff_blend_init(FilterParams *param, int depth) |
| 650 | 751 | { |
| @@ -664,15 +765,18 @@ void ff_blend_init(FilterParams *param, int depth) · 13 unmodified lines | ||
| 664 | 765 | case 16: |
| 665 | 766 | init_blend_func_16_16bit(param); |
| 666 | 767 | break; |
| 768 | + case 32: | |
| 769 | + init_blend_func_32_32bit(param); | |
| 770 | + break; | |
| 667 | 771 | } |
| 668 | 772 | |
| 669 | 773 | if (param->opacity == 0 && param->mode != BLEND_NORMAL) { |
| 670 | − param->blend = depth > 8 ? blend_copytop_16 : blend_copytop_8; | |
| 774 | + param->blend = depth > 8 ? depth > 16 ? blend_copytop_32 : blend_copytop_16 : blend_copytop_8; | |
| 671 | 775 | } else if (param->mode == BLEND_NORMAL) { |
| 672 | 776 | if (param->opacity == 1) |
| 673 | − param->blend = depth > 8 ? blend_copytop_16 : blend_copytop_8; | |
| 777 | + param->blend = depth > 8 ? depth > 16 ? blend_copytop_32 : blend_copytop_16 : blend_copytop_8; | |
| 674 | 778 | else if (param->opacity == 0) |
| 675 | − param->blend = depth > 8 ? blend_copybottom_16 : blend_copybottom_8; | |
| 779 | + param->blend = depth > 8 ? depth > 16 ? blend_copybottom_32 : blend_copybottom_16 : blend_copybottom_8; | |
| 676 | 780 | } |
| 677 | 781 | |
| 678 | 782 | if (ARCH_X86) |
| @@ -740,7 +844,7 @@ static int config_output(AVFilterLink *outlink) · 61 unmodified lines | ||
| 740 | 844 | NULL, NULL, NULL, NULL, 0, ctx); |
| 741 | 845 | if (ret < 0) |
| 742 | 846 | return ret; |
| 743 | − param->blend = s->depth > 8 ? blend_expr_16bit : blend_expr_8bit; | |
| 847 | + param->blend = s->depth > 8 ? s->depth > 16 ? blend_expr_32bit : blend_expr_16bit : blend_expr_8bit; | |
| 744 | 848 | } |
| 745 | 849 | } |
| 746 | 850 | |