static void Print(Bitmap what, int resol, bool smooth, Point offset) { DateTime startDate = DateTime.Now; Random rnd = new Random(); int left = 0, top = 0; int resolHoriz = resol * 3 / 4; // what.RotateFlip(RotateFlipType.Rotate90FlipNone); Dictionary <Color, int> inds = new Dictionary <Color, int>(); Col c; for (int i = 0; i < what.Height; i += resol) { Console.SetCursorPosition(left + offset.X, top + i / resol + offset.Y); for (int j = 0; j < what.Width; j += resolHoriz) { Color clr = what.GetPixel(j, i); if (smooth) { int[] rgb = new int[3] { 0, 0, 0 }; int countPixels = 0; for (int i2 = 0; i2 < resol; i2++) { for (int j2 = 0; j2 < resolHoriz; j2++) { if (i + i2 >= what.Height) { continue; } if (j + j2 >= what.Width) { continue; } rgb[0] += what.GetPixel(j + j2, i + i2).R; rgb[1] += what.GetPixel(j + j2, i + i2).G; rgb[2] += what.GetPixel(j + j2, i + i2).B; countPixels++; } } clr = Color.FromArgb((int)(rgb[0] / (countPixels * 1.0)), (int)(rgb[1] / (countPixels * 1.0)), (int)(rgb[2] / (countPixels * 1.0)));//what.GetPixel(j, i); } //root.FindFast(0, clr).Print(); //if (usePreviousExpirience && inds.ContainsKey(clr)) //{ // dictionary[inds.FirstOrDefault(x => x.Key == clr).Value].Print(); //} //else //{ c = root.FindFast(0, clr); if (c.isBlack() && clr != Color.Black) { drawCostil(clr); } else { c.Print(); } // c; // if (!inds.ContainsKey(clr)) // inds.Add(clr, dictionary.IndexOf(c)); //} // int bestInd = 0, minDiff = 255 * 3, minClose = 255 * 3; // for (int d = 0; d < dictionary.Count; d++) // { // int cd = diff(dictionary[d].associate, clr) // // // ;// +(int)(dictionary[d].colorDiff / 300.0); // // // if (cd < minDiff || ((cd <= minDiff) && (minClose < dictionary[d].colorDiff))) { minDiff = cd; bestInd = d; minClose = dictionary[d].colorDiff; } // if (cd < minDiff) { minDiff = cd; bestInd = d; } // if (minDiff <= 0) break; // } // dictionary[bestInd].Print(); // inds.Add(clr, bestInd); //} } } msSpentOnFrameDraw.Add((DateTime.Now - startDate).Milliseconds); }
public Col FindFast(int rgb, Color need) { if (left == null && right == null && child.Count == 0) { return(new Col()); } if (child.Count > 0) { int bestInd = -1, minDiff = 255 * 3, minClose = 255 * 3; for (int d = 0; d < child.Count; d++) { int cd = diff(child[d].associate, need) // ; // +(int)(child[d].colorDiff / 300.0); // if (cd < minDiff || ((cd <= minDiff) && (minClose < child[d].colorDiff))) { minDiff = cd; bestInd = d; minClose = child[d].colorDiff; } if (cd < minDiff) { minDiff = cd; bestInd = d; } if (minDiff <= 0) { break; } } if (bestInd >= 0 && (minDiff == 0 || (left == null && right == null))) { return(child[bestInd]); } } this.L += 0; if (rgb == 0) { if (need.R < separat.R) { return(left.FindFast((rgb + 1) % 3, need)); } else { return(right.FindFast((rgb + 1) % 3, need)); } } if (rgb == 1) { if (need.G < separat.G) { return(left.FindFast((rgb + 1) % 3, need)); } else { return(right.FindFast((rgb + 1) % 3, need)); } } if (rgb == 2) { if (need.B < separat.B) { return(left.FindFast((rgb + 1) % 3, need)); } else { return(right.FindFast((rgb + 1) % 3, need)); } } return(new Col(ConsoleColor.DarkRed, ConsoleColor.Red, '@', Color.Red)); }