Exemple #1
0
        /// <summary>
        /// Get a Preview image for the current job and preview number.
        /// </summary>
        /// <param name="job">
        /// The job.
        /// </param>
        /// <param name="preview">
        /// The preview.
        /// </param>
        /// <returns>
        /// The <see cref="BitmapImage"/>.
        /// </returns>
        public BitmapImage GetPreview(EncodeTask job, int preview)
        {
            if (this.instance == null)
            {
                return(null);
            }

            BitmapImage bitmapImage = null;

            try
            {
                EncodeTaskFactory factory    = new EncodeTaskFactory(this.userSettingService);
                JsonEncodeObject  jobDict    = factory.Create(job, HBConfigurationFactory.Create());
                RawPreviewData    bitmapData = this.instance.GetPreview(jobDict, preview);
                bitmapImage = BitmapUtilities.ConvertToBitmapImage(BitmapUtilities.ConvertByteArrayToBitmap(bitmapData));
            }
            catch (AccessViolationException e)
            {
                Debug.WriteLine(e);
            }

            return(bitmapImage);
        }
Exemple #2
0
        /// <summary>
        /// Get a Preview image for the current job and preview number.
        /// </summary>
        /// <param name="job">
        /// The job.
        /// </param>
        /// <param name="preview">
        /// The preview.
        /// </param>
        /// <param name="configuraiton">
        /// The configuraiton.
        /// </param>
        /// <returns>
        /// The <see cref="BitmapImage"/>.
        /// </returns>
        public BitmapImage GetPreview(EncodeTask job, int preview, HBConfiguration configuraiton)
        {
            if (this.instance == null)
            {
                return(null);
            }

            BitmapImage bitmapImage = null;

            try
            {
                PreviewSettings settings = new PreviewSettings
                {
                    Cropping          = new Cropping(job.Cropping),
                    MaxWidth          = job.MaxWidth ?? 0,
                    MaxHeight         = job.MaxHeight ?? 0,
                    KeepDisplayAspect = job.KeepDisplayAspect,
                    TitleNumber       = job.Title,
                    Anamorphic        = job.Anamorphic,
                    Modulus           = job.Modulus,
                    Width             = job.Width ?? 0,
                    Height            = job.Height ?? 0,
                    PixelAspectX      = job.PixelAspectX,
                    PixelAspectY      = job.PixelAspectY
                };

                var bitmapData = this.instance.GetPreview(settings, preview, job.DeinterlaceFilter != DeinterlaceFilter.Off);
                bitmapImage = BitmapUtilities.ConvertToBitmapImage(BitmapUtilities.ConvertByteArrayToBitmap(bitmapData));
            }
            catch (AccessViolationException e)
            {
                Debug.WriteLine(e);
            }

            return(bitmapImage);
        }
