summaryrefslogtreecommitdiff
path: root/libavcodec/libopenjpegdec.c
diff options
context:
space:
mode:
authorLuca Barbato <lu_zero@gentoo.org>2012-07-19 01:31:39 +0200
committerLuca Barbato <lu_zero@gentoo.org>2012-07-20 13:23:18 +0200
commitce64e5bfd11ae63af0fb10317a2aea6f7501be62 (patch)
tree60543c0ea9a95fa3932d9a648df3ced7085df351 /libavcodec/libopenjpegdec.c
parent5eb9c495af75721dd5e401ab3aacf316d2f25433 (diff)
libopenjpeg: introduce lowres and lowqual private options
OpenJPEG can decode in lower resolution or decode only a number of enhancement layers.
Diffstat (limited to 'libavcodec/libopenjpegdec.c')
-rw-r--r--libavcodec/libopenjpegdec.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/libavcodec/libopenjpegdec.c b/libavcodec/libopenjpegdec.c
index 799ccd7745..4b3e8d6e48 100644
--- a/libavcodec/libopenjpegdec.c
+++ b/libavcodec/libopenjpegdec.c
@@ -24,6 +24,7 @@
* JPEG 2000 decoder using libopenjpeg
*/
+#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
#include "avcodec.h"
#include "libavutil/intreadwrite.h"
@@ -35,8 +36,11 @@
#define JP2_SIG_VALUE 0x0D0A870A
typedef struct {
+ AVClass *class;
opj_dparameters_t dec_params;
AVFrame image;
+ int lowres;
+ int lowqual;
} LibOpenJPEGContext;
static int check_image_attributes(opj_image_t *image)
@@ -104,6 +108,8 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
opj_set_event_mgr((opj_common_ptr)dec, NULL, NULL);
ctx->dec_params.cp_limit_decoding = LIMIT_TO_MAIN_HEADER;
+ ctx->dec_params.cp_reduce = ctx->lowres;
+ ctx->dec_params.cp_layer = ctx->lowqual;
// Tie decoder with decoding parameters
opj_setup_decoder(dec, &ctx->dec_params);
stream = opj_cio_open((opj_common_ptr)dec, buf, buf_size);
@@ -123,6 +129,12 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
}
width = image->x1 - image->x0;
height = image->y1 - image->y0;
+
+ if (ctx->lowres) {
+ width = (width + (1 << ctx->lowres) - 1) >> ctx->lowres;
+ height = (height + (1 << ctx->lowres) - 1) >> ctx->lowres;
+ }
+
if(av_image_check_size(width, height, 0, avctx) < 0) {
av_log(avctx, AV_LOG_ERROR, "%dx%d dimension invalid.\n", width, height);
goto done;
@@ -208,6 +220,21 @@ static av_cold int libopenjpeg_decode_close(AVCodecContext *avctx)
return 0 ;
}
+#define OFFSET(x) offsetof(LibOpenJPEGContext, x)
+#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
+
+static const AVOption options[] = {
+ { "lowqual", "Limit the number of layers used for decoding", OFFSET(lowqual), AV_OPT_TYPE_INT, { 0 }, 0, INT_MAX, VD },
+ { "lowres", "Lower the decoding resolution by a power of two", OFFSET(lowres), AV_OPT_TYPE_INT, { 0 }, 0, INT_MAX, VD },
+ { NULL },
+};
+
+static const AVClass class = {
+ .class_name = "libopenjpeg",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
AVCodec ff_libopenjpeg_decoder = {
.name = "libopenjpeg",
@@ -219,5 +246,6 @@ AVCodec ff_libopenjpeg_decoder = {
.decode = libopenjpeg_decode_frame,
.capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
.long_name = NULL_IF_CONFIG_SMALL("OpenJPEG based JPEG 2000 decoder"),
+ .priv_class = &class,
.init_thread_copy = ONLY_IF_THREADS_ENABLED(libopenjpeg_decode_init_thread_copy),
};