private CanvasSize GetImageSizeInBlocks(CountsRepoReader countsRepo) { bool foundMax = false; int w = 10; int h = 0; KPoint key = new KPoint(w, h); foundMax = !countsRepo.ContainsKey(key); if (foundMax) { return(new CanvasSize(0, 0)); } // Find max value where w and h are equal. while (!foundMax) { w++; h++; key = new KPoint(w, h); foundMax = !countsRepo.ContainsKey(key); } w--; h--; foundMax = false; // Find max value of h while (!foundMax) { h++; key = new KPoint(w, h); foundMax = !countsRepo.ContainsKey(key); } h--; foundMax = false; // Find max value of h while (!foundMax) { w++; key = new KPoint(w, h); foundMax = !countsRepo.ContainsKey(key); } //w--; return(new CanvasSize(w, ++h)); }
public void Build(string fn, bool hiRez) { // TODO: HiRez, blockWidth and blockHeight should come from the RepoFile. MapInfoWithColorMap miwcm = ReadFromJson(fn); int maxIterations = miwcm.MapInfo.MaxIterations; ColorMap colorMap = miwcm.ColorMap; string repofilename = miwcm.MapInfo.Name; //ValueRecords<KPoint, MapSectionWorkResult> countsRepo = new ValueRecords<KPoint, MapSectionWorkResult>(repofilename, useHiRezFolder: hiRez); //int blockLength = BlockWidth * BlockHeight; //MapSectionWorkResult workResult = new MapSectionWorkResult(blockLength, hiRez: hiRez, includeZValuesOnRead: false); //CanvasSize imageSizeInBlocks = GetImageSizeInBlocks(countsRepo); int blockLength = BlockWidth * BlockHeight; CountsRepoReader countsRepoReader = new CountsRepoReader(repofilename, hiRez, BlockWidth, BlockHeight); CanvasSize imageSizeInBlocks = GetImageSizeInBlocks(countsRepoReader); int w = imageSizeInBlocks.Width; int h = imageSizeInBlocks.Height; CanvasSize imageSize = new CanvasSize(w * BlockWidth, h * BlockHeight); string imagePath = GetImageFilename(fn, imageSize.Width, hiRez, BasePath); KPoint key = new KPoint(0, 0); using (PngImage pngImage = new PngImage(imagePath, imageSize.Width, imageSize.Height)) { for (int vBPtr = 0; vBPtr < h; vBPtr++) { key.Y = vBPtr; for (int lPtr = 0; lPtr < 100; lPtr++) { ImageLine iLine = pngImage.ImageLine; int linePtr = vBPtr * BlockHeight + lPtr; for (int hBPtr = 0; hBPtr < w; hBPtr++) { key.X = hBPtr; //if (countsRepo.ReadParts(key, workResult)) //{ // int[] allCounts = workResult.Counts; // int[] countsForThisLine = GetOneLineFromCountsBlock(allCounts, lPtr); // BuildPngImageLineSegment(hBPtr * BlockWidth, countsForThisLine, iLine, maxIterations, colorMap); //} //else //{ // BuildBlankPngImageLineSegment(hBPtr * BlockWidth, BlockWidth, iLine); //} int[] countsForThisLine = countsRepoReader.GetCounts(key, lPtr); if (countsForThisLine != null) { BuildPngImageLineSegment(hBPtr * BlockWidth, countsForThisLine, iLine, maxIterations, colorMap); } else { BuildBlankPngImageLineSegment(hBPtr * BlockWidth, BlockWidth, iLine); } } pngImage.WriteLine(iLine); } } } }