On Thu, Jul 19, 2012 at 03:41:11AM +0200, Luca Barbato wrote: > From: Michael Bradshaw <mbrads...@sorensonmedia.com> > > Based on FFmpeg version from > commit 3275981207e30e140cffaea334ac390f1a04266a > --- > libavcodec/libopenjpegdec.c | 305 > +++++++++++++++++++++++++++++++++++-------- > 1 files changed, 250 insertions(+), 55 deletions(-) > > diff --git a/libavcodec/libopenjpegdec.c b/libavcodec/libopenjpegdec.c > index 799ccd7..1c08f8a 100644 > --- a/libavcodec/libopenjpegdec.c > +++ b/libavcodec/libopenjpegdec.c > @@ -24,29 +24,200 @@ > * JPEG 2000 decoder using libopenjpeg > */ > > +#define OPJ_STATIC > +#include <openjpeg.h> > + > +#include "libavutil/intreadwrite.h" > #include "libavutil/imgutils.h" > +#include "libavutil/pixfmt.h" > +#include "libavutil/opt.h" > #include "avcodec.h" > -#include "libavutil/intreadwrite.h" > #include "thread.h" > -#define OPJ_STATIC > -#include <openjpeg.h> > > #define JP2_SIG_TYPE 0x6A502020 > #define JP2_SIG_VALUE 0x0D0A870A > > +// pix_fmts with lower bpp have to be listed before > +// similar pix_fmts with higher bpp. > +#define RGB_PIXEL_FORMATS PIX_FMT_RGB24, PIX_FMT_RGBA, \ > + PIX_FMT_RGB48 > + > +#define GRAY_PIXEL_FORMATS PIX_FMT_GRAY8, PIX_FMT_Y400A, \ > + PIX_FMT_GRAY16 > + > +#define YUV_PIXEL_FORMATS PIX_FMT_YUV410P, PIX_FMT_YUV411P, \ > + PIX_FMT_YUVA420P, \ > + PIX_FMT_YUV420P, PIX_FMT_YUV422P, \ > + PIX_FMT_YUV440P, PIX_FMT_YUV444P, \ > + PIX_FMT_YUV420P9, PIX_FMT_YUV422P9, \ > + PIX_FMT_YUV444P9, \ > + PIX_FMT_YUV420P10, PIX_FMT_YUV422P10, \ > + PIX_FMT_YUV444P10, \ > + PIX_FMT_YUV420P16, PIX_FMT_YUV422P16, \ > + PIX_FMT_YUV444P16 > + > +static const enum PixelFormat rgb_pix_fmts[] = {RGB_PIXEL_FORMATS}; > +static const enum PixelFormat gray_pix_fmts[] = {GRAY_PIXEL_FORMATS}; > +static const enum PixelFormat yuv_pix_fmts[] = {YUV_PIXEL_FORMATS}; > +static const enum PixelFormat any_pix_fmts[] = {RGB_PIXEL_FORMATS, > + GRAY_PIXEL_FORMATS, > + YUV_PIXEL_FORMATS}; > + > typedef struct { > opj_dparameters_t dec_params; > AVFrame image; > } LibOpenJPEGContext; > > -static int check_image_attributes(opj_image_t *image) > +static inline int libopenjpeg_matches_pix_fmt(const opj_image_t *image, > + enum PixelFormat pix_fmt) > +{ > + AVPixFmtDescriptor descriptor = av_pix_fmt_descriptors[pix_fmt]; > + int match = 1; > + > + if (descriptor.nb_components != image->numcomps) { > + return 0; > + } > + > + switch (descriptor.nb_components) { > + case 4: match = match && descriptor.comp[3].depth_minus1 + 1 >= > image->comps[3].prec && > + 1 == image->comps[3].dx && > + 1 == image->comps[3].dy; > + case 3: match = match && descriptor.comp[2].depth_minus1 + 1 >= > image->comps[2].prec && > + 1 << descriptor.log2_chroma_w == > image->comps[2].dx && > + 1 << descriptor.log2_chroma_h == > image->comps[2].dy; > + case 2: match = match && descriptor.comp[1].depth_minus1 + 1 >= > image->comps[1].prec && > + 1 << descriptor.log2_chroma_w == > image->comps[1].dx && > + 1 << descriptor.log2_chroma_h == > image->comps[1].dy; > + case 1: match = match && descriptor.comp[0].depth_minus1 + 1 >= > image->comps[0].prec && > + 1 == image->comps[0].dx && > + 1 == image->comps[0].dy; > + default: > + break; > + }
we have loops for that, Duff's devices are not needed but in general patch looks passable _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel