[FFmpeg-devel] [PATCH]Basic XSUB encoder (take 2)

Reimar Döffinger Reimar.Doeffinger
Tue Feb 3 10:29:19 CET 2009


On Tue, Feb 03, 2009 at 12:12:54AM +0100, Reimar D?ffinger wrote:
> You should try to handle the margin case somehow nicer.
> E.g.
> >    for (y = 0; y < h; y++) {
> >        x = 0;
> >        while (x < w) {
> >            x1 = x;
> >            color = bitmap[x1++] & 3;
> >            while (x1 < w && (bitmap[x1] & 3) == color) x1++;
> >            len = x1 - x;
> >            if (x == 0) {
> >                if (color == MARGIN_COLOR) len += MARGIN;
> >                else put_xsub_rle(&pb, MARGIN, MARGIN_COLOR);
> >            }
> >            // Run can't be longer than 255, unless it is the rest of a row
> >            if (x1 == w && color == MARGIN_COLOR) len += MARGIN;
> >            else len = FFMIN(len, 255);
> >            put_xsub_rle(&pb, len, color);
> >            x += len;
> >        }
> >        if (color != MARGIN_COLOR)
> >            put_xsub_rle(&pb, MARGIN + odd, MARGIN_COLOR);

Sorry, here
> >            else len = FFMIN(len, 255);
> >            put_xsub_rle(&pb, len, color);
> >            x += len;

should be

> else if (len > 255) {
>     x1 -= len - 255;
>     len = 255;
> }
> put_xsub_rle(&pb, len, color);
> x = x1;

(and yes I know that's almost how the code was originally).
Also replacing "color == MARGIN_COLOR" by "color == MARGIN_COLOR || !MARGIN"
and "color != MARGIN_COLOR" by "color != MARGIN_COLORi && MARGIN"
you can also support MARGIN == 0.




More information about the ffmpeg-devel mailing list