Пример #1
0
        public Bitmap Run(IList<ImageLayout> extractResult, NationColorOffset nationColorOffset, int imageNumber, RawParser rawParser, IRenderer renderer, Color[] imagePaletteArray, Color[] generalPaletteColors)
        {
            var imageGenerator = new ImageGenerator();

            var partialLayouts = extractResult[imageNumber].PartialLayouts;

            var largestWidth = partialLayouts
                .Select(it => it.Width + it.offsetX)
                .OrderByDescending(it => it)
                .First();

            var largestHeight = partialLayouts
                .Select(it => it.Height + it.offsetY)
                .OrderByDescending(it => it)
                .First();

            var bitMap = new Bitmap(largestWidth, largestHeight);
            renderer.SetupCanvas(bitMap);

            foreach (var layout in partialLayouts)
            {

                ImageLayoutInfo layout1 = layout;

                var imageView = new ImageView(layout1.Width + layout1.offsetX, layout1.Height + layout1.offsetY);

                var firstPartBlocks = Helper.WithMeasurement(() =>
                {
                    var rawFirstPartBlocks = rawParser.ParseRawBlockGroups(layout1.Bytes, layout1.NumberOfRows);
                    return rawFirstPartBlocks.ConvertToAbsoluteCoordinatesBlocks();

                }, "firstPartBlocks");

                var secondPartBlocks = Helper.WithMeasurement(() => rawParser.GetRawColorBlocks(layout1.Bytes, layout1.ColorBlocksSectionOffset, (int)layout1.GlobalByteOffsetStart + layout1.ColorBlocksSectionOffset + layout1.HeaderBytes.Length, layout1.IsNationColorImage), "secondPartBlocks");

                Helper.WithMeasurement(() =>
                {
                    imageGenerator.RenderShapeBlocks(imageView, firstPartBlocks, layout1);
                    imageGenerator.RenderCounterBlocksOnBitmap(imageView, nationColorOffset, firstPartBlocks, secondPartBlocks, layout1, imagePaletteArray, generalPaletteColors);
                }, "RenderCounterBlocksOnBitmap");

                Helper.WithMeasurement(() => renderer.RenderImage(bitMap, imageView), "Render on bitmap");
            }

            return bitMap;
        }
Пример #2
0
        private IList<Bitmap> DrawImage(IList<ImageLayout> extractResult, NationColorOffset nationColorOffset, int numberOfImages, RawParser rawParser, IRenderer renderer, Color[] imagePaletteArray,
            Color[] generalPalleteArray)
        {
            return Helper.WithMeasurement(
                () =>
                {
                    var bitMapCollection = new Collection<Bitmap>();

                    //var idsForProcessing = new[] { 0 };
                    var idsForProcessing = Enumerable.Range(1, numberOfImages - 1).ToList();

                    foreach (var imageNumber in idsForProcessing)
                    {
                        Debug.WriteLine("***************************** " + imageNumber);
                        Watch(extractResult[imageNumber].PartialLayouts.ToList());
                    }

                    foreach (int i in idsForProcessing)
                    {
                        Helper.WithMeasurement(() =>
                        {
                            try
                            {
                                var bitMap = new Runner().Run(extractResult, nationColorOffset, i, rawParser, renderer, imagePaletteArray, generalPalleteArray);
                                bitMapCollection.Add(bitMap);
                            }
                            catch (Exception ex)
                            {

                            }
                        }, "Image", onFinish: elapsed => richTextBox1.Text += String.Format("[{0,4}] - {1:g}\n", i, elapsed));
                    }

                    return bitMapCollection;

                },
                name: "Run",
                onFinish: elapsed => richTextBox1.Text += String.Format("Finished in {0:c}\n ", elapsed));
        }
