Esempio n. 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>
        /// <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
                };

                bitmapImage = BitmapUtilities.ConvertToBitmapImage(this.instance.GetPreview(settings, preview));
            }
            catch (AccessViolationException e)
            {
                Debug.WriteLine(e);
            }

            return(bitmapImage);
        }
Esempio n. 2
0
        private void CreateBannerImage()
        {
            if (bannerBitmap != null)
            {
                bannerBitmap.Dispose();
            }

            ushort[] DecodedImageData = DecodeBNRImage(ImageData); //C4.DecodeC4(ImageData, 96, 32);
            uint[]   PixelData        = new uint[96 * 32];

            for (int i = 0; i < DecodedImageData.Length; i++)
            {
                PixelData[i] = RGB5A3.ToARGB8(DecodedImageData[i]);
            }

            byte[] BitmapSourceData = new byte[4 * 96 * 32];
            for (int i = 0; i < PixelData.Length; i++)
            {
                int idx = i * 4;
                BitmapSourceData[idx + 3] = (byte)((PixelData[i] >> 24) & 0xFF);
                BitmapSourceData[idx + 2] = (byte)((PixelData[i] >> 16) & 0xFF);
                BitmapSourceData[idx + 1] = (byte)((PixelData[i] >> 8) & 0xFF);
                BitmapSourceData[idx + 0] = (byte)((PixelData[i] >> 0) & 0xFF);
            }

            bannerBitmap = BitmapUtilities.CreateBitmap(BitmapSourceData, 96, 32);
            bannerImage  = bannerBitmap.ToBitmapSource();
        }
Esempio n. 3
0
        private void screenshotPortraitsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Bitmap screenshot = modelManager1.GrabScreenshot(true);

            int    size = Math.Min(screenshot.Width, screenshot.Height);
            Bitmap rect = new Bitmap(size, (int)(size * 160.0 / 128.0));

            using (Graphics g = Graphics.FromImage(rect))
            {
                int x = (screenshot.Width - rect.Width) / -2;
                int y = (screenshot.Height - rect.Height) / -2;
                g.DrawImage(screenshot, x, y);
            }

            string iconFile = Path.GetTempPath() + Guid.NewGuid() + ".png";

            BitmapUtilities.Resize(rect, new Size(128, 160)).Save(iconFile);
            cssPortraitViewer1.ReplaceMain(iconFile, false);

            try
            {
                File.Delete(iconFile);
            }
            catch (Exception)
            {
                Console.WriteLine("Could not delete temporary file " + iconFile);
            }
        }
Esempio n. 4
0
        private static ImageEngineFormat DetermineBestDDSFormat(Bitmap bitmap)
        {
            var ddsFormat = ImageEngineFormat.DDS_DXT1;

            if (BitmapUtilities.HasTransparency(bitmap))
            {
                ddsFormat = ImageEngineFormat.DDS_DXT3;
            }

            return(ddsFormat);
        }
Esempio n. 5
0
 public AskNameDialog(Bitmap bg)
 {
     InitializeComponent();
     panel1.BackgroundImage = bg;
     panel1.Width           = bg.Width;
     panel1.Height          = bg.Height;
     textBox1.Text          = BitmapUtilities.HasAlpha(bg) && BitmapUtilities.HasNonAlpha(bg)
         ? "MenSelmapMark."
         : "MenSelchrMark.";
     textBox1.Select(textBox1.Text.Length, 0);
     AcceptButton = button1;
 }
