public static byte[] decrypt(byte[] input, byte[] key) { int i; byte[] tmp = new byte[input.Count()]; byte[] bloc = new byte[16]; Nb = 4; Nk = key.Count() / 4; Nr = Nk + 6; w = generateSubkeys(key); for (i = 0; i < input.Count(); i++) { if (i > 0 && i % 16 == 0) { bloc = decryptBloc(bloc); Array.Copy(bloc, 0, tmp, i - 16, bloc.Count()); } if (i < input.Count()) bloc[i % 16] = input[i]; } bloc = decryptBloc(bloc); Array.Copy(bloc, 0, tmp, i - 16, bloc.Count()); tmp = deletePadding(tmp); return tmp; }
public EditorMapManager(ContentManager Content, SpriteBatch spriteBatch) { this.Content = Content; Spritebatch = spriteBatch; Initialized = false; PlayerPlaced = false; GoalPlaced = false; TileSize = 40; xTiles = 80; yTiles = 50; collisionLayer = new byte[xTiles, yTiles]; backgroundLayer = new byte[xTiles, yTiles]; platformLayer = new byte[xTiles, yTiles]; specialsLayer = new byte[xTiles, yTiles]; selectedLayer = backgroundLayer; selectedLayerNum = 0; SelectedTileValue = 0; selectionTopLeft = new Point(0, 0); selectionBottomRight = new Point(0, 0); }
public LBPCreator(ImageGrayData imageData, bool isTeaching, bool isDivideToFragments, bool isMultithread = true) { var needSize = RecognitionParameters.RecognitionFragmentSize; if (isTeaching) { needSize = RecognitionParameters.FragmentsSize; } if ((imageData.Width < needSize) || (imageData.Height < needSize)) { throw new ArgumentException("Размер изображения меньше размера фрагмента для разбиения. \n" + "Невозможно создать LBP-гистограмму"); } fragmentSize = needSize; this.isTeaching = isTeaching; this.isDivideToFragments = isDivideToFragments; this.isMultithread = isMultithread; data = imageData.Data; width = imageData.Width; height = imageData.Height; feature = null; ConstructFeature(); }
public void Dispose() { currentField = null; if (this._newEntries != null) this._newEntries.Clear(); }
internal void BanzaiEnd() { room.GetGameManager().StopGame(); banzaiStarted = false; field.destroy(); this.floorMap = null; Team winners = room.GetGameManager().getWinningTeam(); if (winners != Team.none) { foreach (RoomItem tile in banzaiTiles.Values) { if (tile.team == winners) { tile.interactionCountHelper = 0; tile.UpdateNeeded = true; } else if (tile.team == Team.none) { tile.ExtraData = "0"; tile.UpdateState(); } } } }
public void Erosion() { byte[,] matr1 = new byte[Width, Height]; matr1 = (byte[,])matr.Clone(); for (int i = 0; i < Width; ++i) for (int j = 0; j < Height; ++j) { if (matr[i, j] == 1) for (int k = 0; k < MaskSize; ++k) for (int l = 0; l < MaskSize; ++l) if (mask[k, l] == 1) { int ii = (i - MaskSize / 2) + k; int jj = (j - MaskSize / 2) + l; if (!((ii < 0) || (ii >= Width))) if (!((jj < 0) || (jj + l >= Height))) if (matr[ii, jj] != 1) { matr1[i, j] = 0; goto NextPixel; } } NextPixel: continue; } this.matr = matr1; }
//TODO Level(string levelname) // Load all variables from Level file. public Level(string levelname) { Name = levelname; Map = LoadMap(levelname + ".tmx"); grid = BuildNavMesh(); //Waves = LoadWaves(levelname + ".xml"); }
public HistoEqualization(RsImage img, int band) { _bandData = img.GetPicData(band); HistoData hd = new HistoData(img, band); _accData = hd.GetAccHistogramData(); StartEqualization(); }
public void RotateRight() { byte[,] tmp = new byte[4, 4]; for (int x = 3; x >= 0; x--) for (int y = 0; y < 4; y++) tmp[3-y, x] = TetrominoGrid[x, y]; TetrominoGrid = tmp; }
/// <summary> /// Gets a path from the startPoint to the endPoint. Or null if there are no possible points /// </summary> /// <param name="startPoint"></param> /// <param name="endPoint"></param> /// <returns></returns> public static Stack<MapCoordinate> GetPath(MapCoordinate startPoint, MapCoordinate endPoint) { if (pathFinder == null) { if (nodes == null) { GameState.LocalMap.GeneratePathfindingMap(); nodes = GameState.LocalMap.PathfindingMap; } //Create the new pathfinder with the map - add the settings pathFinder = new PathFinderFast(nodes); pathFinder.Formula = HeuristicFormula.Manhattan; pathFinder.Diagonals = false; pathFinder.HeavyDiagonals = false; pathFinder.HeuristicEstimate = 2; pathFinder.PunishChangeDirection = true; pathFinder.TieBreaker = false; pathFinder.SearchLimit = 5000; } List<PathFinderNode> path = pathFinder.FindPath(new Point(startPoint.X, startPoint.Y), new Point(endPoint.X, endPoint.Y)); Stack<MapCoordinate> coordStack = new Stack<MapCoordinate>(); if (path == null) { Console.WriteLine("No path found :("); return null; } //Check that all points are valid foreach (var point in path) { if (nodes[point.X, point.Y] > 100) { Console.WriteLine("No path found :( "); return null; } } foreach (PathFinderNode node in path) { coordStack.Push(new MapCoordinate(node.X, node.Y, 0, startPoint.MapType)); } if (coordStack.Count == 0) { return null; } else { coordStack.Pop(); //remove the start node return coordStack; } }
public SimpleImage(Bitmap source) { image = source; width = image.Width; height = image.Height; int imageStride = 0; var sourceData = GetImageData(image, out imageStride); grayData = GrayFilter(sourceData, imageStride); }
public MyBitmap(Image image, String path) { this.preBitmap = convertTo24bpp(image); this.curBitmap = convertTo24bpp(image); this.byteArray = toByteArray(curBitmap, ImageFormat.Bmp); this.bitmapInfo = new MyBitmapInfo(image,byteArray[10],byteArray[28],path); this.pixelArray = convertArray(this.byteArray, image.Width, image.Height); //bitmap.Dispose(); }
public SimpleImage(string url) { image = new Bitmap(url); width = image.Width; height = image.Height; int imageStride = 0; var sourceData = GetImageData(image, out imageStride); grayData = GrayFilter(sourceData, imageStride); }
/// <summary> /// Generates new wave /// </summary> /// <param name="WaveLength"></param> /// <param name="MaxEnemiesOnScreen"></param> /// <param name="TotalEnemiesInWave"></param> public IEnumerator generateNewWave(float WaveLength, int MaxEnemiesOnScreen) { currentWaveCol = 0; currentWave = waves.first9Waves[(GameManager.instance.wave - 1) % 10]; WaveEndTime = Time.time + WaveLength; this.WaveLength = WaveLength; isWaveEnded = false; StartCoroutine (generateEnemies()); yield return null; }
/// <summary> /// Constructor for the class PlayField /// Creates a field as a matrix, having rows, columns and /// the maximum value a ballon in the playfield could have. /// The matrix is created on via a random generator /// </summary> /// <param name="rowsNumber">Number of rows in field</param> /// <param name="colsNumber">Number of columns in field</param> /// <param name="maxBubbleNumber">Maximal value of bubbles in field</param> public PlayField(byte rowsNumber, byte colsNumber, byte maxBubbleNumber=4) { if (maxBubbleNumber == 0) { throw new ArgumentException("Cannot create a field with maxBubbleNumber"+ " less or equal to zero"); } this.MaxBubbleNumber = maxBubbleNumber; this.field = GenerateRandomField(rowsNumber, colsNumber); }
// Создаем физическое отображение лабиринта public void InstantiateMaze(byte level) { mazeMatrix = Levels[level - 1]; width = height = base_sum + level * 4; cells = new MazeCell[width, height]; for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) if (mazeMatrix[y, x] == 1) CreateCell(x, y); }
internal void Destroy() { Array.Clear(SqState, 0, SqState.Length); Array.Clear(SqFloorHeight, 0, SqFloorHeight.Length); Array.Clear(SqSeatRot, 0, SqSeatRot.Length); staticModel = null; Heightmap = null; SqState = null; SqFloorHeight = null; SqSeatRot = null; }
public static byte[] encrypt(byte[] message, byte[] key) { Nb = 4; Nk = key.Count() / 4; Nr = Nk + 6; int lenght = 0; byte[] padding = new byte[1]; int i; lenght = 16 - message.Count() % 16; padding = new byte[lenght]; padding[0] = (byte)0x80; for (i = 1; i < lenght; i++) { padding[i] = 0; } byte[] encryptedmsg = new byte[message.Count() + lenght]; byte[] bloc = new byte[16]; w = generateSubkeys(key); int count = 0; for (i = 0; i < message.Count() + lenght; i++) { if (i > 0 && i % 16 == 0) { bloc = encryptBloc(bloc); Array.Copy(bloc, 0, encryptedmsg, i - 16, bloc.Count()); } if (i < message.Count()) { bloc[i % 16] = message[i]; } else { bloc[i % 16] = padding[count % 16]; count++; } } if (bloc.Count() == 16) { bloc = encryptBloc(bloc); Array.Copy(bloc, 0, encryptedmsg, i - 16, bloc.Count()); } return encryptedmsg; }
/// <summary> /// Конструктор формы /// </summary> /// <param name="cells"></param> /// <param name="_evol"></param> /// <param name="_r_surv"></param> /// <param name="_r_born"></param> /// <param name="_check"></param> public CadrForm(byte[,] cells, byte[,] _evol, bool[] _r_surv, bool[] _r_born, bool _check) { InitializeComponent(); Cells = (byte[,])cells.Clone(); Evol = (byte[,])_evol.Clone(); r_surv = (bool[])_r_surv.Clone(); r_born = (bool[])_r_born.Clone(); if (_check) s = CellAutomaton.CellularAutomaton; else s = CellAutomaton.CellularAutomatonNT; }
public void Crop() { if (Empty) return; Width = Right - Left + 1; Height = Bottom - Top + 1; byte[,] b = new byte[Width, Height]; for (int x = 0; x < Width; x++) { for (int z = 0; z < Height; z++) { b[x, z] = Biomes[Left + x, Top + z]; } } Biomes = b; }
protected Char(SerializationInfo info, StreamingContext context) { AspectRatioWidth = (float)info.GetValue("AspectRatioWidth", typeof(float)); AspectRatioHeight = (float)info.GetValue("AspectRatioHeight", typeof(float)); logicalWidth = (byte)info.GetValue("logicalWidth", typeof(byte)); baseLine = (byte)info.GetValue("baseLine", typeof(byte)); xHeight = (byte)info.GetValue("xHeight", typeof(byte)); capHeight = (byte)info.GetValue("capHeight", typeof(byte)); width = (byte)info.GetValue("width", typeof(byte)); // = ()info.GetValue("", typeof()); height = (byte)info.GetValue("height", typeof(byte)); // = ()info.GetValue("", typeof()); Codepoint = (char)info.GetValue("Codepoint", typeof(char)); Name = (string)info.GetValue("Name", typeof(string)); bitmap = (byte[,])info.GetValue("bitmap", typeof(byte[,])); }
public void deserialize( string blob ) { try { blob = blob.Replace ("-" , "/").Replace ("_" , "="); byte[] bytes = Convert.FromBase64String (blob); bytes = CLZF2.Decompress (bytes); MemoryStream mem = new MemoryStream (bytes , false); BinaryFormatter binf = new BinaryFormatter (); coverage = (byte[,])binf.Deserialize (mem); } catch (Exception e) { coverage = new byte[360 , 180]; heightmap = new float[360 , 180]; throw e; } resetImages (); }
public int test(string ImagePath) { double Min = double.MinValue; int index=0; buffer = ImageOperation.OpenImage(ImagePath); NW.IS.GetInputpublic(buffer, ImageOperation.GetWidth(buffer), ImageOperation.GetHeight(buffer),NW.InputLayer); NW.FirstPassSignal(); for(int j=0;j<NW.OutputLayer.Length;j++) { if(NW.OutputLayer[j].NetInput>Min) { Min = NW.OutputLayer[j].NetInput; index = j; } } return index+1; }
// SiDComponent public override void LoadFromByteStream(BinaryReader br, Int32 streamLength) { Iterate((Int32 x, Int32 y, ref PixelRGBA pixel, ref byte transFlags) => { pixel.R = br.ReadByte(); pixel.G = br.ReadByte(); pixel.B = br.ReadByte(); pixel.A = br.ReadByte(); }); Iterate((Int32 x, Int32 y, ref PixelRGBA pixel, ref byte transFlags) => { transFlags = br.ReadByte(); }); Name = ByteUtils.readNullTermString11(br); }
public Mbc1(byte[] fileData, Mbc romType, int romSize, string saveFile) { _saveFile = saveFile; _romType = romType; romBanks = romSize / BANK_SIZE; _rom = new byte[romBanks, BANK_SIZE]; _ram = LoadSave(); for (int i = 0, k = 0; i < romBanks; i++) { for (int j = 0; j < BANK_SIZE; j++, k++) { _rom[i, j] = fileData[k]; } } #if DEBUG Console.WriteLine("DEBUG: Init OK"); #endif }
public void Dilation() { byte[,] matr1 = new byte[Width, Height]; matr1 = (byte[,])matr.Clone(); for (int i = 0; i < Width; ++i) for (int j = 0; j < Height; ++j) if (matr[i, j] == 1) for (int k = 0; k < MaskSize; ++k) for (int l = 0; l < MaskSize; ++l) if (mask[k, l] == 1) { int ii = (i - MaskSize / 2) + k; int jj = (j - MaskSize / 2) + l; if (!((ii < 0) || (ii >= Width))) if (!((jj < 0) || (jj >= Height))) matr1[(i - MaskSize / 2) + k, (j - MaskSize / 2) + l] = 1; } this.matr = matr1; }
private void button1_Click(object sender, EventArgs e) { Bitmap ORG = IncludeFile(); ColorChange color = new ColorChange(); SIFT sift = new SIFT(); Filter f = new Filter(); IMG = color.rgb2gray(ORG); list = sift.serachKeypoint(IMG, 3,1.6); /*DoGlist = sift.DoG(IMG, Math.Pow(2, 1 / (double)3), 1.6, 6); for (int x = 0; x < DoGlist[0].GetLength(0); x++) { for (int y = 0; y <DoGlist[0].GetLength(1); y++) { IMG[x, y] = (byte)(Math.Abs((byte)DoGlist[0].GetValue(x, y) - (byte)DoGlist[1].GetValue(x, y))); } }*/ imshow(IMG); }
public void Training(string Path) { RI.ListAllFiles(Path); string ImagePath; int index; int Count = 0; while(true) { ImagePath = RI.GetImage(); if (ImagePath == null || Count==RI.Table.Count-1) break; buffer = ImageOperation.OpenImage(ImagePath); NW.IS.GetInputpublic(buffer, ImageOperation.GetWidth(buffer), ImageOperation.GetHeight(buffer),NW.InputLayer,PCAout,NofIteration,PCAlearningRate); NW.FirstPassSignal(); index = GetIndex(ImagePath) - 1; NW.BackWardSignal(index); NW.UpdateWeights(); Count++; } }
public KeySchedule(byte[,] key) { if(key.GetLength(1) == 4){ schedule = new byte[4,44]; //For 128-bit key keyLength = 4; numRounds = 10; } else if(key.GetLength(1) == 6){ schedule = new byte[4,52]; //For 192-bit key keyLength = 6; numRounds = 12; } else if(key.GetLength(1) == 8){ schedule = new byte[4,60]; //For 256-bit key keyLength = 8; numRounds = 14; } else{ Console.WriteLine("ERROR: KEY MATRIX PASSED TO SCHEDULE IS INCORRECT!!!!"); schedule = null; return; } this.generateSchedule(key); }
public void BanzaiEnd(bool userTriggered = false) { //TODO banzaiStarted = false; _room.GetGameManager().StopGame(); floorMap = null; if (!userTriggered) { _room.GetWired().TriggerEvent(WiredBoxType.TriggerGameEnds, null); } TEAM winners = _room.GetGameManager().GetWinningTeam(); _room.GetGameManager().UnlockGates(); foreach (Item tile in _banzaiTiles.Values) { if (tile.team == winners) { tile.interactionCount = 0; tile.interactionCountHelper = 0; tile.UpdateNeeded = true; } else if (tile.team == TEAM.NONE) { tile.ExtraData = "0"; tile.UpdateState(); } } if (winners != TEAM.NONE) { List <RoomUser> Winners = _room.GetRoomUserManager().GetRoomUsers(); foreach (RoomUser User in Winners.ToList()) { if (User.Team != TEAM.NONE) { if (PlusEnvironment.GetUnixTimestamp() - timestarted > 5) { PlusEnvironment.GetGame().GetAchievementManager().ProgressAchievement(User.GetClient(), "ACH_BattleBallTilesLocked", User.LockedTilesCount); PlusEnvironment.GetGame().GetAchievementManager().ProgressAchievement(User.GetClient(), "ACH_BattleBallPlayer", 1); } } if (winners == TEAM.BLUE) { if (User.CurrentEffect == 35) { if (PlusEnvironment.GetUnixTimestamp() - timestarted > 5) { PlusEnvironment.GetGame().GetAchievementManager().ProgressAchievement(User.GetClient(), "ACH_BattleBallWinner", 1); } _room.SendMessage(new ActionComposer(User.VirtualId, 1)); } } else if (winners == TEAM.RED) { if (User.CurrentEffect == 33) { if (PlusEnvironment.GetUnixTimestamp() - timestarted > 5) { PlusEnvironment.GetGame().GetAchievementManager().ProgressAchievement(User.GetClient(), "ACH_BattleBallWinner", 1); } _room.SendMessage(new ActionComposer(User.VirtualId, 1)); } } else if (winners == TEAM.GREEN) { if (User.CurrentEffect == 34) { if (PlusEnvironment.GetUnixTimestamp() - timestarted > 5) { PlusEnvironment.GetGame().GetAchievementManager().ProgressAchievement(User.GetClient(), "ACH_BattleBallWinner", 1); } _room.SendMessage(new ActionComposer(User.VirtualId, 1)); } } else if (winners == TEAM.YELLOW) { if (User.CurrentEffect == 36) { if (PlusEnvironment.GetUnixTimestamp() - timestarted > 5) { PlusEnvironment.GetGame().GetAchievementManager().ProgressAchievement(User.GetClient(), "ACH_BattleBallWinner", 1); } _room.SendMessage(new ActionComposer(User.VirtualId, 1)); } } } if (field != null) { field.Dispose(); } } }
public RAWSequenceSource(RAWDATAFORMAT theRawDataFormat, int theWidth, int theHeight, byte[,] theBayerPattern, string[] thePaths) { rawDataFormat = theRawDataFormat; width = theWidth; height = theHeight; bayerPattern = theBayerPattern; paths = thePaths; }
}//PrintEmptyBoard /// <summary> /// Print the board configuration /// </summary> public static void PrintBoard(byte[,] board) { PrintAllGorizontLines('_', new Point(ConsoleCursorLeft(), 6)); PrintAllVerticalLines('|', new Point(ConsoleCursorLeft(), 7)); PrintValue(new Point(ConsoleCursorLeft() + 3, 8), null, board); }//PrintBoard
public DrumPattern(IEnumerable <string> notes, int steps) { noteNames = new List <string>(notes); Steps = steps; hits = new byte[Notes, steps]; }
private bool CheckEdgeStrictHorizontalBottom(byte[,] map, int left, int right, int top, int bottom, ref Rectangle margin) { return(CheckEdgeHorizontalBottom(map, left, right, top, bottom) && CheckEndOfEdgeHorizontalBottom(map, left, right, top, bottom, ref margin) && CheckEnoughLengthHorizontalBottom(map, left, right, top, bottom)); }
// The PrintPage event is raised for each page to be printed. private void PrintPage(object sender, PrintPageEventArgs ev) { float yPos = 0; float xPos = 0; float leftMargin = ev.MarginBounds.Left; float topMargin = ev.MarginBounds.Top; Font printFont = new Font("Arial", (ev.MarginBounds.Right - ev.MarginBounds.Left) / 18); float width = ev.Graphics.MeasureString("M", printFont).Width; float height = printFont.Height; // Center leftMargin += ((ev.MarginBounds.Right - ev.MarginBounds.Left) - width * 9) / 2; topMargin += ((ev.MarginBounds.Bottom - ev.MarginBounds.Top) - height * 9) / 2; byte[,] d = GetData(); for (int y = 0; y < 9; y++) { for (int x = 0; x < 9; x++) { // Draw symbols if (d[y, x] == 0) { continue; } string symbol = new String((char)(d[y, x] + '0'), 1); xPos = leftMargin + x * width; yPos = topMargin + y * height; ev.Graphics.DrawString(symbol, printFont, Brushes.Black, xPos, yPos); } } Pen penBlack = new Pen(Color.Black, 5); Pen penGray = new Pen(Color.Black, 1); // Draw lines for (int x = 0; x < 10; x++) { if (x % 3 == 0) { ev.Graphics.DrawLine(penBlack, leftMargin + x * width, topMargin, leftMargin + x * width, topMargin + 9 * height); } else { ev.Graphics.DrawLine(penGray, leftMargin + x * width, topMargin, leftMargin + x * width, topMargin + 9 * height); } } // Draw lines for (int y = 0; y < 10; y++) { if (y % 3 == 0) { ev.Graphics.DrawLine(penBlack, leftMargin, topMargin + y * height, leftMargin + 9 * width, topMargin + y * height); } else { ev.Graphics.DrawLine(penGray, leftMargin, topMargin + y * height, leftMargin + 9 * width, topMargin + y * height); } } printFont.Dispose(); // Print header printFont = new Font("Arial", 10); xPos = (float)ev.MarginBounds.Left; yPos = (float)ev.MarginBounds.Top; ev.Graphics.DrawString("Sudoku created: " + DateTime.Now.ToShortDateString(), printFont, Brushes.Black, xPos, yPos); printFont.Dispose(); penBlack.Dispose(); penGray.Dispose(); ev.HasMorePages = false; }
public bool CheckMoveD(Circle obj, bool Was) { int X = obj.X; int Y = obj.Y; byte[,] swap; //свапаем доски, если ход дамки нижних шашек if (Form1.turn == true) { swap = board1; board1 = board2; board2 = swap; } //вверх влево if (Y - 1 >= 0 && X - 1 >= 0 && board1[X - 1, Y - 1] == 0 && board2[X - 1, Y - 1] == 0 && Was == false) { if (Form1.turn == true) { swap = board1; board1 = board2; board2 = swap; } return(true); } else if (X - 2 >= 0 && Y - 2 >= 0 && board1[X - 1, Y - 1] == 0 && board2[X - 1, Y - 1] > 0 && board1[X - 2, Y - 2] == 0 && board2[X - 2, Y - 2] == 0) { if (Form1.turn == true) { swap = board1; board1 = board2; board2 = swap; } return(true); } else if (Y + 1 <= 7 && X - 1 >= 0 && board1[X - 1, Y + 1] == 0 && board2[X - 1, Y + 1] == 0 && Was == false) { if (Form1.turn == true) { swap = board1; board1 = board2; board2 = swap; } return(true); } else if (X - 2 >= 0 && Y + 2 <= 7 && board1[X - 1, Y + 1] == 0 && board2[X - 1, Y + 1] > 0 && board1[X - 2, Y + 2] == 0 && board2[X - 2, Y + 2] == 0) { if (Form1.turn == true) { swap = board1; board1 = board2; board2 = swap; } return(true); } else if (Y + 1 <= 7 && X + 1 <= 7 && board1[X + 1, Y + 1] == 0 && board2[X + 1, Y + 1] == 0 && Was == false) { if (Form1.turn == true) { swap = board1; board1 = board2; board2 = swap; } return(true); } else if (X + 2 <= 7 && Y + 2 <= 7 && board1[X + 1, Y + 1] == 0 && board2[X + 1, Y + 1] > 0 && board1[X + 2, Y + 2] == 0 && board2[X + 2, Y + 2] == 0) { if (Form1.turn == true) { swap = board1; board1 = board2; board2 = swap; } return(true); } else if (Y - 1 >= 0 && X + 1 <= 7 && board1[X + 1, Y - 1] == 0 && board2[X + 1, Y - 1] == 0 && Was == false) { if (Form1.turn == true) { swap = board1; board1 = board2; board2 = swap; } return(true); } else if (X + 2 <= 7 && Y - 2 >= 0 && board1[X + 1, Y - 1] == 0 && board2[X + 1, Y - 1] > 0 && board1[X + 2, Y - 2] == 0 && board2[X + 2, Y - 2] == 0) { if (Form1.turn == true) { swap = board1; board1 = board2; board2 = swap; } return(true); } else if (Was == true) { bool Return = false; //вверх влево for (int i = 1; i < obj.X; i++) { if (obj.X - i >= 0 && obj.Y - i >= 0 && board1[obj.X - i, obj.Y - i] > 0) { break; } if (obj.X - i >= 0 && obj.Y - i >= 0 && obj.X - i - 1 >= 0 && obj.Y - i - 1 >= 0 && board2[obj.X - i, obj.Y - i] > 0 && board1[obj.X - i - 1, obj.Y - i - 1] == 0 && board2[obj.X - i - 1, obj.Y - i - 1] == 0) { Return = true; break; } } //вверх вправо for (int i = 1; i < 7 - obj.Y; i++) { if (obj.X - i >= 0 && obj.Y + i <= 7 && board1[obj.X - i, obj.Y + i] > 0) { break; } if (obj.X - i >= 0 && obj.Y + i <= 7 && obj.X - i - 1 >= 0 && obj.Y + i + 1 <= 7 && board2[obj.X - i, obj.Y + i] > 0 && board1[obj.X - i - 1, obj.Y + i + 1] == 0 && board2[obj.X - i - 1, obj.Y + i + 1] == 0) { Return = true; break; } } //вниз влево for (int i = 1; i < 7 - obj.X; i++) { if (obj.X + i >= 0 && obj.Y - i >= 0 && board1[obj.X + i, obj.Y - i] > 0) { break; } if (obj.X + i >= 0 && obj.Y - i >= 0 && obj.X + i + 1 >= 0 && obj.Y - i - 1 >= 0 && board2[obj.X + i, obj.Y - i] > 0 && board1[obj.X + i + 1, obj.Y - i - 1] == 0 && board2[obj.X + i + 1, obj.Y - i - 1] == 0) { Return = true; break; } } //вниз вправо for (int i = 1; i < 7 - obj.Y; i++) { if (obj.X + i <= 7 && obj.Y + i <= 7 && board1[obj.X + i, obj.Y + i] > 0) { break; } if (obj.X + i <= 7 && obj.Y + i <= 7 && obj.X + i + 1 <= 7 && obj.Y + i + 1 <= 7 && board2[obj.X + i, obj.Y + i] > 0 && board1[obj.X + i + 1, obj.Y + i + 1] == 0 && board2[obj.X + i + 1, obj.Y + i + 1] == 0) { Return = true; break; } } if (Form1.turn == true) { swap = board1; board1 = board2; board2 = swap; } return(Return); } else { if (Form1.turn == true) { swap = board1; board1 = board2; board2 = swap; } return(false); } }
/// <summary> /// Stretches components as needed to normalize the size of all components. /// For example, in a 2x1 (4:2:2) sequence, the Cr and Cb channels will be /// scaled vertically by a factor of 2. /// </summary> public void scaleByFactors(BlockUpsamplingMode mode) { int factorUpVertical = factorUpV, factorUpHorizontal = factorUpH; if (factorUpVertical == 1 && factorUpHorizontal == 1) { return; } for (int i = 0; i < scanDecoded.Count; i++) { byte[,] src = scanDecoded[i]; int oldV = src.GetLength(0), oldH = src.GetLength(1), newV = oldV * factorUpVertical, newH = oldH * factorUpHorizontal; byte[,] dest = new byte[newV, newH]; switch (mode) { case BlockUpsamplingMode.BoxFilter: #region Upsampling by repeating values /* Perform scaling (Box filter) */ for (int u = 0; u < newH; u++) { int src_u = u / factorUpHorizontal; for (int v = 0; v < newV; v++) { int src_v = v / factorUpVertical; dest[v, u] = src[src_v, src_u]; } } #endregion break; case BlockUpsamplingMode.Interpolate: #region Upsampling by interpolation for (int u = 0; u < newH; u++) { for (int v = 0; v < newV; v++) { int val = 0; for (int x = 0; x < factorUpHorizontal; x++) { int src_u = (u + x) / factorUpHorizontal; if (src_u >= oldH) { src_u = oldH - 1; } for (int y = 0; y < factorUpVertical; y++) { int src_v = (v + y) / factorUpVertical; if (src_v >= oldV) { src_v = oldV - 1; } val += src[src_v, src_u]; } } dest[v, u] = (byte)(val / (factorUpHorizontal * factorUpVertical)); } } #endregion break; default: throw new ArgumentException("Upsampling mode not supported."); } scanDecoded[i] = dest; } }
public NESSettings() { Palette = (byte[, ])Palettes.QuickNESPalette.Clone(); }
public TwofishCipher(byte[] key, bool encrypt, bool preComputations) { if (key == null) { throw new ArgumentNullException("key"); } if (key.Length < 16 || key.Length > 32 || key.Length % 8 != 0) { throw new ArgumentException("Invalid key size"); } _encrypt = encrypt; int k = key.Length / 8; byte[,] me = new byte[k, 4]; byte[,] mo = new byte[k, 4]; _s = new byte[k, 4]; // Initialize Me, Mo and S vectors for (int i = 0, j = k - 1, pos = 0; i < k; i++, j--, pos += 8) { me[i, 0] = key[pos]; me[i, 1] = key[pos + 1]; me[i, 2] = key[pos + 2]; me[i, 3] = key[pos + 3]; mo[i, 0] = key[pos + 4]; mo[i, 1] = key[pos + 5]; mo[i, 2] = key[pos + 6]; mo[i, 3] = key[pos + 7]; uint x0 = Helper.ToLEUInt32(key, pos); uint x1 = Helper.ToLEUInt32(key, pos + 4); uint res = RSMultiply(x0, x1); _s[j, 0] = (byte)(res); _s[j, 1] = (byte)(res >> 8); _s[j, 2] = (byte)(res >> 16); _s[j, 3] = (byte)(res >> 24); } // Compute expanded keys _keys = new uint[40]; for (int i = 0; i < _keys.Length; i += 2) { byte bt = (byte)i; uint a = GFunction(bt, bt, bt, bt, me); bt++; uint b = Helper.RotateLeft(GFunction(bt, bt, bt, bt, mo), 8); _keys[i] = a + b; _keys[i + 1] = Helper.RotateLeft(a + 2 * b, 9); } // Perform pre-computations if (preComputations) { _gTable0 = new uint[256]; _gTable1 = new uint[256]; _gTable2 = new uint[256]; _gTable3 = new uint[256]; for (int i = 0; i < 256; i++) { byte b = (byte)i; RawGFunction(b, b, b, b, _s, out _gTable0[i], out _gTable1[i], out _gTable2[i], out _gTable3[i]); } _s = null; // pre-computations signal } }
public Cell(CellInformation cellInformation, List <SentServant> sentServants) { this.matrix = cellInformation.matrix; this.cellObjects = cellInformation.cellObjects; this.SentServants = sentServants; }
public Cell() { this.matrix = new byte[size, size]; }
} // end of ImagePerimeter /// <summary> /// 按指定的区域号绘制出对应的区域 /// </summary> /// <param name="b">二值位图流</param> /// <param name="Region">区域号</param> /// <param name="showContour">指定bool值,是显示轮廓线,否显示区域块</param> /// <returns></returns> public Bitmap ImageRegion(Bitmap b, ushort[] Region, bool showContour) { // 将原始二值图转化为二维数组 byte[,] srcGray = Image2Array(b); // 进行区域标记 ushort[,] Sign = ImageSign(srcGray); // 按轮廓线进行显示 if (showContour) { Sign = ContourTrace(Sign); } int len = Region.Length; int width = b.Width; int height = b.Height; BitmapData data = b.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); unsafe { byte *p = (byte *)data.Scan0; int offset = data.Stride - width * BPP; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { ushort sign = Sign[x, y]; bool showRegion = false; for (int i = 0; i < len; i++) { if (sign == Region[i]) { showRegion = true; break; } } // i // 绘制区域 if (showRegion) { p[0] = p[1] = p[2] = 0; } else { p[0] = p[1] = p[2] = 255; } p += BPP; } // x p += offset; } // y } b.UnlockBits(data); return(b); } // end of ImageRegion
public void ResizeMatrix(int newHeight, int newWidth) { /* Initialize new arrays */ ushort[,] newHeaders = new ushort[newHeight, newWidth]; byte[,] newAltitudes = new byte[newHeight, newWidth]; ushort[,] newMaps = new ushort[newHeight, newWidth]; /* Copy existing headers and altitudes rows into new arrays. If new matrix is greater in any dimension, new entries will be zero */ if (hasHeadersSection) { for (int i = 0; i < Math.Min(height, newHeight); i++) { for (int j = 0; j < Math.Min(width, newWidth); j++) { newHeaders[i, j] = headers[i, j]; } } } if (hasHeightsSection) { for (int i = 0; i < Math.Min(height, newHeight); i++) { for (int j = 0; j < Math.Min(width, newWidth); j++) { newAltitudes[i, j] = altitudes[i, j]; } } } /* Copy existing map rows into new array, and fill eventual new ones with Matrix.EMPTY (FF FF) */ for (int i = 0; i < Math.Min(height, newHeight); i++) { for (int j = 0; j < Math.Min(width, newWidth); j++) { newMaps[i, j] = maps[i, j]; } } if (newHeight > height) { for (int i = height; i < newHeight; i++) { for (int j = 0; j < newWidth; j++) { newMaps[i, j] = Matrix.EMPTY; } } } if (newWidth > width) { for (int j = width; j < newWidth; j++) { for (int i = 0; i < newHeight; i++) { newMaps[i, j] = Matrix.EMPTY; } } } /* Substitute old arrays with new arrays */ headers = newHeaders; altitudes = newAltitudes; maps = newMaps; /* Set new width and height */ height = (byte)newHeight; width = (byte)newWidth; }
public TeamData(bool isOfficialLeagueBotTeam, int tID, string name, string shortName, byte shirtStyle, byte[,] shirtColors) { this.isOfficialLeagueBotTeam = isOfficialLeagueBotTeam; this.tID = tID; this.name = name; this.shortName = shortName; this.shirtStyle = shirtStyle; this.shirtColors = shirtColors; }
public FramePattern(byte[,] pattern, Vec2i angle) { this.pattern = pattern; this.angle = angle; }
// Methods static Aes() { Sbox = new byte[, ] { { 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 1, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76 }, { 0xca, 130, 0xc9, 0x7d, 250, 0x59, 0x47, 240, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0 }, { 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15 }, { 4, 0xc7, 0x23, 0xc3, 0x18, 150, 5, 0x9a, 7, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75 }, { 9, 0x83, 0x2c, 0x1a, 0x1b, 110, 90, 160, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84 }, { 0x53, 0xd1, 0, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 190, 0x39, 0x4a, 0x4c, 0x58, 0xcf }, { 0xd0, 0xef, 170, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 2, 0x7f, 80, 60, 0x9f, 0xa8 }, { 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 210 }, { 0xcd, 12, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 100, 0x5d, 0x19, 0x73 }, { 0x60, 0x81, 0x4f, 220, 0x22, 0x2a, 0x90, 0x88, 70, 0xee, 0xb8, 20, 0xde, 0x5e, 11, 0xdb }, { 0xe0, 50, 0x3a, 10, 0x49, 6, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79 }, { 0xe7, 200, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 8 }, { 0xba, 120, 0x25, 0x2e, 0x1c, 0xa6, 180, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a }, { 0x70, 0x3e, 0xb5, 0x66, 0x48, 3, 0xf6, 14, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e }, { 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 30, 0x87, 0xe9, 0xce, 0x55, 40, 0xdf }, { 140, 0xa1, 0x89, 13, 0xbf, 230, 0x42, 0x68, 0x41, 0x99, 0x2d, 15, 0xb0, 0x54, 0xbb, 0x16 } }; iSbox = new byte[, ] { { 0x52, 9, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb }, { 0x7c, 0xe3, 0x39, 130, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb }, { 0x54, 0x7b, 0x94, 50, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 11, 0x42, 250, 0xc3, 0x4e }, { 8, 0x2e, 0xa1, 0x66, 40, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25 }, { 0x72, 0xf8, 0xf6, 100, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92 }, { 0x6c, 0x70, 0x48, 80, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 70, 0x57, 0xa7, 0x8d, 0x9d, 0x84 }, { 0x90, 0xd8, 0xab, 0, 140, 0xbc, 0xd3, 10, 0xf7, 0xe4, 0x58, 5, 0xb8, 0xb3, 0x45, 6 }, { 0xd0, 0x2c, 30, 0x8f, 0xca, 0x3f, 15, 2, 0xc1, 0xaf, 0xbd, 3, 1, 0x13, 0x8a, 0x6b }, { 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 220, 0xea, 0x97, 0xf2, 0xcf, 0xce, 240, 180, 230, 0x73 }, { 150, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 110 }, { 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 14, 170, 0x18, 190, 0x1b }, { 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 210, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 120, 0xcd, 90, 0xf4 }, { 0x1f, 0xdd, 0xa8, 0x33, 0x88, 7, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f }, { 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 13, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef }, { 160, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 200, 0xeb, 0xbb, 60, 0x83, 0x53, 0x99, 0x61 }, { 0x17, 0x2b, 4, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 20, 0x63, 0x55, 0x21, 12, 0x7d } }; Rcon = new byte[, ] { { 0, 0, 0, 0 }, { 1, 0, 0, 0 }, { 2, 0, 0, 0 }, { 4, 0, 0, 0 }, { 8, 0, 0, 0 }, { 0x10, 0, 0, 0 }, { 0x20, 0, 0, 0 }, { 0x40, 0, 0, 0 }, { 0x80, 0, 0, 0 }, { 0x1b, 0, 0, 0 }, { 0x36, 0, 0, 0 } }; gfmultby02 = new byte[] { 0, 2, 4, 6, 8, 10, 12, 14, 0x10, 0x12, 20, 0x16, 0x18, 0x1a, 0x1c, 30, 0x20, 0x22, 0x24, 0x26, 40, 0x2a, 0x2c, 0x2e, 0x30, 50, 0x34, 0x36, 0x38, 0x3a, 60, 0x3e, 0x40, 0x42, 0x44, 70, 0x48, 0x4a, 0x4c, 0x4e, 80, 0x52, 0x54, 0x56, 0x58, 90, 0x5c, 0x5e, 0x60, 0x62, 100, 0x66, 0x68, 0x6a, 0x6c, 110, 0x70, 0x72, 0x74, 0x76, 120, 0x7a, 0x7c, 0x7e, 0x80, 130, 0x84, 0x86, 0x88, 0x8a, 140, 0x8e, 0x90, 0x92, 0x94, 150, 0x98, 0x9a, 0x9c, 0x9e, 160, 0xa2, 0xa4, 0xa6, 0xa8, 170, 0xac, 0xae, 0xb0, 0xb2, 180, 0xb6, 0xb8, 0xba, 0xbc, 190, 0xc0, 0xc2, 0xc4, 0xc6, 200, 0xca, 0xcc, 0xce, 0xd0, 210, 0xd4, 0xd6, 0xd8, 0xda, 220, 0xde, 0xe0, 0xe2, 0xe4, 230, 0xe8, 0xea, 0xec, 0xee, 240, 0xf2, 0xf4, 0xf6, 0xf8, 250, 0xfc, 0xfe, 0x1b, 0x19, 0x1f, 0x1d, 0x13, 0x11, 0x17, 0x15, 11, 9, 15, 13, 3, 1, 7, 5, 0x3b, 0x39, 0x3f, 0x3d, 0x33, 0x31, 0x37, 0x35, 0x2b, 0x29, 0x2f, 0x2d, 0x23, 0x21, 0x27, 0x25, 0x5b, 0x59, 0x5f, 0x5d, 0x53, 0x51, 0x57, 0x55, 0x4b, 0x49, 0x4f, 0x4d, 0x43, 0x41, 0x47, 0x45, 0x7b, 0x79, 0x7f, 0x7d, 0x73, 0x71, 0x77, 0x75, 0x6b, 0x69, 0x6f, 0x6d, 0x63, 0x61, 0x67, 0x65, 0x9b, 0x99, 0x9f, 0x9d, 0x93, 0x91, 0x97, 0x95, 0x8b, 0x89, 0x8f, 0x8d, 0x83, 0x81, 0x87, 0x85, 0xbb, 0xb9, 0xbf, 0xbd, 0xb3, 0xb1, 0xb7, 0xb5, 0xab, 0xa9, 0xaf, 0xad, 0xa3, 0xa1, 0xa7, 0xa5, 0xdb, 0xd9, 0xdf, 0xdd, 0xd3, 0xd1, 0xd7, 0xd5, 0xcb, 0xc9, 0xcf, 0xcd, 0xc3, 0xc1, 0xc7, 0xc5, 0xfb, 0xf9, 0xff, 0xfd, 0xf3, 0xf1, 0xf7, 0xf5, 0xeb, 0xe9, 0xef, 0xed, 0xe3, 0xe1, 0xe7, 0xe5 }; gfmultby03 = new byte[] { 0, 3, 6, 5, 12, 15, 10, 9, 0x18, 0x1b, 30, 0x1d, 20, 0x17, 0x12, 0x11, 0x30, 0x33, 0x36, 0x35, 60, 0x3f, 0x3a, 0x39, 40, 0x2b, 0x2e, 0x2d, 0x24, 0x27, 0x22, 0x21, 0x60, 0x63, 0x66, 0x65, 0x6c, 0x6f, 0x6a, 0x69, 120, 0x7b, 0x7e, 0x7d, 0x74, 0x77, 0x72, 0x71, 80, 0x53, 0x56, 0x55, 0x5c, 0x5f, 90, 0x59, 0x48, 0x4b, 0x4e, 0x4d, 0x44, 0x47, 0x42, 0x41, 0xc0, 0xc3, 0xc6, 0xc5, 0xcc, 0xcf, 0xca, 0xc9, 0xd8, 0xdb, 0xde, 0xdd, 0xd4, 0xd7, 210, 0xd1, 240, 0xf3, 0xf6, 0xf5, 0xfc, 0xff, 250, 0xf9, 0xe8, 0xeb, 0xee, 0xed, 0xe4, 0xe7, 0xe2, 0xe1, 160, 0xa3, 0xa6, 0xa5, 0xac, 0xaf, 170, 0xa9, 0xb8, 0xbb, 190, 0xbd, 180, 0xb7, 0xb2, 0xb1, 0x90, 0x93, 150, 0x95, 0x9c, 0x9f, 0x9a, 0x99, 0x88, 0x8b, 0x8e, 0x8d, 0x84, 0x87, 130, 0x81, 0x9b, 0x98, 0x9d, 0x9e, 0x97, 0x94, 0x91, 0x92, 0x83, 0x80, 0x85, 0x86, 0x8f, 140, 0x89, 0x8a, 0xab, 0xa8, 0xad, 0xae, 0xa7, 0xa4, 0xa1, 0xa2, 0xb3, 0xb0, 0xb5, 0xb6, 0xbf, 0xbc, 0xb9, 0xba, 0xfb, 0xf8, 0xfd, 0xfe, 0xf7, 0xf4, 0xf1, 0xf2, 0xe3, 0xe0, 0xe5, 230, 0xef, 0xec, 0xe9, 0xea, 0xcb, 200, 0xcd, 0xce, 0xc7, 0xc4, 0xc1, 0xc2, 0xd3, 0xd0, 0xd5, 0xd6, 0xdf, 220, 0xd9, 0xda, 0x5b, 0x58, 0x5d, 0x5e, 0x57, 0x54, 0x51, 0x52, 0x43, 0x40, 0x45, 70, 0x4f, 0x4c, 0x49, 0x4a, 0x6b, 0x68, 0x6d, 110, 0x67, 100, 0x61, 0x62, 0x73, 0x70, 0x75, 0x76, 0x7f, 0x7c, 0x79, 0x7a, 0x3b, 0x38, 0x3d, 0x3e, 0x37, 0x34, 0x31, 50, 0x23, 0x20, 0x25, 0x26, 0x2f, 0x2c, 0x29, 0x2a, 11, 8, 13, 14, 7, 4, 1, 2, 0x13, 0x10, 0x15, 0x16, 0x1f, 0x1c, 0x19, 0x1a }; gfmultby09 = new byte[] { 0, 9, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f, 0x48, 0x41, 90, 0x53, 0x6c, 0x65, 0x7e, 0x77, 0x90, 0x99, 130, 0x8b, 180, 0xbd, 0xa6, 0xaf, 0xd8, 0xd1, 0xca, 0xc3, 0xfc, 0xf5, 0xee, 0xe7, 0x3b, 50, 0x29, 0x20, 0x1f, 0x16, 13, 4, 0x73, 0x7a, 0x61, 0x68, 0x57, 0x5e, 0x45, 0x4c, 0xab, 0xa2, 0xb9, 0xb0, 0x8f, 0x86, 0x9d, 0x94, 0xe3, 0xea, 0xf1, 0xf8, 0xc7, 0xce, 0xd5, 220, 0x76, 0x7f, 100, 0x6d, 0x52, 0x5b, 0x40, 0x49, 0x3e, 0x37, 0x2c, 0x25, 0x1a, 0x13, 8, 1, 230, 0xef, 0xf4, 0xfd, 0xc2, 0xcb, 0xd0, 0xd9, 0xae, 0xa7, 0xbc, 0xb5, 0x8a, 0x83, 0x98, 0x91, 0x4d, 0x44, 0x5f, 0x56, 0x69, 0x60, 0x7b, 0x72, 5, 12, 0x17, 30, 0x21, 40, 0x33, 0x3a, 0xdd, 0xd4, 0xcf, 0xc6, 0xf9, 240, 0xeb, 0xe2, 0x95, 0x9c, 0x87, 0x8e, 0xb1, 0xb8, 0xa3, 170, 0xec, 0xe5, 0xfe, 0xf7, 200, 0xc1, 0xda, 0xd3, 0xa4, 0xad, 0xb6, 0xbf, 0x80, 0x89, 0x92, 0x9b, 0x7c, 0x75, 110, 0x67, 0x58, 0x51, 0x4a, 0x43, 0x34, 0x3d, 0x26, 0x2f, 0x10, 0x19, 2, 11, 0xd7, 0xde, 0xc5, 0xcc, 0xf3, 250, 0xe1, 0xe8, 0x9f, 150, 0x8d, 0x84, 0xbb, 0xb2, 0xa9, 160, 0x47, 0x4e, 0x55, 0x5c, 0x63, 0x6a, 0x71, 120, 15, 6, 0x1d, 20, 0x2b, 0x22, 0x39, 0x30, 0x9a, 0x93, 0x88, 0x81, 190, 0xb7, 0xac, 0xa5, 210, 0xdb, 0xc0, 0xc9, 0xf6, 0xff, 0xe4, 0xed, 10, 3, 0x18, 0x11, 0x2e, 0x27, 60, 0x35, 0x42, 0x4b, 80, 0x59, 0x66, 0x6f, 0x74, 0x7d, 0xa1, 0xa8, 0xb3, 0xba, 0x85, 140, 0x97, 0x9e, 0xe9, 0xe0, 0xfb, 0xf2, 0xcd, 0xc4, 0xdf, 0xd6, 0x31, 0x38, 0x23, 0x2a, 0x15, 0x1c, 7, 14, 0x79, 0x70, 0x6b, 0x62, 0x5d, 0x54, 0x4f, 70 }; gfmultby0b = new byte[] { 0, 11, 0x16, 0x1d, 0x2c, 0x27, 0x3a, 0x31, 0x58, 0x53, 0x4e, 0x45, 0x74, 0x7f, 0x62, 0x69, 0xb0, 0xbb, 0xa6, 0xad, 0x9c, 0x97, 0x8a, 0x81, 0xe8, 0xe3, 0xfe, 0xf5, 0xc4, 0xcf, 210, 0xd9, 0x7b, 0x70, 0x6d, 0x66, 0x57, 0x5c, 0x41, 0x4a, 0x23, 40, 0x35, 0x3e, 15, 4, 0x19, 0x12, 0xcb, 0xc0, 0xdd, 0xd6, 0xe7, 0xec, 0xf1, 250, 0x93, 0x98, 0x85, 0x8e, 0xbf, 180, 0xa9, 0xa2, 0xf6, 0xfd, 0xe0, 0xeb, 0xda, 0xd1, 0xcc, 0xc7, 0xae, 0xa5, 0xb8, 0xb3, 130, 0x89, 0x94, 0x9f, 70, 0x4d, 80, 0x5b, 0x6a, 0x61, 0x7c, 0x77, 30, 0x15, 8, 3, 50, 0x39, 0x24, 0x2f, 0x8d, 0x86, 0x9b, 0x90, 0xa1, 170, 0xb7, 0xbc, 0xd5, 0xde, 0xc3, 200, 0xf9, 0xf2, 0xef, 0xe4, 0x3d, 0x36, 0x2b, 0x20, 0x11, 0x1a, 7, 12, 0x65, 110, 0x73, 120, 0x49, 0x42, 0x5f, 0x54, 0xf7, 0xfc, 0xe1, 0xea, 0xdb, 0xd0, 0xcd, 0xc6, 0xaf, 0xa4, 0xb9, 0xb2, 0x83, 0x88, 0x95, 0x9e, 0x47, 0x4c, 0x51, 90, 0x6b, 0x60, 0x7d, 0x76, 0x1f, 20, 9, 2, 0x33, 0x38, 0x25, 0x2e, 140, 0x87, 0x9a, 0x91, 160, 0xab, 0xb6, 0xbd, 0xd4, 0xdf, 0xc2, 0xc9, 0xf8, 0xf3, 0xee, 0xe5, 60, 0x37, 0x2a, 0x21, 0x10, 0x1b, 6, 13, 100, 0x6f, 0x72, 0x79, 0x48, 0x43, 0x5e, 0x55, 1, 10, 0x17, 0x1c, 0x2d, 0x26, 0x3b, 0x30, 0x59, 0x52, 0x4f, 0x44, 0x75, 0x7e, 0x63, 0x68, 0xb1, 0xba, 0xa7, 0xac, 0x9d, 150, 0x8b, 0x80, 0xe9, 0xe2, 0xff, 0xf4, 0xc5, 0xce, 0xd3, 0xd8, 0x7a, 0x71, 0x6c, 0x67, 0x56, 0x5d, 0x40, 0x4b, 0x22, 0x29, 0x34, 0x3f, 14, 5, 0x18, 0x13, 0xca, 0xc1, 220, 0xd7, 230, 0xed, 240, 0xfb, 0x92, 0x99, 0x84, 0x8f, 190, 0xb5, 0xa8, 0xa3 }; gfmultby0d = new byte[] { 0, 13, 0x1a, 0x17, 0x34, 0x39, 0x2e, 0x23, 0x68, 0x65, 0x72, 0x7f, 0x5c, 0x51, 70, 0x4b, 0xd0, 0xdd, 0xca, 0xc7, 0xe4, 0xe9, 0xfe, 0xf3, 0xb8, 0xb5, 0xa2, 0xaf, 140, 0x81, 150, 0x9b, 0xbb, 0xb6, 0xa1, 0xac, 0x8f, 130, 0x95, 0x98, 0xd3, 0xde, 0xc9, 0xc4, 0xe7, 0xea, 0xfd, 240, 0x6b, 0x66, 0x71, 0x7c, 0x5f, 0x52, 0x45, 0x48, 3, 14, 0x19, 20, 0x37, 0x3a, 0x2d, 0x20, 0x6d, 0x60, 0x77, 0x7a, 0x59, 0x54, 0x43, 0x4e, 5, 8, 0x1f, 0x12, 0x31, 60, 0x2b, 0x26, 0xbd, 0xb0, 0xa7, 170, 0x89, 0x84, 0x93, 0x9e, 0xd5, 0xd8, 0xcf, 0xc2, 0xe1, 0xec, 0xfb, 0xf6, 0xd6, 0xdb, 0xcc, 0xc1, 0xe2, 0xef, 0xf8, 0xf5, 190, 0xb3, 0xa4, 0xa9, 0x8a, 0x87, 0x90, 0x9d, 6, 11, 0x1c, 0x11, 50, 0x3f, 40, 0x25, 110, 0x63, 0x74, 0x79, 90, 0x57, 0x40, 0x4d, 0xda, 0xd7, 0xc0, 0xcd, 0xee, 0xe3, 0xf4, 0xf9, 0xb2, 0xbf, 0xa8, 0xa5, 0x86, 0x8b, 0x9c, 0x91, 10, 7, 0x10, 0x1d, 0x3e, 0x33, 0x24, 0x29, 0x62, 0x6f, 120, 0x75, 0x56, 0x5b, 0x4c, 0x41, 0x61, 0x6c, 0x7b, 0x76, 0x55, 0x58, 0x4f, 0x42, 9, 4, 0x13, 30, 0x3d, 0x30, 0x27, 0x2a, 0xb1, 0xbc, 0xab, 0xa6, 0x85, 0x88, 0x9f, 0x92, 0xd9, 0xd4, 0xc3, 0xce, 0xed, 0xe0, 0xf7, 250, 0xb7, 0xba, 0xad, 160, 0x83, 0x8e, 0x99, 0x94, 0xdf, 210, 0xc5, 200, 0xeb, 230, 0xf1, 0xfc, 0x67, 0x6a, 0x7d, 0x70, 0x53, 0x5e, 0x49, 0x44, 15, 2, 0x15, 0x18, 0x3b, 0x36, 0x21, 0x2c, 12, 1, 0x16, 0x1b, 0x38, 0x35, 0x22, 0x2f, 100, 0x69, 0x7e, 0x73, 80, 0x5d, 0x4a, 0x47, 220, 0xd1, 0xc6, 0xcb, 0xe8, 0xe5, 0xf2, 0xff, 180, 0xb9, 0xae, 0xa3, 0x80, 0x8d, 0x9a, 0x97 }; gfmultby0e = new byte[] { 0, 14, 0x1c, 0x12, 0x38, 0x36, 0x24, 0x2a, 0x70, 0x7e, 0x6c, 0x62, 0x48, 70, 0x54, 90, 0xe0, 0xee, 0xfc, 0xf2, 0xd8, 0xd6, 0xc4, 0xca, 0x90, 0x9e, 140, 130, 0xa8, 0xa6, 180, 0xba, 0xdb, 0xd5, 0xc7, 0xc9, 0xe3, 0xed, 0xff, 0xf1, 0xab, 0xa5, 0xb7, 0xb9, 0x93, 0x9d, 0x8f, 0x81, 0x3b, 0x35, 0x27, 0x29, 3, 13, 0x1f, 0x11, 0x4b, 0x45, 0x57, 0x59, 0x73, 0x7d, 0x6f, 0x61, 0xad, 0xa3, 0xb1, 0xbf, 0x95, 0x9b, 0x89, 0x87, 0xdd, 0xd3, 0xc1, 0xcf, 0xe5, 0xeb, 0xf9, 0xf7, 0x4d, 0x43, 0x51, 0x5f, 0x75, 0x7b, 0x69, 0x67, 0x3d, 0x33, 0x21, 0x2f, 5, 11, 0x19, 0x17, 0x76, 120, 0x6a, 100, 0x4e, 0x40, 0x52, 0x5c, 6, 8, 0x1a, 20, 0x3e, 0x30, 0x22, 0x2c, 150, 0x98, 0x8a, 0x84, 0xae, 160, 0xb2, 0xbc, 230, 0xe8, 250, 0xf4, 0xde, 0xd0, 0xc2, 0xcc, 0x41, 0x4f, 0x5d, 0x53, 0x79, 0x77, 0x65, 0x6b, 0x31, 0x3f, 0x2d, 0x23, 9, 7, 0x15, 0x1b, 0xa1, 0xaf, 0xbd, 0xb3, 0x99, 0x97, 0x85, 0x8b, 0xd1, 0xdf, 0xcd, 0xc3, 0xe9, 0xe7, 0xf5, 0xfb, 0x9a, 0x94, 0x86, 0x88, 0xa2, 0xac, 190, 0xb0, 0xea, 0xe4, 0xf6, 0xf8, 210, 220, 0xce, 0xc0, 0x7a, 0x74, 0x66, 0x68, 0x42, 0x4c, 0x5e, 80, 10, 4, 0x16, 0x18, 50, 60, 0x2e, 0x20, 0xec, 0xe2, 240, 0xfe, 0xd4, 0xda, 200, 0xc6, 0x9c, 0x92, 0x80, 0x8e, 0xa4, 170, 0xb8, 0xb6, 12, 2, 0x10, 30, 0x34, 0x3a, 40, 0x26, 0x7c, 0x72, 0x60, 110, 0x44, 0x4a, 0x58, 0x56, 0x37, 0x39, 0x2b, 0x25, 15, 1, 0x13, 0x1d, 0x47, 0x49, 0x5b, 0x55, 0x7f, 0x71, 0x63, 0x6d, 0xd7, 0xd9, 0xcb, 0xc5, 0xef, 0xe1, 0xf3, 0xfd, 0xa7, 0xa9, 0xbb, 0xb5, 0x9f, 0x91, 0x83, 0x8d }; }
/// <summary> /// 加网格 /// </summary> private void AddGrid() { grid = new Grid() { ShowGridLines = IsShowGrid.IsChecked.Value, Width = width, Height = height, }; int cols = (int)(grid.Width) / gridwidth + 1; int rows = (int)(grid.Height) / gridheight + 1; for (int y = 0; y < cols; y++) { ColumnDefinition col = new ColumnDefinition() { Width = new GridLength(gridwidth) }; grid.ColumnDefinitions.Add(col); } for (int x = 0; x < rows; x++) { RowDefinition row = new RowDefinition() { Height = new GridLength(gridheight) }; grid.RowDefinitions.Add(row); } ObstructionViewer.Content = grid; //初始化地图数据 //看数据是否为空,来渲染障碍物 if (Matrix != null) { for (int x = 0; x <= Matrix.GetUpperBound(1); x++) { for (int y = 0; y <= Matrix.GetUpperBound(0); y++) { if (Matrix[y, x] == obstruct) { //为障碍物 grid.UnregisterName("rect" + x + "_" + y); } } } } if (startPos != null) { grid.UnregisterName("startPos"); } if (endPos != null) { grid.UnregisterName("endPos"); } if (paths != null) { foreach (var item in paths) { grid.UnregisterName("path" + item.x + "_" + item.y); } } startPos = null; endPos = null; paths = null; //初始化障碍物数据 Matrix = new byte[rows, cols]; for (int y = 0; y < rows; y++) { for (int x = 0; x < cols; x++) { Matrix[y, x] = 1; } } }
private void CaptureAndProcces() { procImage = new byte[480, 640]; // list of pixel positions for counter clockwise search int[,] position = new int[8, 2] { { -1, -1 }, { 0, -1 }, { 1, -1 }, { 1, 0 }, { 1, 1 }, { 0, 1 }, { -1, 1 }, { -1, 0 } }; byte indexPos; int count; bool stopVar; // clear the list of border points borderX.Clear(); borderY.Clear(); // wait for image to be availabe and make a copy of the frame for processing while (webcamImage.Image == null) { ; } // get the frame to be captured Bitmap temp = new Bitmap(webcamImage.Image as Bitmap); BitmapData bmData = temp.LockBits(new Rectangle(0, 0, temp.Width, temp.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); // get stride int stride = bmData.Stride; // get the adress of first pixel IntPtr Scan0 = bmData.Scan0; // copy the information from the image to the helper matrix unsafe { byte *p = (byte *)Scan0; int nOffset = stride - temp.Width * 3; for (int x = 0; x < temp.Height; x++) { for (int y = 0; y < temp.Width; y++) { procImage[x, y] = p[0]; // go to next pixel p += 3; } // compensate for the stride offset p += nOffset; } } stopVar = false; // get the image border // we start from 50 to lose some noise from the margins // and assume only one object in picture for (int i = 50; i < temp.Height; i++) { for (int j = 50; j < temp.Width; j++) { if (procImage[i, j] == 255) { borderX.Add(i); borderY.Add(j); stopVar = true; break; } } if (stopVar) { break; } } // start from left highside corner indexPos = 0; count = 0; // check if any object is present if (stopVar == true) { // get the border of the object do { // search in counter clock wise direction for another pixel while (procImage[(int)borderX[count] + position[indexPos % 8, 0], (int)borderY[count] + position[indexPos % 8, 1]] != 255 && indexPos < 18) { indexPos++; } // if single pixel detected maybe message if (indexPos >= 18) { break; } // add the pixel to the list count++; borderX.Add((int)borderX[count - 1] + position[indexPos % 8, 0]); borderY.Add((int)borderY[count - 1] + position[indexPos % 8, 1]); // find the next counter clockwise position after the butlast pixel if ((int)borderX[count - 1] - (int)borderX[count] == -1 && (int)borderY[count - 1] - (int)borderY[count] == 0) { indexPos = 0; } else if ((int)borderX[count - 1] - (int)borderX[count] == -1 && (int)borderY[count - 1] - (int)borderY[count] == -1) { indexPos = 1; } else if ((int)borderX[count - 1] - (int)borderX[count] == 0 && (int)borderY[count - 1] - (int)borderY[count] == -1) { indexPos = 2; } else if ((int)borderX[count - 1] - (int)borderX[count] == 1 && (int)borderY[count - 1] - (int)borderY[count] == -1) { indexPos = 3; } else if ((int)borderX[count - 1] - (int)borderX[count] == 1 && (int)borderY[count - 1] - (int)borderY[count] == 0) { indexPos = 4; } else if ((int)borderX[count - 1] - (int)borderX[count] == 1 && (int)borderY[count - 1] - (int)borderY[count] == 1) { indexPos = 5; } else if ((int)borderX[count - 1] - (int)borderX[count] == 0 && (int)borderY[count - 1] - (int)borderY[count] == 1) { indexPos = 6; } else if ((int)borderX[count - 1] - (int)borderX[count] == -1 && (int)borderY[count - 1] - (int)borderY[count] == 1) { indexPos = 7; } if (count > 3000) { break; } } while (((int)borderX[0] != (int)borderX[count]) || ((int)borderY[0] != (int)borderY[count])); } // check if the object found is too big or too small if (count > 100 && count <= 3000) { // remove last item from border list because it's useless borderX.RemoveAt(count); borderY.RemoveAt(count); textBox.AppendText("Border count=" + count.ToString() + "\n"); // initialize variables used for feature extraction borderLength = 0; objectArea = 0; xCOG = 0; yCOG = 0; xMax = 0; xMin = temp.Height; yMax = 0; yMin = temp.Width; // now we process the list and compute the features Parallel.Invoke(() => GetFeatureSet1(count), () => GetFeatureSet2(count)); // get the final features objectArea /= 2; xCOG /= 6 * objectArea; yCOG /= 6 * objectArea; objectPx = (xMax - xCOG) / (xCOG - xMin); objectPy = (yMax - yCOG) / (yCOG - yMin); objectCompactness = 4 * Math.PI * objectArea / (borderLength * borderLength); objectArea /= temp.Height * temp.Width; // print the result textBox.AppendText("Compactness=" + objectCompactness.ToString() + "\n"); textBox.AppendText("Area=" + objectArea.ToString() + "\n"); textBox.AppendText("Px=" + objectPx.ToString() + " Py=" + objectPy.ToString() + "\n"); } else { textBox.AppendText("Object extraction error\n"); } // copy the processed image back unsafe { int width = temp.Width; byte *p = (byte *)Scan0; int nOffset = stride - temp.Width * 3; int finished; Task[] t = new Task[Environment.ProcessorCount]; for (int x = 0; x < Environment.ProcessorCount; x++) { int xTemp = x; byte *pTemp = p; t[x] = Task.Factory.StartNew(() => CopyImageBack(pTemp, xTemp, width)); p += stride; } for (int x = Environment.ProcessorCount; x < temp.Height; x++) { int xTemp = x; byte *pTemp = p; finished = Task.WaitAny(t); t[finished] = Task.Factory.StartNew(() => CopyImageBack(pTemp, xTemp, width)); // add stride to go to next line p += stride; } Task.WaitAll(t); } temp.UnlockBits(bmData); capturedImage.Image = temp.Clone() as Image; }
public async Task ComparePictures(byte[,] r_master, byte[,] g_master, byte[,] b_master, byte[,] r_slave, byte[,] g_slave, byte[,] b_slave, string heatmap_file_name, string scoremap_file_name, byte rt, byte gt, byte bt, byte filter_background = 1, byte edge_threshold = 7, bool is_simplified = false, bool black_background = false) { // checking if arrays have the same length and if not then set an error code if ((r_master.Length + b_master.Length + g_master.Length) == (b_slave.Length + g_slave.Length + r_slave.Length)) { // saving to variables resolution of the image int width = r_master.GetLength(0); int height = r_master.GetLength(1); // declaration of new 2D arrays BackgroundArray = new bool[width, height]; byte[,] r_difference = new byte[width, height]; byte[,] g_difference = new byte[width, height]; byte[,] b_difference = new byte[width, height]; byte[,] difference = new byte[width, height]; byte[,] score = new byte[width, height]; // reseting counters and score GoodPixelCount = 0; BadPixelCount = 0; BackgroundPixelCount = 0; Score = 0; // funtion that checks background if (filter_background == 1) { CheckBackground(r_master, g_master, b_master, r_slave, g_slave, b_slave, edge_threshold, is_simplified, black_background); } // calculating an absolute value of difference in color between two images for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { r_difference[i, j] = (byte)Math.Abs(r_master[i, j] - r_slave[i, j]); g_difference[i, j] = (byte)Math.Abs(g_master[i, j] - g_slave[i, j]); b_difference[i, j] = (byte)Math.Abs(b_master[i, j] - b_slave[i, j]); difference[i, j] = (byte)((r_difference[i, j] + g_difference[i, j] + b_difference[i, j]) / 3); // if a pixel is background then set 2 in score array if (BackgroundArray[i, j] == true) { score[i, j] = 2; BackgroundPixelCount++; } // if a pixel difference is lesser than color difference then set 1 in score array else if (r_difference[i, j] <= rt && g_difference[i, j] <= gt && b_difference[i, j] <= bt) { score[i, j] = 1; GoodPixelCount++; } // if a pixel difference is greater than color difference then set 0 in score array else { score[i, j] = 0; BadPixelCount++; } } } // calculate the score Score = ((100 * GoodPixelCount) / (GoodPixelCount + BadPixelCount)); // functions that create heatmap and scoremap await HeatMap(difference, heatmap_file_name); await ScoreMap(score, scoremap_file_name); } else { ErrorCode = "Resolution of images are different"; // MessageBox can be used } }
private bool CheckEdgeStrictVerticalRight(byte[,] map, int left, int right, int top, int bottom, ref Rectangle margin) { return(CheckEdgeVerticalRight(map, left, right, top, bottom) && CheckEndOfEdgeVerticalRight(map, left, right, top, bottom, ref margin) && CheckEnoughLengthVerticalRight(map, left, right, top, bottom)); }
private void writeBlockScaled(byte[][,] raster, byte[,] blockdata, int compIndex, int x, int y, BlockUpsamplingMode mode) { int w = raster[0].GetLength(0), h = raster[0].GetLength(1); int factorUpVertical = factorUpV, factorUpHorizontal = factorUpH; int oldV = blockdata.GetLength(0), oldH = blockdata.GetLength(1), newV = oldV * factorUpVertical, newH = oldH * factorUpHorizontal; byte[,] comp = raster[compIndex]; // Blocks may spill over the frame so we bound by the frame size int yMax = newV; if ((y + yMax) > h) { yMax = h - y; } int xMax = newH; if ((x + xMax) > w) { xMax = w - x; } switch (mode) { case BlockUpsamplingMode.BoxFilter: #region Upsampling by repeating values // Special case 1: No scale-up if (factorUpVertical == 1 && factorUpHorizontal == 1) { for (int u = 0; u < xMax; u++) { for (int v = 0; v < yMax; v++) { comp[u + x, y + v] = blockdata[v, u]; } } } // Special case 2: Perform scale-up 4 pixels at a time else if (factorUpHorizontal == 2 && factorUpVertical == 2 && xMax == newH && yMax == newV) { for (int src_u = 0; src_u < oldH; src_u++) { int bx = src_u * 2 + x; for (int src_v = 0; src_v < oldV; src_v++) { byte val = blockdata[src_v, src_u]; int by = src_v * 2 + y; comp[bx, by] = val; comp[bx, by + 1] = val; comp[bx + 1, by] = val; comp[bx + 1, by + 1] = val; } } } else { /* Perform scaling (Box filter) */ for (int u = 0; u < xMax; u++) { int src_u = u / factorUpHorizontal; for (int v = 0; v < yMax; v++) { int src_v = v / factorUpVertical; comp[u + x, y + v] = blockdata[src_v, src_u]; } } } #endregion break; // JRP 4/7/08 -- This mode is disabled temporarily as it needs to be fixed after // recent performance tweaks. // It can produce slightly better (less blocky) decodings. //case BlockUpsamplingMode.Interpolate: // #region Upsampling by interpolation // for (int u = 0; u < newH; u++) // { // for (int v = 0; v < newV; v++) // { // int val = 0; // for (int x = 0; x < factorUpHorizontal; x++) // { // int src_u = (u + x) / factorUpHorizontal; // if (src_u >= oldH) src_u = oldH - 1; // for (int y = 0; y < factorUpVertical; y++) // { // int src_v = (v + y) / factorUpVertical; // if (src_v >= oldV) src_v = oldV - 1; // val += src[src_v, src_u]; // } // } // dest[v, u] = (byte)(val / (factorUpHorizontal * factorUpVertical)); // } // } // #endregion // break; default: throw new ArgumentException("Upsampling mode not supported."); } }
private void CheckBackground(byte[,] r_master, byte[,] g_master, byte[,] b_master, byte[,] r_slave, byte[,] g_slave, byte[,] b_slave, byte edge_threshold, bool is_simplified, bool black_background) { // saving to variables resolution of the image int width = r_master.GetLength(0); int height = r_master.GetLength(1); // setting background tolerance byte tr = 192; if (is_simplified == true) { tr = 170; } byte tg = 170; byte tb = 128; double threshold = 90; // start of function that measures elapsed time var watch = new Stopwatch(); watch.Start(); // this part of function is executed when the background is black - used for edge detection if (black_background == true) { byte t = 128; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { // algorithm has a deadzone - protection from getting out of array if (((i > 1 * edge_threshold) && (i < width - 1 * edge_threshold)) && ((j > 1 * edge_threshold) && (j < height - 1 * edge_threshold))) { uint background_counter = 0; uint foreground_counter = 0; // executing of an algoritms that cross-checks in 8 directions // and counts how many pixels there are below background tolerance // and tags checked pixel as background or not for (int k = (-edge_threshold); k <= edge_threshold; k++) { if (k == 0) { continue; } if (r_master[i + k, j + k] < t && r_slave[i + k, j + k] < t && g_master[i + k, j + k] < t && g_slave[i + k, j + k] < t && b_master[i + k, j + k] < t && b_slave[i + k, j + k] < t) { background_counter++; } else { foreground_counter++; } if (r_master[i + k, j - k] < t && r_slave[i + k, j - k] < t && g_master[i + k, j - k] < t && g_slave[i + k, j - k] < t && b_master[i + k, j + k] < t && b_slave[i + k, j - k] < t) { background_counter++; } else { foreground_counter++; } if (r_master[i + k, j + 0] < t && r_slave[i + k, j + 0] < t && g_master[i + k, j + 0] < t && g_slave[i + k, j + 0] < t && b_master[i + k, j + 0] < t && b_slave[i + k, j + 0] < t) { background_counter++; } else { foreground_counter++; } if (r_master[i + 0, j + k] < t && r_slave[i + 0, j + k] < t && g_master[i + 0, j + k] < t && g_slave[i + 0, j + k] < t && b_master[i + 0, j + k] < t && b_slave[i + 0, j + k] < t) { background_counter++; } else { foreground_counter++; } } if (100 * background_counter / (foreground_counter + background_counter) > threshold) { BackgroundArray[i, j] = true; } else { BackgroundArray[i, j] = false; } } else { BackgroundArray[i, j] = true; } } } } // algorithm for white background - the difference is in sign // and counts how many pixels there are above background tolerance else { for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (((i > 1 * edge_threshold) && (i < width - 1 * edge_threshold)) && ((j > 1 * edge_threshold) && (j < height - 1 * edge_threshold))) { uint background_counter = 0; uint foreground_counter = 0; for (int k = (-edge_threshold); k <= edge_threshold; k++) { if (k == 0) { continue; } if (r_master[i + k, j + k] >= tr && r_slave[i + k, j + k] >= tr && g_master[i + k, j + k] >= tg && g_slave[i + k, j + k] >= tg && b_master[i + k, j + k] >= tb && b_slave[i + k, j + k] >= tb) { background_counter++; } else { foreground_counter++; } if (r_master[i + k, j - k] >= tr && r_slave[i + k, j - k] >= tr && g_master[i + k, j - k] >= tg && g_slave[i + k, j - k] >= tg && b_master[i + k, j + k] >= tb && b_slave[i + k, j - k] >= tb) { background_counter++; } else { foreground_counter++; } if (r_master[i + k, j + 0] >= tr && r_slave[i + k, j + 0] >= tr && g_master[i + k, j + 0] >= tg && g_slave[i + k, j + 0] >= tg && b_master[i + k, j + 0] >= tb && b_slave[i + k, j + 0] >= tb) { background_counter++; } else { foreground_counter++; } if (r_master[i + 0, j + k] >= tr && r_slave[i + 0, j + k] >= tr && g_master[i + 0, j + k] >= tg && g_slave[i + 0, j + k] >= tg && b_master[i + 0, j + k] >= tb && b_slave[i + 0, j + k] >= tb) { background_counter++; } else { foreground_counter++; } } if (100 * background_counter / (foreground_counter + background_counter) > threshold) { BackgroundArray[i, j] = true; } else { BackgroundArray[i, j] = false; } } else { BackgroundArray[i, j] = true; } } } } // end of function that measures elapsed time and displays the value in debugger watch.Stop(); System.Diagnostics.Debug.WriteLine("Time elapsed: " + watch.Elapsed); }
public async Task SetPixel(byte[,] r_color, byte[,] g_color, byte[,] b_color, string file_name, byte simplifier) { // saving to variables resolution of the image int width = r_color.GetLength(0); int height = r_color.GetLength(1); // simplify colors by dividing without remainder and then multipling by simplifier { for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { b_color[i, j] = Convert.ToByte(b_color[i, j] / simplifier); b_color[i, j] *= simplifier; g_color[i, j] = Convert.ToByte(g_color[i, j] / simplifier); g_color[i, j] *= simplifier; r_color[i, j] = Convert.ToByte(r_color[i, j] / simplifier); r_color[i, j] *= simplifier; } } byte t = 192; sbyte border = 2; // distance from the central pixel to border of checking mask byte threshold = 55; bool is_background = false; // setting up background detecting for each simplifier in the program if (simplifier == 85) { t = 170; } else if (simplifier == 64) { t = 192; } else { t = 204; } // algorithm has a deadzone - protection from getting out of array for (int i = border; i < width - border; i = i + border + 1) { for (int j = border; j < height - border; j = j + border + 1) { uint goodpixel_counter = 0, badpixel_counter = 0; // checking if pixel is background-pixel if (r_color[i, j] == t && g_color[i, j] == t && b_color[i, j] == t) { is_background = true; } else { is_background = false; } // if pixel is not background-pixel, the algorithm executes cross-checking in 8 directions // and counts how many positive scores there are - above setpoint // if there is pixels above setpoint, then every neighbor pixel takes value of center pixel if (is_background == false) { for (int n = (-border); n <= border; n++) { if (n == 0) { continue; } if (r_color[i + n, j + n] == r_color[i, j] && g_color[i + n, j + n] == g_color[i, j] && b_color[i + n, j + n] == b_color[i, j]) { goodpixel_counter++; } else { badpixel_counter++; } if (r_color[i + n, j - n] == r_color[i, j] && g_color[i + n, j - n] == g_color[i, j] && b_color[i + n, j - n] == b_color[i, j]) { goodpixel_counter++; } else { badpixel_counter++; } if (r_color[i + n, j + 0] == r_color[i, j] && g_color[i + n, j + 0] == g_color[i, j] && b_color[i + n, j + 0] == b_color[i, j]) { goodpixel_counter++; } else { badpixel_counter++; } if (r_color[i + n, j + n] == r_color[i, j] && g_color[i + n, j + n] == g_color[i, j] && b_color[i + n, j + n] == b_color[i, j]) { goodpixel_counter++; } else { badpixel_counter++; } } if (100 * goodpixel_counter / (badpixel_counter + goodpixel_counter) > threshold) { for (int x = -(border); x <= border; x++) { for (int y = -(border); y <= border; y++) { if (x == 0 & y == 0) { continue; } r_color[i + x, j + y] = r_color[i, j]; g_color[i + x, j + y] = g_color[i, j]; b_color[i + x, j + y] = b_color[i, j]; } } } } } } } // WriteableBitmap uses BGRA format - 4 bytes per pixel byte[] image_array = new byte[width * height * 4]; BitmapAlphaMode alpha_mode = BitmapAlphaMode.Ignore; // saving to byte array the 2D color arrays for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { image_array[4 * ((width * j) + i) + 0] = b_color[i, j]; // blue image_array[4 * ((width * j) + i) + 1] = g_color[i, j]; // green image_array[4 * ((width * j) + i) + 2] = r_color[i, j]; // red } } // saving data to file with sent image settings (parameters) await SaveToFile(image_array, file_name, CreationCollisionOption.ReplaceExisting, BitmapPixelFormat.Bgra8, alpha_mode); }
// ------------------------------------------------------------------------------------------------------ // ----------- Terrain generation and initialization stuff: -------------------------------------------------------- // ------------------------------------------------------------------------------------------------------ private void generateTerrain() { // TerrainBuilderReturnPacket terrainPacket = TerrainBuilder.generateTerrain(Constants.roomWidthHeight, Constants.numOfVertsPerEdge); TerrainBuilderReturnPacket terrainPacket = persistentData.getTerrainPacket(); Mesh[,] terrainMeshes = terrainPacket.getTerrainMeshes(); // Mesh[,] terrainMeshes = TerrainBuilder.sliceHeightArrayIntoMultipleMeshes(terrainPacket.getHeightArray(), Constants.roomWidthHeight, Constants.numOfVertsPerEdge); boolArray = terrainPacket.getBoolArray(); persistentData.setAreaTotal(terrainPacket.getNumOfRooms()); persistentData.setKeysTotal(terrainPacket.getNumOfKeys()); persistentData.setDoorsTotal(terrainPacket.getNumOfLockedDoors()); numOfRooms_horizontal = (byte)terrainMeshes.GetLength(0); numOfRooms_vertical = (byte)terrainMeshes.GetLength(1); waterManager.setWaterSize(numOfRooms_horizontal, numOfRooms_vertical, Constants.roomWidthHeight); // color the pixels in the terrainMaterial? // Color32[] terrainColors = TerrainColorGenerator.GenerateTerrainColors(); Color32[] terrainColors = persistentData.getTerrainColors(); Texture2D terrainTexture = new Texture2D(4, 1); terrainTexture.wrapMode = TextureWrapMode.Clamp; terrainTexture.filterMode = FilterMode.Point; terrainMaterial.mainTexture = terrainTexture; //terrainTexture.SetPixel(0, 0, terrainColors[3]); terrainTexture.SetPixel(0, 0, terrainColors[0]); terrainTexture.SetPixel(1, 0, terrainColors[1]); terrainTexture.SetPixel(2, 0, terrainColors[2]); terrainTexture.SetPixel(3, 0, terrainColors[3]); terrainTexture.Apply(); //waterManager.setWaterTint(terrainColors[3]); waterManager.setWaterTint(terrainColors[0]); Debug.Log("Water color is: " + (terrainColors[0])); persistentData.setTerrainColors(terrainColors); // Instantiate the 3D terrain meshes: GameObject newTerrainParent = new GameObject("terrainParent"); MeshFilter terrainMeshFilter; MeshRenderer terrainMeshRenderer; for (int indexX = 0; indexX < numOfRooms_horizontal; indexX++) { for (int indexY = 0; indexY < numOfRooms_vertical; indexY++) { GameObject newTerrain = new GameObject("terrainPiece"); terrainMeshFilter = newTerrain.AddComponent <MeshFilter>(); terrainMeshFilter.mesh = terrainMeshes[indexX, indexY]; terrainMeshRenderer = newTerrain.AddComponent <MeshRenderer>(); terrainMeshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; terrainMeshRenderer.material = terrainMaterial; newTerrain.transform.position = new Vector3(((indexX * Constants.roomWidthHeight) - 2f * Constants.roomWidthHeight), -0.5f, ((-indexY * Constants.roomWidthHeight) + 2f * Constants.roomWidthHeight)); newTerrain.transform.parent = newTerrainParent.transform; } } // Move the player's boat to the starting location: playerBoatTransform_target.position = new Vector3((((float)terrainPacket.getPlayerStartingLocation()[0]) + 0.5f) * Constants.roomWidthHeight, 0f, (((float)terrainPacket.getPlayerStartingLocation()[1]) + 0.5f) * -Constants.roomWidthHeight); playerBoatTransform_delayed.position = playerBoatTransform_target.position; // And bookmark the first 'port town' where the player spawns: // bookmarkNewPortTownLocation(playerBoatTransform_target.position.x, playerBoatTransform_target.position.z); // Instantiate the interactables: doorHitboxManager = new DoorHitboxManager(terrainPacket.getDoorLocations(), terrainPacket.getDoorSides(), terrainPacket.getDoorColors()); // first instantiate the final treasure: interactablesManager.addObjectToArray(instantiateItem_initial(terrainPacket.getFinalTreasureLocation()[0], terrainPacket.getFinalTreasureLocation()[1], Constants.interactableID_treasureFinal), Constants.interactableID_treasureFinal, 0); // Then instantiate all the keys: byte[,] itemLocations = terrainPacket.getKeyLocations(); bool[] hasKey = terrainPacket.getHasKey(); byte[] itemIDs = { Constants.interactableID_key1, Constants.interactableID_key2, Constants.interactableID_key3, Constants.interactableID_key4, Constants.interactableID_key5, Constants.interactableID_key6 }; for (short index = 0; index < 6; index++) { if (hasKey[index]) { interactablesManager.addObjectToArray(instantiateItem_initial(itemLocations[index, 0], itemLocations[index, 1], itemIDs[index]), itemIDs[index], index); } } // then instantiate all the door prefabs: itemLocations = terrainPacket.getDoorLocations(); itemIDs = terrainPacket.getDoorColors(); byte[] doorSide = terrainPacket.getDoorSides(); for (short index = 0; index < itemIDs.Length; index++) { interactablesManager.addObjectToArray(instantiateDoor_initial(itemLocations[index, 0], itemLocations[index, 1], itemIDs[index], doorSide[index]), itemIDs[index], index); } // Now instantiate the minimap: minimapManager.initializeMinimapData(terrainPacket.getSimplePacket(), terrainPacket.getBoolArray_noNoise(), persistentData); // Now instantiate all the port towns: PortTownReturnPacket portTownPacket = terrainPacket.getPortTownPacket(); placeAllPortTowns(portTownPacket); minimapManager.setPortTownData(portTownPacket); // Instantiate the enemy manager: enemyManager.placeStartingEnemies(playerBoatTransform_target.position, boolArray, doorHitboxManager, (byte)(numOfRooms_horizontal - 3), (byte)(numOfRooms_vertical - 3), portTownPacket, persistentData.getDensityOfEnemies_value()); // Cannonball related stuff: touchManager.setArrowAndWheelColors(terrainColors[0]); cannonballManager.initializeCannonballData(boolArray, doorHitboxManager, persistentData.getDensityOfEnemies_value(), persistentData.getShipColors()[5]); }
public Cell(CellInformation cellInformation) { this.matrix = cellInformation.matrix; this.cellObjects = cellInformation.cellObjects; this.SentServants = new List <SentServant>(); }
//====================================== 红中麻将====================================================== /** * 判断是否普通胡牌 * @param byaTileNum 各种花色的牌各个值的张数,一维的5代表花色;二维的10的0位置保存这个花色的总张数,1~9位置保存对应值的牌张数 * @param resultType 结果信息 * 癞子的花色 * 癞子的牌值@return 是否胡牌 */ public bool JudgeNormalWin(byte[,] byaTileNum, byte byLaiziSuit, byte byLaiziValue) { //byaTileNum=new byte [5, 10]; byte bySuit = 0; byte byValue = 0; byte byChangeValue = 0; // 变化的牌值 byte byLaiziNum = 0; //癞子牌数量 byte byEmployLaiZiNum = 0; //使用癞子的数量 byte byIndex = 0; // 当前牌的下标 byte byRemainingNum = 0; // 去除正常顺子刻子后剩余的牌 byte[] byaTiles = new byte[14]; // 用于保存需要癞子的牌,包括将牌 byte[,] byaSaveTileNum = byaTileNum; // 用于保存手牌 bool bSuccess = false; // 能否胡牌 bool bJong = false; // 将是否存在 bool bJongTile = false; //奖牌是否找到 byte byRemainder = 0; // 余数 byte byJongSuit = 0; // 将牌的花色 byte byJongValue = 0; // 将牌的牌值 //memset(byaTiles, 0, byaTiles.Length ); //保存手牌 //memset(byaSaveTileNum, 0, byaSaveTileNum.Length ); // memcpy(byaSaveTileNum, byaTileNum, byaSaveTileNum.Length ); //计算癞子的数量 // 是否满足33332模型 // 这里考虑没有癞子时候 要先找出将牌 if (byLaiziSuit < 1) { Debug.LogError("byLaiziSuit:" + byLaiziSuit); return(false); } byLaiziNum = byaSaveTileNum[byLaiziSuit - 1, byLaiziValue]; byaSaveTileNum[byLaiziSuit - 1, byLaiziValue] = 0; byaSaveTileNum[byLaiziSuit - 1, 0] -= byLaiziNum; for (bySuit = SUIT_CHARACTER; bySuit < SUIT_FLOWER; bySuit++) // 5种花色 { byRemainder = (byte)(byaSaveTileNum[bySuit - 1, 0] % 3); if (byLaiziNum == 0) { if (byRemainder == 1) { Debug.LogError("MahjongHelper::JudgeNormalWin A"); return(false); } else if (byRemainder == 2) { if (bJong) { Debug.LogError("MahjongHelper::JudgeNormalWin B"); return(false); } byJongSuit = bySuit; bJong = true; } } else if (byLaiziNum > 0) { if (byRemainder == 1) { continue; } else if (byRemainder == 2) { if (bySuit < SUIT_WIND) { for (byValue = 1; byValue < 10; byValue++) { if (byValue < 8 && ((byaSaveTileNum[bySuit - 1, byValue] == 3 && byaSaveTileNum[bySuit - 1, byValue + 1] == 1 && byaSaveTileNum[bySuit - 1, byValue + 2] == 1) || (byaSaveTileNum[bySuit - 1, byValue] == 1 && byaSaveTileNum[bySuit - 1, byValue + 1] == 1 && byaSaveTileNum[bySuit - 1, byValue + 2] == 3))) { if (bJong) { break; } byJongSuit = bySuit; bJong = true; } } } } } } Debug.LogWarningFormat("MahjongHelper::JudgeNormalWin,癞子牌{0},{1}数量{2}", byLaiziSuit, byLaiziValue, byLaiziNum); //去除不许要癞子成扑的牌 for (bySuit = SUIT_CHARACTER; bySuit < SUIT_FLOWER; bySuit++) { if (bJong && byJongSuit == bySuit) { for (byValue = 1; byValue < 10; byValue++) { if (!bJongTile && byaSaveTileNum[bySuit - 1, byValue] >= 2) { //memset(&tempResult, 0, sizeof(tempResult)); // memcpy(&tempResult, &resultType, sizeof(ResultTypeDef)); // 除去2张将牌 byaSaveTileNum[byJongSuit - 1, byValue] -= 2; byaSaveTileNum[byJongSuit - 1, 0] -= 2; byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, bySuit - 1); if (AnalyzeSuit(bySuit > SUIT_BAMBOO ? true : false, byJongSuit)) { SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, bySuit - 1); byaTiles[byRemainingNum] = (byte)(byJongSuit << 4 | byValue); byRemainingNum++; byaTiles[byRemainingNum] = (byte)(byJongSuit << 4 | byValue); byRemainingNum++; byJongValue = byValue; bJongTile = true; } else { // 还原2张将牌 byaSaveTileNum[byJongSuit - 1, byValue] += 2; byaSaveTileNum[byJongSuit - 1, 0] += 2; } } } } Debug.Log("==================22222 bySuit:" + bySuit); byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, bySuit - 1); AnalyzeSuit(bySuit, byLaiziSuit, byLaiziValue, 20001); SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, bySuit - 1); } // Debug.LogWarningFormat("MahjongHelper::JudgeNormalWin 万总张数{0}:{1}{2}{3}{4}{5}{6}{7}{8}{9}",byaSaveTileNum[0][0],byaSaveTileNum[0][1] ,byaSaveTileNum[0][2],byaSaveTileNum[0][3],byaSaveTileNum[0][4],byaSaveTileNum[0][5],byaSaveTileNum[0][6],byaSaveTileNum[0][7],byaSaveTileNum[0][8],byaSaveTileNum[0][9]); //Debug.LogWarningFormat("MahjongHelper::JudgeNormalWin 筒总张数[%d]:" + byaSaveTileNum[1][0] + " " + byaSaveTileNum[1][1] + " " + byaSaveTileNum[1][2] + " " + byaSaveTileNum[1][3] + " " + byaSaveTileNum[1][4] + " " + // byaSaveTileNum[1][5] + " " + byaSaveTileNum[1][6] + " " + byaSaveTileNum[1][7] + " " + byaSaveTileNum[1][8], byaSaveTileNum[1][9]); //Debug.LogWarningFormat("MahjongHelper::JudgeNormalWin 索总张数[%d]:" + byaSaveTileNum[2][0] + " " + byaSaveTileNum[2][1] + " " + byaSaveTileNum[2][2] + " " + byaSaveTileNum[2][3] + " " + byaSaveTileNum[2][4] + " " + //// byaSaveTileNum[2][5] + " " + byaSaveTileNum[2][6] + " " + byaSaveTileNum[2][7] + " " + byaSaveTileNum[2][8] + " " + byaSaveTileNum[2][9]); //Debug.LogWarningFormat("MahjongHelper::JudgeNormalWin 风总张数[%d]:" + byaSaveTileNum[3][0] + " " + byaSaveTileNum[3][1] + " " + byaSaveTileNum[3][2] + " " + byaSaveTileNum[3][3] + " " + byaSaveTileNum[3][4] + " " + // byaSaveTileNum[3][5] + " " + byaSaveTileNum[3][6] + " " + byaSaveTileNum[3][7] + " " + byaSaveTileNum[3][8] + " " + byaSaveTileNum[3][9]); //Debug.LogWarningFormat("MahjongHelper::JudgeNormalWin 箭总张数[%d]:" + byaSaveTileNum[4][0] + " " + byaSaveTileNum[4][1] + " " + byaSaveTileNum[4][2] + " " + byaSaveTileNum[4][3] + " " + byaSaveTileNum[4][4] + " " + // byaSaveTileNum[4][5] + " " + byaSaveTileNum[4][6] + " " + byaSaveTileNum[4][7] + " " + byaSaveTileNum[4][8] + " " + byaSaveTileNum[4][9]); // 将剩余的牌加入数组中 for (bySuit = SUIT_CHARACTER; bySuit < SUIT_FLOWER; bySuit++) { if (byaSaveTileNum[bySuit - 1, 0] == 0) { continue; } for (byValue = 1; byValue < 10; byValue++) { if (byaSaveTileNum[bySuit - 1, byValue] > 0) { byaSaveTileNum[bySuit - 1, byValue]--; byaSaveTileNum[bySuit - 1, 0]--; byaTiles[byRemainingNum] = (byte)(bySuit << 4 | byValue); byRemainingNum++; byValue--; } } } Debug.LogWarningFormat("byRemainingNum:{0}\n", byRemainingNum); Debug.LogWarningFormat("byaTiles:{0}-{1}-{2}-{3}-{4}-{5}-{6}-{7}\n", byaTiles[0], byaTiles[1], byaTiles[2], byaTiles[3], byaTiles[4], byaTiles[5], byaTiles[6], byaTiles[7]); //分析需要癞子的牌 if (byLaiziNum == 0) // 没有癞子或者不玩癞子 { if (byRemainingNum == 2 && byaTiles[0] == byaTiles[1] && bJong) { bSuccess = true; bySuit = (byte)(byaTiles[0] >> 4); byValue = (byte)(byaTiles[0] & 0x0F); byaSaveTileNum[bySuit - 1, 0] += 2; byaSaveTileNum[bySuit - 1, byValue] += 2; //增加结果信息 byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, bySuit - 1); AddResult(byLaiziSuit, byLaiziValue, bySuit, byValue, 3, false); SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, bySuit - 1); } } else { for (int i = 0; i < byLaiziNum + 1; i++) { bySuit = (byte)(byaTiles[byIndex] >> 4); byValue = (byte)(byaTiles[byIndex] & 0x0F); if (byRemainingNum == 0)// 剩下的牌为 0 { // 癞子总数减去已使用后数为 3 并且 将牌已确定 (这里就组成 红中刻子)(可以胡牌 直接结束) if (byLaiziNum - byEmployLaiZiNum == 3 && bJong) { bSuccess = true; byaSaveTileNum[byLaiziSuit - 1, 0] += byLaiziNum; byaSaveTileNum[byLaiziSuit - 1, byLaiziValue] += byLaiziNum; byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, byLaiziSuit - 1); AddResult(byLaiziSuit, byLaiziValue, byLaiziSuit, byLaiziValue, 1, false); SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, byLaiziSuit - 1); break; } // 癞子总数减去已使用后数为2 并且 将牌没有确定 (这里就组成 将牌 (红中))(可以胡牌 直接结束) else if (byLaiziNum - byEmployLaiZiNum == 2 && !bJong) { bJong = true; bSuccess = true; byaSaveTileNum[byLaiziSuit - 1, 0] += 2; byaSaveTileNum[byLaiziSuit - 1, byLaiziValue] += 2; byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, byLaiziSuit - 1); AddResult(byLaiziSuit, byLaiziValue, byLaiziSuit, byLaiziValue, 3, false); SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, byLaiziSuit - 1); break; } else if (byLaiziNum - byEmployLaiZiNum != 0) // 癞子总数减去已使用后数不为 0 直接退出 没有胡牌 { Debug.LogError("MahjongHelper::JudgeNormalWin C"); return(false); } } else if (byRemainingNum == 1) { // 癞子总数减去已使用后数为 1 并且将牌没有确定 (这里就组成将牌) (可以胡牌 直接结束) if (byLaiziNum - byEmployLaiZiNum == 1 && !bJong) { bJong = true; bSuccess = true; byChangeValue = byValue; byaSaveTileNum[bySuit - 1, 0] += 1; byaSaveTileNum[bySuit - 1, byValue] += 1; //增加结果信息 byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, bySuit - 1); AddResult(byLaiziSuit, byLaiziValue, bySuit, byValue, 3, true, bySuit, byChangeValue, 1); SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, bySuit - 1); byEmployLaiZiNum += 1; byRemainingNum -= 1; break; } // 癞子总数减去已使用后数为 2 并且将牌已确定 (这里就组成刻子) (可以胡牌 直接结束) else if (byLaiziNum - byEmployLaiZiNum == 2 && bJong) { bSuccess = true; byChangeValue = byValue; byaSaveTileNum[bySuit - 1, 0] += 1; byaSaveTileNum[bySuit - 1, byValue] += 1; //增加结果信息 byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, bySuit - 1); AddResult(byLaiziSuit, byLaiziValue, bySuit, byValue, 1, true, bySuit, byChangeValue, 2); SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, bySuit - 1); byEmployLaiZiNum += 2; byRemainingNum -= 1; break; } else { Debug.LogError("MahjongHelper::JudgeNormalWin D"); return(false); } } // 剩下的牌数为 2 else if (byRemainingNum == 2) { if (byaTiles[byIndex] == byaTiles[byIndex + 1] && !bJong) { bJong = true; bSuccess = true; byaSaveTileNum[bySuit - 1, 0] += 2; byaSaveTileNum[bySuit - 1, byValue] += 2; //增加结果信息 byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, bySuit - 1); AddResult(byLaiziSuit, byLaiziValue, bySuit, byValue, 3, false); SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, bySuit - 1); byRemainingNum -= 2; byIndex += 2; } // 癞子总数减去已使用后数大于0 如果两张相同 并且有将牌 (这里就组成刻字牌) else if (byLaiziNum - byEmployLaiZiNum > 0 && byaTiles[byIndex] == byaTiles[byIndex + 1] && bJong) { bSuccess = true; byChangeValue = byValue; byaSaveTileNum[bySuit - 1, 0] += 2; byaSaveTileNum[bySuit - 1, byValue] += 2; //增加结果信息 byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, bySuit - 1); AddResult(byLaiziSuit, byLaiziValue, bySuit, byValue, 1, true, bySuit, byChangeValue, 1); SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, bySuit - 1); byRemainingNum -= 2; byIndex += 2; byEmployLaiZiNum += 1; } /*else if (byaTiles[byIndex] == byaTiles[byIndex + 1] && !bJong) * { * bJong = true; * bSuccess = true; * byaSaveTileNum[bySuit - 1,0] += 2; * byaSaveTileNum[bySuit - 1,byValue] += 2; * AddResult(resultType, byaSaveTileNum[bySuit - 1], bySuit,byValue, 3, false); * byRemainingNum -= 2; * byIndex += 2; * break; * }*/ else if (byaTiles[byIndex + 1] - byaTiles[byIndex] < 0x03 && bySuit < SUIT_WIND) { bool bHu = false; if (byLaiziNum - byEmployLaiZiNum == 1 && bJong) // 癞子总数减去已使用后数为 2 并且将牌已确定 可以胡牌 { bSuccess = true; bHu = true; } //增加结果信息 byChangeValue = (byte)(byValue + 0x03 - (byaTiles[byIndex + 1] - byaTiles[byIndex])); byaSaveTileNum[bySuit - 1, 0] += 2; byaSaveTileNum[bySuit - 1, byValue] += 1; byaSaveTileNum[bySuit - 1, byValue + 1] += 1; byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, bySuit - 1); AddResult(byLaiziSuit, byLaiziValue, bySuit, byValue, 2, true, bySuit, byChangeValue, 1); SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, bySuit - 1); byRemainingNum -= 2; byIndex += 2; byEmployLaiZiNum += 1; if (bHu) // 可以胡牌直接結束 { break; } } else if (byLaiziNum - byEmployLaiZiNum == 3 && !bJong) // 癞子总数减去已使用后数为 3 并且将牌没有确定 (这里就组成顺子) { byChangeValue = byValue; byRemainingNum -= 1; byaSaveTileNum[bySuit - 1, 0] += 1; byaSaveTileNum[bySuit - 1, byValue] += 1; byIndex++; //增加结果信息 byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, bySuit - 1); AddResult(byLaiziSuit, byLaiziValue, bySuit, (byte)(byValue == 8 ? byValue - 1 : byValue), 2, true, bySuit, byChangeValue, 2); SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, bySuit - 1); byEmployLaiZiNum += 2; } else { Debug.LogError("MahjongHelper::JudgeNormalWin E"); return(false); } } else if (byRemainingNum > 2) { if (bJong && byJongSuit == bySuit && byJongValue == byValue) { //增加结果信息 byaSaveTileNum[bySuit - 1, 0] += 2; byaSaveTileNum[bySuit - 1, byValue] += 2; byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, bySuit - 1); AddResult(byLaiziSuit, byLaiziValue, bySuit, byValue, 3, false); SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, bySuit - 1); byRemainingNum -= 2; byIndex += 2; } // 剩下的牌减去2张将加上剩余的癞子数大于2 并且两张牌相同 将牌没有确定 (这里就组成将牌) else if (((byRemainingNum - 2) + (byLaiziNum - byEmployLaiZiNum)) > 2 && byaTiles[byIndex] == byaTiles[byIndex + 1] && !bJong) { bJong = true; //增加结果信息 byaSaveTileNum[bySuit - 1, 0] += 2; byaSaveTileNum[bySuit - 1, byValue] += 2; byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, bySuit - 1); AddResult(byLaiziSuit, byLaiziValue, bySuit, byValue, 3, false); SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, bySuit - 1); byRemainingNum -= 2; byIndex += 2; } // 癞子总数减去已使用后数大于 0 并且将牌已确定 (这里就组成刻子) else if (byLaiziNum - (byEmployLaiZiNum + 1) > 0 && byaTiles[byIndex] == byaTiles[byIndex + 1] && bJong) { //增加结果信息 byChangeValue = byValue; byaSaveTileNum[bySuit - 1, 0] += 2; byaSaveTileNum[bySuit - 1, byValue] += 2; byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, bySuit - 1); AddResult(byLaiziSuit, byLaiziValue, bySuit, byValue, 1, true, bySuit, byChangeValue, 1); SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, bySuit - 1); byRemainingNum -= 2; byIndex += 2; byEmployLaiZiNum += 1; } // 癞子总数减去已使用后数大于 0 后面的牌值减前面的牌值 小于 3 并且是序数牌 (这里组成顺子) else if (byLaiziNum - (byEmployLaiZiNum + 1) > 0 && byaTiles[byIndex + 1] - byaTiles[byIndex] < 0x03 && bySuit < SUIT_WIND) { //增加结果信息 byChangeValue = (byte)(byValue + 0x03 - (byaTiles[byIndex + 1] - byaTiles[byIndex])); byaSaveTileNum[bySuit - 1, 0] += 2; byaSaveTileNum[bySuit - 1, byValue] += 1; byaSaveTileNum[bySuit - 1, byValue + 1] += 1; byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, bySuit - 1); AddResult(byLaiziSuit, byLaiziValue, bySuit, byValue, 2, true, bySuit, byChangeValue, 1); SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, bySuit - 1); byRemainingNum -= 2; byIndex += 2; byEmployLaiZiNum += 1; } else if (byRemainingNum - 2 == 1 && byLaiziNum - byEmployLaiZiNum == 2 && !bJong) // 剩下的牌加剩下的癞子牌一共5张 ,剩下的牌减去2张将牌等于 1 癞子总数减去已使用后数等于2 并且将牌没有确定 { bool flag = false; int k = 0; for (k = 0; k < 13; k++) { if (byaTiles[k] > 0 && byaTiles[k] == byaTiles[k + 1]) // 找到两张相同的牌 { bJong = true; //增加结果信息 bySuit = (byte)(byaTiles[k] >> 4); byValue = (byte)(byaTiles[k] & 0x0F); byaSaveTileNum[bySuit - 1, 0] += 2; byaSaveTileNum[bySuit - 1, byValue] += 2; byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, bySuit - 1); AddResult(byLaiziSuit, byLaiziValue, bySuit, byValue, 3, false); SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, bySuit - 1); byRemainingNum -= 2; flag = true; break; } } if (!flag && ((byRemainingNum - 1) + (byLaiziNum - (byEmployLaiZiNum + 1))) > 2 && !bJong) // 剩下的牌减去1张将加上剩余的癞子数大于2 并且将牌没有确定 (这里组成将牌) { bJong = true; byChangeValue = byValue; byaSaveTileNum[bySuit - 1, 0] += 1; byaSaveTileNum[bySuit - 1, byValue] += 1; byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, bySuit - 1); AddResult(byLaiziSuit, byLaiziValue, bySuit, byValue, 3, true, bySuit, byChangeValue, 1); SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, bySuit - 1); byRemainingNum--; byIndex++; byEmployLaiZiNum += 1; } else if (flag) { //TODO 这里不能直接结束 还需要继续组合 } else { Debug.LogError("MahjongHelper::JudgeNormalWin F111"); return(false); } } else { // 剩下的牌减去1张将加上剩余的癞子数大于2 并且将牌没有确定 (这里组成将牌) if (((byRemainingNum - 1) + (byLaiziNum - (byEmployLaiZiNum + 1))) > 2 && !bJong) { bJong = true; byChangeValue = byValue; byaSaveTileNum[bySuit - 1, 0] += 1; byaSaveTileNum[bySuit - 1, byValue] += 1; byaSuitTileNum = DobouleByte2Single(byaSaveTileNum, bySuit - 1); AddResult(byLaiziSuit, byLaiziValue, bySuit, byValue, 3, true, bySuit, byChangeValue, 1); SingleByte2Doboule(ref byaSaveTileNum, byaSuitTileNum, bySuit - 1); byRemainingNum--; byIndex++; byEmployLaiZiNum += 1; } else { Debug.Log("MahjongHelper::JudgeNormalWin G"); return(false); } } } } } if (bJong == false) { Debug.LogError("MahjongHelper::JudgeNormalWin 没有找到将牌"); bSuccess = false; } for (bySuit = SUIT_CHARACTER; bySuit < SUIT_FLOWER; bySuit++) { if (byaSaveTileNum[bySuit - 1, 0] > 0) { bSuccess = false; Debug.LogError("MahjongHelper::JudgeNormalWin 分析牌失败"); break; } } Debug.LogWarning("MahjongHelper::JudgeNormalWinb Success=" + bSuccess + "bJong= " + bJong); return(bSuccess); }
public unsafe void getYCbCr(Bitmap bmp, ref byte[,] Y_Data, ref byte[,] Cb_Data, ref byte[,] Cr_Data) { int width = bmp.Width; int height = bmp.Height; Y_Data = new byte[width, height]; //luma Cb_Data = new byte[width, height]; //Cb - blue Cr_Data = new byte[width, height]; //Cr - red unsafe { BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, bmp.PixelFormat); int heightInPixels = bitmapData.Height; int widthInBytes = width * 3; byte * ptrFirstPixel = (byte *)bitmapData.Scan0; //Convert to YCbCr for (int y = 0; y < heightInPixels; y++) { byte *currentLine = ptrFirstPixel + (y * bitmapData.Stride); for (int x = 0; x < width; x++) { int xPor3 = x * 3; /*float blue = currentLine[xPor3++]; * float green = currentLine[xPor3++]; * float red = currentLine[xPor3];*/ float red = currentLine[xPor3++]; float green = currentLine[xPor3++]; float blue = currentLine[xPor3]; Y_Data[x, y] = (byte)((0.299 * red) + (0.587 * green) + (0.114 * blue)); Cb_Data[x, y] = (byte)(128 - (0.168736 * red) - (0.331264 * green) + (0.5 * blue)); Cr_Data[x, y] = (byte)(128 + (0.5 * red) - (0.418688 * green) - (0.081312 * blue)); } } bmp.UnlockBits(bitmapData); } }
/// <summary> /// Create a bitmap from an byte array /// </summary> /// <param name="r">Red source</param> /// <param name="g">Green source</param> /// <param name="b">Blue source</param> public ThreeChannelBitmap(byte[,] r, byte[,] g, byte[,] b) { _r = new OneChannelBitmap(r); _g = new OneChannelBitmap(g); _b = new OneChannelBitmap(b); }
private void Process() { MatchedData = new RS_Lib.HistoMatch(_a.GetPicData(comboBox1.SelectedIndex + 1), _b.GetPicData(comboBox2.SelectedIndex + 1)).MatchedData; }
public Cell(byte[,] matrix) { this.matrix = matrix; }