Пример #3
0
        public void RenderCounterBlocksOnBitmap(ImageView imageView, NationColorOffset nationColorOffset, List <AbsoluteBlock> piactureElements, Collection <RawColorBlock> secondPartBlocks, ImageLayoutInfo layout, Color[] imagePaletteArray, Color[] generalPaletteColors)
        {
            var blocksDistributor = new BlocksDistributor();

            var blockContainerCollection = Helper.WithMeasurement(() =>
                                                                  blocksDistributor.GetDistributedCounterPartBlocks(piactureElements, secondPartBlocks), "GetDistributedCounterPartBlocks");

            foreach (var blockContainer in blockContainerCollection)
            {
                foreach (var counterBlockContainer in blockContainer.CounterBlockContainers)
                {
                    var sourceOffset = counterBlockContainer.RawColorBlock.Offset +
                                       counterBlockContainer.StripePadding;

                    if (counterBlockContainer.RawColorBlock.type == RawColorBlockType.MultiPixel)
                    {
                        var offsetX           = layout.offsetX + blockContainer.Block.OffsetX + counterBlockContainer.Offset;
                        var offsetY           = layout.offsetY + blockContainer.Block.OffsetY;
                        var destinationOffset = offsetY * imageView.Width + offsetX;

                        Array.Copy(
                            sourceArray: imagePaletteArray,
                            sourceIndex: sourceOffset,
                            destinationArray: imageView.Pixels,
                            destinationIndex: destinationOffset,
                            length: counterBlockContainer.Width);
                    }
                    else if (counterBlockContainer.RawColorBlock.type == RawColorBlockType.FourPixel)
                    {
                        var offsetX           = layout.offsetX + blockContainer.Block.OffsetX + counterBlockContainer.Offset;
                        var offsetY           = layout.offsetY + blockContainer.Block.OffsetY;
                        var destinationOffset = offsetY * imageView.Width + offsetX;

                        var colorByte = counterBlockContainer.RawColorBlock.One; // Codes 4 pixels: 2 bits for pixel

                        var _1 = colorByte & 0x03;
                        var _2 = (colorByte >> 2) & 0x03;
                        var _3 = (colorByte >> 4) & 0x03;
                        var _4 = (colorByte >> 6) & 0x03;

                        var slice = new[]
                        {
                            generalPaletteColors[nationColorOffset.Offset + _1],
                            generalPaletteColors[nationColorOffset.Offset + _2],
                            generalPaletteColors[nationColorOffset.Offset + _3],
                            generalPaletteColors[nationColorOffset.Offset + _4]
                        };

                        Array.Copy(
                            sourceArray: slice,
                            sourceIndex: sourceOffset,
                            destinationArray: imageView.Pixels,
                            destinationIndex: destinationOffset,
                            length: counterBlockContainer.Width);
                    }
                    else
                    {
                        var colorIndex = counterBlockContainer.RawColorBlock.One;
                        var color      = generalPaletteColors[colorIndex];

                        imageView.DrawColorPixel(color,
                                                 layout.offsetX + blockContainer.Block.OffsetX + counterBlockContainer.Offset,
                                                 layout.offsetY + blockContainer.Block.OffsetY);
                    }
                }
            }
        }
Пример #4
0
        public void RenderCounterBlocksOnBitmap(ImageView imageView, NationColorOffset nationColorOffset, List<AbsoluteBlock> piactureElements, Collection<RawColorBlock> secondPartBlocks, ImageLayoutInfo layout, Color[] imagePaletteArray, Color[] generalPaletteColors)
        {
            var blocksDistributor = new BlocksDistributor();

               var blockContainerCollection = Helper.WithMeasurement(() =>
             blocksDistributor.GetDistributedCounterPartBlocks(piactureElements, secondPartBlocks), "GetDistributedCounterPartBlocks");

            foreach (var blockContainer in blockContainerCollection)
            {
                foreach (var counterBlockContainer in blockContainer.CounterBlockContainers)
                {
                    var sourceOffset = counterBlockContainer.RawColorBlock.Offset +
                                          counterBlockContainer.StripePadding;

                    if (counterBlockContainer.RawColorBlock.type == RawColorBlockType.MultiPixel)
                    {
                        var offsetX = layout.offsetX + blockContainer.Block.OffsetX + counterBlockContainer.Offset;
                        var offsetY = layout.offsetY + blockContainer.Block.OffsetY;
                        var destinationOffset = offsetY * imageView.Width + offsetX;

                        Array.Copy(
                            sourceArray: imagePaletteArray,
                            sourceIndex: sourceOffset,
                            destinationArray: imageView.Pixels,
                            destinationIndex: destinationOffset,
                            length: counterBlockContainer.Width);

                    }
                    else if (counterBlockContainer.RawColorBlock.type == RawColorBlockType.FourPixel)
                    {

                        var offsetX = layout.offsetX + blockContainer.Block.OffsetX + counterBlockContainer.Offset;
                        var offsetY = layout.offsetY + blockContainer.Block.OffsetY;
                        var destinationOffset = offsetY * imageView.Width + offsetX;

                        var colorByte = counterBlockContainer.RawColorBlock.One; // Codes 4 pixels: 2 bits for pixel

                        var _1 = colorByte & 0x03;
                        var _2 = (colorByte >> 2) & 0x03;
                        var _3 = (colorByte >> 4) & 0x03;
                        var _4 = (colorByte >> 6) & 0x03;

                        var slice = new[]
                        {
                             generalPaletteColors[nationColorOffset.Offset + _1],
                             generalPaletteColors[nationColorOffset.Offset + _2],
                             generalPaletteColors[nationColorOffset.Offset + _3],
                             generalPaletteColors[nationColorOffset.Offset + _4]
                        };

                        Array.Copy(
                            sourceArray: slice,
                            sourceIndex: sourceOffset,
                            destinationArray: imageView.Pixels,
                            destinationIndex: destinationOffset,
                            length: counterBlockContainer.Width);
                    }
                    else
                    {
                        var colorIndex = counterBlockContainer.RawColorBlock.One;
                        var color = generalPaletteColors[colorIndex];

                        imageView.DrawColorPixel(color,
                           layout.offsetX + blockContainer.Block.OffsetX + counterBlockContainer.Offset,
                           layout.offsetY + blockContainer.Block.OffsetY);
                    }
                }
            }
        }