private unsafe static void BitmapToRGBColorMatrix(Bitmap img, ref RGBColor[,] textureMatrix) { using (img) { BitmapData imgData = img.LockBits(new Rectangle(0, 0, img.Width, img.Height), ImageLockMode.ReadOnly, img.PixelFormat); byte bitsPerPixel = GetBitsPerPixel(imgData.PixelFormat); byte *scan0 = (byte *)imgData.Scan0.ToPointer(); for (int x = 0; x < imgData.Height; ++x) { for (int y = 0; y < imgData.Width; ++y) { byte *data = scan0 + x * imgData.Stride + y * bitsPerPixel / 8; textureMatrix[y, x] = new RGBColor(data[2], data[1], data[0]); textureMatrix[y, x].Normalize(); } } img.UnlockBits(imgData); } }
public RGBColor GetPixel(float x, float y) { int pixelX1 = (int)Math.Floor(x); int pixelX2 = (int)Math.Ceiling(x); float xLerp = x - (float)Math.Truncate(x); int pixelY1 = (int)Math.Floor(y); int pixelY2 = (int)Math.Ceiling(y); float yLerp = y - (float)Math.Truncate(y); RGBColor c11 = GetPixel(pixelX1, pixelY1); RGBColor c12 = GetPixel(pixelX1, pixelY2); RGBColor c21 = GetPixel(pixelX2, pixelY1); RGBColor c22 = GetPixel(pixelX2, pixelY2); return(c11 * (1 - xLerp) * (1 - yLerp) + c12 * (1 - xLerp) * yLerp + c21 * xLerp * (1 - yLerp) + c22 * xLerp * yLerp); }
public static HSBColor FromColor(RGBColor rgbColor) { return(FromColor(rgbColor.ToColor())); }
public static RGBColor ToRGBColor(HSBColor hsbColor) { return(RGBColor.FromColor(ToColor(hsbColor))); }