public static void Blit(IndexedTexture Source, Palette SourcePalette, MemoryTexture Destination) { if (Source == null || SourcePalette == null || Destination == null) { return; } var width = Math.Min(Source.Width, Destination.Width); var height = Math.Min(Source.Height, Destination.Height); for (var y = 0; y < height; ++y) { var sourceIndex = Source.Index(0, y); var destinationIndex = Destination.Index(0, y); var endSourceIndex = sourceIndex + width; while (sourceIndex < endSourceIndex) { var sourcePixel = SourcePalette[Source.Data[sourceIndex]]; if (sourcePixel.A != 0) { Destination.Data[destinationIndex] = sourcePixel; } sourceIndex += 1; destinationIndex += 1; } } }
public static MemoryTexture ComposeTexture(IndexedTexture Source, Palette Palette) { var r = new MemoryTexture(Source.Width, Source.Height); for (var i = 0; i < Source.Data.Length; ++i) { r.Data[i] = Palette[Source.Data[i]]; } return(r); }
public static IndexedTexture DecomposeTexture(MemoryTexture Source, Palette Palette) { var r = new IndexedTexture(Source.Width, Source.Height); for (var i = 0; i < Source.Data.Length; ++i) { var index = Palette.IndexOf(Source.Data[i]); if (index >= 0) { r.Data[i] = (byte)index; } else { r.Data[i] = 0; } } return(r); }