[FFmpeg-devel] [PATCH] libopenjpeg wrapper for jpeg2k decoding
Michael Niedermayer
michaelni
Tue Jan 27 19:56:57 CET 2009
On Tue, Jan 27, 2009 at 05:12:31PM +0530, Jai Menon wrote:
> Hi,
>
> On Tue, Jan 27, 2009 at 4:52 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
> > On Tue, Jan 27, 2009 at 10:26:19AM +0530, Jai Menon wrote:
[...]
> > [...]
> >> + switch(image->numcomps)
> >> + {
> >> + case 1: avctx->pix_fmt = PIX_FMT_GRAY8;
> >> + break;
> >
> > the { should likely be on the same line as the switch and case and
> > switch should not be indented relative to each other.
> > Anyway this is just a suggestion, not important if you dislike it
>
> can i keep it this way? :-)
> its easier on my eyes.
ok
[...]
> +static int libopenjpeg_decode_frame(AVCodecContext *avctx,
> + void *data, int *data_size,
> + const uint8_t *buf, int buf_size)
> +{
> + LibOpenJPEGContext *ctx = avctx->priv_data;
> + AVPicture *picture = data;
> + opj_dinfo_t *dec = NULL;
> + opj_cio_t *stream = NULL;
> + opj_image_t *image = NULL;
> + int width, height, has_alpha = 0, ret = -1;
> + int x, y, index;
> + int picture_size;
> + uint8_t *img_ptr;
> + float scale;
> +
> + *data_size = 0;
> +
> + // Check if input is a raw jpeg2k codestream or in jp2 wrapping
> + if((AV_RB32(buf) == 12) && (AV_RB32(buf + 4) == JP2_SIG_TYPE)
> + && (AV_RB32(buf + 8) == JP2_SIG_VALUE))
> + dec = opj_create_decompress(CODEC_JP2);
> + else dec = opj_create_decompress(CODEC_J2K);
> +
> + if(!dec) {
> + av_log (avctx, AV_LOG_ERROR, "Error initializing decoder\n");
> + return -1;
> + }
> + opj_set_event_mgr((opj_common_ptr)dec, NULL, NULL);
> + // Tie decoder with decoding parameters
> + opj_setup_decoder(dec, &ctx->dec_params);
> + stream = opj_cio_open((opj_common_ptr)dec, buf, buf_size);
> + if(!stream) {
> + av_log (avctx, AV_LOG_ERROR, "Codestream could not be opened for reading\n");
> + opj_destroy_decompress(dec);
> + return -1;
> + }
> + // Decode the codestream
> + image = opj_decode_with_info(dec, stream, NULL);
> + opj_cio_close(stream);
> + if(!image) {
> + av_log (avctx, AV_LOG_ERROR, "Error decoding codestream\n");
> + opj_destroy_decompress(dec);
> + return -1;
> + }
> + width = image->comps[0].w;
> + height = image->comps[0].h;
tab
grep ' ' in the file will tell you if there are more
> + if (avcodec_check_dimensions(avctx, width, height) < 0) {
> + av_log(avctx, AV_LOG_ERROR, "%dx%d dimension invalid \n", width, height);
> + ret = -1;
unneded
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Into a blind darkness they enter who follow after the Ignorance,
they as if into a greater darkness enter who devote themselves
to the Knowledge alone. -- Isha Upanishad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090127/9523286e/attachment.pgp>
More information about the ffmpeg-devel
mailing list