public unsafe Dictionary <int, int> STRetournerDecompteValeur(Bitmap bmp2, Carte.Type theSign) { //Fonction faisant lanalyse selon la strategie SingleThread BitmapData bmp = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, bmp2.PixelFormat); List <Bitmap> bmpValueList = RetournerListeBmpValeur(theSign); List <BitmapData> bmpReferences = new List <BitmapData>(); for (int i = 0; i < bmpValueList.Count; i++) { bmpReferences.Add(bmpValueList[i].LockBits(new Rectangle(0, 0, bmpValueList[i].Width, bmpValueList[i].Height), ImageLockMode.ReadOnly, bmpValueList[i].PixelFormat)); } int bytesPerPixel = System.Drawing.Bitmap.GetPixelFormatSize(bmp2.PixelFormat) / 8; int heightInPixels = bmp.Height; int widthInBytes = bytesPerPixel * bmp.Width; byte *ptrFirstPixel = (byte *)bmp.Scan0; byte *[] ptrSignArray = new byte *[bmpReferences.Count]; for (int i = 0; i < bmpReferences.Count; i++) // 13 == bmpValueList.count { ptrSignArray[i] = (byte *)bmpReferences[i].Scan0; } Dictionary <int, int> decompte = new Dictionary <int, int>(); for (int i = 0; i < bmpReferences.Count; i++) { decompte[i] = 0; } for (int y = 0; y < heightInPixels; y++) { for (int i = 0; i < bmpReferences.Count; i++) { byte *currentLine = ptrFirstPixel + (y * bmp.Stride); byte *currentLineSign = ptrSignArray[i] + (y * bmpReferences[i].Stride); for (int j = 0; j < widthInBytes; j += bytesPerPixel) { int difB = (int)Math.Pow(currentLine[j] - currentLineSign[j], 2); int difG = (int)Math.Pow(currentLine[j + 1] - currentLineSign[j + 1], 2); int difR = (int)Math.Pow(currentLine[j + 2] - currentLineSign[j + 2], 2); decompte[i] += difB + difG + difR; } } } bmp2.UnlockBits(bmp); for (int i = 0; i < bmpReferences.Count; i++) { bmpValueList[i].UnlockBits(bmpReferences[i]); } return(decompte); }
public unsafe Dictionary <int, int> MTRetournerDecompteValeur(Bitmap bmp2, Carte.Type theSign) { //Fonction faisant lanalyse selon la strategie MultiThread BitmapData bmp = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, bmp2.PixelFormat); List <Bitmap> bmpValueList = RetournerListeBmpValeur(theSign); List <BitmapData> bmpReferences = new List <BitmapData>(); for (int i = 0; i < bmpValueList.Count; i++) { bmpReferences.Add(bmpValueList[i].LockBits(new Rectangle(0, 0, bmpValueList[i].Width, bmpValueList[i].Height), ImageLockMode.ReadOnly, bmpValueList[i].PixelFormat)); } int bytesPerPixel = System.Drawing.Bitmap.GetPixelFormatSize(bmp2.PixelFormat) / 8; int heightInPixels = bmp.Height; int widthInBytes = bytesPerPixel * bmp.Width; byte *ptrFirstPixel = (byte *)bmp.Scan0; byte *[] ptrSignArray = new byte *[bmpReferences.Count]; for (int i = 0; i < bmpReferences.Count; i++) // 13 == bmpValueList.count { ptrSignArray[i] = (byte *)bmpReferences[i].Scan0; } Dictionary <int, int> decompte = new Dictionary <int, int>(); for (int i = 0; i < bmpReferences.Count; i++) { decompte[i] = 0; } List <Task> qwe = new List <Task>(); for (int y = 0; y < heightInPixels; y++) { qwe.Add( Task.Run(() => { MethodWithParameter(ref bmpReferences, ref ptrFirstPixel, ref bmp, ref ptrSignArray, ref widthInBytes, ref bytesPerPixel, ref decompte); })); } foreach (var item in qwe) { item.Wait(); } sharedVariableY = -1; bmp2.UnlockBits(bmp); for (int i = 0; i < bmpReferences.Count; i++) { bmpValueList[i].UnlockBits(bmpReferences[i]); } return(decompte); }
public List <Bitmap> RetournerListeBmpValeur(Carte.Type _type) { //Images de references List <Bitmap> bmpList = new List <Bitmap>(); if ((_type == Carte.Type.Diamonds) || (_type == Carte.Type.Hearts)) { bmpList.Add(Properties.Resources.R2); bmpList.Add(Properties.Resources.R3); bmpList.Add(Properties.Resources.R4); bmpList.Add(Properties.Resources.R5); bmpList.Add(Properties.Resources.R6); bmpList.Add(Properties.Resources.R7); bmpList.Add(Properties.Resources.R8); bmpList.Add(Properties.Resources.R9); bmpList.Add(Properties.Resources.R10); bmpList.Add(Properties.Resources.RJ); bmpList.Add(Properties.Resources.RQ); bmpList.Add(Properties.Resources.RK); bmpList.Add(Properties.Resources.RA); } else { bmpList.Add(Properties.Resources.B2); bmpList.Add(Properties.Resources.B3); bmpList.Add(Properties.Resources.B4); bmpList.Add(Properties.Resources.B5); bmpList.Add(Properties.Resources.B6); bmpList.Add(Properties.Resources.B7); bmpList.Add(Properties.Resources.B8); bmpList.Add(Properties.Resources.B9); bmpList.Add(Properties.Resources.B10); bmpList.Add(Properties.Resources.BJ); bmpList.Add(Properties.Resources.BQ); bmpList.Add(Properties.Resources.BK); bmpList.Add(Properties.Resources.BA); } return(bmpList); }