/// <param name="componentSize">Component size</param> /// <param name="width">Image width</param> /// <param name="height">Image height</param> /// <param name="pixels"> /// Pixels are represented as a 2D array. The first dimension represents /// the component type size and the second dimension contains pixel data. /// Note that the first element of the second dimension (intensity value) /// is XY(0,0) which is bottom left of the image not top left. /// </param> public SFImage( SFImageComponentSize componentSize, int width, int height, byte[,] pixels) { this.UpdateImage(componentSize, width, height, pixels); }
public void UpdateImage( SFImageComponentSize componentSize, int width, int height, byte[,] pixels) { ValidateImage(componentSize, width, height, pixels); this.ComponentSize = componentSize; this.Width = width; this.Height = height; this.Pixels = pixels; }
private static void ValidateImage( SFImageComponentSize componentSize, int width, int height, byte[,] pixels) { if (componentSize == SFImageComponentSize.Unknown) { if (pixels != null) { // Validation 1. When component is unknown, pixel should // not have any elements in it. throw new ArgumentException(string.Format("Component type and pixel data are mismatched. Component Format = {0} and Pixel Format = {1}", (int)componentSize, pixels.GetLength(0))); } } else { if (pixels == null) { // Validation 2. When component is specified, pixel // should not be NULL. throw new ArgumentException(string.Format("Component type and pixel data are mismatched. Component Format = {0} and Pixel Format = NULL", (int)componentSize)); } if ((int)componentSize != pixels.GetLength(0)) { // Validation 3. When component is known, component // size and 1D size must be matched. throw new ArgumentException(string.Format("Component type and pixel data are mismatched. Component Format = {0} and Pixel Format = {1}", (int)componentSize, pixels.GetLength(0))); } if (width * height != pixels.GetLength(1)) { // Validation 4. When component is known, // width x height and 2D size must be matched. throw new ArgumentException(string.Format("Image size and pixel data size are mismatched. Component Format = {0} and Pixel Format = {1}", (int)componentSize, pixels.GetLength(0))); } } }
private static SFImage GenerateTestImage(SFImageComponentSize size) { if (size == SFImageComponentSize.Unknown) { return(new SFImage()); } const int width = 100; const int height = 100; var components = (int)size; var pixels = new byte[components, (width * height)]; for (var component = 0; component < components; component++) { for (var pos = 0; pos < (width * height); pos++) { pixels[component, pos] = (byte)(pos % 255); } } return(new SFImage(size, width, height, pixels)); }