コード例 #1
0
        public PreviewResourcePackWindow
        (
            Firmware firmware,
            IList <int> originalImageIndices,
            IList <bool[, ]> importedImages,
            bool resourceImport          = false,
            BlockType?defaultImportBlock = null
        ) : this()
        {
            if (originalImageIndices.Count != importedImages.Count)
            {
                throw new InvalidOperationException("Source and imported images count does not match.");
            }
            m_firmware = firmware;

            if (m_firmware.Block2Images.Any())
            {
                ImportModeComboBox.Items.Add("Block 1 & 2");
                ImportModeComboBox.Items.Add("Block 1");
                ImportModeComboBox.Items.Add("Block 2");

                if (defaultImportBlock.HasValue)
                {
                    ImportModeComboBox.SelectedIndex = defaultImportBlock == BlockType.Block1 ? 1 : 2;
                }
                else
                {
                    ImportModeComboBox.SelectedIndex = 0;
                }
            }
            else
            {
                ImportModeComboBox.Items.Add("Block 1");
                ImportModeComboBox.SelectedIndex = 0;
            }

            OptionsGroupBox.Enabled = !resourceImport;
            LeftLayoutPanel.SuspendLayout();
            RightLayoutPanel.SuspendLayout();
            for (var i = 0; i < originalImageIndices.Count; i++)
            {
                var originalImageIndex = originalImageIndices[i];
                var originalImage      = GetImageByIndex(originalImageIndex);
                if (originalImage == null)
                {
                    continue;
                }

                var importedImage        = importedImages[i];
                var croppedImportedImage = FirmwareImageProcessor.PasteImage(originalImage, importedImage);

                m_originalImportedImages[i] = importedImage;
                m_croppedImportedImages[i]  = croppedImportedImage;

                LeftLayoutPanel.Controls.Add(CreateGrid(originalImage));
                RightLayoutPanel.Controls.Add(CreateGrid(croppedImportedImage));
            }
            LeftLayoutPanel.ResumeLayout();
            RightLayoutPanel.ResumeLayout();
        }
コード例 #2
0
        private void ImportBlockImage(IDictionary <int, FirmwareImageMetadata> blockMetadataDictionary, int imageIndex, bool[,] importedImage, bool allowResizeOriginalImages)
        {
            FirmwareImageMetadata imageMetadata;

            if (!blockMetadataDictionary.TryGetValue(imageIndex, out imageMetadata))
            {
                return;
            }

            if (allowResizeOriginalImages)
            {
                ProcessImage(x => importedImage, imageMetadata);
            }
            else
            {
                ProcessImage(x => FirmwareImageProcessor.PasteImage(imageMetadata.CreateImage(), importedImage), imageMetadata);
            }
        }
コード例 #3
0
        private void ImportResourcePack([NotNull] IList <int> originalImageIndices, [NotNull] IList <bool[, ]> importedImages)
        {
            if (importedImages == null)
            {
                throw new ArgumentNullException("importedImages");
            }
            if (originalImageIndices == null)
            {
                throw new ArgumentNullException("originalImageIndices");
            }
            if (importedImages.Count == 0)
            {
                return;
            }

            for (var i = 0; i < originalImageIndices.Count; i++)
            {
                var originalImageIndex = originalImageIndices[i];
                var importedImage      = importedImages[i];

                if (m_firmware.Block1Images.Count > 0)
                {
                    FirmwareImageMetadata block1ImageMetadata;
                    if (m_firmware.Block1Images.TryGetValue(originalImageIndex, out block1ImageMetadata))
                    {
                        var block1Image = FirmwareImageProcessor.PasteImage(block1ImageMetadata.CreateImage(), importedImage);
                        m_firmware.WriteImage(block1Image, block1ImageMetadata);
                    }
                }

                if (m_firmware.Block2Images.Count > 0)
                {
                    FirmwareImageMetadata block2ImageMetadata;
                    if (m_firmware.Block2Images.TryGetValue(originalImageIndex, out block2ImageMetadata))
                    {
                        var block2Image = FirmwareImageProcessor.PasteImage(block2ImageMetadata.CreateImage(), importedImage);
                        m_firmware.WriteImage(block2Image, block2ImageMetadata);
                    }
                }
            }

            IsDirty = true;
            ImageCacheManager.RebuildCache(m_firmware);
        }
コード例 #4
0
        private void ImportResourcePack([NotNull] IList <int> originalImageIndices, [NotNull] IList <bool[, ]> importedImages)
        {
            if (importedImages == null)
            {
                throw new ArgumentNullException("importedImages");
            }
            if (originalImageIndices == null)
            {
                throw new ArgumentNullException("originalImageIndices");
            }
            if (importedImages.Count == 0)
            {
                return;
            }

            var block1MetadataDictionary = m_firmware.Block1Images.ToDictionary(x => x.Index, x => x);
            var block2MetadataDictionary = m_firmware.Block2Images.ToDictionary(x => x.Index, x => x);

            for (var i = 0; i < originalImageIndices.Count; i++)
            {
                var originalImageIndex = originalImageIndices[i];
                var importedImage      = importedImages[i];

                if (block1MetadataDictionary.Count > 0)
                {
                    var block1ImageMetadata = block1MetadataDictionary[originalImageIndex];
                    var block1Image         = FirmwareImageProcessor.PasteImage(block1ImageMetadata.CreateImage(), importedImage);
                    m_firmware.WriteImage(block1Image, block1ImageMetadata);
                }

                if (block2MetadataDictionary.Count > 0)
                {
                    var block2ImageMetadata = block2MetadataDictionary[originalImageIndex];
                    var block2Image         = FirmwareImageProcessor.PasteImage(block2ImageMetadata.CreateImage(), importedImage);
                    m_firmware.WriteImage(block2Image, block2ImageMetadata);
                }
            }

            ImageCacheManager.RebuildImageCache(m_firmware);
        }
コード例 #5
0
        private void ImportImages([NotNull] IList <int> originalImageIndices, [NotNull] IList <bool[, ]> importedImages)
        {
            if (importedImages == null)
            {
                throw new ArgumentNullException("importedImages");
            }
            if (originalImageIndices == null)
            {
                throw new ArgumentNullException("originalImageIndices");
            }
            if (importedImages.Count == 0)
            {
                return;
            }

            var minimumImagesCount = Math.Min(originalImageIndices.Count, importedImages.Count);

            originalImageIndices = originalImageIndices.Take(minimumImagesCount).ToList();
            importedImages       = importedImages.Take(minimumImagesCount).ToList();

            ImageImportMode importMode;
            bool            allowResizeOriginalImages;

            using (var importWindow = new PreviewResourcePackWindow(m_firmware, originalImageIndices, importedImages, false, m_currentBlock))
            {
                importWindow.Text             = Consts.ApplicationTitleWoVersion + @" - Paste image(s)";
                importWindow.ImportButtonText = "Paste";
                if (importWindow.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                importMode = importWindow.GetImportMode();
                allowResizeOriginalImages = importWindow.AllowResizeOriginalImages;
            }

            for (var i = 0; i < minimumImagesCount; i++)
            {
                var index = i;
                var originalImageIndex = originalImageIndices[index];
                var importedImage      = importedImages[index];
                if (importMode == ImageImportMode.Block1)
                {
                    var block1ImageMetadata = m_firmware.Block1Images.First(x => x.Index == originalImageIndex);
                    if (allowResizeOriginalImages)
                    {
                        ProcessImage(x => importedImage, block1ImageMetadata);
                    }
                    else
                    {
                        ProcessImage(x => FirmwareImageProcessor.PasteImage(block1ImageMetadata.CreateImage(), importedImage), block1ImageMetadata);
                    }
                }
                else if (importMode == ImageImportMode.Block2)
                {
                    var block2ImageMetadata = m_firmware.Block2Images.First(x => x.Index == originalImageIndex);
                    if (allowResizeOriginalImages)
                    {
                        ProcessImage(x => importedImage, block2ImageMetadata);
                    }
                    else
                    {
                        ProcessImage(x => FirmwareImageProcessor.PasteImage(block2ImageMetadata.CreateImage(), importedImage), block2ImageMetadata);
                    }
                }
                else
                {
                    var block1ImageMetadata = m_firmware.Block1Images.First(x => x.Index == originalImageIndex);
                    var block2ImageMetadata = m_firmware.Block2Images.First(x => x.Index == originalImageIndex);

                    if (allowResizeOriginalImages)
                    {
                        ProcessImage(x => importedImage, block1ImageMetadata);
                        ProcessImage(x => importedImage, block2ImageMetadata);
                    }
                    else
                    {
                        ProcessImage(x => FirmwareImageProcessor.PasteImage(block1ImageMetadata.CreateImage(), importedImage), block1ImageMetadata);
                        ProcessImage(x => FirmwareImageProcessor.PasteImage(block2ImageMetadata.CreateImage(), importedImage), block2ImageMetadata);
                    }
                }
            }

            ImageCacheManager.RebuildImageCache(m_firmware);
            ImageListBox.Invalidate();
            ImageListBox_SelectedValueChanged(ImageListBox, EventArgs.Empty);
        }
コード例 #6
0
        private void BitmapImportButton_Click(object sender, EventArgs eventArgs)
        {
            if (LastSelectedImageMetadata == null)
            {
                return;
            }

            try
            {
                using (var imageConverterWindow = new ImageConverterWindow(true, LastSelectedImageMetadata.Width, LastSelectedImageMetadata.Height))
                {
                    if (imageConverterWindow.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    using (var monochrome = imageConverterWindow.GetConvertedImage())
                    {
                        var imageData = BitmapProcessor.CreateRawFromBitmap(monochrome);
                        ImagePixelGrid.CreateUndo();
                        ImagePixelGrid.Data = ImagePreviewPixelGrid.Data = ProcessImage(x => FirmwareImageProcessor.PasteImage(x, imageData), LastSelectedImageMetadata, true);
                    }
                }
            }
            catch (Exception ex)
            {
                InfoBox.Show("Unable to import bitmap image.\n" + ex.Message);
            }
        }
コード例 #7
0
        private void BitmapImportButton_Click(object sender, EventArgs eventArgs)
        {
            if (LastSelectedImageMetadata == null)
            {
                return;
            }

            using (var op = new OpenFileDialog {
                Filter = Consts.BitmapImportFilter
            })
            {
                if (op.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                try
                {
                    var bitmapFile = op.FileName;
                    using (var bitmap = (Bitmap)Image.FromFile(bitmapFile))
                    {
                        if (bitmap.Width > 2048 || bitmap.Height > 2048)
                        {
                            InfoBox.Show("Selected images is too big. Choose an image that has dimension lower than 2048x2048.");
                            return;
                        }
                        using (var scaledBitmap = BitmapProcessor.ScaleBitmapIfNecessary(bitmap, new Size(LastSelectedImageMetadata.Width, LastSelectedImageMetadata.Height)))
                            using (var monochrome = BitmapProcessor.ConvertTo1Bit(scaledBitmap))
                            {
                                var imageData = BitmapProcessor.CreateRawFromBitmap(monochrome);
                                ImagePixelGrid.CreateUndo();
                                ImagePixelGrid.Data = ImagePreviewPixelGrid.Data = ProcessImage(x => FirmwareImageProcessor.PasteImage(x, imageData), LastSelectedImageMetadata, true);
                            }
                    }
                }
                catch (Exception ex)
                {
                    InfoBox.Show("Unable to import bitmap image.\n" + ex.Message);
                }
            }
        }
コード例 #8
0
        private void BitmapImportButton_Click(object sender, EventArgs eventArgs)
        {
            if (LastSelectedImageMetadata == null)
            {
                return;
            }

            using (var op = new OpenFileDialog {
                Filter = Consts.BitmapImportFilter
            })
            {
                if (op.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                try
                {
                    var bitmapFile = op.FileName;
                    using (var bitmap = (Bitmap)Image.FromFile(bitmapFile))
                    {
                        if (bitmap.Width > Consts.MaximumImageWidthAndHeight || bitmap.Height > Consts.MaximumImageWidthAndHeight)
                        {
                            InfoBox.Show("Image is too big. Image width and height must be lower or equals to {0} pixels.", Consts.MaximumImageWidthAndHeight);
                            return;
                        }
                        var imageData = FirmwareImageProcessor.ImportBitmap(bitmap);
                        ImagePixelGrid.CreateUndo();
                        ImagePixelGrid.Data = ImagePreviewPixelGrid.Data = ProcessImage(x => FirmwareImageProcessor.PasteImage(x, imageData), LastSelectedImageMetadata, true);
                    }
                }
                catch (Exception ex)
                {
                    InfoBox.Show("Unable to import bitmap image.\n" + ex.Message);
                }
            }
        }