Esempio n. 6
0
        public void ResizeAllPrevbases(Size newSize)
        {
            if (sc_selmap == null)
            {
                return;
            }
            var prevbases = from c in sc_selmap.FindChild("MiscData[80]/Textures(NW4R)", false).Children
                            where c is TEX0Node && c.Name.Contains("MenSelmapPrevbase")
                            select(TEX0Node) c;
            int i = 0;

            foreach (TEX0Node node in prevbases)
            {
                Bitmap origImage = node.GetImage(0);
                if (origImage.Width <= newSize.Width && origImage.Height <= newSize.Height)
                {
                    continue;
                }

                string file = TempFiles.Create(".png");
                if (useTextureConverter)
                {
                    origImage.Save(file);

                    TextureConverterDialog d = new TextureConverterDialog();
                    d.ImageSource = file;
                    d.InitialSize = newSize;
                    if (d.ShowDialog(null, node) == DialogResult.OK)
                    {
                        node.IsDirty = true;
                        Console.WriteLine("Resized " + node);
                        i++;
                    }
                    else if (MessageBox.Show(this, "Stop resizing textures here?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        break;
                    }
                }
                else
                {
                    Bitmap b = BitmapUtilities.Resize(origImage, newSize);
                    b.Save(file);

                    node.Replace(file);
                    Console.WriteLine("Resized " + node);
                    i++;
                }

                File.Delete(file);
            }
            MessageBox.Show("Resized " + i + " images.");
            UpdateImage();
        }
Esempio n. 7
0
        /// <summary>
        /// Replace the MenSelmapMark texture in toReplace with the image in newBitmap, flipping the channels if the image has solid black in all four corners.
        /// </summary>
        /// <param name="newBitmap">The new texture to use</param>
        /// <param name="toReplace">The TEX0 to insert the texture in</param>
        /// <param name="createNew">If true, the format of the existing texture will not be used as a fallback, even if useExistingAsFallback is true</param>
        private void ReplaceSelmapMark(Bitmap newBitmap, TEX0Node toReplace, bool createNew)
        {
            WiiPixelFormat format =
                selmapMarkFormat != null
                                        ? selmapMarkFormat.Value
                                : useExistingAsFallback && !createNew
                                        ? toReplace.Format
                                : BitmapUtilities.HasAlpha(newBitmap)
                                        ? WiiPixelFormat.IA4
                                        : WiiPixelFormat.I4;

            Console.WriteLine(format);
            Bitmap toEncode = BitmapUtilities.HasSolidCorners(newBitmap) ? BitmapUtilities.AlphaSwap(newBitmap) : newBitmap;

            BrawlLib.IO.FileMap tMap = TextureConverter.Get(format).EncodeTEX0Texture(toEncode, 1);
            toReplace.ReplaceRaw(tMap);
        }
        public void InitializePlayButton()
        {
            // Already initialized
            if (PlayButton.Children.Count > 0)
            {
                return;
            }
            double canvasHeight    = this.CellHeight / 5;
            double canvasWidth     = this.CellWidth;
            double ellipseDiameter = canvasHeight * .7;
            double ellipseRadius   = ellipseDiameter / 2;

            this.PlayButton.Height = canvasHeight;

            Ellipse ellipse = new Ellipse
            {
                Width  = ellipseDiameter,
                Height = ellipseDiameter,
                Fill   = new SolidColorBrush
                {
                    Color   = selectedColor,
                    Opacity = 0.5
                }
            };

            Canvas.SetLeft(ellipse, canvasWidth / 2 - ellipseDiameter / 2);

            Point           center         = new Point(ellipseRadius, ellipseRadius);
            PointCollection trianglePoints = BitmapUtilities.GetTriangleVerticesInscribedInCircle(center, (float)ellipseDiameter * .7f / 2);

            // Construct the triangle
            Polygon triangle = new Polygon
            {
                Points = trianglePoints,
                Fill   = new SolidColorBrush
                {
                    Color   = Colors.Blue,
                    Opacity = 0.5
                },
            };

            Canvas.SetLeft(triangle, canvasWidth / 2 - ellipseDiameter / 2);

            this.PlayButton.Children.Add(ellipse);
            this.PlayButton.Children.Add(triangle);
        }
Esempio n. 9
0
        private void OverlayName()
        {
            Image orig = textureData[0].Panel.BackgroundImage;

            Bitmap name    = new Bitmap(textureData[1].Texture.GetImage(0));
            Bitmap swapped = BitmapUtilities.AlphaSwap(name);
            Bitmap blurred = BitmapUtilities.BlurCombine(swapped, Color.Black);

            Bitmap   overlaid = new Bitmap(orig.Width, orig.Height);
            Graphics g        = Graphics.FromImage(overlaid);

            g.DrawImage(orig,
                        new Rectangle(0, 0, 128, 160),
                        new Rectangle(0, 0, 128, 160),
                        GraphicsUnit.Pixel);
            g.DrawImage(blurred, new Point[] {
                new Point(0, 84),
                new Point(131, 84),
                new Point(-3, 127)
            });
            textureData[0].Panel.BackgroundImage = overlaid;
        }
Esempio n. 10
0
        private void setBG(Panel panel)
        {
            var    texInfo = GetTexInfoFor(panel);
            Bitmap bgi     = null;

            if (texInfo.tex0 == null)
            {
                Bitmap b = new Bitmap(1, 1);
                b.SetPixel(0, 0, Color.Brown);
                bgi = b;
            }
            else
            {
                Bitmap image = new Bitmap(texInfo.tex0.GetImage(0));
                if (panel == seriesicon && selmapMarkPreview)
                {
                    bgi = BitmapUtilities.Invert(BitmapUtilities.AlphaSwap(image));
                }
                else if (panel == prevbase && selmapMarkPreview && scribble != null)
                {
                    bgi = BitmapUtilities.ApplyMask(image, scribble);
                }
                else
                {
                    bgi = image;
                }
                if (bgi.Size != panel.Size)
                {
                    bgi = BitmapUtilities.Resize(bgi, panel.Size);
                }
            }

            if (!texInfo.ForThisFrameIndex)
            {
                bgi = BitmapUtilities.Border(bgi, Color.Brown, 2);
            }

            panel.BackgroundImage = bgi;
        }
        // When the user enters a listbox item, show the image
        private void Row_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (!(sender is DataGridRow dgr))
            {
                return;
            }
            if (dgr?.Item == null)
            {
                return;
            }

            Tuple <string, string, bool> tuple = (Tuple <string, string, bool>)dgr.Item;
            string path  = Path.Combine(this.FolderPath, tuple.Item1);
            Image  image = new Image()
            {
                Source = Util.FilesFolders.GetFileTypeByItsExtension(path) == FileExtensionEnum.IsImage
                ? BitmapUtilities.GetBitmapFromImageFile(path, Constant.ImageValues.PreviewWidth480, ImageDisplayIntentEnum.Ephemeral, ImageDimensionEnum.UseWidth, out _)
                : BitmapUtilities.GetBitmapFromVideoFile(path, Constant.ImageValues.PreviewWidth480, ImageDisplayIntentEnum.Ephemeral, ImageDimensionEnum.UseWidth, out _),
                HorizontalAlignment = HorizontalAlignment.Left
            };

            dgr.ToolTip = image;
        }
