From a77624551376c138dcda4d0bce167abe379a0a6b Mon Sep 17 00:00:00 2001
Date: Mon, 18 Feb 2013 11:08:55 +0000
Subject: [PATCH] Support-raw-dvdsub-palette-as-stored-on-normal-dvd-s

---
 libavcodec/dvdsubdec.c |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
index cc9e11b..52ec0a8 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -54,6 +54,24 @@ static void yuv_a_to_rgba(const uint8_t *ycbcr, const uint8_t *alpha, uint32_t *
     }
 }
 
+static void ayvu_to_argb(const uint8_t *ayvu, uint32_t *argb, int num_values)
+{
+    uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
+    uint8_t r, g, b;
+    int i, y, cb, cr, a;
+    int r_add, g_add, b_add;
+
+    for (i = num_values; i > 0; i--) {
+        a = *ayvu++;
+        y = *ayvu++;
+        cr = *ayvu++;
+        cb = *ayvu++;
+        YUV_TO_RGB1_CCIR(cb, cr);
+        YUV_TO_RGB2_CCIR(r, g, b, y);
+        *argb++ = (a << 24) | (r << 16) | (g << 8) | b;
+    }
+}
+
 static int decode_run_2bit(GetBitContext *gb, int *color)
 {
     unsigned int v, t;
@@ -574,6 +592,12 @@ static int dvdsub_init(AVCodecContext *avctx)
 
     if (ctx->palette_str)
         parse_palette(ctx, ctx->palette_str);
+
+    if (!ctx->has_palette && avctx->extradata_size == 64) {
+        ayvu_to_argb((uint8_t*)avctx->extradata, ctx->palette, 16);
+        ctx->has_palette = 1;
+    }
+
     if (ctx->has_palette) {
         int i;
         av_log(avctx, AV_LOG_DEBUG, "palette:");
-- 
1.7.10.4

