Ticket #3302: 0001-Issue-3302-fix-WIP.patch

File 0001-Issue-3302-fix-WIP.patch, 5.2 KB (added by Andrey Utkin, 12 years ago)
  • libavfilter/drawutils.c

    From 71f4c72692a6c21b9f41273f93ecc97f0d595812 Mon Sep 17 00:00:00 2001
    From: Andrey Utkin <andrey.krieger.utkin@gmail.com>
    Date: Fri, 20 Jun 2014 20:28:55 +0300
    Subject: [PATCH] Issue #3302 fix WIP
    
    ---
     libavfilter/drawutils.c | 30 ++++++++++++++++++++----------
     1 file changed, 20 insertions(+), 10 deletions(-)
    
    diff --git a/libavfilter/drawutils.c b/libavfilter/drawutils.c
    index 4437c2c..8b6a738 100644
    a b int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)  
    182182    memcpy(draw->pixelstep, pixelstep, sizeof(draw->pixelstep));
    183183    draw->hsub[1] = draw->hsub[2] = draw->hsub_max = desc->log2_chroma_w;
    184184    draw->vsub[1] = draw->vsub[2] = draw->vsub_max = desc->log2_chroma_h;
    185     for (i = 0; i < ((desc->nb_components - 1) | 1); i++)
     185    for (i = 0; i < desc->nb_components; i++)
    186186        draw->comp_mask[desc->comp[i].plane] |=
    187187            1 << (desc->comp[i].offset_plus1 - 1);
    188188    return 0;
    void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color,  
    397397
    398398static void blend_pixel(uint8_t *dst, unsigned src, unsigned alpha,
    399399                        uint8_t *mask, int mask_linesize, int l2depth,
    400                         unsigned w, unsigned h, unsigned shift, unsigned xm0)
     400                        unsigned w, unsigned h, unsigned shift, unsigned xm0, int strategy)
    401401{
     402    if (strategy == 1) {
     403        /* Reverting expression: alpha = (0x10307 * color->rgba[3] + 0x3) >> 8 */
     404        *dst = ((alpha << 8) - 0x3) / 0x10307;
     405        return;
     406    }
    402407    unsigned xm, x, y, t = 0;
    403408    unsigned xmshf = 3 - l2depth;
    404409    unsigned xmmod = 7 >> l2depth;
    static void blend_line_hv(uint8_t *dst, int dst_delta,  
    422427                          unsigned src, unsigned alpha,
    423428                          uint8_t *mask, int mask_linesize, int l2depth, int w,
    424429                          unsigned hsub, unsigned vsub,
    425                           int xm, int left, int right, int hband)
     430                          int xm, int left, int right, int hband, int strategy)
    426431{
    427432    int x;
    428433
    429434    if (left) {
    430435        blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
    431                     left, hband, hsub + vsub, xm);
     436                    left, hband, hsub + vsub, xm, strategy);
    432437        dst += dst_delta;
    433438        xm += left;
    434439    }
    435440    for (x = 0; x < w; x++) {
    436441        blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
    437                     1 << hsub, hband, hsub + vsub, xm);
     442                    1 << hsub, hband, hsub + vsub, xm, strategy);
    438443        dst += dst_delta;
    439444        xm += 1 << hsub;
    440445    }
    441446    if (right)
    442447        blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
    443                     right, hband, hsub + vsub, xm);
     448                    right, hband, hsub + vsub, xm, strategy);
    444449}
    445450
    446451void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color,
    447452                   uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h,
    448453                   uint8_t *mask,  int mask_linesize, int mask_w, int mask_h,
    449                    int l2depth, unsigned endianness, int x0, int y0)
     454                   int l2depth, unsigned endianness, int x0, int y0 /* TODO , int strategy */)
    450455{
    451456    unsigned alpha, nb_planes, nb_comp, plane, comp;
    452457    int xm0, ym0, w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
    void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color,  
    475480                continue;
    476481            p = p0 + comp;
    477482            m = mask;
     483            /* Treat alpha component specially. TODO Support more cases */
     484            int strategy = 0 /* use existing algorithm */;
     485            if (draw->format == AV_PIX_FMT_RGBA && comp == 3)
     486                strategy = 1 /* just set *dst to alpha */;
     487
    478488            if (top) {
    479489                blend_line_hv(p, draw->pixelstep[plane],
    480490                              color->comp[plane].u8[comp], alpha,
    481491                              m, mask_linesize, l2depth, w_sub,
    482492                              draw->hsub[plane], draw->vsub[plane],
    483                               xm0, left, right, top);
     493                              xm0, left, right, top, strategy);
    484494                p += dst_linesize[plane];
    485495                m += top * mask_linesize;
    486496            }
    void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color,  
    489499                              color->comp[plane].u8[comp], alpha,
    490500                              m, mask_linesize, l2depth, w_sub,
    491501                              draw->hsub[plane], draw->vsub[plane],
    492                               xm0, left, right, 1 << draw->vsub[plane]);
     502                              xm0, left, right, 1 << draw->vsub[plane], strategy);
    493503                p += dst_linesize[plane];
    494504                m += mask_linesize << draw->vsub[plane];
    495505            }
    void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color,  
    498508                              color->comp[plane].u8[comp], alpha,
    499509                              m, mask_linesize, l2depth, w_sub,
    500510                              draw->hsub[plane], draw->vsub[plane],
    501                               xm0, left, right, bottom);
     511                              xm0, left, right, bottom, strategy);
    502512        }
    503513    }
    504514}