Esempio n. 12
0
        static void refreshBlankImage(ImageSource templateImage, ref BitmapSource blankImage)
        {
            if (blankImage != null)
            {
                if (blankImage.Height == templateImage.Height &&
                    blankImage.Width == templateImage.Width)
                {
                    return;
                }
            }

            int stride = BitmapUtilities.CalculateStride(PixelFormats.Bgra32, (int)templateImage.Width);

            byte[] pixelValues = new byte[(int)templateImage.Height * stride];
            for (int i = 0; i < pixelValues.Length; i = i + 4)
            {
                pixelValues[i]     = 0;
                pixelValues[i + 1] = 0;
                pixelValues[i + 2] = 0;
                pixelValues[i + 3] = 255;
            }
            blankImage = BitmapSource.Create((int)templateImage.Width, (int)templateImage.Height, 96, 96, PixelFormats.Bgra32, null, pixelValues, stride);
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
        public bool AddMenSelmapMark(string path, bool ask)
        {
            string tmp = null;

            if (path.EndsWith(".tex0", StringComparison.InvariantCultureIgnoreCase))
            {
                tmp = TempFiles.Create(".png");
                NodeFactory.FromFile(null, path).Export(tmp);
            }
            Bitmap bitmap = new Bitmap(tmp ?? path);

            if (BitmapUtilities.HasSolidCorners(bitmap))
            {
                bitmap = BitmapUtilities.AlphaSwap(bitmap);
            }
            string name = Path.GetFileNameWithoutExtension(path);

            if (ask)
            {
                using (var nameDialog = new AskNameDialog(bitmap)) {
                    nameDialog.Text = name;
                    if (nameDialog.ShowDialog() != DialogResult.OK)
                    {
                        return(false);
                    }
                    else
                    {
                        name = nameDialog.NameText;
                    }
                }
            }
            BRRESNode bres = sc_selmap.FindChild("MiscData[80]", false) as BRRESNode;
            TEX0Node  tex0 = bres.CreateResource <TEX0Node>(name);

            ReplaceSelmapMark(bitmap, tex0, true);
            return(true);
        }
Esempio n. 15
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;
                    }
                }
            }
        }
