aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/dvdsubdec.c
diff options
context:
space:
mode:
authorNicolas George <nicolas.george@normalesup.org>2012-12-01 14:47:14 +0100
committerNicolas George <nicolas.george@normalesup.org>2012-12-05 09:25:48 +0100
commit217b10de3f30325961d45af3827d4d097e8af5ec (patch)
treedb40c2046bd0b1fcf46e58b4a2c87f6370bbfaf5 /libavcodec/dvdsubdec.c
parent9db3fb6ed8d35ae02a1d3c322777bd45bb4579c9 (diff)
downloadffmpeg-217b10de3f30325961d45af3827d4d097e8af5ec.tar.gz
lavc/dvdsubdec: accept palette from options.
On DVDs, the palette is part of the IFO file and therefore not available when reading from a dumped VOB file.
Diffstat (limited to 'libavcodec/dvdsubdec.c')
-rw-r--r--libavcodec/dvdsubdec.c55
1 files changed, 45 insertions, 10 deletions
diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
index 9c2dd8cf05..cc9e11bc92 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -22,13 +22,16 @@
#include "get_bits.h"
#include "dsputil.h"
#include "libavutil/colorspace.h"
+#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
//#define DEBUG
typedef struct DVDSubContext
{
+ AVClass *class;
uint32_t palette[16];
+ char *palette_str;
int has_palette;
uint8_t colormap[4];
uint8_t alpha[256];
@@ -513,7 +516,19 @@ static int dvdsub_decode(AVCodecContext *avctx,
return buf_size;
}
-static int dvdsub_init(AVCodecContext *avctx)
+static void parse_palette(DVDSubContext *ctx, char *p)
+{
+ int i;
+
+ ctx->has_palette = 1;
+ for(i=0;i<16;i++) {
+ ctx->palette[i] = strtoul(p, &p, 16);
+ while(*p == ',' || isspace(*p))
+ p++;
+ }
+}
+
+static int dvdsub_parse_extradata(AVCodecContext *avctx)
{
DVDSubContext *ctx = (DVDSubContext*) avctx->priv_data;
char *dataorig, *data;
@@ -533,14 +548,7 @@ static int dvdsub_init(AVCodecContext *avctx)
break;
if (strncmp("palette:", data, 8) == 0) {
- int i;
- char *p = data+8;
- ctx->has_palette = 1;
- for(i=0;i<16;i++) {
- ctx->palette[i] = strtoul(p, &p, 16);
- while(*p == ',' || isspace(*p))
- p++;
- }
+ parse_palette(ctx, data + 8);
} else if (strncmp("size:", data, 5) == 0) {
int w, h;
if (sscanf(data + 5, "%dx%d", &w, &h) == 2 &&
@@ -552,6 +560,20 @@ static int dvdsub_init(AVCodecContext *avctx)
data += strspn(data, "\n\r");
}
+ av_free(dataorig);
+ return 1;
+}
+
+static int dvdsub_init(AVCodecContext *avctx)
+{
+ DVDSubContext *ctx = (DVDSubContext*) avctx->priv_data;
+ int ret;
+
+ if ((ret = dvdsub_parse_extradata(avctx)) < 0)
+ return ret;
+
+ if (ctx->palette_str)
+ parse_palette(ctx, ctx->palette_str);
if (ctx->has_palette) {
int i;
av_log(avctx, AV_LOG_DEBUG, "palette:");
@@ -560,10 +582,22 @@ static int dvdsub_init(AVCodecContext *avctx)
av_log(avctx, AV_LOG_DEBUG, "\n");
}
- av_free(dataorig);
return 1;
}
+#define OFFSET(field) offsetof(DVDSubContext, field)
+#define VD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
+static const AVOption options[] = {
+ { "palette", "set the global palette", OFFSET(palette_str), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VD },
+ { NULL }
+};
+static const AVClass class = {
+ .class_name = "dvdsubdec",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVCodec ff_dvdsub_decoder = {
.name = "dvdsub",
.type = AVMEDIA_TYPE_SUBTITLE,
@@ -572,4 +606,5 @@ AVCodec ff_dvdsub_decoder = {
.init = dvdsub_init,
.decode = dvdsub_decode,
.long_name = NULL_IF_CONFIG_SMALL("DVD subtitles"),
+ .priv_class = &class,
};