Revision 9cb5a11e ffplay.c

View differences:

ffplay.c
422 422

  
423 423
#define BPP 1
424 424

  
425
static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect)
425
static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect, int imgw, int imgh)
426 426
{
427 427
    int wrap, wrap3, width2, skip2;
428 428
    int y, u, v, a, u1, v1, a1, w, h;
429 429
    uint8_t *lum, *cb, *cr;
430 430
    const uint8_t *p;
431 431
    const uint32_t *pal;
432

  
433
    lum = dst->data[0] + rect->y * dst->linesize[0];
434
    cb = dst->data[1] + (rect->y >> 1) * dst->linesize[1];
435
    cr = dst->data[2] + (rect->y >> 1) * dst->linesize[2];
436

  
437
    width2 = (rect->w + 1) >> 1;
438
    skip2 = rect->x >> 1;
432
    int dstx, dsty, dstw, dsth;
433

  
434
    dstx = FFMIN(FFMAX(rect->x, 0), imgw);
435
    dstw = FFMIN(FFMAX(rect->w, 0), imgw - dstx);
436
    dsty = FFMIN(FFMAX(rect->y, 0), imgh);
437
    dsth = FFMIN(FFMAX(rect->h, 0), imgh - dsty);
438
    lum = dst->data[0] + dsty * dst->linesize[0];
439
    cb = dst->data[1] + (dsty >> 1) * dst->linesize[1];
440
    cr = dst->data[2] + (dsty >> 1) * dst->linesize[2];
441

  
442
    width2 = (dstw + 1) >> 1;
443
    skip2 = dstx >> 1;
439 444
    wrap = dst->linesize[0];
440 445
    wrap3 = rect->linesize;
441 446
    p = rect->bitmap;
442 447
    pal = rect->rgba_palette;  /* Now in YCrCb! */
443 448

  
444
    if (rect->y & 1) {
445
        lum += rect->x;
449
    if (dsty & 1) {
450
        lum += dstx;
446 451
        cb += skip2;
447 452
        cr += skip2;
448 453

  
449
        if (rect->x & 1) {
454
        if (dstx & 1) {
450 455
            YUVA_IN(y, u, v, a, p, pal);
451 456
            lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
452 457
            cb[0] = ALPHA_BLEND(a >> 2, cb[0], u, 0);
......
456 461
            lum++;
457 462
            p += BPP;
458 463
        }
459
        for(w = rect->w - (rect->x & 1); w >= 2; w -= 2) {
464
        for(w = dstw - (dstx & 1); w >= 2; w -= 2) {
460 465
            YUVA_IN(y, u, v, a, p, pal);
461 466
            u1 = u;
462 467
            v1 = v;
......
481 486
            cb[0] = ALPHA_BLEND(a >> 2, cb[0], u, 0);
482 487
            cr[0] = ALPHA_BLEND(a >> 2, cr[0], v, 0);
483 488
        }
484
        p += wrap3 + (wrap3 - rect->w * BPP);
485
        lum += wrap + (wrap - rect->w - rect->x);
489
        p += wrap3 + (wrap3 - dstw * BPP);
490
        lum += wrap + (wrap - dstw - dstx);
486 491
        cb += dst->linesize[1] - width2 - skip2;
487 492
        cr += dst->linesize[2] - width2 - skip2;
488 493
    }
489
    for(h = rect->h - (rect->y & 1); h >= 2; h -= 2) {
490
        lum += rect->x;
494
    for(h = dsth - (dsty & 1); h >= 2; h -= 2) {
495
        lum += dstx;
491 496
        cb += skip2;
492 497
        cr += skip2;
493 498

  
494
        if (rect->x & 1) {
499
        if (dstx & 1) {
495 500
            YUVA_IN(y, u, v, a, p, pal);
496 501
            u1 = u;
497 502
            v1 = v;
......
511 516
            p += -wrap3 + BPP;
512 517
            lum += -wrap + 1;
513 518
        }
514
        for(w = rect->w - (rect->x & 1); w >= 2; w -= 2) {
519
        for(w = dstw - (dstx & 1); w >= 2; w -= 2) {
515 520
            YUVA_IN(y, u, v, a, p, pal);
516 521
            u1 = u;
517 522
            v1 = v;
......
566 571
            p += -wrap3 + BPP;
567 572
            lum += -wrap + 1;
568 573
        }
569
        p += wrap3 + (wrap3 - rect->w * BPP);
570
        lum += wrap + (wrap - rect->w - rect->x);
574
        p += wrap3 + (wrap3 - dstw * BPP);
575
        lum += wrap + (wrap - dstw - dstx);
571 576
        cb += dst->linesize[1] - width2 - skip2;
572 577
        cr += dst->linesize[2] - width2 - skip2;
573 578
    }
574 579
    /* handle odd height */
575 580
    if (h) {
576
        lum += rect->x;
581
        lum += dstx;
577 582
        cb += skip2;
578 583
        cr += skip2;
579 584

  
580
        if (rect->x & 1) {
585
        if (dstx & 1) {
581 586
            YUVA_IN(y, u, v, a, p, pal);
582 587
            lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
583 588
            cb[0] = ALPHA_BLEND(a >> 2, cb[0], u, 0);
......
587 592
            lum++;
588 593
            p += BPP;
589 594
        }
590
        for(w = rect->w - (rect->x & 1); w >= 2; w -= 2) {
595
        for(w = dstw - (dstx & 1); w >= 2; w -= 2) {
591 596
            YUVA_IN(y, u, v, a, p, pal);
592 597
            u1 = u;
593 598
            v1 = v;
......
705 710
                    pict.linesize[2] = vp->bmp->pitches[1];
706 711

  
707 712
                    for (i = 0; i < sp->sub.num_rects; i++)
708
                        blend_subrect(&pict, &sp->sub.rects[i]);
713
                        blend_subrect(&pict, &sp->sub.rects[i],
714
                                      vp->bmp->w, vp->bmp->h);
709 715

  
710 716
                    SDL_UnlockYUVOverlay (vp->bmp);
711 717
                }

Also available in: Unified diff