示例#1
0
        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();
            }
        }
示例#2
0
        private void StartPrecalculating()
        {
            // 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();

            // 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;
        }
示例#3
0
 private void replaceHighCommas_CheckedChanged(object sender, EventArgs e)
 {
     AppOptions.replaceHighCommas = replaceHighCommas.Checked;
     if (subfile != null)
     {
         currentSubtitle = LoadSubtitleImage(currentNum);
         UpdateBitmaps();
     }
 }
示例#4
0
        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();
            }
        }
示例#5
0
        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);
            }
        }
示例#6
0
 private void ImageOCR(SubtitleImage si)
 {
     si.ImageOCR(fonts, false);
     si.FixSpaces();
 }
示例#7
0
        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();
            }
        }