public static void WriteImageToStream(Image source, Stream fs, PixelFormat pixelFormat) { for (var y = 0; y < source.Height; y += 8) { for (var x = 0; x < source.Width; x += 8) { EncodeTile(8, 8, 0, 0, source, fs, pixelFormat); } } }
private static void EncodeTile(int iconSize, int tileSize, int ax, int ay, Image bmp, Stream fs, PixelFormat pixelFormat) { if (tileSize == 0) { EncodeColor(bmp.GetPixel(ax, ay), pixelFormat, TempBytes); fs.Write(TempBytes, 0, PixelFormatBytes(pixelFormat)); } else { for (var y = 0; y < iconSize; y += tileSize) { for (var x = 0; x < iconSize; x += tileSize) { EncodeTile(tileSize, tileSize / 2, x + ax, y + ay, bmp, fs, pixelFormat); } } } }
private static void DecodeTile(int iconSize, int tileSize, int ax, int ay, Image bmp, Stream fs, PixelFormat pixelFormat) { if (tileSize == 0) { fs.Read(TempBytes, 0, 2); bmp.SetPixel(ax, ay, DecodeColor((TempBytes[1] << 8) + TempBytes[0], pixelFormat)); } else { for (var y = 0; y < iconSize; y += tileSize) { for (var x = 0; x < iconSize; x += tileSize) { DecodeTile(tileSize, tileSize / 2, x + ax, y + ay, bmp, fs, pixelFormat); } } } }
public static Image ReadImageFromStream(Stream fs, int width, int height, PixelFormat pixelFormat) { Image image = new Image { Width = width, Height = height, Comp = 4, Data = new byte[width * height * 4] }; for (var y = 0; y < height; y += 8) { for (var x = 0; x < width; x += 8) { DecodeTile(8, 8, x, y, image, fs, pixelFormat); } } return(image); }