//public Square(Engine engine, Bitmap bitmap, int x, int y) public Square(Engine engine, BGRA *Data, int Width, int Height, int x, int y) { m_Engine = engine; // 0 1 2 // 3 4 5 // 6 7 8 m_Colors[0] = GetColor(Data, Width, Height, x - 1, y - 1); m_Colors[1] = GetColor(Data, Width, Height, x, y - 1); m_Colors[2] = GetColor(Data, Width, Height, x + 1, y - 1); m_Colors[3] = GetColor(Data, Width, Height, x - 1, y); m_Colors[4] = GetColor(Data, Width, Height, x, y); m_Colors[5] = GetColor(Data, Width, Height, x + 1, y); m_Colors[6] = GetColor(Data, Width, Height, x - 1, y + 1); m_Colors[7] = GetColor(Data, Width, Height, x, y + 1); m_Colors[8] = GetColor(Data, Width, Height, x + 1, y + 1); // 0 1 2 // 3 4 // 5 6 7 m_Shape[1 << 0] = m_Engine.Threshold.Similar(m_Colors[4], m_Colors[0]); m_Shape[1 << 1] = m_Engine.Threshold.Similar(m_Colors[4], m_Colors[1]); m_Shape[1 << 2] = m_Engine.Threshold.Similar(m_Colors[4], m_Colors[2]); m_Shape[1 << 3] = m_Engine.Threshold.Similar(m_Colors[4], m_Colors[3]); m_Shape[1 << 4] = m_Engine.Threshold.Similar(m_Colors[4], m_Colors[5]); m_Shape[1 << 5] = m_Engine.Threshold.Similar(m_Colors[4], m_Colors[6]); m_Shape[1 << 6] = m_Engine.Threshold.Similar(m_Colors[4], m_Colors[7]); m_Shape[1 << 7] = m_Engine.Threshold.Similar(m_Colors[4], m_Colors[8]); }
public unsafe void ToIndexedBgra(Action <int, BGRA> iRgba) { int width = (int)(this.Width * this.Scale); int height = (int)(this.Height * this.Scale); using (Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb)) { DrawLines(bitmap, HOT, 0, 0, 0); using (var bitmapInRgbFormat = bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), PixelFormat.Format32bppArgb)) { BitmapData d = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmapInRgbFormat.PixelFormat); int i = 0; BGRA *ptr = (BGRA *)d.Scan0.ToPointer(); BGRA *lastptr = ptr + (width * height - 1); while (ptr < lastptr) { iRgba(i++, *(ptr++)); } bitmap.UnlockBits(d); } } }
/// <summary> /// Return the next pixel /// </summary> /// <returns>The next pixel, or null if done</returns> public BGRA *GetNextPixel() { BGRA *pReturnPixel = pCurrentPixel; if (xLocation == size.X) { xLocation = 0; yLocation++; if (yLocation == size.Y) { UnlockBitmap(); return(null); } else { pCurrentPixel = this[0, yLocation]; } } else { xLocation++; pCurrentPixel++; } return(pReturnPixel); }
public static unsafe BGRA* GetRowAddressUnchecked(this System.Drawing.Imaging.BitmapData surf, int y) { BGRA* dstPtr = (BGRA*)surf.Scan0; dstPtr += y * surf.Width; return dstPtr; }
private BGRA GetColor(BGRA *Data, int Width, int Height, int x, int y) { if (x < 0 || y < 0 || x >= Width || y >= Height) { return(BGRA.FromArgb(0, 0, 0, 0)); } return(Data[y * Width + x]); }
private static unsafe IImage <T> ReadToArray <T>(System.Drawing.Image img, Func <BGRA, T> convColor, Func <BGRA, T> convBlack, Func <int, int, T[], IImage <T> > generator) where T : struct, IEquatable <T> { Bitmap bitmap = img as Bitmap ?? new Bitmap(img); Func <BGRA, T> conv = convColor; using (var bitmapInRgbFormat = bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), PixelFormat.Format32bppArgb)) { BitmapData d = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmapInRgbFormat.PixelFormat); var width = bitmapInRgbFormat.Width; var height = bitmapInRgbFormat.Height; var data = new T[width * height]; int i = 0; BGRA *ptr = (BGRA *)d.Scan0.ToPointer(); BGRA *lastptr = ptr + (data.Length - 1); // We want to use the grayscale transform if possible to ensure most accurate conversion // So ensure that the file is color and not greyscale if (bitmap.PixelFormat != PixelFormat.Format16bppGrayScale) { bool useGrayscale = true; for (BGRA *ptr2 = ptr; ptr2 < lastptr; ptr2++) { if (ptr2->R != ptr2->G || ptr2->G != ptr2->B) { useGrayscale = false; break; } } if (useGrayscale) { // Use Grayscale Algorithm conv = convBlack; } } else { // Use Grayscale Algorithm conv = convBlack; } while (ptr <= lastptr) { data[i++] = conv(*(ptr)); ptr++; } bitmap.UnlockBits(d); return(generator(width, height, data)); } }
public UnsafeBitmapEnumerator(UnsafeBitmap fastBitmap) { fastBitmap.LockBitmap(); locked = true; this.fastBitmap = fastBitmap; x = -1; y = 0; pCurrentPixel = fastBitmap[x, y]; }
public static unsafe System.Drawing.Bitmap Load(Stream input) { DDSLoadInfo info = new DDSLoadInfo(); LoadDdsFile(input, ref info); if (info == default(DDSLoadInfo)) { return null; } var bitmap = new System.Drawing.Bitmap(info.width, info.height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); var rect = new System.Drawing.Rectangle(0, 0, info.width, info.height); var data = bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.WriteOnly, bitmap.PixelFormat); try { for (int y = 0; y < info.height; y++) { byte* src = (byte*)info.scan0 + (y * info.stride); BGRA* dst = data.GetRowAddressUnchecked(y); for (int x = 0; x < info.width; x++) { dst->R = src[0]; dst->G = src[1]; dst->B = src[2]; dst->A = src[3]; src += 4; dst++; } } } finally { Free(ref info); } bitmap.UnlockBits(data); return bitmap; }
unsafe public byte[] ToBGRA() { byte[] bgra = new byte[this.Length * 4]; fixed(BGRA* _dataPtr = &this.data[0]) fixed (byte* _bgraPtr = &bgra[0]) { BGRA* bgraPtr = (BGRA*)_bgraPtr; BGRA* dataPtr = _dataPtr; for (int i = 0; i <= this.data.Length; i++) { *(bgraPtr++) = *(dataPtr++); } } return bgra; }
public static PixelData GetPixelData(BGRA *pixel, Types model) { Color clr = Color.FromArgb(pixel->red, pixel->green, pixel->blue); PixelData pd = new PixelData(0, 0, 0, clr.Name); switch (model) { case Types.RGB: pd.Ch1 = pixel->red; pd.Ch2 = pixel->green; pd.Ch3 = pixel->blue; break; default: throw new Exception("Konversi tidak terimplementasi"); } pd.Name = clr.Name; return(pd); }
//---------------------------------------------------- public bool MoveNext() { x++; pCurrentPixel++; if (x == fastBitmap.Size.X) { y++; if (y == fastBitmap.Size.Y) { return(false); } else { x = 0; pCurrentPixel = fastBitmap[0, y]; } } return(true); }
public bool MoveNext() { x++; pCurrentPixel++; if (x == fastBitmap.Size.X) { y++; if (y == fastBitmap.Size.Y) { return(false); } else { x = 0; pCurrentPixel = fastBitmap[0, y]; //Debug.WriteLine(String.Format("{0}", pCurrentPixel - fastBitmap[0, 0])); } } return(true); }
/// <summary> /// Return the next pixel /// </summary> /// <returns>The next pixel, or null if done</returns> public BGRA* GetNextPixel() { BGRA* pReturnPixel = pCurrentPixel; if (xLocation == size.X) { xLocation = 0; yLocation++; if (yLocation == size.Y) { UnlockBitmap(); return null; } else { pCurrentPixel = this[0, yLocation]; } } else { xLocation++; pCurrentPixel++; } return pReturnPixel; }
private static float Max(BGRA *pixel) { return(Max((float)pixel->red, (float)pixel->green, (float)pixel->blue)); }
public static PixelData RGBToHSV(BGRA *pixel) { return(RGBToHSV(pixel->red, pixel->green, pixel->blue)); }
public bool MoveNext() { x++; pCurrentPixel++; if (x == fastBitmap.Size.X) { y++; if (y == fastBitmap.Size.Y) { return false; } else { x = 0; pCurrentPixel = fastBitmap[0, y]; //Debug.WriteLine(String.Format("{0}", pCurrentPixel - fastBitmap[0, 0])); } } return true; }