private void ReadFromBitmap(Bitmap bmp) { using Bitmap tmp = new(bmp); using Bitmap copy = tmp.Clone(new Rectangle(0, 0, tmp.Width, tmp.Height), PixelFormat.Format32bppArgb); BitmapLocker lck = copy; Scalar factor = new Scalar(255d).Inverse; lck.LockPixels((px, w, h) => { for (int i = 0, l = w * h; i < l; ++i) { _coefficients[i] = new Vector4( px[i * 4 + 2], // r px[i * 4 + 1], // g px[i * 4 + 0], // b px[i * 4 + 3] // a ) * factor; } }); }
public Bitmap ToBitmap() { Bitmap bmp = new(Width, Height, PixelFormat.Format32bppArgb); BitmapLocker lck = bmp; Scalar factor = 255; lck.LockPixels((px, w, h) => { for (int i = 0, l = w * h; i < l; ++i) { Vector4 col = _coefficients[i].Value; px[i * 4 + 2] = (byte)col.X.Clamp().Multiply(factor); // r px[i * 4 + 1] = (byte)col.Y.Clamp().Multiply(factor); // g px[i * 4 + 0] = (byte)col.Z.Clamp().Multiply(factor); // b px[i * 4 + 3] = (byte)col.W.Clamp().Multiply(factor); // a } }); return(bmp); }