Пример #1
0
        private void SplitDvbForEachSubImage()
        {
            var list = new List<TransportStreamSubtitle>();
            foreach (var dvbSub in _dvbSubtitles)
            {
                if (dvbSub.ActiveImageIndex == null)
                {
                    var tempList = new List<TransportStreamSubtitle>();
                    for (int i = 0; i < dvbSub.Pes.ObjectDataList.Count; i++)
                    {
                        if (dvbSub.Pes.ObjectDataList[i].TopFieldDataBlockLength > 8)
                        {
                            tempList.Add(new TransportStreamSubtitle
                            {
                                Pes = dvbSub.Pes,
                                ActiveImageIndex = i,
                                StartMilliseconds = dvbSub.StartMilliseconds,
                                EndMilliseconds = dvbSub.EndMilliseconds
                            });
                        }
                    }

                    if (tempList.Count > 1)
                    {
                        var lastColor = Color.Transparent;
                        bool allAlike = true;
                        foreach (var item in tempList)
                        {
                            var dvbBmp = item.GetActiveImage();
                            var nDvbBmp = new NikseBitmap(dvbBmp);
                            var color = nDvbBmp.GetBrightestColor();
                            if (lastColor != Color.Transparent && (Math.Abs(color.R - lastColor.R) > 10 || Math.Abs(color.G - lastColor.G) > 10 || Math.Abs(color.B - lastColor.B) > 10))
                            {
                                allAlike = false;
                                break;
                            }
                            lastColor = color;
                        }
                        if (allAlike)
                        {
                            tempList.Clear();
                            tempList.Add(dvbSub);
                        }
                    }
                    list.AddRange(tempList);
                }
                else
                {
                    list.Add(dvbSub);
                }
            }
            _dvbSubtitles = list;
            _tesseractAsyncStrings = null;
            ShowDvbSubs();
        }
