]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/libopenjpegenc.c
lavu: Drop the {minus,plus}1 suffix from AVComponentDescriptor fields
[ffmpeg] / libavcodec / libopenjpegenc.c
index b84e6a4e310cabe6a6476029516f892ed4611f87..d1af0210e320725850f15167202bc3fc927b65d2 100644 (file)
@@ -34,7 +34,7 @@
 #include "avcodec.h"
 #include "internal.h"
 
-typedef struct {
+typedef struct LibOpenJPEGContext {
     AVClass *avclass;
     opj_image_t *image;
     opj_cparameters_t enc_params;
@@ -90,12 +90,13 @@ static opj_image_t *libopenjpeg_create_image(AVCodecContext *avctx,
     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:
@@ -130,8 +131,8 @@ static opj_image_t *libopenjpeg_create_image(AVCodecContext *avctx,
     }
 
     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];
@@ -168,12 +169,6 @@ static av_cold int libopenjpeg_encode_init(AVCodecContext *avctx)
         return AVERROR(ENOMEM);
     }
 
-    avctx->coded_frame = av_frame_alloc();
-    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");
@@ -184,13 +179,12 @@ static av_cold int libopenjpeg_encode_init(AVCodecContext *avctx)
     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;
 }
 
@@ -202,7 +196,7 @@ static void libopenjpeg_copy_packed8(AVCodecContext *avctx,
     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;
@@ -212,7 +206,6 @@ static void libopenjpeg_copy_packed8(AVCodecContext *avctx,
                 frame_index += numcomps;
             }
         }
-    }
 }
 
 static void libopenjpeg_copy_packed16(AVCodecContext *avctx,
@@ -221,10 +214,10 @@ 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;
@@ -234,7 +227,6 @@ static void libopenjpeg_copy_packed16(AVCodecContext *avctx,
                 frame_index += numcomps;
             }
         }
-    }
 }
 
 static void libopenjpeg_copy_unpacked8(AVCodecContext *avctx,
@@ -247,7 +239,7 @@ 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;
@@ -271,9 +263,9 @@ static void libopenjpeg_copy_unpacked16(AVCodecContext *avctx,
     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);
@@ -288,8 +280,8 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                                     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;
 
@@ -297,16 +289,17 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     // 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:
@@ -340,7 +333,7 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     }
 
     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);
@@ -371,7 +364,6 @@ static av_cold int libopenjpeg_encode_close(AVCodecContext *avctx)
 
     opj_destroy_compress(ctx->compress);
     opj_image_destroy(ctx->image);
-    av_freep(&avctx->coded_frame);
     return 0;
 }
 
@@ -423,7 +415,8 @@ AVCodec ff_libopenjpeg_encoder = {
     .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,