/// <summary> /// Indexed alpha: grayscale indexed 255 color image with single color gradient /// Transparency is determined by index value /// </summary> /// <param name="image"></param> /// <returns></returns> private static Rgba32[] ConvertIndexedAlpha(IndexedColor256Image image) { var size = image.Size; var pixels = new Rgba32[size]; ref var color = ref image.Palette[IndexedAlphaColorIndex];
/// <summary> /// Convert an indexed 256 color image to an Rgba32 image /// </summary> /// <param name="image"></param> /// <returns></returns> private static Rgba32[] ConvertNormal(IndexedColor256Image image) { var size = image.Size; var pixels = new Rgba32[size]; foreach (var i in Enumerable.Range(0, size)) { image.Palette[image.Pixels[i]].ToRgba32(ref pixels[i]); } return(pixels); }
/// <summary> /// Alpha test: convert all indices to their color except index 255, which is converted as fully transparent /// </summary> /// <param name="image"></param> /// <returns></returns> private static Rgba32[] ConvertAlphaTest(IndexedColor256Image image) { var size = image.Size; var pixels = new Rgba32[size]; foreach (var i in Enumerable.Range(0, size)) { var index = image.Pixels[i]; if (index != AlphaTestTransparentIndex) { image.Palette[index].ToRgba32(ref pixels[i]); } else { //RGB values default to 0 in array initializer pixels[i].A = 0; } } return(pixels); }