void ReleaseDesignerOutlets() { if (chartWeightAddBtn != null) { chartWeightAddBtn.Dispose(); chartWeightAddBtn = null; } if (chartWeightTB != null) { chartWeightTB.Dispose(); chartWeightTB = null; } if (HomeBtn != null) { HomeBtn.Dispose(); HomeBtn = null; } if (SubtitleImage != null) { SubtitleImage.Dispose(); SubtitleImage = null; } if (TitleImage != null) { TitleImage.Dispose(); TitleImage = null; } }
public void UpdateSubtitleText(int n, SubtitleImage si) { captions[n].Text = si.GetText(); captions[n].UpdateSRTText(); //lines[n].Text = s; //lines[n].UpdateSRTText(); }
private void autoOCRButton_Click(object sender, EventArgs e) { oldNum = currentNum; // Set up the thread for scanning the images stopEvent = new ManualResetEvent(false); finishedEvent = new ManualResetEvent(false); stopEvent.Reset(); finishedEvent.Reset(); updateProgressDelegate = new DelegateUpdateProgress(this.UpdateProgress); OcrThread worker = new OcrThread(this, stopEvent, finishedEvent, subfile.NumSubtitles); Thread thread = new Thread(new ThreadStart(worker.Run)); // Start the thread thread.Start(); using (pf = new ProgressForm(this, subfile.NumSubtitles)) pf.ShowDialog(); // If we ordinarily finished, then the thread has already run out. // But if the user pressed the cancel button, we have to stop the thread if (!finishedEvent.WaitOne(0, true)) { CancelThread(); } currentNum = oldNum; currentSubtitle = LoadSubtitleImage(currentNum); UpdateSRTPage(); mainTabControl.SelectedIndex = 1; }
private void LoadSubtitleFile(string fileName) { SubtitleFile newSubFile; try { newSubFile = new SubtitleFile(fileName); //subfile.SaveXml("c:\\temp\\test.xml"); } catch (SUPFileFormatException) { MessageBox.Show("Couldn't open the file\n" + fileName + ".\nMaybe it's not a BluRay .sup file?\nStandard resolution DVD and HD DVD subtitles aren't supported.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); newSubFile = null; } catch (IOException e) { MessageBox.Show("Couldn't open the file\n" + fileName + "\nbecause of \n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); newSubFile = null; } catch (Exception e) { ErrorForm form = new ErrorForm(e); form.ShowDialog(); newSubFile = null; } if (newSubFile != null) { //If the new file has been loaded successfully, dispose of the old one if (subfile != null) { subfile.Close(); } subfile = newSubFile; nextButton.Enabled = true; previousButton.Enabled = true; autoOCRButton.Enabled = true; ocrButton.Enabled = true; letterOKButton.Enabled = true; saveButton.Enabled = true; subtitleType.Text = "Bluray"; /*else if (subfile.Type == SubtitleFile.SubtitleType.Scenarist) * subtitleType.Text = "Scenarist";*/ currentNum = 0; #if DEBUG currentNum = 17; #endif currentSubtitle = LoadSubtitleImage(currentNum); UpdateTextBox(); totalPages.Text = "/ " + subfile.NumSubtitles; UpdateBitmaps(); // Update the window title Text = "SupRip " + version + " - " + fileName.Substring(fileName.LastIndexOf('\\') + 1); } }
private void replaceHighCommas_CheckedChanged(object sender, EventArgs e) { AppOptions.replaceHighCommas = replaceHighCommas.Checked; if (subfile != null) { currentSubtitle = LoadSubtitleImage(currentNum); UpdateBitmaps(); } }
private void StartImageOCR() { ImageOCR(currentSubtitle); UpdateTextBox(); subfile.UpdateSubtitleText(currentNum, currentSubtitle); ActivateNextUnknownLetter(); // If the checkbox to continue with the next subtitle is checked, try to search the whole movie for an unknown character // We do that in another thread so we don't block the UI if (activeLetter == null && autoProgress.Checked) { oldNum = currentNum; // Set up the thread for scanning the images stopEvent = new ManualResetEvent(false); finishedEvent = new ManualResetEvent(false); stopEvent.Reset(); finishedEvent.Reset(); updateProgressDelegate = new DelegateUpdateProgress(this.UpdateProgress); OcrThread worker = new OcrThread(this, stopEvent, finishedEvent, currentNum, subfile.NumSubtitles); Thread thread = new Thread(new ThreadStart(worker.Run)); // Start the thread thread.Start(); using (pf = new ProgressForm(this, subfile.NumSubtitles)) pf.ShowDialog(); if (!finishedEvent.WaitOne(0, true)) { // FIXME. Add some code so that when the user clicks cancel, the image stays on the last processed subtitle } if (worker.FoundNum != -1) { currentNum = worker.FoundNum; } else { currentNum = subfile.NumSubtitles - 1; } currentSubtitle = LoadSubtitleImage(currentNum); ImageOCR(currentSubtitle); UpdateTextBox(); ActivateNextUnknownLetter(); } }
public void WriteBitmaps(string supName, int numSubtitles, int spacing) { Bitmap[] workBitmaps = new Bitmap[numSubtitles]; int j = 0, k = 0; while (j < captions.Count) { // Create the bitmaps from the subtitle file // We're not writing them to a collected bitmap yet because we have to find out the total height SubtitleImage img = null; int maxWidth = 0, totalHeight = 0; numSubtitles = Math.Min(numSubtitles, captions.Count - j); for (int i = j; i < j + numSubtitles; i++) { img = new SubtitleImage(captions[i].GetBitmap(), captions[i]); workBitmaps[i - j] = img.GetBitmap(); if (workBitmaps[i - j].Width > maxWidth) { maxWidth = workBitmaps[i - j].Width; } totalHeight += workBitmaps[i - j].Height + spacing; } // Create the final bitmap and write all the earlier created ones to it. Bitmap finalBitmap = new Bitmap(maxWidth, totalHeight, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(finalBitmap); g.FillRectangle(new SolidBrush(Color.Black), 0, 0, finalBitmap.Width, finalBitmap.Height); int y = 0; for (int i = 0; i < numSubtitles; i++) { g.DrawImage(workBitmaps[i], 0, y); y += workBitmaps[i].Height + spacing; } int x = supName.LastIndexOf('.'); string bitmapName = supName.Substring(0, x) + "." + k + ".png"; finalBitmap.Save(bitmapName); // Increase the indexes to work on the next bitmap file. k++; j += numSubtitles; } }
// </SnippetRegisterMetadataHandlerForImageSubtitles> // <SnippetImageSubtitleCueEntered> private async void metadata_ImageSubtitleCueEntered(TimedMetadataTrack timedMetadataTrack, MediaCueEventArgs args) { // Check in case there are different tracks and the handler was used for more tracks if (timedMetadataTrack.TimedMetadataKind == TimedMetadataKind.ImageSubtitle) { var cue = args.Cue as ImageCue; if (cue != null) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { var source = new SoftwareBitmapSource(); await source.SetBitmapAsync(cue.SoftwareBitmap); SubtitleImage.Source = source; SubtitleImage.Width = cue.Extent.Width; SubtitleImage.Height = cue.Extent.Height; SubtitleImage.SetValue(Canvas.LeftProperty, cue.Position.X); SubtitleImage.SetValue(Canvas.TopProperty, cue.Position.Y); }); } } }
private SubtitleImage LoadSubtitleImage(int number) { #if !DEBUG try { #endif pageNum.Text = (currentNum + 1).ToString(); //Debugger.Print("## Image " + number); SubtitleImage r = subfile.LoadSubtitleImage(number); //fixme AdjustFormScrollbars space length after narrow characters activeLetter = null; ImageOCR(r); return(r); #if !DEBUG } catch (Exception e) { fonts.Save(); throw new Exception(e.Message + "\n\n" + e.StackTrace); } #endif }
private void MoveToImage(int num) { fontName.Text = fonts.DefaultFontName; if (currentSubtitle != null && num != currentNum) { subfile.UpdateSubtitleText(currentNum, currentSubtitle); currentNum = num; if (currentNum < 0) { currentNum = 0; } if (currentNum >= subfile.NumSubtitles) { currentNum = subfile.NumSubtitles - 1; } currentSubtitle = LoadSubtitleImage(currentNum); UpdateTextBox(); UpdateBitmaps(); } }
void ReleaseDesignerOutlets() { if (EnableDiarySw != null) { EnableDiarySw.Dispose(); EnableDiarySw = null; } if (EverydayLbl != null) { EverydayLbl.Dispose(); EverydayLbl = null; } if (SetTimeBtn != null) { SetTimeBtn.Dispose(); SetTimeBtn = null; } if (HomeBtn != null) { HomeBtn.Dispose(); HomeBtn = null; } if (HoursTb != null) { HoursTb.Dispose(); HoursTb = null; } if (MinutesTb != null) { MinutesTb.Dispose(); MinutesTb = null; } if (OnResetHistory != null) { OnResetHistory.Dispose(); OnResetHistory = null; } if (SubtitleImage != null) { SubtitleImage.Dispose(); SubtitleImage = null; } if (TitleImage != null) { TitleImage.Dispose(); TitleImage = null; } if (TimePicker != null) { TimePicker.Dispose(); TimePicker = null; } }
private void ApplyOptions() { if (!initialized) { return; } try { if (Int32.Parse(minimumSpaceCharacterWidthTextBox.Text) < 1 || Int32.Parse(minimumSpaceCharacterWidthTextBox.Text) > 20) { throw new FormatException(); } AppOptions.minimumSpaceCharacterWidth = Int32.Parse(minimumSpaceCharacterWidthTextBox.Text); } catch (FormatException) { minimumSpaceCharacterWidthTextBox.Text = AppOptions.minimumSpaceCharacterWidth.ToString(); } try { if (Int32.Parse(charSplitTolerance.Text) < 1 || Int32.Parse(charSplitTolerance.Text) > 20) { throw new FormatException(); } AppOptions.charSplitTolerance = Int32.Parse(charSplitTolerance.Text); } catch (FormatException) { charSplitTolerance.Text = AppOptions.charSplitTolerance.ToString(); } try { if (Int32.Parse(similarityTolerance.Text) < 1 || Int32.Parse(similarityTolerance.Text) > 200) { throw new FormatException(); } AppOptions.similarityTolerance = Int32.Parse(similarityTolerance.Text); } catch (FormatException) { similarityTolerance.Text = AppOptions.similarityTolerance.ToString(); } try { if (Int32.Parse(contrast.Text) < 0 || Int32.Parse(contrast.Text) > 10) { throw new FormatException(); } AppOptions.contrast = Int32.Parse(contrast.Text); } catch (FormatException) { contrast.Text = AppOptions.contrast.ToString(); } if (subfile != null) { currentSubtitle = LoadSubtitleImage(currentNum); UpdateBitmaps(); UpdateTextBox(); } }
/* * private void ImageOCR(SubtitleImage si, bool reportUnknownCharacter) * { * if (si.letters == null) * { * // We haven't scanned for letters yet, this probably means I'm debugging something as this shouldn't normally happen * return; * } * * fonts.debugStrings.Clear(); * // First try to scan all the letters we can * foreach (SubtitleLetter l in si.letters) * { * if (l.Text == null) * { * // This letter is unknown, try to scan it * DateTime t = DateTime.Now; * SubtitleLetter l2 = fonts.FindMatch(l, AppOptions.similarityTolerance * 100); * Debugger.scanTime += (DateTime.Now - t).TotalMilliseconds; * * if (l2 != null) * { * //Debugger.Print(" found letter " + l2.Text); * if (AppOptions.replaceHighCommas && l.Height < -10 && l2.Text.Equals(",")) * l.Text = "'"; * else if (AppOptions.replaceHighCommas && l.Height > 10 && l2.Text.Equals("'")) * l.Text = ","; * else * l.Text = l2.Text; * } * // If we should report unknown characters, then throw an exception, otherwise just skip it * else if (reportUnknownCharacter) * throw new UnknownCharacterException(); * } * } * } * */ public void ImageOCR(int n, bool report) { SubtitleImage si = subfile.LoadSubtitleImage(n); si.ImageOCR(fonts, report); }
private void ImageOCR(SubtitleImage si) { si.ImageOCR(fonts, false); si.FixSpaces(); }