| 485 | } |
| 486 | |
| 487 | static hb_buffer_t * compose_subsample_ass(hb_filter_private_t *pv, const ASS_Image *frame_list, |
| 488 | const unsigned width, const unsigned height, |
| 489 | const unsigned x, const unsigned y) |
| 490 | { |
| 491 | const ASS_Image *frame = frame_list; |
| 492 | const unsigned flat_stride = width << 2; |
| 493 | uint8_t *compo = calloc(flat_stride * height, sizeof(uint8_t)); |
| 494 | |
| 495 | if (!compo) |
| 496 | { |
| 497 | return NULL; |
| 498 | } |
| 499 | |
| 500 | while (frame) |
| 501 | { |
| 502 | if (frame->w && frame->h && |
| 503 | x <= frame->dst_x && x + width >= frame->dst_x + frame->w && |
| 504 | y <= frame->dst_y && y + height >= frame->dst_y + frame->h) |
| 505 | { |
| 506 | const int yuv = pv->rgb2yuv_fn(frame->color >> 8); |
| 507 | |
| 508 | const unsigned frame_y = (yuv >> 16) & 0xff; |
| 509 | const unsigned frame_v = (yuv >> 8 ) & 0xff; |
| 510 | const unsigned frame_u = (yuv >> 0 ) & 0xff; |
| 511 | unsigned frame_a, res_alpha, alpha_compo, alpha_in_scaled; |
| 512 | |
| 513 | const unsigned ini_fx = (frame->dst_x - x) * 4 + (frame->dst_y - y) * flat_stride; |
| 514 | |
| 515 | for (int yy = 0, fx = ini_fx; yy < frame->h; yy++, fx = ini_fx + yy * flat_stride) |
| 516 | { |
| 517 | for (int xx = 0; xx < frame->w; xx++, fx += 4) |
| 518 | { |
| 519 | frame_a = ssa_alpha(frame, xx, yy); |
| 520 | |
| 521 | // Skip if transparent |
| 522 | if (frame_a) |
| 523 | { |
| 524 | if (compo[fx+3]) |
| 525 | { |
| 526 | alpha_in_scaled = frame_a * 255; |
| 527 | alpha_compo = compo[fx+3] * (255 - frame_a); |
| 528 | res_alpha = (alpha_in_scaled + alpha_compo); |
| 529 | |
| 530 | compo[fx ] = ALPHA_BLEND(alpha_in_scaled, frame_y, alpha_compo, compo[fx ], res_alpha); |
| 531 | compo[fx+1] = ALPHA_BLEND(alpha_in_scaled, frame_u, alpha_compo, compo[fx+1], res_alpha); |
| 532 | compo[fx+2] = ALPHA_BLEND(alpha_in_scaled, frame_v, alpha_compo, compo[fx+2], res_alpha); |
| 533 | compo[fx+3] = div255(res_alpha); |
| 534 | } |
| 535 | else |
| 536 | { |
| 537 | compo[fx ] = frame_y; |
| 538 | compo[fx+1] = frame_u; |
| 539 | compo[fx+2] = frame_v; |
| 540 | compo[fx+3] = frame_a; |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 | } |
no test coverage detected