[FFmpeg-devel] [PATCH] libopenjpeg: support decoding with bits per pixel greater than 8

Alex Zhukov zhukov.alex at gmail.com
Thu Dec 22 22:34:43 CET 2011


On Thu, Dec 22, 2011 at 1:26 PM, Jean First <jeanfirst at gmail.com> wrote:
>
> > lets see what the code path would be for PIX_FMT_RGB24
> > in check_image_attributes
> > the compRatio should be anything but 0111111/0112121/0112222, which means
> > non-equal component size rgb24 (haven't heard of one yet)
> >
> > or if it's equal component size - precision is checked to be 8 to return
> > rgb24:
> >     switch (c0.prec) {
> >     case 8:  return PIX_FMT_RGB24;
> >
> > i'm fine with applying the patch, there's nothing wrong with it, but to me
> > it's a bit of premature optimization.
> > isnt it mostly a matter of taste?
> > to my taste i'd just wait to see if someone finds an example where error is
> > triggered.
> >
> > On Thu, Dec 22, 2011 at 10:27 AM, Jean First <jeanfirst at gmail.com> wrote:
> >
> > > On Wed Dec 21 21:26:45 2011, Alex Zhukov wrote:
> > >
> > >> from the top of my head: copyto8 expects the 8bit precision therefore no
> > >> ">>adjust" should be needed
> > >> can you provide an example video where this is not the case?
> > >>
> > >> On Wed, Dec 21, 2011 at 5:33 AM, Jean First<jeanfirst at gmail.com>  wrote:
> > >>
> > >>  Hi,
> > >>>
> > >>> attached patch fixes a regression introduced with commit eb511ef6.
> > >>> maybe libopenjpeg_copyto8 and libopenjpeg_copyto16 need this fix too.
> > >>>  Alex Zhukov, can you please check this ?
> > >>>
> > >>> Jean
> > >>>
> > >>> ---
> > >>>
> > >>
> > > Hi Alex,
> > > No atm not. I suggest to apply the patch until we have a sample that
> > > triggers the error.
> > > Jean
>
> Well it's not an optimisation - it is a fix for a regression. We might wait
> a long time for that sample - in the meantime this is fixed.
>
> I added PIX_FMT_48 decoding, although the conversion from <16 bit to 16 bit
> might not be the best solution. Everything above 8 bit will be treated as
> 16 bit.
>
> And should I start top posting - or will you start bottom posting ;)
>
> Jean
>
> ---
>  libavcodec/libopenjpegdec.c |   32 +++++++++++++++++++++++++++++++-
>  1 files changed, 31 insertions(+), 1 deletions(-)
>
> diff --git a/libavcodec/libopenjpegdec.c b/libavcodec/libopenjpegdec.c
> index baa516b..1f904da 100644
> --- a/libavcodec/libopenjpegdec.c
> +++ b/libavcodec/libopenjpegdec.c
> @@ -54,7 +54,7 @@ static enum PixelFormat check_image_attributes(AVCodecContext *avctx, opj_image_
>     case 0111111: goto libopenjpeg_yuv444_rgb;
>     case 0112121: goto libopenjpeg_yuv422;
>     case 0112222: goto libopenjpeg_yuv420;
> -    default: return PIX_FMT_RGB24;
> +    default: goto libopenjpeg_rgb;
>     }
>
>  libopenjpeg_yuv420:
> @@ -80,6 +80,13 @@ libopenjpeg_yuv444_rgb:
>     case 10: return PIX_FMT_YUV444P10;
>     case 16: return PIX_FMT_YUV444P16;
>     }
> +
> +libopenjpeg_rgb:
> +    switch (c0.prec) {
> +    case 8: return PIX_FMT_RGB24;
> +    default: return PIX_FMT_RGB48;
> +    }
> +
>     return PIX_FMT_RGB24;
>  }
>
> @@ -107,6 +114,24 @@ static inline void libopenjpeg_copy_to_packed8(AVFrame *picture, opj_image_t *im
>     }
>  }
>
> +static inline void libopenjpeg_copy_to_packed16(AVFrame *picture, opj_image_t *image) {
> +    uint16_t *img_ptr;
> +    int index, x, y, c;
> +    int adjust[4];
> +    for (x = 0; x < image->numcomps; x++) {
> +        adjust[x] = FFMAX(FFMIN(16 - image->comps[x].prec, 8), 0);
> +    }
> +    for (y = 0; y < picture->height; y++) {
> +        index = y*picture->width;
> +        img_ptr = (uint16_t*) (picture->data[0] + y*picture->linesize[0]);
> +        for (x = 0; x < picture->width; x++, index++) {
> +            for (c = 0; c < image->numcomps; c++) {
> +                *img_ptr++ = image->comps[c].data[index] << adjust[c];
> +            }
> +        }
> +    }
> +}
> +
>  static inline void libopenjpeg_copyto8(AVFrame *picture, opj_image_t *image) {
>     int *comp_data;
>     uint8_t *img_ptr;
> @@ -277,6 +302,11 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
>             libopenjpeg_copy_to_packed8(picture, image);
>         }
>         break;
> +    case 6:
> +        if (ispacked) {
> +            libopenjpeg_copy_to_packed16(picture, image);
> +        }
> +        break;
>     default:
>         av_log(avctx, AV_LOG_ERROR, "unsupported pixel size %d\n", pixel_size);
>         goto done;
> --
> 1.7.6.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

bottom posting
good point :)
re patch - ok


More information about the ffmpeg-devel mailing list