#include "avcodec.h"
#include "internal.h"
-typedef struct {
+typedef struct LibOpenJPEGContext {
AVClass *avclass;
opj_image_t *image;
opj_cparameters_t enc_params;
switch (avctx->pix_fmt) {
case AV_PIX_FMT_GRAY8:
case AV_PIX_FMT_GRAY16:
- case AV_PIX_FMT_Y400A:
+ case AV_PIX_FMT_YA8:
color_space = CLRSPC_GRAY;
break;
case AV_PIX_FMT_RGB24:
case AV_PIX_FMT_RGBA:
case AV_PIX_FMT_RGB48:
+ case AV_PIX_FMT_RGBA64:
color_space = CLRSPC_SRGB;
break;
case AV_PIX_FMT_YUV410P:
}
for (i = 0; i < numcomps; i++) {
- cmptparm[i].prec = desc->comp[i].depth_minus1 + 1;
- cmptparm[i].bpp = desc->comp[i].depth_minus1 + 1;
+ cmptparm[i].prec = desc->comp[i].depth;
+ cmptparm[i].bpp = desc->comp[i].depth;
cmptparm[i].sgnd = 0;
cmptparm[i].dx = sub_dx[i];
cmptparm[i].dy = sub_dy[i];
return AVERROR(ENOMEM);
}
- avctx->coded_frame = avcodec_alloc_frame();
- if (!avctx->coded_frame) {
- av_log(avctx, AV_LOG_ERROR, "Error allocating coded frame\n");
- goto fail;
- }
-
ctx->image = libopenjpeg_create_image(avctx, &ctx->enc_params);
if (!ctx->image) {
av_log(avctx, AV_LOG_ERROR, "Error creating the mj2 image\n");
ctx->event_mgr.info_handler = info_callback;
ctx->event_mgr.error_handler = error_callback;
ctx->event_mgr.warning_handler = warning_callback;
- opj_set_event_mgr((opj_common_ptr)ctx->compress, &ctx->event_mgr, avctx);
+ opj_set_event_mgr((opj_common_ptr) ctx->compress, &ctx->event_mgr, avctx);
return 0;
fail:
av_freep(&ctx->compress);
- av_freep(&avctx->coded_frame);
return err;
}
int image_index, frame_index;
const int numcomps = image->numcomps;
- for (compno = 0; compno < numcomps; ++compno) {
+ for (compno = 0; compno < numcomps; ++compno)
for (y = 0; y < avctx->height; ++y) {
image_index = y * avctx->width;
frame_index = y * frame->linesize[0] + compno;
frame_index += numcomps;
}
}
- }
}
static void libopenjpeg_copy_packed16(AVCodecContext *avctx,
int compno;
int x, y;
int image_index, frame_index;
- const int numcomps = image->numcomps;
- uint16_t *frame_ptr = (uint16_t*)frame->data[0];
+ const int numcomps = image->numcomps;
+ uint16_t *frame_ptr = (uint16_t *)frame->data[0];
- for (compno = 0; compno < numcomps; ++compno) {
+ for (compno = 0; compno < numcomps; ++compno)
for (y = 0; y < avctx->height; ++y) {
image_index = y * avctx->width;
frame_index = y * (frame->linesize[0] / 2) + compno;
frame_index += numcomps;
}
}
- }
}
static void libopenjpeg_copy_unpacked8(AVCodecContext *avctx,
const int numcomps = image->numcomps;
for (compno = 0; compno < numcomps; ++compno) {
- width = avctx->width / image->comps[compno].dx;
+ width = avctx->width / image->comps[compno].dx;
height = avctx->height / image->comps[compno].dy;
for (y = 0; y < height; ++y) {
image_index = y * width;
uint16_t *frame_ptr;
for (compno = 0; compno < numcomps; ++compno) {
- width = avctx->width / image->comps[compno].dx;
- height = avctx->height / image->comps[compno].dy;
- frame_ptr = (uint16_t*)frame->data[compno];
+ width = avctx->width / image->comps[compno].dx;
+ height = avctx->height / image->comps[compno].dy;
+ frame_ptr = (uint16_t *)frame->data[compno];
for (y = 0; y < height; ++y) {
image_index = y * width;
frame_index = y * (frame->linesize[compno] / 2);
const AVFrame *frame, int *got_packet)
{
LibOpenJPEGContext *ctx = avctx->priv_data;
- opj_cinfo_t *compress = ctx->compress;
- opj_image_t *image = ctx->image;
+ opj_cinfo_t *compress = ctx->compress;
+ opj_image_t *image = ctx->image;
opj_cio_t *stream;
int ret, len;
// x1, y1 is the width, height of the reference grid
image->x0 = 0;
image->y0 = 0;
- image->x1 = (avctx->width - 1) * ctx->enc_params.subsampling_dx + 1;
+ image->x1 = (avctx->width - 1) * ctx->enc_params.subsampling_dx + 1;
image->y1 = (avctx->height - 1) * ctx->enc_params.subsampling_dy + 1;
switch (avctx->pix_fmt) {
case AV_PIX_FMT_RGB24:
case AV_PIX_FMT_RGBA:
- case AV_PIX_FMT_Y400A:
+ case AV_PIX_FMT_YA8:
libopenjpeg_copy_packed8(avctx, frame, image);
break;
case AV_PIX_FMT_RGB48:
+ case AV_PIX_FMT_RGBA64:
libopenjpeg_copy_packed16(avctx, frame, image);
break;
case AV_PIX_FMT_GRAY8:
}
opj_setup_encoder(compress, &ctx->enc_params, image);
- stream = opj_cio_open((opj_common_ptr)compress, NULL, 0);
+ stream = opj_cio_open((opj_common_ptr) compress, NULL, 0);
if (!stream) {
av_log(avctx, AV_LOG_ERROR, "Error creating the cio stream\n");
return AVERROR(ENOMEM);
opj_destroy_compress(ctx->compress);
opj_image_destroy(ctx->image);
- av_freep(&avctx->coded_frame);
return 0;
}
.capabilities = 0,
.pix_fmts = (const enum AVPixelFormat[]) {
AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA, AV_PIX_FMT_RGB48,
- AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY16, AV_PIX_FMT_Y400A,
+ AV_PIX_FMT_RGBA64,
+ AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY16, AV_PIX_FMT_YA8,
AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVA420P,
AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,