public double[] SaturateNormalizedPixels(double[] inputNormalizedPixels, ColorVector saturator1, ColorVector saturator2) { //For each slot in normalizedPixels (section off blocks of 4 at a time in this case). double[] outputNormalizedPixels = new double[inputNormalizedPixels.Length]; for (int n = 0; n < outputNormalizedPixels.Length; n += 4) { //Make a temporary ColorVector for that slot ([n, n + 3]) ColorVector inputCurrentPixel = new ColorVector( inputNormalizedPixels[n], inputNormalizedPixels[n + 1], inputNormalizedPixels[n + 2], inputNormalizedPixels[n + 3], 1 ); double dot1 = inputCurrentPixel.Dot(saturator1); //Dot that temporary ColorVector against saturator1. double dot2 = inputCurrentPixel.Dot(saturator2); //Dot that temporary ColorVector against saturator2. //Compare these two dot products. Array.Copy(dot1 > dot2 ? saturator1.ToArray() : saturator2.ToArray(), 0, outputNormalizedPixels, n, 4); } return(outputNormalizedPixels); }
public Bitmap SaturateBitmap(MemoryStream outputBitmapMemoryStream, Bitmap inputBitmap64, ColorVector cv1, ColorVector cv2) { inputBitmap64.Save(outputBitmapMemoryStream, ImageFormat.Bmp); //Initialize primitives. byte[] currentPixelBytes = new byte[8]; ColorVector cv = new ColorVector(); byte[] cvBytesToCopy = new byte[8]; //Starting at HeaderOffset in inputBitmapMemoryStream. outputBitmapMemoryStream.Position = BitmapHeaderLength; for (long n = outputBitmapMemoryStream.Position; n < outputBitmapMemoryStream.Length; n += 8) { //Grab 8 bytes. //Convert them to a ColorVector. outputBitmapMemoryStream.Read(currentPixelBytes, 0, currentPixelBytes.Length); cv = new ColorVector(currentPixelBytes); //Dot that ColorVector with cv1 and cv2. //For whichever of cv1 and cv2 that has the bigger dot product, //Turn that ColorVector into a byte[8]. cvBytesToCopy = (cv1.Dot(cv) > cv2.Dot(cv)) ? cv1.ToByteArray() : cv2.ToByteArray(); //Transplant that byte[8] where the original 8 bytes were. outputBitmapMemoryStream.Position -= 8; outputBitmapMemoryStream.Write(cvBytesToCopy, 0, cvBytesToCopy.Length); } return(new Bitmap(outputBitmapMemoryStream)); }