From 012b73c2241150216d56061ecee035d8d9ee3be9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Wed, 4 Mar 2015 04:01:41 +0100
Subject: dxva2: Fill h264 luma and chroma weights / offsets with default
 values in case they are not specified.

---
 dlls/dxva2/vaapi-h264.c | 50 +++++++++++++++++++++++++++++++++++++------------
 1 file changed, 38 insertions(+), 12 deletions(-)

diff --git a/dlls/dxva2/vaapi-h264.c b/dlls/dxva2/vaapi-h264.c
index 1a5817e..7fe145c 100644
--- a/dlls/dxva2/vaapi-h264.c
+++ b/dlls/dxva2/vaapi-h264.c
@@ -382,21 +382,47 @@ static HRESULT process_slice_control_buffer( WineVideoDecoderH264Impl *This, con
 
         for (j = 0; j < 32; j++)
         {
-            slice[i].luma_weight_l0[j]      = This->d3dSliceInfo[i].Weights[0][j][0][0];
-            slice[i].luma_offset_l0[j]      = This->d3dSliceInfo[i].Weights[0][j][0][1];
+            if (This->d3dSliceInfo[i].RefPicList[0][j].bPicEntry != 0xFF)
+            {
+                slice[i].luma_weight_l0[j]      = This->d3dSliceInfo[i].Weights[0][j][0][0];
+                slice[i].luma_offset_l0[j]      = This->d3dSliceInfo[i].Weights[0][j][0][1];
+
+                slice[i].chroma_weight_l0[j][0] = This->d3dSliceInfo[i].Weights[0][j][1][0];
+                slice[i].chroma_offset_l0[j][0] = This->d3dSliceInfo[i].Weights[0][j][1][1];
+                slice[i].chroma_weight_l0[j][1] = This->d3dSliceInfo[i].Weights[0][j][2][0];
+                slice[i].chroma_offset_l0[j][1] = This->d3dSliceInfo[i].Weights[0][j][2][1];
+            }
+            else
+            {
+                slice[i].luma_weight_l0[j]      = 1 << This->d3dSliceInfo[i].luma_log2_weight_denom;
+                slice[i].luma_offset_l0[j]      = 0;
+
+                slice[i].chroma_weight_l0[j][0] = 1 << This->d3dSliceInfo[i].chroma_log2_weight_denom;
+                slice[i].chroma_offset_l0[j][0] = 0;
+                slice[i].chroma_weight_l0[j][1] = 1 << This->d3dSliceInfo[i].chroma_log2_weight_denom;
+                slice[i].chroma_offset_l0[j][1] = 0;
+            }
 
-            slice[i].chroma_weight_l0[j][0] = This->d3dSliceInfo[i].Weights[0][j][1][0];
-            slice[i].chroma_offset_l0[j][0] = This->d3dSliceInfo[i].Weights[0][j][1][1];
-            slice[i].chroma_weight_l0[j][1] = This->d3dSliceInfo[i].Weights[0][j][2][0];
-            slice[i].chroma_offset_l0[j][1] = This->d3dSliceInfo[i].Weights[0][j][2][1];
+            if (This->d3dSliceInfo[i].RefPicList[1][j].bPicEntry != 0xFF)
+            {
+                slice[i].luma_weight_l1[j]      = This->d3dSliceInfo[i].Weights[1][j][0][0];
+                slice[i].luma_offset_l1[j]      = This->d3dSliceInfo[i].Weights[1][j][0][1];
 
-            slice[i].luma_weight_l1[j]      = This->d3dSliceInfo[i].Weights[1][j][0][0];
-            slice[i].luma_offset_l1[j]      = This->d3dSliceInfo[i].Weights[1][j][0][1];
+                slice[i].chroma_weight_l1[j][0] = This->d3dSliceInfo[i].Weights[1][j][1][0];
+                slice[i].chroma_offset_l1[j][0] = This->d3dSliceInfo[i].Weights[1][j][1][1];
+                slice[i].chroma_weight_l1[j][1] = This->d3dSliceInfo[i].Weights[1][j][2][0];
+                slice[i].chroma_offset_l1[j][1] = This->d3dSliceInfo[i].Weights[1][j][2][1];
+            }
+            else
+            {
+                slice[i].luma_weight_l1[j]      = 1 << This->d3dSliceInfo[i].luma_log2_weight_denom;
+                slice[i].luma_offset_l1[j]      = 0;
 
-            slice[i].chroma_weight_l1[j][0] = This->d3dSliceInfo[i].Weights[1][j][1][0];
-            slice[i].chroma_offset_l1[j][0] = This->d3dSliceInfo[i].Weights[1][j][1][1];
-            slice[i].chroma_weight_l1[j][1] = This->d3dSliceInfo[i].Weights[1][j][2][0];
-            slice[i].chroma_offset_l1[j][1] = This->d3dSliceInfo[i].Weights[1][j][2][1];
+                slice[i].chroma_weight_l1[j][0] = 1 << This->d3dSliceInfo[i].chroma_log2_weight_denom;
+                slice[i].chroma_offset_l1[j][0] = 0;
+                slice[i].chroma_weight_l1[j][1] = 1 << This->d3dSliceInfo[i].chroma_log2_weight_denom;
+                slice[i].chroma_offset_l1[j][1] = 0;
+            }
         }
     }
 
-- 
2.3.0