Пример #2
0
        public Bitmap GetSubtitleBitmap(int index)
        {
            Bitmap returnBmp = null;
            Color background;
            Color pattern;
            Color emphasis1;
            Color emphasis2;

            if (_mp4List != null)
            {
                if (checkBoxCustomFourColors.Checked)
                {
                    GetCustomColors(out background, out pattern, out emphasis1, out emphasis2);

                    returnBmp = _mp4List[index].Picture.GetBitmap(null, background, pattern, emphasis1, emphasis2, true);
                    if (checkBoxAutoTransparentBackground.Checked)
                        returnBmp.MakeTransparent();
                }
                else
                {
                    returnBmp = _mp4List[index].Picture.GetBitmap(null, Color.Transparent, Color.Black, Color.White, Color.Black, false);
                    if (checkBoxAutoTransparentBackground.Checked)
                        returnBmp.MakeTransparent();
                }
            }
            else if (_spList != null)
            {
                if (checkBoxCustomFourColors.Checked)
                {
                    GetCustomColors(out background, out pattern, out emphasis1, out emphasis2);

                    returnBmp = _spList[index].Picture.GetBitmap(null, background, pattern, emphasis1, emphasis2, true);
                    if (checkBoxAutoTransparentBackground.Checked)
                        returnBmp.MakeTransparent();
                }
                else
                {
                    returnBmp = _spList[index].Picture.GetBitmap(null, Color.Transparent, Color.Black, Color.White, Color.Black, false);
                    if (checkBoxAutoTransparentBackground.Checked)
                        returnBmp.MakeTransparent();
                }
            }
            else if (_bdnXmlSubtitle != null)
            {
                if (index >= 0 && index < _bdnXmlSubtitle.Paragraphs.Count)
                {
                    var fileNames = _bdnXmlSubtitle.Paragraphs[index].Text.SplitToLines();
                    var bitmaps = new List<Bitmap>();
                    int maxWidth = 0;
                    int totalHeight = 0;

                    foreach (string fn in fileNames)
                    {
                        string fullFileName = Path.Combine(Path.GetDirectoryName(_bdnFileName), fn);
                        if (!File.Exists(fullFileName))
                        {
                            // fix AVISubDetector lines
                            int idxOfIEquals = fn.IndexOf("i=", StringComparison.OrdinalIgnoreCase);
                            if (idxOfIEquals >= 0)
                            {
                                int idxOfSpace = fn.IndexOf(' ', idxOfIEquals);
                                if (idxOfSpace > 0)
                                {
                                    fullFileName = Path.Combine(Path.GetDirectoryName(_bdnFileName), fn.Remove(0, idxOfSpace).Trim());
                                }
                            }
                        }
                        if (File.Exists(fullFileName))
                        {
                            try
                            {
                                var temp = new Bitmap(fullFileName);
                                if (temp.Width > maxWidth)
                                    maxWidth = temp.Width;
                                totalHeight += temp.Height;
                                bitmaps.Add(temp);
                            }
                            catch
                            {
                                return null;
                            }
                        }
                    }

                    Bitmap b = null;
                    if (bitmaps.Count > 1)
                    {
                        var merged = new Bitmap(maxWidth, totalHeight + 7 * bitmaps.Count);
                        int y = 0;
                        for (int k = 0; k < bitmaps.Count; k++)
                        {
                            Bitmap part = bitmaps[k];
                            if (checkBoxAutoTransparentBackground.Checked)
                                part.MakeTransparent();
                            using (var g = Graphics.FromImage(merged))
                                g.DrawImage(part, 0, y);
                            y += part.Height + 7;
                            part.Dispose();
                        }
                        b = merged;
                    }
                    else if (bitmaps.Count == 1)
                    {
                        b = bitmaps[0];
                    }

                    if (b != null)
                    {
                        if (_isSon && checkBoxCustomFourColors.Checked)
                        {
                            GetCustomColors(out background, out pattern, out emphasis1, out emphasis2);

                            FastBitmap fbmp = new FastBitmap(b);
                            fbmp.LockImage();
                            for (int x = 0; x < fbmp.Width; x++)
                            {
                                for (int y = 0; y < fbmp.Height; y++)
                                {
                                    Color c = fbmp.GetPixel(x, y);
                                    if (c.R == Color.Red.R && c.G == Color.Red.G && c.B == Color.Red.B) // normally anti-alias
                                        fbmp.SetPixel(x, y, emphasis2);
                                    else if (c.R == Color.Blue.R && c.G == Color.Blue.G && c.B == Color.Blue.B) // normally text?
                                        fbmp.SetPixel(x, y, pattern);
                                    else if (c.R == Color.White.R && c.G == Color.White.G && c.B == Color.White.B) // normally background
                                        fbmp.SetPixel(x, y, background);
                                    else if (c.R == Color.Black.R && c.G == Color.Black.G && c.B == Color.Black.B) // outline/border
                                        fbmp.SetPixel(x, y, emphasis1);
                                    else
                                        fbmp.SetPixel(x, y, c);
                                }
                            }
                            fbmp.UnlockImage();
                        }
                        if (checkBoxAutoTransparentBackground.Checked)
                            b.MakeTransparent();
                        returnBmp = b;
                    }
                }
            }
            else if (_xSubList != null)
            {
                if (checkBoxCustomFourColors.Checked)
                {
                    GetCustomColors(out background, out pattern, out emphasis1, out emphasis2);
                    returnBmp = _xSubList[index].GetImage(background, pattern, emphasis1, emphasis2);
                }
                else
                {
                    returnBmp = _xSubList[index].GetImage();
                }
            }
            else if (_dvbSubtitles != null)
            {
                var dvbBmp = _dvbSubtitles[index].GetActiveImage();
                var nDvbBmp = new NikseBitmap(dvbBmp);
                nDvbBmp.CropTopTransparent(2);
                nDvbBmp.CropTransparentSidesAndBottom(2, true);
                if (checkBoxTransportStreamGetColorAndSplit.Checked)
                    _dvbSubColor = nDvbBmp.GetBrightestColor();
                if (checkBoxAutoTransparentBackground.Checked)
                    nDvbBmp.MakeBackgroundTransparent((int)numericUpDownAutoTransparentAlphaMax.Value);
                if (checkBoxTransportStreamGrayscale.Checked)
                    nDvbBmp.GrayScale();
                dvbBmp.Dispose();
                returnBmp = nDvbBmp.GetBitmap();
            }
            else if (_bluRaySubtitlesOriginal != null)
            {
                returnBmp = _bluRaySubtitles[index].GetBitmap();
            }
            else if (checkBoxCustomFourColors.Checked)
            {
                GetCustomColors(out background, out pattern, out emphasis1, out emphasis2);

                returnBmp = _vobSubMergedPackist[index].SubPicture.GetBitmap(null, background, pattern, emphasis1, emphasis2, true);
                if (checkBoxAutoTransparentBackground.Checked)
                    returnBmp.MakeTransparent();
            }
            else
            {
                returnBmp = _vobSubMergedPackist[index].SubPicture.GetBitmap(_palette, Color.Transparent, Color.Black, Color.White, Color.Black, false);
                if (checkBoxAutoTransparentBackground.Checked)
                    returnBmp.MakeTransparent();
            }

            if (returnBmp == null)
                return null;

            if (_binaryOcrDb == null && _nOcrDb == null)
                return returnBmp;

            var n = new NikseBitmap(returnBmp);
            n.MakeTwoColor(280);
            returnBmp.Dispose();
            return n.GetBitmap();
        }