From 622f5f1b5e76283e70772152134c7562b6e17e9d Mon Sep 17 00:00:00 2001
From: Joakim Plate <elupus@ecce.se>
Date: Sun, 11 Sep 2011 19:04:51 +0200
Subject: [PATCH 01/17] Support raw dvdsub palette as stored on normal dvd's

This is how the palette is stored on dvd's. Currently
only xbmc passes the palette information to libavcodec
this way.
---
 libavcodec/dvdsubdec.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
index 7355c03..4a945d9 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -61,6 +61,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_crop_tab + 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;
@@ -629,6 +647,12 @@ static av_cold 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.9.3