Exemple #3
0
        private void ProcessPreviewImageWork(object state)
        {
            PreviewImageJob imageJob;
            bool            workLeft = true;

            while (workLeft)
            {
                lock (this.imageSync)
                {
                    if (this.previewImageWorkQueue.Count == 0)
                    {
                        this.previewImageQueueProcessing = false;
                        return;
                    }

                    imageJob = this.previewImageWorkQueue.Dequeue();
                    while (imageJob.UpdateVersion < updateVersion)
                    {
                        if (this.previewImageWorkQueue.Count == 0)
                        {
                            this.previewImageQueueProcessing = false;
                            return;
                        }

                        imageJob = this.previewImageWorkQueue.Dequeue();
                    }
                }

                string imagePath = Path.Combine(
                    Utilities.ImageCacheFolder,
                    Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture),
                    imageJob.UpdateVersion.ToString(CultureInfo.InvariantCulture),
                    imageJob.PreviewIndex.ToString(CultureInfo.InvariantCulture) + ".bmp");
                BitmapSource imageSource = null;

                // Check the disc cache for the image
                lock (imageJob.ImageFileSync)
                {
                    if (File.Exists(imagePath))
                    {
                        Uri imageUri;
                        if (Uri.TryCreate(imagePath, UriKind.Absolute, out imageUri))
                        {
                            // When we read from disc cache the image is already transformed.
                            var bitmapImage = new BitmapImage();
                            bitmapImage.BeginInit();
                            bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                            bitmapImage.UriSource   = imageUri;
                            bitmapImage.EndInit();
                            bitmapImage.Freeze();

                            imageSource = bitmapImage;
                        }
                        else
                        {
                            StaticResolver.Resolve <IAppLogger>().LogError($"Could not load cached preview image from {imagePath} . Did not parse as a URI.");
                        }
                    }
                }

                if (imageSource == null && !imageJob.ScanInstance.IsDisposed)
                {
                    // Make a HandBrake call to get the image
                    imageSource = BitmapUtilities.ConvertToBitmapImage(BitmapUtilities.ConvertByteArrayToBitmap(imageJob.ScanInstance.GetPreview(imageJob.Profile.CreatePreviewSettings(imageJob.Title), imageJob.PreviewIndex, imageJob.Profile.DeinterlaceType != VCDeinterlace.Off)));

                    // Transform the image as per rotation and reflection settings
                    VCProfile profile = imageJob.Profile;
                    if (profile.FlipHorizontal || profile.FlipVertical || profile.Rotation != VCPictureRotation.None)
                    {
                        imageSource = CreateTransformedBitmap(imageSource, profile);
                    }

                    // Start saving the image file in the background and continue to process the queue.
                    ThreadPool.QueueUserWorkItem(this.BackgroundFileSave, new SaveImageJob
                    {
                        PreviewNumber = imageJob.PreviewIndex,
                        UpdateVersion = imageJob.UpdateVersion,
                        FilePath      = imagePath,
                        Image         = imageSource,
                        ImageFileSync = imageJob.ImageFileSync
                    });
                }

                lock (this.imageSync)
                {
                    if (imageJob.UpdateVersion == updateVersion)
                    {
                        this.previewImageCache[imageJob.PreviewIndex] = imageSource;
                        int previewIndex = imageJob.PreviewIndex;
                        DispatchUtilities.BeginInvoke(() =>
                        {
                            this.ImageLoaded?.Invoke(this, new PreviewImageLoadInfo {
                                PreviewImage = imageSource, PreviewIndex = previewIndex
                            });
                            //this.previewBitmapSource = imageSource;
                            //this.RefreshFromBitmapImage();
                        });
                        //if (this.SelectedPreview == imageJob.PreviewIndex)
                        //   {
                        //    DispatchUtilities.BeginInvoke(() =>
                        //    {
                        //	    this.previewBitmapSource = imageSource;
                        //	    this.RefreshFromBitmapImage();
                        //    });
                        //   }
                    }

                    if (this.previewImageWorkQueue.Count == 0)
                    {
                        workLeft = false;
                        this.previewImageQueueProcessing = false;
                    }
                }
            }
        }
        public QueueTitlesWindowViewModel()
        {
            this.main           = StaticResolver.Resolve <MainViewModel>();
            this.PickersService = StaticResolver.Resolve <PickersService>();
            this.windowManager  = StaticResolver.Resolve <IWindowManager>();

            this.titleStartOverrideEnabled = Config.QueueTitlesUseTitleOverride;
            this.titleStartOverride        = Config.QueueTitlesTitleOverride;
            this.nameOverrideEnabled       = Config.QueueTitlesUseNameOverride;
            this.nameOverride = Config.QueueTitlesNameOverride;

            this.RefreshTitles();

            this.main.WhenAnyValue(x => x.SourceData)
            .Skip(1)
            .Subscribe(_ =>
            {
                this.RefreshTitles();
            });

            this.PickersService.WhenAnyValue(x => x.SelectedPicker.Picker.TitleRangeSelectEnabled)
            .Skip(1)
            .Subscribe(_ =>
            {
                this.SetSelectedFromRange();
            });

            this.PickersService.WhenAnyValue(x => x.SelectedPicker.Picker.TitleRangeSelectStartMinutes)
            .Skip(1)
            .Subscribe(_ =>
            {
                this.SetSelectedFromRange();
            });

            this.PickersService.WhenAnyValue(x => x.SelectedPicker.Picker.TitleRangeSelectEndMinutes)
            .Skip(1)
            .Subscribe(_ =>
            {
                this.SetSelectedFromRange();
            });

            this.SelectedTitles.CollectionChanged +=
                (sender, args) =>
            {
                this.RaisePropertyChanged(nameof(this.TitleDetailsVisible));

                if (this.SelectedTitles.Count == 1)
                {
                    SourceTitle title = this.SelectedTitles[0].Title;

                    // Do preview
                    var previewProfile =
                        new VCProfile
                    {
                        CustomCropping = true,
                        Cropping       = new VCCropping(),
                        VideoEncoder   = "x264",
                        AudioEncodings = new List <AudioEncoding>()
                    };

                    this.PreviewImage = BitmapUtilities.ConvertToBitmapImage(BitmapUtilities.ConvertByteArrayToBitmap(this.main.ScanInstance.GetPreview(previewProfile.CreatePreviewSettings(title), 2, deinterlace: false)));
                    this.RaisePropertyChanged(nameof(this.TitleText));
                }
            };
        }