/// <summary> /// Convert an image to grayscale. /// </summary> /// <param name="src">The image buffer (RGBA pixels).</param> /// <param name="srcPos">Initial position on the source buffer.</param> /// <param name="width">The width of the image.</param> /// <param name="height">The height of the image.</param> /// <param name="stride">The distance, in bytes, between rows of the image buffer.</param> static void GrayscaleImage(byte[] src, int srcPos, int width, int height, int stride) { int pos = srcPos; for (int y = 0; y < height; y++, pos += stride - width * 4) { for (int x = 0; x < width; x++, pos += 4) { ColorRGBA srcColor = ColorRGBA.Read(src, pos); ColorRGBA grayscaleColor = ColorRGBA.FromIntensityAlpha(srcColor.Intensity(), srcColor.Alpha); grayscaleColor.Write(src, pos); } } }
public static byte ColorToIA4(ColorRGBA c) { return((byte)(Bits8To4[c.Intensity()] | (Bits8To4[c.Alpha] << 4))); }
public static byte ColorToI8(ColorRGBA c) { return(c.Intensity()); }
public static byte ColorToI4(ColorRGBA c) { return(Bits8To4[c.Intensity()]); }