OpenJPEG can decode in lower resolution or decode only a number
of enhancement layers.
---
libavcodec/libopenjpegdec.c | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/libavcodec/libopenjpegdec.c b/libavcodec/libopenjpegdec.c
index 1c08f8a..cead61d 100644
--- a/libavcodec/libopenjpegdec.c
+++ b/libavcodec/libopenjpegdec.c
@@ -66,6 +66,8 @@ static const enum PixelFormat any_pix_fmts[] =
{RGB_PIXEL_FORMATS,
typedef struct {
opj_dparameters_t dec_params;
AVFrame image;
+ int lowres;
+ int lowqual;
} LibOpenJPEGContext;
static inline int libopenjpeg_matches_pix_fmt(const opj_image_t *image,
@@ -330,6 +332,8 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
}
ctx->dec_params.cp_limit_decoding = NO_LIMITATION;
+ 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);
@@ -403,6 +407,20 @@ 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", "Low quality decoding", OFFSET(lowqual),
AV_OPT_TYPE_INT, { 0 }, 0, INT_MAX, VD },
+ { "lowres", "Low resolution decoding", OFFSET(lowres),
AV_OPT_TYPE_INT, { 0 }, 0, INT_MAX, VD },
+};
+
+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",
@@ -414,5 +432,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),
};
--
1.7.8.rc1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel