private void ImportFontMenuItem_Click(object sender, EventArgs e)
        {
            if (SelectedImageMetadata.Count == 0)
            {
                return;
            }

            using (var importFontWindow = new ImportFontWindow(SelectedImageMetadata))
            {
                if (importFontWindow.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var importedData = importFontWindow.GetImportedData();
                foreach (var imageDataTuple in importedData)
                {
                    var metadata  = imageDataTuple.Item1;
                    var imageData = imageDataTuple.Item2;

                    ProcessImage(x => imageData, metadata);
                }
                ImageCacheManager.RebuildCache(m_firmware);
                ImageListBox.Invalidate();
                ImageListBox_SelectedValueChanged(ImageListBox, EventArgs.Empty);
            }
        }
        private bool[,] ProcessImage(Func <bool[, ], bool[, ]> imageDataProcessor, FirmwareImageMetadata imageMetadata, bool rebuildCache = false)
        {
            var processedData      = imageDataProcessor(ImagePixelGrid.Data);
            var processedImageSize = processedData.GetSize();
            var imageSizeChanged   = imageMetadata.Width != processedImageSize.Width || imageMetadata.Height != processedImageSize.Height;

            imageMetadata.Width  = (byte)processedImageSize.Width;
            imageMetadata.Height = (byte)processedImageSize.Height;

            m_firmware.WriteImage(processedData, imageMetadata);

            if (imageSizeChanged || rebuildCache)
            {
                ImageCacheManager.RebuildCache(m_firmware);
                ImageListBox.Invalidate();
            }
            else
            {
                var cachedImage = BitmapProcessor.CreateBitmapFromRaw(processedData);
                ImageCacheManager.SetGlyphImage(imageMetadata.Index, imageMetadata.BlockType, cachedImage);
                ImageCacheManager.RebuildStringImageCache(m_firmware, imageMetadata.BlockType);
                var updateCache = new Action(() =>
                {
                    ImageListBox.Invoke(new Action(() =>
                    {
                        var itemRect = ImageListBox.GetItemRectangle(imageMetadata.Index - 1);
                        ImageListBox.Invalidate(itemRect);
                    }));
                });
                updateCache.BeginInvoke(null, null);
            }

            IsDirty = true;
            return(processedData);
        }
Пример #3
0
        public void ReloadFirmware(IEditorTabPage initiator)
        {
            if (m_firmware == null)
            {
                return;
            }

            m_tabPages.ForEach(x => x.OnWorkspaceReset());
            m_firmware.ReloadResources(m_loader);
            ImageCacheManager.RebuildCache(m_firmware);
            m_tabPages.ForEach(x => x.OnFirmwareLoaded(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;
            }

            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);
        }
Пример #5
0
        private void OpenFirmware(string firmwareFile, Func <string, Firmware> readFirmwareDelegate)
        {
            ResetWorkspace();
            try
            {
                var firmware = readFirmwareDelegate(firmwareFile);
                if (firmware == null)
                {
                    throw new InvalidOperationException("No one definition is not appropriate for the selected firmware file.");
                }

                m_firmware     = firmware;
                m_firmwareFile = firmwareFile;

                ImageCacheManager.RebuildCache(m_firmware);
                m_tabPages.ForEach(x =>
                {
                    x.OnFirmwareLoaded(m_firmware);
                    x.IsDirty = false;
                });

                SaveMenuItem.Enabled          = true;
                SaveEncryptedMenuItem.Enabled = true;
                SaveDecryptedMenuItem.Enabled = SaveDecryptedMenuItem.Visible = m_firmware.EncryptionType != EncryptionType.ArcticFox;
                StatusLabel.Text = @"Firmware file has been successfully loaded.";

                m_mruFirmwares.Add(firmwareFile);
                UpdateOpenedFirmwareInfo();
            }
            catch (Exception ex)
            {
                m_mruFirmwares.Remove(firmwareFile);
                InfoBox.Show("Unable to load firmware.\n{0}", ex.Message);
            }
            finally
            {
                InitializeMruMenu();
            }
        }
        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)
                {
                    ImportBlockImage(m_firmware.Block1Images, originalImageIndex, importedImage, allowResizeOriginalImages);
                }
                else if (importMode == ImageImportMode.Block2)
                {
                    ImportBlockImage(m_firmware.Block2Images, originalImageIndex, importedImage, allowResizeOriginalImages);
                }
                else
                {
                    ImportBlockImage(m_firmware.Block1Images, originalImageIndex, importedImage, allowResizeOriginalImages);
                    ImportBlockImage(m_firmware.Block2Images, originalImageIndex, importedImage, allowResizeOriginalImages);
                }
            }

            ImageCacheManager.RebuildCache(m_firmware);
            ImageListBox.Invalidate();
            ImageListBox_SelectedValueChanged(ImageListBox, EventArgs.Empty);
        }