mirror of https://git.ffmpeg.org/ffmpeg.git
libopenjpegenc: switch to encode2()
Signed-off-by: Paul B Mahol <onemda@gmail.com> Reviewed-by: Michael Bradshaw <mbradshaw@sorensonmedia.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
a5b823368a
commit
b222c28ee8
|
@ -28,6 +28,7 @@
|
||||||
#include "libavutil/avassert.h"
|
#include "libavutil/avassert.h"
|
||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
#include "libavutil/intreadwrite.h"
|
#include "libavutil/intreadwrite.h"
|
||||||
|
#include "internal.h"
|
||||||
#define OPJ_STATIC
|
#define OPJ_STATIC
|
||||||
#include <openjpeg.h>
|
#include <openjpeg.h>
|
||||||
|
|
||||||
|
@ -201,7 +202,7 @@ static av_cold int libopenjpeg_encode_init(AVCodecContext *avctx)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int libopenjpeg_copy_packed8(AVCodecContext *avctx, AVFrame *frame, opj_image_t *image)
|
static int libopenjpeg_copy_packed8(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
|
||||||
{
|
{
|
||||||
int compno;
|
int compno;
|
||||||
int x;
|
int x;
|
||||||
|
@ -231,7 +232,7 @@ static int libopenjpeg_copy_packed8(AVCodecContext *avctx, AVFrame *frame, opj_i
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int libopenjpeg_copy_packed16(AVCodecContext *avctx, AVFrame *frame, opj_image_t *image)
|
static int libopenjpeg_copy_packed16(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
|
||||||
{
|
{
|
||||||
int compno;
|
int compno;
|
||||||
int x;
|
int x;
|
||||||
|
@ -262,7 +263,7 @@ static int libopenjpeg_copy_packed16(AVCodecContext *avctx, AVFrame *frame, opj_
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int libopenjpeg_copy_unpacked8(AVCodecContext *avctx, AVFrame *frame, opj_image_t *image)
|
static int libopenjpeg_copy_unpacked8(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
|
||||||
{
|
{
|
||||||
int compno;
|
int compno;
|
||||||
int x;
|
int x;
|
||||||
|
@ -295,7 +296,7 @@ static int libopenjpeg_copy_unpacked8(AVCodecContext *avctx, AVFrame *frame, opj
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int libopenjpeg_copy_unpacked16(AVCodecContext *avctx, AVFrame *frame, opj_image_t *image)
|
static int libopenjpeg_copy_unpacked16(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
|
||||||
{
|
{
|
||||||
int compno;
|
int compno;
|
||||||
int x;
|
int x;
|
||||||
|
@ -330,15 +331,15 @@ static int libopenjpeg_copy_unpacked16(AVCodecContext *avctx, AVFrame *frame, op
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int libopenjpeg_encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void *data)
|
static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||||
|
const AVFrame *frame, int *got_packet)
|
||||||
{
|
{
|
||||||
AVFrame *frame = data;
|
|
||||||
LibOpenJPEGContext *ctx = avctx->priv_data;
|
LibOpenJPEGContext *ctx = avctx->priv_data;
|
||||||
opj_cinfo_t *compress = ctx->compress;
|
opj_cinfo_t *compress = ctx->compress;
|
||||||
opj_image_t *image = ctx->image;
|
opj_image_t *image = ctx->image;
|
||||||
opj_cio_t *stream;
|
opj_cio_t *stream;
|
||||||
int cpyresult = 0;
|
int cpyresult = 0;
|
||||||
int len = 0;
|
int ret, len;
|
||||||
|
|
||||||
// x0, y0 is the top left corner of the image
|
// x0, y0 is the top left corner of the image
|
||||||
// x1, y1 is the width, height of the reference grid
|
// x1, y1 is the width, height of the reference grid
|
||||||
|
@ -402,15 +403,16 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf
|
||||||
}
|
}
|
||||||
|
|
||||||
len = cio_tell(stream);
|
len = cio_tell(stream);
|
||||||
if (len > buf_size) {
|
if ((ret = ff_alloc_packet2(avctx, pkt, len)) < 0) {
|
||||||
opj_cio_close(stream);
|
opj_cio_close(stream);
|
||||||
av_log(avctx, AV_LOG_ERROR, "Error with buf_size, not large enough to hold the frame\n");
|
return ret;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(buf, stream->buffer, len);
|
memcpy(pkt->data, stream->buffer, len);
|
||||||
|
pkt->flags |= AV_PKT_FLAG_KEY;
|
||||||
|
*got_packet = 1;
|
||||||
opj_cio_close(stream);
|
opj_cio_close(stream);
|
||||||
return len;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold int libopenjpeg_encode_close(AVCodecContext *avctx)
|
static av_cold int libopenjpeg_encode_close(AVCodecContext *avctx)
|
||||||
|
@ -430,7 +432,7 @@ AVCodec ff_libopenjpeg_encoder = {
|
||||||
.id = CODEC_ID_JPEG2000,
|
.id = CODEC_ID_JPEG2000,
|
||||||
.priv_data_size = sizeof(LibOpenJPEGContext),
|
.priv_data_size = sizeof(LibOpenJPEGContext),
|
||||||
.init = libopenjpeg_encode_init,
|
.init = libopenjpeg_encode_init,
|
||||||
.encode = libopenjpeg_encode_frame,
|
.encode2 = libopenjpeg_encode_frame,
|
||||||
.close = libopenjpeg_encode_close,
|
.close = libopenjpeg_encode_close,
|
||||||
.capabilities = 0,
|
.capabilities = 0,
|
||||||
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24,PIX_FMT_RGBA,PIX_FMT_RGB48,PIX_FMT_RGBA64,
|
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24,PIX_FMT_RGBA,PIX_FMT_RGB48,PIX_FMT_RGBA64,
|
||||||
|
|
Loading…
Reference in New Issue