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); }
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))); }