Ticket #2304: bmovl-stride.patch

File bmovl-stride.patch, 3.4 KB (added by floemker, 10 years ago)

Patch to fix incorrect accessing of the local image in the bmovl filter.

  • libmpcodecs/vf_bmovl.c

    old new put_image(struct vf_instance *vf, mp_ima  
    328328                                        memset( vf->priv->bitmap.a  + (ypos*vf->priv->w) + imgx, 0, imgw );
    329329                                        memset( vf->priv->bitmap.oa + (ypos*vf->priv->w) + imgx, 0, imgw );
    330330                                        if(ypos%2) {
    331                                                 memset( vf->priv->bitmap.u + ((ypos/2)*dmpi->stride[1]) + (imgx/2), 128, imgw/2 );
    332                                                 memset( vf->priv->bitmap.v + ((ypos/2)*dmpi->stride[2]) + (imgx/2), 128, imgw/2 );
     331                                                memset( vf->priv->bitmap.u + ((ypos/2)*vf->priv->w) + (imgx/2), 128, imgw/2 );
     332                                                memset( vf->priv->bitmap.v + ((ypos/2)*vf->priv->w) + (imgx/2), 128, imgw/2 );
    333333                                        }
    334334                                }       // Recalculate area that contains graphics
    335335                                if( (imgx <= vf->priv->x1) && ( (imgw+imgx) >= vf->priv->x2) ) {
    put_image(struct vf_instance *vf, mp_ima  
    389389                                                vf->priv->bitmap.oa[pos] = alpha;
    390390                                                vf->priv->bitmap.a[pos]  = INRANGE((alpha+imgalpha),0,255);
    391391                                                if((buf_y%2) && ((buf_x/pxsz)%2)) {
    392                                                         pos = ( ((buf_y+imgy)/2) * dmpi->stride[1] ) + (((buf_x/pxsz)+imgx)/2);
     392                                                        pos = ( ((buf_y+imgy)/2) * vf->priv->w ) + (((buf_x/pxsz)+imgx)/2);
    393393                                                        vf->priv->bitmap.u[pos] = rgb2u(red,green,blue);
    394394                                                        vf->priv->bitmap.v[pos] = rgb2v(red,green,blue);
    395395                                                }
    put_image(struct vf_instance *vf, mp_ima  
    421421        } else { // Blit the bitmap to the videoscreen, pixel for pixel
    422422            for( ypos=vf->priv->y1 ; ypos < vf->priv->y2 ; ypos++ ) {
    423423                for ( xpos=vf->priv->x1 ; xpos < vf->priv->x2 ; xpos++ ) {
    424                                 pos = (ypos * dmpi->stride[0]) + xpos;
     424                                int s = ypos * vf->priv->w + xpos;
     425                                int d = ypos * dmpi->stride[0] + xpos;
    425426
    426                                 alpha = vf->priv->bitmap.a[pos];
     427                                alpha = vf->priv->bitmap.a[s];
    427428
    428429                                if (alpha == 0) continue; // Completly transparent pixel
    429430
    430431                                if (alpha == 255) {     // Opaque pixel
    431                                         dmpi->planes[0][pos] = vf->priv->bitmap.y[pos];
     432                                        dmpi->planes[0][d] = vf->priv->bitmap.y[s];
    432433                                        if ((ypos%2) && (xpos%2)) {
    433                                                 pos = ( (ypos/2) * dmpi->stride[1] ) + (xpos/2);
    434                                                 dmpi->planes[1][pos] = vf->priv->bitmap.u[pos];
    435                                                 dmpi->planes[2][pos] = vf->priv->bitmap.v[pos];
     434                                                s = (ypos/2) * vf->priv->w + xpos/2;
     435                                                d = (ypos/2) * dmpi->stride[1] + xpos/2;
     436                                                dmpi->planes[1][d] = vf->priv->bitmap.u[s];
     437                                                dmpi->planes[2][d] = vf->priv->bitmap.v[s];
    436438                                        }
    437439                                } else { // Alphablended pixel
    438                                         dmpi->planes[0][pos] =
    439                                                 ((255 - alpha) * (int)dmpi->planes[0][pos] +
    440                                                 alpha * (int)vf->priv->bitmap.y[pos]) >> 8;
     440                                        dmpi->planes[0][d] =
     441                                                ((255 - alpha) * (int)dmpi->planes[0][d] +
     442                                                alpha * (int)vf->priv->bitmap.y[s]) >> 8;
    441443
    442444                                        if ((ypos%2) && (xpos%2)) {
    443                                                 pos = ( (ypos/2) * dmpi->stride[1] ) + (xpos/2);
    444 
    445                                                 dmpi->planes[1][pos] =
    446                                                         ((255 - alpha) * (int)dmpi->planes[1][pos] +
    447                                                         alpha * (int)vf->priv->bitmap.u[pos]) >> 8;
    448 
    449                                                 dmpi->planes[2][pos] =
    450                                                         ((255 - alpha) * (int)dmpi->planes[2][pos] +
    451                                                         alpha * (int)vf->priv->bitmap.v[pos]) >> 8;
     445                                                s = (ypos/2) * vf->priv->w + xpos/2;
     446                                                d = (ypos/2) * dmpi->stride[1] + xpos/2;
     447                                                dmpi->planes[1][d] =
     448                                                        ((255 - alpha) * (int)dmpi->planes[1][d] +
     449                                                        alpha * (int)vf->priv->bitmap.u[s]) >> 8;
     450                                                dmpi->planes[2][d] =
     451                                                        ((255 - alpha) * (int)dmpi->planes[2][d] +
     452                                                        alpha * (int)vf->priv->bitmap.v[s]) >> 8;
    452453                                        }
    453454                            }
    454455                        } // for xpos