/// <summary> /// Sets the value. /// </summary> /// <param name="container">The container.</param> public void SetValue(ImageContainer container) { this.Value = container; }
/// <summary> /// Converts a RGB image into grayscale 8 bit. /// </summary> /// <returns></returns> public override bool Run() { ImageContainer inputContainer = (ImageContainer)_inputImage.Value; byte[] data = inputContainer.Data; byte bpp = inputContainer.BytesPerPixel; int width = inputContainer.Width; int height = inputContainer.Height; byte[] destination = new byte[width * height]; if (bpp == 1) { _outputImage.Value = _inputImage.Value; return true; } unsafe { fixed (byte* ptr = data) { fixed (byte* destPtr = destination) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { byte r = ptr[(y * width + x) * bpp]; byte g = ptr[(y * width + x) * bpp + 1]; byte b = ptr[(y * width + x) * bpp + 2]; destPtr[(y * width + x)] = (byte)((r + g + b) / 3); } } } } } ImageContainer outContainer = new ImageContainer(); outContainer.Data = destination; outContainer.BytesPerPixel = 1; outContainer.Height = height; outContainer.Width = width; outContainer.Stride = width; _outputImage.Value = outContainer; return true; }
/// <summary> /// Sets the value. /// </summary> /// <param name="data">The data.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="bytesPerPixel">The bytes per pixel.</param> public void SetValue(byte[] data, int width, int height, int stride, byte bytesPerPixel) { ImageContainer container = new ImageContainer(); container.Data = data; container.Width = width; container.Height = height; container.Stride = stride; container.BytesPerPixel = bytesPerPixel; this.Value = container; }