Esempio n. 16
0
 // Return the aspect ratio (as Width/Height) of a bitmap or its placeholder as efficiently as possible
 // Timing tests suggests this can be done very quickly i.e., 0 - 10 msecs
 // While this is marked as virtual, there is currently no over-ride for getting it from a video.
 // So it should only be invoked if we know the file is an image
 public virtual double GetBitmapAspectRatioFromFile(string rootFolderPath)
 {
     return(BitmapUtilities.GetBitmapAspectRatioFromImageFile(this.GetFilePath(rootFolderPath)));
 }
Esempio n. 17
0
 /// <summary>
 //// Load: Full form
 /// Get a bitmap of the desired width. If its not there or something is wrong it will return a placeholder bitmap displaying the 'error'.
 /// Also sets a flag (isCorruptOrMissing) indicating if the bitmap wasn't retrieved (signalling a placeholder bitmap was returned)
 /// </summary>
 public virtual BitmapSource LoadBitmap(string rootFolderPath, Nullable <int> desiredWidthOrHeight, ImageDisplayIntentEnum displayIntent, ImageDimensionEnum imageDimension, out bool isCorruptOrMissing)
 {
     // Invoke the static version. The only change is that we get the full file path and pass that as a parameter
     return(BitmapUtilities.GetBitmapFromImageFile(this.GetFilePath(rootFolderPath), desiredWidthOrHeight, displayIntent, imageDimension, out isCorruptOrMissing));
 }
Esempio n. 18
0
 private void qualitySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
 {
     BitmapUtilities.setEncoderQuality((int)qualitySlider.Value);
 }
        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));
                }
            };
        }
