From d93ad296e5d96c59961db873fe9531406ce6e1b3 Mon Sep 17 00:00:00 2001 From: niksedk Date: Tue, 13 Sep 2011 18:19:57 +0000 Subject: [PATCH] VobSub - Added reading of transparency settings + fixed bug where background color was not changed (sometimes background color is used for... not background) git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@636 99eadd0c-20b8-1223-b5c4-2a2b2df33de2 --- src/Logic/VobSub/SubPicture.cs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Logic/VobSub/SubPicture.cs b/src/Logic/VobSub/SubPicture.cs index a09525c04..ece370850 100644 --- a/src/Logic/VobSub/SubPicture.cs +++ b/src/Logic/VobSub/SubPicture.cs @@ -108,7 +108,17 @@ namespace Nikse.SubtitleEdit.Logic.VobSub commandIndex += 3; break; case (int)DisplayControlCommand.SetContrast: // 4 - imageContrast = new[] { _data[commandIndex + 1], _data[commandIndex + 2] }; + if (colorLookUpTable != null && fourColors.Count == 4) + { + imageContrast = new[] { _data[commandIndex + 1], _data[commandIndex + 2] }; + //if (imageContrast[0] + imageContrast[1] > 0) + //{ + SetTransparency(fourColors, 3, (imageContrast[0] & 0xF0) >> 4); + SetTransparency(fourColors, 2, imageContrast[0] & Helper.B00001111); + SetTransparency(fourColors, 1, (imageContrast[1] & 0xF0) >> 4); + SetTransparency(fourColors, 0, imageContrast[1] & Helper.B00001111); + //} + } commandIndex += 3; break; case (int)DisplayControlCommand.SetDisplayArea: // 5 @@ -157,10 +167,18 @@ namespace Nikse.SubtitleEdit.Logic.VobSub private static void SetColor(List fourColors, int fourColorIndex, int clutIndex, List colorLookUpTable) { - if (clutIndex >= 0 && clutIndex < colorLookUpTable.Count && fourColorIndex > 0) + if (clutIndex >= 0 && clutIndex < colorLookUpTable.Count && fourColorIndex >= 0) fourColors[fourColorIndex] = colorLookUpTable[clutIndex]; } + private static void SetTransparency(List fourColors, int fourColorIndex, int alpha) + { + // alpha: 0x0 = transparent, 0xF = opaque (in C# 0 is fully transparent, and 255 is fully opaque so we have to multiply by 17) + + if (fourColorIndex >= 0) + fourColors[fourColorIndex] = Color.FromArgb(alpha * 17, fourColors[fourColorIndex].R, fourColors[fourColorIndex].G, fourColors[fourColorIndex].B); + } + private Bitmap GenerateBitmap(Rectangle imageDisplayArea, int imageTopFieldDataAddress, int imageBottomFieldDataAddress, List fourColors) { var bmp = new Bitmap(imageDisplayArea.Width + 1, imageDisplayArea.Height + 1);