37 #if HAVE_OPENJPEG_1_5_OPENJPEG_H
38 # include <openjpeg-1.5/openjpeg.h>
40 # include <openjpeg.h>
78 opj_image_cmptparm_t *cmptparm;
84 OPJ_COLOR_SPACE color_space = CLRSPC_UNKNOWN;
86 sub_dx[0] = sub_dx[3] = 1;
87 sub_dy[0] = sub_dy[3] = 1;
97 color_space = CLRSPC_GRAY;
109 color_space = CLRSPC_SRGB;
144 color_space = CLRSPC_SYCC;
148 "The requested pixel format '%s' is not supported\n",
153 cmptparm =
av_mallocz(numcomps *
sizeof(*cmptparm));
158 for (i = 0; i < numcomps; i++) {
161 cmptparm[i].sgnd = 0;
162 cmptparm[i].dx = sub_dx[i];
163 cmptparm[i].dy = sub_dy[i];
164 cmptparm[i].w = avctx->
width / sub_dx[i];
165 cmptparm[i].h = avctx->
height / sub_dy[i];
168 img = opj_image_create(numcomps, cmptparm, color_space);
178 opj_set_default_encoder_parameters(&ctx->
enc_params);
239 memset(&ctx->
event_mgr, 0,
sizeof(opj_event_mgr_t));
260 const int numcomps = image->numcomps;
262 for (compno = 0; compno < numcomps; ++compno) {
263 if (image->comps[compno].w > frame->
linesize[0] / numcomps) {
269 for (compno = 0; compno < numcomps; ++compno) {
270 for (y = 0; y < avctx->
height; ++
y) {
271 image_index = y * avctx->
width;
272 frame_index = y * frame->
linesize[0] + compno;
273 for (x = 0; x < avctx->
width; ++x) {
274 image->comps[compno].data[image_index++] = frame->
data[0][frame_index];
275 frame_index += numcomps;
290 const int numcomps = image->numcomps;
291 uint16_t *frame_ptr = (uint16_t*)frame->
data[0];
293 for (compno = 0; compno < numcomps; ++compno) {
294 if (image->comps[compno].w > frame->
linesize[0] / numcomps) {
300 for (compno = 0; compno < numcomps; ++compno) {
301 for (y = 0; y < avctx->
height; ++
y) {
302 image_index = y * avctx->
width;
303 frame_index = y * (frame->
linesize[0] / 2) + compno;
304 for (x = 0; x < avctx->
width; ++x) {
305 image->comps[compno].data[image_index++] = frame_ptr[frame_index];
306 frame_index += numcomps;
323 const int numcomps = image->numcomps;
325 for (compno = 0; compno < numcomps; ++compno) {
326 if (image->comps[compno].w > frame->
linesize[compno]) {
332 for (compno = 0; compno < numcomps; ++compno) {
333 width = avctx->
width / image->comps[compno].dx;
334 height = avctx->
height / image->comps[compno].dy;
336 image_index = y *
width;
337 frame_index = y * frame->
linesize[compno];
338 for (x = 0; x <
width; ++x)
339 image->comps[compno].data[image_index++] = frame->
data[compno][frame_index++];
355 const int numcomps = image->numcomps;
358 for (compno = 0; compno < numcomps; ++compno) {
359 if (image->comps[compno].w > frame->
linesize[compno]) {
365 for (compno = 0; compno < numcomps; ++compno) {
366 width = avctx->
width / image->comps[compno].dx;
367 height = avctx->
height / image->comps[compno].dy;
368 frame_ptr = (uint16_t*)frame->
data[compno];
370 image_index = y *
width;
371 frame_index = y * (frame->
linesize[compno] / 2);
372 for (x = 0; x <
width; ++x)
373 image->comps[compno].data[image_index++] = frame_ptr[frame_index++];
384 opj_cinfo_t *compress = ctx->
compress;
385 opj_image_t *image = ctx->
image;
468 "The frame's pixel format '%s' is not supported\n",
476 "Could not copy the frame data to the internal image buffer\n");
480 opj_setup_encoder(compress, &ctx->
enc_params, image);
481 stream = opj_cio_open((opj_common_ptr)compress,
NULL, 0);
487 if (!opj_encode(compress, stream, image,
NULL)) {
488 opj_cio_close(stream);
493 len = cio_tell(stream);
495 opj_cio_close(stream);
499 memcpy(pkt->
data, stream->buffer, len);
502 opj_cio_close(stream);
510 opj_destroy_compress(ctx->
compress);
511 opj_image_destroy(ctx->
image);
516 #define OFFSET(x) offsetof(LibOpenJPEGContext, x)
517 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
519 {
"format",
"Codec Format",
OFFSET(format),
AV_OPT_TYPE_INT, { .i64 = CODEC_JP2 }, CODEC_J2K, CODEC_JP2,
VE,
"format" },
526 {
"cinema_mode",
"Digital Cinema",
OFFSET(cinema_mode),
AV_OPT_TYPE_INT, { .i64 = OFF }, OFF, CINEMA4K_24,
VE,
"cinema_mode" },
531 {
"prog_order",
"Progression Order",
OFFSET(prog_order),
AV_OPT_TYPE_INT, { .i64 = LRCP }, LRCP, CPRL,
VE,
"prog_order" },
553 .
name =
"libopenjpeg",
580 .priv_class = &
class,