VobSub export - images now uses inner anti-alising instead of outer anti-alising with transparency (seems to be more compatible)

This commit is contained in:
niksedk 2014-03-11 22:27:36 +01:00
parent bbb0287d85
commit ae6d17517d
3 changed files with 34 additions and 34 deletions

View File

@ -364,7 +364,7 @@ namespace Nikse.SubtitleEdit.Forms
if (_exportType == "BLURAYSUP")
binarySubtitleFile = new FileStream(saveFileDialog1.FileName, FileMode.Create);
else if (_exportType == "VOBSUB")
vobSubWriter = new VobSubWriter(saveFileDialog1.FileName, width, height, comboBoxBottomMargin.SelectedIndex, 32, _subtitleColor, _borderColor, GetOutlineColor(_borderColor), IfoParser.ArrayOfLanguage[comboBoxLanguage.SelectedIndex], IfoParser.ArrayOfLanguageCode[comboBoxLanguage.SelectedIndex]);
vobSubWriter = new VobSubWriter(saveFileDialog1.FileName, width, height, comboBoxBottomMargin.SelectedIndex, 32, _subtitleColor, _borderColor, IfoParser.ArrayOfLanguage[comboBoxLanguage.SelectedIndex], IfoParser.ArrayOfLanguageCode[comboBoxLanguage.SelectedIndex]);
progressBar1.Value = 0;
progressBar1.Maximum = _subtitle.Paragraphs.Count-1;
@ -1208,13 +1208,6 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
_borderWidth = float.Parse(comboBoxBorderWidth.SelectedItem.ToString());
}
private static Color GetOutlineColor(Color borderColor)
{
if (borderColor.R + borderColor.G + borderColor.B < 30)
return Color.FromArgb(200, 75, 75, 75);
return Color.FromArgb(150, borderColor.R, borderColor.G, borderColor.B);
}
private static Font SetFont(MakeBitmapParameter parameter, float fontSize)
{
Font font;
@ -1320,7 +1313,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
if (_exportType == "VOBSUB" || _exportType == "STL" || _exportType == "SPUMUX")
{
var nbmp = new NikseBitmap(bmp);
nbmp.ConverToFourColors(Color.Transparent, _subtitleColor, _borderColor, GetOutlineColor(_borderColor));
nbmp.ConverToFourColors(Color.Transparent, _subtitleColor, _borderColor, true);
bmp = nbmp.GetBitmap();
}
return bmp;

View File

@ -198,13 +198,11 @@ namespace Nikse.SubtitleEdit.Logic
/// <summary>
/// Convert a x-color image to four colors, for e.g. dvd sub pictures.
/// Colors CAN be in any order but should not...
/// </summary>
/// <param name="background">Background color</param>
/// <param name="pattern">Pattern color, normally white or yellow</param>
/// <param name="emphasis1">Emphasis 1, normally black or near black (border)</param>
/// <param name="emphasis2">Emphasis 1, normally black or near black (anti-alias)</param>
public void ConverToFourColors(Color background, Color pattern, Color emphasis1, Color emphasis2)
public void ConverToFourColors(Color background, Color pattern, Color emphasis1, bool useInnerAntialize)
{
byte[] backgroundBuffer = new byte[4];
backgroundBuffer[0] = (byte)background.B;
@ -224,12 +222,6 @@ namespace Nikse.SubtitleEdit.Logic
emphasis1Buffer[2] = (byte)emphasis1.R;
emphasis1Buffer[3] = (byte)emphasis1.A;
byte[] emphasis2Buffer = new byte[4];
emphasis2Buffer[0] = (byte)emphasis2.B;
emphasis2Buffer[1] = (byte)emphasis2.G;
emphasis2Buffer[2] = (byte)emphasis2.R;
emphasis2Buffer[3] = (byte)emphasis2.A;
for (int i = 0; i < _bitmapData.Length; i += 4)
{
int smallestDiff = 10000;
@ -253,21 +245,38 @@ namespace Nikse.SubtitleEdit.Logic
smallestDiff = emphasis1Diff;
buffer = emphasis1Buffer;
}
int emphasis2Diff = Math.Abs(emphasis2Buffer[0] - _bitmapData[i]) + Math.Abs(emphasis2Buffer[1] - _bitmapData[i + 1]) + Math.Abs(emphasis2Buffer[2] - _bitmapData[i + 2]) + Math.Abs(emphasis2Buffer[3] - _bitmapData[i + 3]);
if (emphasis2Diff < smallestDiff)
{
smallestDiff = emphasis2Diff;
buffer = emphasis2Buffer;
}
else if (_bitmapData[i + 3] >= 10 && _bitmapData[i + 3] < 90) // anti-alias
{
smallestDiff = emphasis2Diff;
buffer = emphasis2Buffer;
}
}
Buffer.BlockCopy(buffer, 0, _bitmapData, i, 4);
}
if (useInnerAntialize)
VobSubAntialize(pattern, emphasis1);
}
private void VobSubAntialize(Color pattern, Color emphasis1)
{
int r = (int) Math.Round(((pattern.R * 3.0 + emphasis1.R) / 4.0));
int g = (int) Math.Round(((pattern.G * 3.0 + emphasis1.G) / 4.0));
int b = (int)Math.Round(((pattern.B * 3.0 + emphasis1.B) / 4.0));
Color antializeColor = Color.FromArgb(r, g, b);
for (int y = 1; y < Height-1; y++)
{
for (int x = 1; x < Width-1; x++)
{
if (GetPixel(x, y) == pattern)
{
if (GetPixel(x - 1, y) == emphasis1 && GetPixel(x, y - 1) == emphasis1)
SetPixel(x, y, antializeColor);
else if (GetPixel(x - 1, y) == emphasis1 && GetPixel(x, y + 1) == emphasis1)
SetPixel(x, y, antializeColor);
else if (GetPixel(x + 1, y) == emphasis1 && GetPixel(x, y + 1) == emphasis1)
SetPixel(x, y, antializeColor);
else if (GetPixel(x + 1, y) == emphasis1 && GetPixel(x, y - 1) == emphasis1)
SetPixel(x, y, antializeColor);
}
}
}
}
public RunLengthTwoParts RunLengthEncodeForDvd(Color background, Color pattern, Color emphasis1, Color emphasis2)