Esempio n. 20
0
        public void Replace(object sender, string filename)
        {
            var ig = StringComparison.CurrentCultureIgnoreCase;

            if (filename.EndsWith(".tex0", ig))
            {
                TEX0Node tex0 = GetTexInfoFor(sender).tex0;
                if (tex0 == null)
                {
                    return;
                }
                tex0.Replace(filename);
                tex0.IsDirty = true;
                UpdateImage();
            }
            else if (filename.EndsWith(".brres", ig))
            {
                using (ResourceNode node = NodeFactory.FromFile(null, filename)) {
                    TEX0Node tex0;
                    if (node is TEX0Node)
                    {
                        tex0 = (TEX0Node)node;
                    }
                    else
                    {
                        tex0 = (TEX0Node)node.FindChild("Textures(NW4R)", false).Children[0];
                    }
                    string tempFile = TempFiles.Create(".png");
                    tex0.Export(tempFile);
                    Replace(sender, tempFile);                     // call self with new file
                }
            }
            else
            {
                TEX0Node tex0 = GetTexInfoFor(sender).tex0;
                if (tex0 == null)
                {
                    AddNewTEX0(sender, filename);
                    return;
                }
                else if (useTextureConverter)
                {
                    using (TextureConverterDialog dlg = new TextureConverterDialog()) {
                        dlg.ImageSource = filename;
                        dlg.InitialSize =
                            sender == prevbase ? prevbaseResizeTo
                                                        : sender == frontstname ? frontstnameResizeTo
                                                        : sender == selmap_mark ? selmapMarkResizeTo
                                                        : null;
                        dlg.FormBorderStyle = FormBorderStyle.FixedSingle;
                        dlg.ShowInTaskbar   = true;
                        if (dlg.ShowDialog(null, tex0) == DialogResult.OK)
                        {
                            tex0.IsDirty = true;
                            UpdateImage();
                        }
                    }
                }
                else
                {
                    Bitmap bmp = new Bitmap(filename);
                    if (sender == prevbase && prevbaseResizeTo != null)
                    {
                        bmp = BitmapUtilities.Resize(bmp, prevbaseResizeTo.Value);
                    }
                    else if (sender == frontstname && frontstnameResizeTo != null)
                    {
                        bmp = BitmapUtilities.Resize(bmp, frontstnameResizeTo.Value);
                    }
                    else if (sender == selmap_mark && selmapMarkResizeTo != null)
                    {
                        bmp = BitmapUtilities.Resize(bmp, selmapMarkResizeTo.Value);
                    }
                    if (sender == selmap_mark)
                    {
                        ReplaceSelmapMark(bmp, tex0, false);
                    }
                    else
                    {
                        int colorCount = BitmapUtilities.CountColors(bmp, 256).Align(16);
                        tex0.Replace(bmp, colorCount);
                    }
                    tex0.IsDirty = true;
                    UpdateImage();
                }
            }
        }
        public QueueTitlesWindowViewModel()
        {
            this.main           = Ioc.Get <MainViewModel>();
            this.PickersService = Ioc.Get <PickersService>();
            this.windowManager  = Ioc.Get <IWindowManager>();

            this.selectedTitles            = new ReactiveList <TitleSelectionViewModel>();
            this.titleStartOverrideEnabled = Config.QueueTitlesUseTitleOverride;
            this.titleStartOverride        = Config.QueueTitlesTitleOverride;
            this.nameOverrideEnabled       = Config.QueueTitlesUseNameOverride;
            this.nameOverride = Config.QueueTitlesNameOverride;

            this.titles = new ReactiveList <TitleSelectionViewModel>();
            this.RefreshTitles();

            this.Play = ReactiveCommand.Create(MvvmUtilities.CreateConstantObservable(!Utilities.IsRunningAsAppx && Players.Installed.Count > 0));
            this.Play.Subscribe(_ => this.PlayImpl());

            this.AddToQueue = ReactiveCommand.Create();
            this.AddToQueue.Subscribe(_ => this.AddToQueueImpl());

            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.CountChanged
            .Select(count => count == 1)
            .ToProperty(this, x => x.TitleDetailsVisible, out this.titleDetailsVisible, initialValue: false);

            this.selectedTitles.CollectionChanged +=
                (sender, args) =>
            {
                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>()
                    };

                    var previewJob =
                        new VCJob
                    {
                        RangeType       = VideoRangeType.All,
                        Title           = title.Index,
                        EncodingProfile = previewProfile
                    };

                    this.PreviewImage = BitmapUtilities.ConvertToBitmapImage(this.main.ScanInstance.GetPreview(previewProfile.CreatePreviewSettings(title), 2, deinterlace: false));
                    this.RaisePropertyChanged(nameof(this.TitleText));
                }
            };
        }
Esempio n. 22
0
 public virtual bool IsDisplayable(string pathToRootFolder)
 {
     return(BitmapUtilities.IsBitmapFileDisplayable(Path.Combine(pathToRootFolder, this.RelativePath, this.File)));
 }