[FFmpeg-devel] [PATCH] libopenjpeg wrapper for jpeg2k decoding

Jai Menon jmenon86
Wed Jan 28 06:54:47 CET 2009


Hi,

On Wed, Jan 28, 2009 at 12:26 AM, Michael Niedermayer <michaelni at gmx.at> wrote:
> 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

sorry again. cleaned up all tabs now ( i think :-) )

>> +    if (avcodec_check_dimensions(avctx, width, height) < 0) {
>> +        av_log(avctx, AV_LOG_ERROR, "%dx%d dimension invalid \n", width, height);
>
>> +        ret = -1;
>
> unneded

yes, missed that one. removed.
revised patch attached.

I guess there are no comments for the configure/makefile
modifications. Should I assume that part
is ok?

> [...]
> 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

After this is accepted, I wanted to send a patch for correct decoding
of jp2 frames in r3d files.
Those frames use 4 components but are interpreted as Y1, Cb, Cr, Y2
instead rgba. So till this
modification is done, r3d files will appear weird :-)
How would you like it done? Do you prefer a new codec id or can I just
differentiate between the two
using the codec_tag field?

-- 
Regards,

Jai
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libopenjpeg_wrapper.patch
Type: text/x-patch
Size: 11669 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090128/bfd9a43e/attachment.bin>



More information about the ffmpeg-devel mailing list