private string[] ConvertAA(Bitmap bmp, string[] aa) { this.bg.ReportProgress(0, new Command("AA開始")); if (this.charm == null || this.fconfig.IsChanged) { this.charm = new CharManager(this.cm); this.fconfig.IsChanged = false; } long start = DateTime.Now.Ticks; if (aa == null) { aa = AAUtil.Convert(bmp, cm, charm, this); } this.fascii.DrawAA(aa, bmp.Size, cm, charm); long dif = DateTime.Now.Ticks - start; this.bg.ReportProgress(0, new Command("AA終了", dif)); return(aa); }
//public void DoThread() //{ // int left = 0; // int width = this.table.GetLength(0); // StringBuilder sb = new StringBuilder(); // char backChar = '\0'; // int toneIndex = -1; // int toneCharIndex = 0; // CharData halfW = this.charm[' ']; // CharData wideW = this.charm[' ']; // CharData priod = this.charm['.']; // while (left < width) // { // CharData append = null; // CharData match = null; // //トーン処理 // if (this.toneTable.GetLength(0) > 0) // { // int t = IsTone(left); // if (t != -1) // { // if (t != toneIndex) // { // toneCharIndex = 0; // toneIndex = t; // } // match = this.charm[this.cm.ToneText[t][toneCharIndex % this.cm.ToneText[t].Length]]; // toneCharIndex++; // goto ADD_CHAR; // } // } // //マッチング処理 // object[] o = GetDirChar(left, ref append); // if (((double)o[1]) > 0.1d) // { // match = (CharData)o[0]; // } // else // { // o = GetChar(left, ref append); // match = (CharData)o[0]; // } // if (append == null) // { // if (backChar == ' ' && match.Character == ' ') // { // left = left - halfW.Width; // match = wideW; // backChar = '\0'; // } // } // else if (append.Character == ' ') // { // if (backChar == ' ') // { // left = left - halfW.Width; // match = wideW; // backChar = '\0'; // append = null; // } // } // ADD_CHAR: // //マッチした文字を追加 // if (backChar != '\0') // { // sb.Append(backChar); // } // if (append != null) // { // sb.Append(append.Character); // left += append.Width; // } // backChar = match.Character; // left += match.Width; // if (sb.Length == 1 && sb[0] == ' ') // { // sb.Remove(0, sb.Length); // left = priod.Width; // backChar = '.'; // continue; // } // } // sb.Append(backChar); // lock (lockObject) // { // this.aa = sb.ToString(); // } //} private int IsTone(int left) { char[,] baseTable = AAUtil.TrimTable(this.toneTable, 0, left, this.table.GetLength(1), this.charm[0].Width, 0); //int cnt = 0; for (int y = 0; y < baseTable.GetLength(1); y++) { for (int x = 0; x < baseTable.GetLength(0); x++) { if (baseTable[x, y] == ' ' || baseTable[x, y] == '□') { return(-1); } } } return(baseTable[baseTable.GetLength(0) / 2, baseTable.GetLength(1) / 2] - '0'); }
public object[] GetMatchData(int left, char addc) { CharData matchData = null; CharData nowData = null; char[,] baseTable = null; char[,] baseDirTable = null; char[,] dirTable = null; int pointCount = 0; int totalPointCount = 0; double score = 0.0d; HashSet <Point> hitCharPoint = new HashSet <Point>(); int hitTable = 0; double maxScore = double.MinValue; baseTable = AAUtil.TrimTable(this.table, 0, left, this.table.GetLength(1), this.charm[this.charm.Count - 1].Width, 1); baseDirTable = new PatturnBuilder(baseTable).Patturn; for (int i = 0; i < this.charm.Count; i++) { nowData = this.charm[i]; //AAUtil.DebugTable(nowData.Patturn); //テーブル初期化 if (i == 0 || this.charm[i - 1].Width != nowData.Width) { //baseTable = AAUtil.TrimTable(this.table, 0, left, this.table.GetLength(1), nowData.Width, 1); dirTable = AAUtil.TrimTable(baseDirTable, 0, 0, nowData.Height, nowData.Width, 0); pointCount = 0; for (int y = 0; y < dirTable.GetLength(1); y++) { for (int x = 0; x < dirTable.GetLength(0); x++) { if (dirTable[x, y] != ' ') { pointCount++; } } } //if (i == 0) //{ // AAUtil.DebugTable(this.table); // AAUtil.DebugTable(baseTable); // AAUtil.DebugTable(baseDirTable); // AAUtil.DebugTable(nowData.Patturn); // AAUtil.DebugTable(nowData.NormalPatturn); //} } if (i == 0 && pointCount <= 2) { return(new object[] { this.charm[' '], 0.0d }); } if (nowData.Character == '|' && addc == '.') { continue; } if (nowData.IsHorizonLine && addc != '\0') { continue; } //if (nowData.IsTarget == true) //{ // continue; //} //スコア関連初期化 score = 0.0d; hitTable = 0; hitCharPoint.Clear(); totalPointCount = (nowData.PointNormalCount * 5 + pointCount * 3); if (totalPointCount == 0) { continue; } //パターンマッチング int height = dirTable.GetLength(1); int width = dirTable.GetLength(0); int matchAreaX = 0; int matchAreaY = 0; if (cm.Match == 1) { matchAreaX = 1; matchAreaY = 1; } else if (cm.Match == 2) { matchAreaX = 2; matchAreaY = 2; } else { matchAreaX = 3; matchAreaY = 3; } bool isHit1; List <Point> lstPoint; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (dirTable[x, y] == ' ') { continue; } isHit1 = false; lstPoint = nowData.GetDirPoint('N'); foreach (Point p in lstPoint) { if (Math.Abs(p.X - x) <= matchAreaX && Math.Abs(p.Y - y) <= matchAreaY) { if (!isHit1) { isHit1 = true; hitTable += 2; } if (!hitCharPoint.Contains(p)) { hitCharPoint.Add(p); hitTable++; // Debug.WriteLine(p); goto LOOP_END; } } } LOOP_END: ; } } score = Convert.ToDouble((hitTable + hitCharPoint.Count * 5)) / Convert.ToDouble(totalPointCount) * 100; if (maxScore < score) { maxScore = score; matchData = nowData; if (maxScore >= this.cm.Score4) { return(new object[] { matchData, maxScore }); } } } if (maxScore < this.cm.Score3) { return(new object[] { this.charm[' '], 0.0d }); } if (matchData == null) { return(new object[] { this.charm[' '], 0.0d }); } return(new object[] { matchData, maxScore }); }