예제 #1
0
        public static Bitmap Create1BitBitmapFromRaw(bool[,] imageData)
        {
            if (imageData == null)
            {
                throw new ArgumentNullException("imageData");
            }

            var size       = FirmwareImageProcessor.GetImageSize(imageData);
            var result     = new Bitmap(size.Width, size.Height, PixelFormat.Format1bppIndexed);
            var bitmapData = result.LockBits(new Rectangle(0, 0, size.Width, size.Height), ImageLockMode.WriteOnly, PixelFormat.Format1bppIndexed);

            try
            {
                var scanLine = bitmapData.Scan0;
                for (var y = 0; y < size.Height; y++, scanLine += bitmapData.Stride)
                {
                    var line = new byte[bitmapData.Stride];
                    for (var x = 0; x < size.Width; x++)
                    {
                        if (imageData[x, y] == false)
                        {
                            continue;
                        }
                        line[x / 8] |= s_bitMasks[x % 8];
                    }
                    Marshal.Copy(line, 0, scanLine, bitmapData.Stride);
                }
            }
            finally
            {
                result.UnlockBits(bitmapData);
            }

            return(result);
        }
예제 #2
0
        public static Image CreateBitmapFromRaw([NotNull] bool[,] imageData, int pixelSize = 2)
        {
            if (imageData == null)
            {
                throw new ArgumentNullException("imageData");
            }

            var size   = FirmwareImageProcessor.GetImageSize(imageData);
            var result = new Bitmap(size.Width * pixelSize, size.Height * pixelSize);

            using (var gfx = Graphics.FromImage(result))
            {
                gfx.Clear(Color.Black);
                for (var col = 0; col < size.Width; col++)
                {
                    for (var row = 0; row < size.Height; row++)
                    {
                        if (!imageData[col, row])
                        {
                            continue;
                        }

                        if (pixelSize <= 1)
                        {
                            result.SetPixel(col, row, Color.White);
                        }
                        else
                        {
                            gfx.FillRectangle(Brushes.White, col * pixelSize, row * pixelSize, pixelSize, pixelSize);
                        }
                    }
                }
            }
            return(result);
        }
        public static void RebuildImageCache([NotNull] Firmware firmware)
        {
            if (firmware == null)
            {
                throw new ArgumentNullException("firmware");
            }

            var block1ImageCache = new Dictionary <int, Image>();

            foreach (var imageMetadata in firmware.Block1Images)
            {
                try
                {
                    var imageData = firmware.ReadImage(imageMetadata);
                    var image     = FirmwareImageProcessor.CreateBitmap(imageData);
                    block1ImageCache[imageMetadata.Index] = image;
                }
                catch
                {
                    block1ImageCache[imageMetadata.Index] = new Bitmap(1, 1);
                }
            }
            block1ImageCache.Add(0, new Bitmap(1, 16));

            var block2ImageCache = new Dictionary <int, Image>();

            foreach (var imageMetadata in firmware.Block2Images)
            {
                try
                {
                    var imageData = firmware.ReadImage(imageMetadata);
                    var image     = FirmwareImageProcessor.CreateBitmap(imageData);
                    block2ImageCache[imageMetadata.Index] = image;
                }
                catch
                {
                    block2ImageCache[imageMetadata.Index] = new Bitmap(1, 1);
                }
            }
            block2ImageCache.Add(0, new Bitmap(1, 16));

            SetCache(BlockType.Block1, block1ImageCache);
            SetCache(BlockType.Block2, block2ImageCache);
        }
        public static void RebuildStringImageCache([NotNull] Firmware firmware, BlockType blockType)
        {
            if (firmware == null)
            {
                throw new ArgumentNullException("firmware");
            }

            var firmwareImages = blockType == BlockType.Block1
                                ? firmware.Block1Images
                                : firmware.Block2Images;

            if (firmwareImages.Count == 0)
            {
                return;
            }

            var glyphData = new Dictionary <int, bool[, ]>();

            foreach (var kvp in firmwareImages)
            {
                glyphData[kvp.Key] = firmware.ReadImage(kvp.Value);
            }

            var stringImageCache = new Dictionary <int, Image>();

            foreach (var stringMetadata in firmware.Block1Strings.Concat(firmware.Block2Strings))
            {
                try
                {
                    var stringData = firmware.ReadString(stringMetadata);
                    var imageData  = FirmwareImageProcessor.GetStringImageData(stringData, glyphData,
                                                                               firmware.Definition.StringsPreviewCorrection != null ? firmware.Definition.StringsPreviewCorrection.ForGlyphs : null);
                    var image = BitmapProcessor.CreateBitmapFromRaw(imageData, 1);

                    stringImageCache[stringMetadata.Index] = image;
                }
                catch
                {
                    stringImageCache[stringMetadata.Index] = new Bitmap(1, 1);
                }
            }
            SetStringCache(blockType, stringImageCache);
        }
예제 #5
0
        public void SetData([NotNull] List <bool[, ]> images)
        {
            if (images == null)
            {
                throw new ArgumentNullException("images");
            }

            var data = new List <ExportedImage>();

            foreach (var image in images)
            {
                var size = FirmwareImageProcessor.GetImageSize(image);
                data.Add(new ExportedImage(0, size, image)
                {
                    DataString = ResourcePacksStorage.WriteImageToAsciiString(size.Width, size.Height, image)
                });
            }
            var buffer = Serializer.Write(data);

            Clipboard.SetText(buffer);
        }