diff options
author | clook <olivier.cloirec@free.fr> | 2013-07-14 04:14:56 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-07-23 01:02:41 +0200 |
commit | 4443213d2ea42fdf66a90c8d3b25293622d2c90a (patch) | |
tree | 927dd91a8094c274d63dfc63d123329547ccff53 /libavcodec | |
parent | b9b1a2c3e47091eff07e4fc506e4f876a3209aed (diff) | |
download | ffmpeg-4443213d2ea42fdf66a90c8d3b25293622d2c90a.tar.gz |
avcodec/libopenjpegen: XYZ 12 bit support for libopenjpeg encoder
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/libopenjpegenc.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/libavcodec/libopenjpegenc.c b/libavcodec/libopenjpegenc.c index 51fc896c4b..957cabfbfb 100644 --- a/libavcodec/libopenjpegenc.c +++ b/libavcodec/libopenjpegenc.c @@ -106,6 +106,7 @@ static opj_image_t *mj2_create_image(AVCodecContext *avctx, opj_cparameters_t *p case AV_PIX_FMT_GBRP12: case AV_PIX_FMT_GBRP14: case AV_PIX_FMT_GBRP16: + case AV_PIX_FMT_XYZ12: color_space = CLRSPC_SRGB; break; case AV_PIX_FMT_YUV410P: @@ -280,6 +281,38 @@ static int libopenjpeg_copy_packed8(AVCodecContext *avctx, const AVFrame *frame, return 1; } +// for XYZ 12 bit +static int libopenjpeg_copy_packed12(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image) +{ + int compno; + int x; + int y; + int image_index; + int frame_index; + const int numcomps = image->numcomps; + uint16_t *frame_ptr = (uint16_t*)frame->data[0]; + + for (compno = 0; compno < numcomps; ++compno) { + if (image->comps[compno].w > frame->linesize[0] / numcomps) { + av_log(avctx, AV_LOG_ERROR, "Error: frame's linesize is too small for the image\n"); + return 0; + } + } + + 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; + for (x = 0; x < avctx->width; ++x) { + image->comps[compno].data[image_index++] = frame_ptr[frame_index] >> 4; + frame_index += numcomps; + } + } + } + + return 1; +} + static int libopenjpeg_copy_packed16(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image) { int compno; @@ -401,6 +434,9 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, case AV_PIX_FMT_GRAY8A: cpyresult = libopenjpeg_copy_packed8(avctx, frame, image); break; + case AV_PIX_FMT_XYZ12: + cpyresult = libopenjpeg_copy_packed12(avctx, frame, image); + break; case AV_PIX_FMT_RGB48: case AV_PIX_FMT_RGBA64: cpyresult = libopenjpeg_copy_packed16(avctx, frame, image); @@ -574,6 +610,7 @@ AVCodec ff_libopenjpeg_encoder = { AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14, AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16, AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16, + AV_PIX_FMT_XYZ12, AV_PIX_FMT_NONE }, .long_name = NULL_IF_CONFIG_SMALL("OpenJPEG JPEG 2000"), |