70 opj_cparameters_t *parameters)
73 opj_image_cmptparm_t *cmptparm;
74 OPJ_COLOR_SPACE color_space;
94 color_space = CLRSPC_GRAY;
99 color_space = CLRSPC_SRGB;
117 color_space = CLRSPC_SYCC;
121 "The requested pixel format '%s' is not supported\n",
126 cmptparm =
av_mallocz(numcomps *
sizeof(*cmptparm));
132 for (i = 0; i < numcomps; i++) {
135 cmptparm[i].sgnd = 0;
136 cmptparm[i].dx = sub_dx[i];
137 cmptparm[i].dy = sub_dy[i];
138 cmptparm[i].w = avctx->
width / sub_dx[i];
139 cmptparm[i].h = avctx->
height / sub_dy[i];
142 img = opj_image_create(numcomps, cmptparm, color_space);
152 opj_set_default_encoder_parameters(&ctx->
enc_params);
198 const AVFrame *frame, opj_image_t *image)
202 int image_index, frame_index;
203 const int numcomps = image->numcomps;
205 for (compno = 0; compno < numcomps; ++compno) {
206 for (y = 0; y < avctx->
height; ++y) {
207 image_index = y * avctx->
width;
208 frame_index = y * frame->
linesize[0] + compno;
209 for (x = 0; x < avctx->
width; ++x) {
210 image->comps[compno].data[image_index++] =
211 frame->
data[0][frame_index];
212 frame_index += numcomps;
219 const AVFrame *frame, opj_image_t *image)
223 int image_index, frame_index;
224 const int numcomps = image->numcomps;
225 uint16_t *frame_ptr = (uint16_t*)frame->
data[0];
227 for (compno = 0; compno < numcomps; ++compno) {
228 for (y = 0; y < avctx->
height; ++y) {
229 image_index = y * avctx->
width;
230 frame_index = y * (frame->
linesize[0] / 2) + compno;
231 for (x = 0; x < avctx->
width; ++x) {
232 image->comps[compno].data[image_index++] =
233 frame_ptr[frame_index];
234 frame_index += numcomps;
241 const AVFrame *frame, opj_image_t *image)
246 int image_index, frame_index;
247 const int numcomps = image->numcomps;
249 for (compno = 0; compno < numcomps; ++compno) {
250 width = avctx->
width / image->comps[compno].dx;
251 height = avctx->
height / image->comps[compno].dy;
252 for (y = 0; y <
height; ++y) {
253 image_index = y *
width;
254 frame_index = y * frame->
linesize[compno];
255 for (x = 0; x <
width; ++x)
256 image->comps[compno].data[image_index++] =
257 frame->
data[compno][frame_index++];
269 int image_index, frame_index;
270 const int numcomps = image->numcomps;
273 for (compno = 0; compno < numcomps; ++compno) {
274 width = avctx->
width / image->comps[compno].dx;
275 height = avctx->
height / image->comps[compno].dy;
276 frame_ptr = (uint16_t*)frame->
data[compno];
278 image_index = y *
width;
279 frame_index = y * (frame->
linesize[compno] / 2);
280 for (x = 0; x <
width; ++x)
281 image->comps[compno].data[image_index++] =
282 frame_ptr[frame_index++];
288 const AVFrame *frame,
int *got_packet)
291 opj_cinfo_t *compress = ctx->
compress;
292 opj_image_t *image = ctx->
image;
336 "The frame's pixel format '%s' is not supported\n",
342 opj_setup_encoder(compress, &ctx->
enc_params, image);
343 stream = opj_cio_open((opj_common_ptr)compress,
NULL, 0);
349 if (!opj_encode(compress, stream, image,
NULL)) {
350 opj_cio_close(stream);
355 len = cio_tell(stream);
357 opj_cio_close(stream);
361 memcpy(pkt->
data, stream->buffer, len);
364 opj_cio_close(stream);
372 opj_destroy_compress(ctx->
compress);
373 opj_image_destroy(ctx->
image);
378 #define OFFSET(x) offsetof(LibOpenJPEGContext, x)
379 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
381 {
"format",
"Codec Format",
OFFSET(format),
AV_OPT_TYPE_INT, { .i64 = CODEC_JP2 }, CODEC_J2K, CODEC_JP2,
VE,
"format" },
388 {
"cinema_mode",
"Digital Cinema",
OFFSET(cinema_mode),
AV_OPT_TYPE_INT, { .i64 = OFF }, OFF, CINEMA4K_24,
VE,
"cinema_mode" },
393 {
"prog_order",
"Progression Order",
OFFSET(prog_order),
AV_OPT_TYPE_INT, { .i64 = LRCP }, LRCP, CPRL,
VE,
"prog_order" },
415 .
name =
"libopenjpeg",
435 .priv_class = &
class,