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); } } } }
//private int[] GetOneLineFromCountsBlock(int[] counts, int lPtr) //{ // int[] result = new int[BlockWidth]; // Array.Copy(counts, lPtr * BlockWidth, result, 0, BlockWidth); // return result; //} //private int[] GetOneLineFromCountsBlock(uint[] counts, int lPtr) //{ // int[] result = new int[BlockWidth]; // int srcPtr = lPtr * BlockWidth; // for (int i = 0; i < result.Length; i++) // result[i] = (int)counts[srcPtr++]; // return result; //} public static void BuildPngImageLineSegment(int pixPtr, int[] counts, ImageLine iLine, int maxIterations, ColorMap colorMap) { for (int xPtr = 0; xPtr < counts.Length; xPtr++) { double escapeVelocity = GetEscVel(counts[xPtr], out int cnt); int[] cComps; if (cnt == maxIterations) { cComps = colorMap.HighColorEntry.StartColor.ColorComps; } else { cComps = colorMap.GetColor(cnt, escapeVelocity); } ImageLineHelper.SetPixel(iLine, pixPtr++, cComps[0], cComps[1], cComps[2]); } }