38 #if HAVE_OPENJPEG_1_5_OPENJPEG_H
39 # include <openjpeg-1.5/openjpeg.h>
41 # include <openjpeg.h>
44 #define JP2_SIG_TYPE 0x6A502020
45 #define JP2_SIG_VALUE 0x0D0A870A
49 #define RGB_PIXEL_FORMATS AV_PIX_FMT_RGB24,AV_PIX_FMT_RGBA,AV_PIX_FMT_RGB48,AV_PIX_FMT_RGBA64
50 #define GRAY_PIXEL_FORMATS AV_PIX_FMT_GRAY8,AV_PIX_FMT_GRAY8A,AV_PIX_FMT_GRAY16
51 #define YUV_PIXEL_FORMATS AV_PIX_FMT_YUV410P,AV_PIX_FMT_YUV411P,AV_PIX_FMT_YUVA420P, \
52 AV_PIX_FMT_YUV420P,AV_PIX_FMT_YUV422P,AV_PIX_FMT_YUVA422P, \
53 AV_PIX_FMT_YUV440P,AV_PIX_FMT_YUV444P,AV_PIX_FMT_YUVA444P, \
54 AV_PIX_FMT_YUV420P9,AV_PIX_FMT_YUV422P9,AV_PIX_FMT_YUV444P9, \
55 AV_PIX_FMT_YUVA420P9,AV_PIX_FMT_YUVA422P9,AV_PIX_FMT_YUVA444P9, \
56 AV_PIX_FMT_YUV420P10,AV_PIX_FMT_YUV422P10,AV_PIX_FMT_YUV444P10, \
57 AV_PIX_FMT_YUVA420P10,AV_PIX_FMT_YUVA422P10,AV_PIX_FMT_YUVA444P10, \
58 AV_PIX_FMT_YUV420P12,AV_PIX_FMT_YUV422P12,AV_PIX_FMT_YUV444P12, \
59 AV_PIX_FMT_YUV420P14,AV_PIX_FMT_YUV422P14,AV_PIX_FMT_YUV444P14, \
60 AV_PIX_FMT_YUV420P16,AV_PIX_FMT_YUV422P16,AV_PIX_FMT_YUV444P16, \
61 AV_PIX_FMT_YUVA420P16,AV_PIX_FMT_YUVA422P16,AV_PIX_FMT_YUVA444P16
63 #define XYZ_PIXEL_FORMATS AV_PIX_FMT_XYZ12
89 case 4: match = match && desc->
comp[3].
depth_minus1 + 1 >= image->comps[3].prec &&
90 1 == image->comps[3].dx &&
91 1 == image->comps[3].dy;
92 case 3: match = match && desc->
comp[2].
depth_minus1 + 1 >= image->comps[2].prec &&
95 case 2: match = match && desc->
comp[1].
depth_minus1 + 1 >= image->comps[1].prec &&
98 case 1: match = match && desc->
comp[0].
depth_minus1 + 1 >= image->comps[0].prec &&
99 1 == image->comps[0].dx &&
100 1 == image->comps[0].dy;
111 int possible_fmts_nb = 0;
113 switch (image->color_space) {
132 for (index = 0; index < possible_fmts_nb; ++
index) {
134 return possible_fmts[
index];
144 int i, component_plane;
151 if (component_plane != desc->
comp[i].
plane)
160 for (y = 0; y < picture->
height; y++) {
161 index = y*picture->
width;
163 for (x = 0; x < picture->
width; x++, index++) {
164 for (c = 0; c < image->numcomps; c++) {
165 *img_ptr++ = 0x80 * image->comps[
c].sgnd + image->comps[
c].data[
index];
175 for (x = 0; x < image->numcomps; x++)
178 for (y = 0; y < picture->
height; y++) {
179 index = y*picture->
width;
180 img_ptr = (uint16_t*) (picture->
data[0] + y*picture->
linesize[0]);
181 for (x = 0; x < picture->
width; x++, index++) {
182 for (c = 0; c < image->numcomps; c++) {
183 *img_ptr++ = (1 << image->comps[
c].prec - 1) * image->comps[c].sgnd +
184 (
unsigned)image->comps[
c].data[
index] << adjust[
c];
195 for (index = 0; index < image->numcomps; index++) {
196 comp_data = image->comps[
index].data;
197 for (y = 0; y < image->comps[
index].h; y++) {
199 for (x = 0; x < image->comps[
index].w; x++) {
200 *img_ptr = 0x80 * image->comps[
index].sgnd + *comp_data;
213 for (x = 0; x < image->numcomps; x++)
216 for (index = 0; index < image->numcomps; index++) {
217 comp_data = image->comps[
index].data;
218 for (y = 0; y < image->comps[
index].h; y++) {
219 img_ptr = (uint16_t*) (picture->
data[index] + y * picture->
linesize[index]);
220 for (x = 0; x < image->comps[
index].w; x++) {
221 *img_ptr = (1 << image->comps[
index].prec - 1) * image->comps[index].sgnd +
222 (
unsigned)*comp_data << adjust[
index];
234 opj_set_default_decoder_parameters(&ctx->
dec_params);
239 void *
data,
int *got_frame,
243 int buf_size = avpkt->
size;
262 dec = opj_create_decompress(CODEC_JP2);
268 dec = opj_create_decompress(CODEC_J2K);
275 opj_set_event_mgr((opj_common_ptr)dec, NULL, NULL);
276 ctx->
dec_params.cp_limit_decoding = LIMIT_TO_MAIN_HEADER;
280 stream = opj_cio_open((opj_common_ptr)dec, buf, buf_size);
284 "Codestream could not be opened for reading.\n");
285 opj_destroy_decompress(dec);
290 image = opj_decode_with_info(dec, stream, NULL);
291 opj_cio_close(stream);
295 opj_destroy_decompress(dec);
299 width = image->x1 - image->x0;
300 height = image->y1 - image->y0;
317 for (i = 0; i < image->numcomps; i++)
324 ctx->
dec_params.cp_limit_decoding = NO_LIMITATION;
328 stream = opj_cio_open((opj_common_ptr)dec, buf, buf_size);
331 "Codestream could not be opened for reading.\n");
336 opj_image_destroy(image);
338 image = opj_decode_with_info(dec, stream, NULL);
339 opj_cio_close(stream);
351 switch (pixel_size) {
388 opj_image_destroy(image);
389 opj_destroy_decompress(dec);
393 #define OFFSET(x) offsetof(LibOpenJPEGContext, x)
394 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
397 {
"lowqual",
"Limit the number of layers used for decoding",
OFFSET(lowqual),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
VD },
409 .
name =
"libopenjpeg",
418 .priv_class = &openjpeg_class,