/// <summary> /// Samples the avg RGB values of the entire image /// </summary> /// <param name="source"></param> /// <returns></returns> public static LatencyTesterVM.RGBVal Sample3Channels(BitmapSource source) { PixelFormat format = source.Format; LatencyTesterVM.RGBVal result = default(LatencyTesterVM.RGBVal); // = new LatencyTesterVM.RGBVal(); LatencyTesterVM.RGBVal sum = default(LatencyTesterVM.RGBVal); // = new LatencyTesterVM.RGBVal(); int count = 0; int width = (int)source.Width; int height = (int)source.Height; int size = width * height; byte[] pixels = new byte[size]; for (int i = 0; i < size; i += 2) { sum.R += pixels[i]; sum.G += pixels[i]; sum.B += pixels[i]; count++; } //TODO Stop assuming RGB format result.R = sum.R / count; result.G = sum.G / count; result.B = sum.B / count; return(result); }
public static LatencyTesterVM.RGBVal Sample3Channels( byte[] image, int width, int height) { LatencyTesterVM.RGBVal result = new LatencyTesterVM.RGBVal(); LatencyTesterVM.RGBVal sum = new LatencyTesterVM.RGBVal(); int count= 0; int size = width * height; for (int i = 0; i < size / 2; i += 3) { sum.R += image[i+2]; // sum.G += (byte) image[i+1]; // sum.B += image[i]; count++; } //TODO Stop assuming RGB format result.R = sum.R / count; // result.G = sum.G / count; // result.B = sum.B / count; return result; }
public static LatencyTesterVM.RGBVal Sample3Channels(byte[] image, int width, int height) { LatencyTesterVM.RGBVal result = new LatencyTesterVM.RGBVal(); LatencyTesterVM.RGBVal sum = new LatencyTesterVM.RGBVal(); int count = 0; int size = width * height; for (int i = 0; i < size / 2; i += 3) { sum.R += image[i + 2]; // sum.G += (byte) image[i+1]; // sum.B += image[i]; count++; } //TODO Stop assuming RGB format result.R = sum.R / count; // result.G = sum.G / count; // result.B = sum.B / count; return(result); }