Esempio n. 1
0
        /// <summary>
        /// Generate snapshots for all episodes.
        /// </summary>
        public bool genSnapshots(WorkerVars workerVars, DialogProgress dialogProgress)
        {
            int      progessCount  = 0;
            int      episodeCount  = 0;
            int      totalEpisodes = workerVars.CombinedAll.Count;
            int      totalLines    = UtilsSubs.getTotalLineCount(workerVars.CombinedAll);
            DateTime lastTime      = UtilsSubs.getLastTime(workerVars.CombinedAll);

            UtilsName name = new UtilsName(Settings.Instance.DeckName, totalEpisodes,
                                           totalLines, lastTime, Settings.Instance.VideoClips.Size.Width,
                                           Settings.Instance.VideoClips.Size.Height);

            // For each episode
            foreach (List <InfoCombined> combArray in workerVars.CombinedAll)
            {
                episodeCount++;

                // For each line in episode, generate a snapshot
                foreach (InfoCombined t in combArray)
                {
                    progessCount++;

                    string progressText = $"Generating snapshot: {progessCount.ToString()} of {totalLines.ToString()}";

                    int progress = Convert.ToInt32(progessCount * (100.0 / totalLines));

                    // Update the progress dialog
                    DialogProgress.updateProgressInvoke(dialogProgress, progress, progressText);

                    InfoCombined comb      = t;
                    DateTime     startTime = comb.Subs1.StartTime;
                    DateTime     endTime   = comb.Subs1.EndTime;
                    DateTime     midTime   = UtilsSubs.getMidpointTime(startTime, endTime);

                    string videoFileName = Settings.Instance.VideoClips.Files[episodeCount - 1];

                    // Create output filename
                    string nameStr = name.createName(ConstantSettings.SnapshotFilenameFormat,
                                                     (int)episodeCount + Settings.Instance.EpisodeStartNumber - 1,
                                                     progessCount, startTime, endTime, comb.Subs1.Text, comb.Subs2.Text);

                    string outFile = $"{workerVars.MediaDir}{Path.DirectorySeparatorChar}{nameStr}"; // {2}

                    // Generate snapshot
                    UtilsSnapshot.takeSnapshotFromVideo(videoFileName, midTime, Settings.Instance.Snapshots.Size,
                                                        Settings.Instance.Snapshots.Crop, outFile);

                    // Did the user press the cancel button?
                    if (dialogProgress.Cancel)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Show full-sized preview of snapshot.
        /// </summary>
        private void pictureBoxImage_Click(object sender, EventArgs e)
        {
            if (previewWorkerVars == null)
            {
                return;
            }

            string snapshotFile = previewWorkerVars.MediaDir + Path.DirectorySeparatorChar + ConstantSettings.TempImageFilename;

            if (File.Exists(snapshotFile))
            {
                DialogPreviewSnapshot dlg = new DialogPreviewSnapshot();

                dlg.Snapshot = UtilsSnapshot.getImageFromFile(snapshotFile);

                dlg.ShowDialog();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Update the image preview.
        /// </summary>
        private void updateImagePreview(InfoCombined selectedComb)
        {
            if (selectedComb == null)
            {
                return;
            }

            // Update the snapshot
            if (Settings.Instance.VideoClips.Files.Length > 0 && checkBoxSnapshotPreview.Checked)
            {
                string   videoFileName = Settings.Instance.VideoClips.Files[comboBoxEpisode.SelectedIndex];
                DateTime midTime       = UtilsSubs.getMidpointTime(selectedComb.Subs1.StartTime, selectedComb.Subs1.EndTime);
                string   outFile       = previewWorkerVars.MediaDir + Path.DirectorySeparatorChar +
                                         ConstantSettings.TempImageFilename;

                try
                {
                    File.Delete(outFile);
                }
                catch
                {
                    // File is locked
                    return;
                }

                UtilsSnapshot.takeSnapshotFromVideo(videoFileName, midTime, Settings.Instance.Snapshots.Size,
                                                    Settings.Instance.Snapshots.Crop, outFile);

                if (File.Exists(outFile))
                {
                    Image image = UtilsSnapshot.getImageFromFile(outFile);

                    image = UtilsSnapshot.fitImageToSize(image,
                                                         new Size(pictureBoxImage.Width, pictureBoxImage.Height));

                    pictureBoxImage.Image = image;
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Update the Subs1 and Subs2 text boxes with the provided combined info.
        /// </summary>
        private void updateTextPreview(InfoCombined selectedComb)
        {
            if (selectedComb == null)
            {
                return;
            }

            if (selectedComb.Active)
            {
                this.textBoxSubs1.BackColor    = activeColor;
                this.textBoxSubs2.BackColor    = activeColor;
                this.pictureBoxSubs1.BackColor = activeColor;
                this.pictureBoxSubs2.BackColor = activeColor;
                this.panelSubs1.BackColor      = activeColor;
                this.panelSubs2.BackColor      = activeColor;
            }
            else
            {
                this.textBoxSubs1.BackColor    = inactiveColor;
                this.textBoxSubs2.BackColor    = inactiveColor;
                this.pictureBoxSubs1.BackColor = inactiveColor;
                this.pictureBoxSubs2.BackColor = inactiveColor;
                this.panelSubs1.BackColor      = inactiveColor;
                this.panelSubs2.BackColor      = inactiveColor;
            }

            // Disable subs2 textbox if there aren't any subs2 files
            this.textBoxSubs2.Enabled    = (Settings.Instance.Subs[1].Files.Length != 0);
            this.pictureBoxSubs2.Enabled = (Settings.Instance.Subs[1].Files.Length != 0);
            this.panelSubs2.Enabled      = (Settings.Instance.Subs[1].Files.Length != 0);

            if (selectedComb.Subs1.Text.EndsWith("png" + ConstantSettings.SrsVobsubFilenameSuffix))
            {
                this.textBoxSubs1.Visible    = false;
                this.pictureBoxSubs1.Visible = true;

                try
                {
                    // Multiple vobsub image can be shown in a single line, so extract each image
                    // and concatenate them before displaying.
                    List <string> vobsubImages = UtilsSubs.extractVobsubFilesFromText(selectedComb.Subs1.Text);
                    List <Image>  vobSubImages = new List <Image>();

                    foreach (string vobsubImage in vobsubImages)
                    {
                        Image image = UtilsSnapshot.getImageFromFile(previewWorkerVars.MediaDir + Path.DirectorySeparatorChar + vobsubImage);
                        vobSubImages.Add(image);
                    }

                    if (vobSubImages.Count != 0)
                    {
                        Image image;

                        if (vobSubImages.Count == 0)
                        {
                            image = vobSubImages[0];
                        }
                        else
                        {
                            image = UtilsSnapshot.concatImages(vobSubImages);
                        }

                        this.pictureBoxSubs1.Image = image;
                    }
                }
                catch
                {
                    // Don't care
                }
            }
            else
            {
                this.textBoxSubs1.Visible    = true;
                this.pictureBoxSubs1.Visible = false;
                this.textBoxSubs1.Text       = selectedComb.Subs1.Text;
            }

            if (Settings.Instance.Subs[1].Files.Length != 0)
            {
                if (selectedComb.Subs2.Text.EndsWith("png" + ConstantSettings.SrsVobsubFilenameSuffix))
                {
                    this.textBoxSubs2.Visible    = false;
                    this.pictureBoxSubs2.Visible = true;

                    try
                    {
                        // Multiple vobsub image can be shown in a single line, so extract each image
                        // and concatenate them before displaying.
                        List <string> vobsubImages = UtilsSubs.extractVobsubFilesFromText(selectedComb.Subs2.Text);
                        List <Image>  vobSubImages = new List <Image>();

                        foreach (string vobsubImage in vobsubImages)
                        {
                            Image image = UtilsSnapshot.getImageFromFile(previewWorkerVars.MediaDir + Path.DirectorySeparatorChar + vobsubImage);
                            vobSubImages.Add(image);
                        }

                        if (vobSubImages.Count != 0)
                        {
                            Image image;

                            if (vobSubImages.Count == 0)
                            {
                                image = vobSubImages[0];
                            }
                            else
                            {
                                image = UtilsSnapshot.concatImages(vobSubImages);
                            }

                            this.pictureBoxSubs2.Image = image;
                        }
                    }
                    catch
                    {
                    }
                }
                else
                {
                    this.textBoxSubs2.Visible    = true;
                    this.pictureBoxSubs2.Visible = false;
                    this.textBoxSubs2.Text       = selectedComb.Subs2.Text;
                }
            }
            else
            {
                this.textBoxSubs2.Visible    = true;
                this.pictureBoxSubs2.Visible = false;
                this.textBoxSubs2.Text       = "";
            }
        }