[FFmpeg-devel] [PATCH]Fix 1bpp palettized png with width not a multiple of 8

Michael Niedermayer michaelni at gmx.at
Wed Jan 30 00:25:47 CET 2013


On Wed, Jan 30, 2013 at 12:20:07AM +0100, Carl Eugen Hoyos wrote:
> On Tuesday 29 January 2013 03:23:12 pm Michael Niedermayer wrote:
> > > +++ b/libavcodec/pngdec.c
> > > @@ -768,7 +768,15 @@ static int decode_frame(AVCodecContext *avctx,
> > >          int i, j;
> > >          uint8_t *pd = s->current_picture->data[0];
> > >          for (j = 0; j < s->height; j++) {
> > > +            i = s->width / 8;
> > > +            if ((s->width&7) >= 7) pd[8*i + 6] = (pd[i]>>1) & 1;
> > > +            if ((s->width&7) >= 6) pd[8*i + 5] = (pd[i]>>2) & 1;
> > > +            if ((s->width&7) >= 5) pd[8*i + 4] = (pd[i]>>3) & 1;
> > > +            if ((s->width&7) >= 4) pd[8*i + 3] = (pd[i]>>4) & 1;
> > > +            if ((s->width&7) >= 3) pd[8*i + 2] = (pd[i]>>5) & 1;
> > > +            if ((s->width&7) >= 2) pd[8*i + 1] = (pd[i]>>6) & 1;
> > > +            if ((s->width&7) >= 1) pd[8*i + 0] =  pd[i]>>7;
> >
> > should be ok if it works
> > alternatively this maybe could be simplified with a loop
> 
> New patch attached.
> 
> Please review, Carl Eugen

>  pngdec.c |    8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 48a94fb79cb98324fd4f9695d61b8426b092004f  patchpngpal1bpp2.diff
> diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
> index 593df60..97c0ad1 100644
> --- a/libavcodec/pngdec.c
> +++ b/libavcodec/pngdec.c
> @@ -765,10 +765,14 @@ static int decode_frame(AVCodecContext *avctx,
>   exit_loop:
>  
>      if (s->bits_per_pixel == 1 && s->color_type == PNG_COLOR_TYPE_PALETTE){
> -        int i, j;
> +        int i, j, k;
>          uint8_t *pd = s->current_picture->data[0];
>          for (j = 0; j < s->height; j++) {
> -            for (i = s->width/8-1; i >= 0; i--) {
> +            i = s->width / 8;
> +            for (k = 7; k >= 1; k--)
> +                if ((s->width&7) >= k)
> +                    pd[8*i + k - 1] = (pd[i]>>8-k) & 1;
> +            for (i--; i >= 0; i--) {

LGTM if it works

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

There will always be a question for which you do not know the correct answer.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130130/92038dab/attachment.asc>


More information about the ffmpeg-devel mailing list