예제 #1
0
파일: Program.cs 프로젝트: klym1/Gpak-tools
        private static void SaveAsPng(string gpFile, string pngDirectory)
        {
            IRenderer renderer = new BitmapRenderer();

            var imagePaletteBytes = new Extractor().GetPaletteBytes(gpFile);
            var extractResult = new Extractor().GetImagesFromOutput(gpFile).ToList();

            var rawParser = new RawParser();

            var paletteBytes = File.ReadAllBytes(@"..\..\..\..\palette\0\agew_1.pal");
            var colorCollection = rawParser.GetColorCollectionFromPalleteFile(paletteBytes);

            var imagePaletteColors = ImageGenerator.OffsetsToColors(imagePaletteBytes, colorCollection);

            var nationColorOffset = NationColorOffset.Red;

            using (var bitMap = new Runner().Run(extractResult, nationColorOffset, 0, rawParser, renderer, imagePaletteColors, colorCollection))
            {
                using (var stream = new MemoryStream())
                {
                    bitMap.Save(stream, ImageFormat.Png);
                    File.WriteAllBytes(Path.Combine(pngDirectory, Path.GetFileNameWithoutExtension(gpFile) + ".png"),
                        stream.ToArray());
                }
            }
        }
예제 #2
0
파일: Runner.cs 프로젝트: klym1/Gpak-tools
        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;
        }
예제 #3
0
파일: Form1.cs 프로젝트: klym1/Gpak-tools
        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));
        }
예제 #4
0
파일: Form1.cs 프로젝트: klym1/Gpak-tools
        private void Do()
        {
            var filePath = @"../../../../gp/test.gp";

            var imagePaletteBytes = new Extractor().GetPaletteBytes(filePath);
            var extractResult = new Extractor().GetImagesFromOutput(filePath).ToList();

            IRenderer renderer = new BitmapRenderer();

            var paletteBytes = File.ReadAllBytes(@"../../../../palette/0/agew_1.pal");

            var rawParser = new RawParser();

            var colorCollection = rawParser.GetColorCollectionFromPalleteFile(paletteBytes);

            var imagePaletteColors = ImageGenerator.OffsetsToColors(imagePaletteBytes, colorCollection);

            var nationColorOffset = NationColorOffset.Blue;

            //Watch(extractResult);

            var bitmapList = DrawImage(extractResult, nationColorOffset, extractResult.Count, rawParser, renderer, imagePaletteColors, colorCollection);

            var itemsForListBox = Enumerable.Range(0, bitmapList.Count).Select(it => it.ToString()).ToList();

            listBox1.DataSource = itemsForListBox;

            listBox1.SelectedIndexChanged += (sender, args) =>
            {
                if ((sender as ListBox).SelectedIndex > -1)
                pictureBox2.Image = bitmapList[(sender as ListBox).SelectedIndex];
            };

            listBox1.ClearSelected();
            listBox1.SelectedIndex = 0;
        }