annotate libopenjpeg.c @ 11102:3b135f70c097 libavcodec

Remove an apparently unneeded && !FRAME_MBAFF. This should speed the affected cases (MBAFF temporal direct MBs) up.
author michael
date Mon, 08 Feb 2010 04:24:50 +0000
parents adf750125dc9
children 8a4984c5cacc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8747
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
1 /*
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
2 * JPEG 2000 decoding support via OpenJPEG
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
3 * Copyright (c) 2009 Jaikrishnan Menon <realityman@gmx.net>
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
4 *
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
5 * This file is part of FFmpeg.
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
6 *
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
11 *
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
15 * Lesser General Public License for more details.
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
16 *
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
20 */
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
21
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
22 /**
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
23 * @file libavcodec/libopenjpeg.c
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
24 * JPEG 2000 decoder using libopenjpeg
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
25 */
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
26
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
27 #include "avcodec.h"
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
28 #include "libavutil/intreadwrite.h"
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
29 #define OPJ_STATIC
8787
9575568668c4 Use default system include path for an installed OpenJPEG library.
diego
parents: 8747
diff changeset
30 #include <openjpeg.h>
8747
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
31
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
32 #define JP2_SIG_TYPE 0x6A502020
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
33 #define JP2_SIG_VALUE 0x0D0A870A
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
34
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
35 typedef struct {
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
36 opj_dparameters_t dec_params;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
37 AVFrame image;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
38 } LibOpenJPEGContext;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
39
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
40 static int check_image_attributes(opj_image_t *image)
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
41 {
10436
a050e8857f00 cosmetics: Remove pointless parentheses from return statement.
diego
parents: 9804
diff changeset
42 return image->comps[0].dx == image->comps[1].dx &&
8747
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
43 image->comps[1].dx == image->comps[2].dx &&
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
44 image->comps[0].dy == image->comps[1].dy &&
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
45 image->comps[1].dy == image->comps[2].dy &&
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
46 image->comps[0].prec == image->comps[1].prec &&
10436
a050e8857f00 cosmetics: Remove pointless parentheses from return statement.
diego
parents: 9804
diff changeset
47 image->comps[1].prec == image->comps[2].prec;
8747
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
48 }
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
49
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
50 static av_cold int libopenjpeg_decode_init(AVCodecContext *avctx)
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
51 {
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
52 LibOpenJPEGContext *ctx = avctx->priv_data;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
53
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
54 opj_set_default_decoder_parameters(&ctx->dec_params);
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
55 avctx->coded_frame = &ctx->image;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
56 return 0;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
57 }
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
58
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
59 static int libopenjpeg_decode_frame(AVCodecContext *avctx,
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
60 void *data, int *data_size,
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8787
diff changeset
61 AVPacket *avpkt)
8747
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
62 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8787
diff changeset
63 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8787
diff changeset
64 int buf_size = avpkt->size;
8747
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
65 LibOpenJPEGContext *ctx = avctx->priv_data;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
66 AVFrame *picture = &ctx->image, *output = data;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
67 opj_dinfo_t *dec;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
68 opj_cio_t *stream;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
69 opj_image_t *image;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
70 int width, height, has_alpha = 0, ret = -1;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
71 int x, y, index;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
72 uint8_t *img_ptr;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
73 int adjust[4];
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
74
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
75 *data_size = 0;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
76
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
77 // Check if input is a raw jpeg2k codestream or in jp2 wrapping
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
78 if((AV_RB32(buf) == 12) &&
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
79 (AV_RB32(buf + 4) == JP2_SIG_TYPE) &&
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
80 (AV_RB32(buf + 8) == JP2_SIG_VALUE)) {
10507
ca71c924b65f cosmetics : fix indentation.
jai_menon
parents: 10436
diff changeset
81 dec = opj_create_decompress(CODEC_JP2);
8747
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
82 } else {
10508
f33404f82b9e Handle JPEG2000 frames stored in the Quicktime container.
jai_menon
parents: 10507
diff changeset
83 // If the AVPacket contains a jp2c box, then skip to
f33404f82b9e Handle JPEG2000 frames stored in the Quicktime container.
jai_menon
parents: 10507
diff changeset
84 // the starting byte of the codestream.
f33404f82b9e Handle JPEG2000 frames stored in the Quicktime container.
jai_menon
parents: 10507
diff changeset
85 if (AV_RB32(buf + 4) == AV_RB32("jp2c"))
f33404f82b9e Handle JPEG2000 frames stored in the Quicktime container.
jai_menon
parents: 10507
diff changeset
86 buf += 8;
10507
ca71c924b65f cosmetics : fix indentation.
jai_menon
parents: 10436
diff changeset
87 dec = opj_create_decompress(CODEC_J2K);
8747
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
88 }
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
89
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
90 if(!dec) {
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
91 av_log(avctx, AV_LOG_ERROR, "Error initializing decoder.\n");
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
92 return -1;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
93 }
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
94 opj_set_event_mgr((opj_common_ptr)dec, NULL, NULL);
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
95
9715
997d2de9cd84 Add lowres support to the libopenjpeg wrapper.
jai_menon
parents: 9714
diff changeset
96 ctx->dec_params.cp_reduce = avctx->lowres;
8747
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
97 // Tie decoder with decoding parameters
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
98 opj_setup_decoder(dec, &ctx->dec_params);
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
99 stream = opj_cio_open((opj_common_ptr)dec, buf, buf_size);
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
100 if(!stream) {
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
101 av_log(avctx, AV_LOG_ERROR, "Codestream could not be opened for reading.\n");
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
102 opj_destroy_decompress(dec);
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
103 return -1;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
104 }
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
105
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
106 // Decode the codestream
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
107 image = opj_decode_with_info(dec, stream, NULL);
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
108 opj_cio_close(stream);
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
109 if(!image) {
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
110 av_log(avctx, AV_LOG_ERROR, "Error decoding codestream.\n");
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
111 opj_destroy_decompress(dec);
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
112 return -1;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
113 }
9715
997d2de9cd84 Add lowres support to the libopenjpeg wrapper.
jai_menon
parents: 9714
diff changeset
114 width = image->comps[0].w << avctx->lowres;
997d2de9cd84 Add lowres support to the libopenjpeg wrapper.
jai_menon
parents: 9714
diff changeset
115 height = image->comps[0].h << avctx->lowres;
8747
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
116 if(avcodec_check_dimensions(avctx, width, height) < 0) {
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
117 av_log(avctx, AV_LOG_ERROR, "%dx%d dimension invalid.\n", width, height);
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
118 goto done;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
119 }
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
120 avcodec_set_dimensions(avctx, width, height);
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
121
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
122 switch(image->numcomps)
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
123 {
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
124 case 1: avctx->pix_fmt = PIX_FMT_GRAY8;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
125 break;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
126 case 3: if(check_image_attributes(image)) {
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
127 avctx->pix_fmt = PIX_FMT_RGB24;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
128 } else {
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
129 avctx->pix_fmt = PIX_FMT_GRAY8;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
130 av_log(avctx, AV_LOG_ERROR, "Only first component will be used.\n");
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
131 }
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
132 break;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
133 case 4: has_alpha = 1;
10737
adf750125dc9 Fix colours for QT JPEG2000, fixes issue 1540.
cehoyos
parents: 10508
diff changeset
134 avctx->pix_fmt = PIX_FMT_RGBA;
8747
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
135 break;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
136 default: av_log(avctx, AV_LOG_ERROR, "%d components unsupported.\n", image->numcomps);
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
137 goto done;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
138 }
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
139
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
140 if(picture->data[0])
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
141 avctx->release_buffer(avctx, picture);
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
142
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
143 if(avctx->get_buffer(avctx, picture) < 0) {
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
144 av_log(avctx, AV_LOG_ERROR, "Couldn't allocate image buffer.\n");
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
145 return -1;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
146 }
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
147
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
148 for(x = 0; x < image->numcomps; x++) {
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
149 adjust[x] = FFMAX(image->comps[x].prec - 8, 0);
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
150 }
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
151
9714
5df11d49abb7 Use dimensions stored in AVCodecContext instead of local variables.
jai_menon
parents: 9355
diff changeset
152 for(y = 0; y < avctx->height; y++) {
5df11d49abb7 Use dimensions stored in AVCodecContext instead of local variables.
jai_menon
parents: 9355
diff changeset
153 index = y*avctx->width;
8747
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
154 img_ptr = picture->data[0] + y*picture->linesize[0];
9714
5df11d49abb7 Use dimensions stored in AVCodecContext instead of local variables.
jai_menon
parents: 9355
diff changeset
155 for(x = 0; x < avctx->width; x++, index++) {
8747
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
156 *img_ptr++ = image->comps[0].data[index] >> adjust[0];
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
157 if(image->numcomps > 2 && check_image_attributes(image)) {
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
158 *img_ptr++ = image->comps[1].data[index] >> adjust[1];
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
159 *img_ptr++ = image->comps[2].data[index] >> adjust[2];
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
160 if(has_alpha)
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
161 *img_ptr++ = image->comps[3].data[index] >> adjust[3];
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
162 }
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
163 }
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
164 }
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
165
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
166 *output = ctx->image;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
167 *data_size = sizeof(AVPicture);
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
168 ret = buf_size;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
169
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
170 done:
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
171 opj_image_destroy(image);
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
172 opj_destroy_decompress(dec);
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
173 return ret;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
174 }
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
175
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
176 static av_cold int libopenjpeg_decode_close(AVCodecContext *avctx)
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
177 {
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
178 LibOpenJPEGContext *ctx = avctx->priv_data;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
179
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
180 if(ctx->image.data[0])
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
181 avctx->release_buffer(avctx, &ctx->image);
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
182 return 0 ;
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
183 }
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
184
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
185
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
186 AVCodec libopenjpeg_decoder = {
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
187 "libopenjpeg",
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
188 CODEC_TYPE_VIDEO,
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
189 CODEC_ID_JPEG2000,
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
190 sizeof(LibOpenJPEGContext),
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
191 libopenjpeg_decode_init,
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
192 NULL,
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
193 libopenjpeg_decode_close,
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
194 libopenjpeg_decode_frame,
9804
00581e706e1d libopenjpeg wrapper uses get_buffer, set CODEC_CAP_DR1
bcoudurier
parents: 9715
diff changeset
195 CODEC_CAP_DR1,
8747
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
196 .long_name = NULL_IF_CONFIG_SMALL("OpenJPEG based JPEG 2000 decoder"),
a261e3271d1f Use libopenjpeg for jpeg2k decoding.
cehoyos
parents:
diff changeset
197 } ;