View File

@ -254,8 +254,7 @@ namespace Nikse.SubtitleEdit.Logic.VobSub
readonly string _languageName = "English";
readonly string _languageNameShort = "en";
public VobSubWriter(string subFileName, int screenWidth, int screenHeight, int bottomMargin, int languageStreamId, Color pattern, Color emphasis1, Color emphasis2,
string languageName, string languageNameShort)
public VobSubWriter(string subFileName, int screenWidth, int screenHeight, int bottomMargin, int languageStreamId, Color pattern, Color emphasis1, string languageName, string languageNameShort)
{
_subFileName = subFileName;
_screenWidth = screenWidth;
@ -264,7 +263,6 @@ namespace Nikse.SubtitleEdit.Logic.VobSub
_languageStreamId = languageStreamId;
_pattern = pattern;
_emphasis1 = emphasis1;
_emphasis2 = emphasis2;
_languageName = languageName;
_languageNameShort = languageNameShort;
_idx = CreateIdxHeader();
@ -341,7 +339,7 @@ namespace Nikse.SubtitleEdit.Logic.VobSub
_idx.AppendLine(string.Format("timestamp: {0:00}:{1:00}:{2:00}:{3:000}, filepos: {4}", p.StartTime.Hours, p.StartTime.Minutes, p.StartTime.Seconds, p.StartTime.Milliseconds, _subFile.Position.ToString("X").PadLeft(9, '0').ToLower()));
var nbmp = new NikseBitmap(bmp);
nbmp.ConverToFourColors(_background, _pattern, _emphasis1, _emphasis2);
nbmp.ConverToFourColors(_background, _pattern, _emphasis1, true);
var twoPartBuffer = nbmp.RunLengthEncodeForDvd(_background, _pattern, _emphasis1, _emphasis2);
var imageBuffer = GetSubImageBuffer(twoPartBuffer, nbmp, p, alignment);