private void Load256ColourPalettised(IwSerialise serialise) { this.data = new byte[this.height * this.pitch]; serialise.Serialise(ref this.data); this.palette = new Color[256]; for (int i = 0; i < this.palette.Length; ++i) { byte r = 0; byte g = 0; byte b = 0; serialise.UInt8(ref r); serialise.UInt8(ref g); serialise.UInt8(ref b); this.palette[i] = Color.FromArgb(r, g, b); } byte[] d = new byte[this.height * this.width * 3]; int j = 0; for (int y = 0; y < this.height; ++y) { for (int x = 0; x < this.width; ++x) { d[j] = this.palette[this.data[x + y * this.pitch]].R; ++j; d[j] = this.palette[this.data[x + y * this.pitch]].G; ++j; d[j] = this.palette[this.data[x + y * this.pitch]].B; ++j; } } this.data = d; ////using (var b = new Bitmap(width,height)) ////{ //// for (int i = 0; i < height;++i) //// for (int x = 0; x < width; ++x) //// { //// b.SetPixel(x,i,palette[data[x+i*pitch]]); //// } //// b.Save("res.bmp"); ////} }
/// <summary> /// The serialise. /// </summary> /// <param name="serialise"> /// The serialise. /// </param> /// <exception cref="FormatException"> /// </exception> public void Serialise(IwSerialise serialise) { serialise.UInt8(ref this.format); serialise.UInt16(ref this.flags); serialise.UInt16(ref this.width); serialise.UInt16(ref this.height); serialise.UInt16(ref this.pitch); uint palette = 0; serialise.UInt32(ref palette); IImageFormat format = null; switch (this.format) { case ABGR_8888: Debug.WriteLine(string.Format("Image ABGR_8888 {0}x{1}", this.width, this.height)); this.LoadUncompressed(serialise); return; case BGR_888: Debug.WriteLine(string.Format("Image BGR_888 {0}x{1}", this.width, this.height)); this.LoadUncompressed(serialise); return; case PALETTE4_ABGR_1555: format = (new Palette4Abgr1555(this.width, this.height, this.pitch)); Debug.WriteLine(string.Format("Image PALETTE4_ABGR_1555 {0}x{1}", this.width, this.height)); break; case PALETTE4_RGB_888: format = (new Palette4Rgb888(this.width, this.height, this.pitch)); Debug.WriteLine(string.Format("Image PALETTE4_RGB_888 {0}x{1}", this.width, this.height)); break; case PALETTE8_ABGR_1555: format = (new Palette8Abgr1555(this.width, this.height, this.pitch)); Debug.WriteLine(string.Format("Image PALETTE8_ABGR_1555 {0}x{1}", this.width, this.height)); break; case ABGR_1555: Debug.WriteLine(string.Format("Image ABGR_1555 {0}x{1}", this.width, this.height)); this.LoadABGR1555(serialise); return; case RGBA_6666: Debug.WriteLine(string.Format("Image RGBA_6666 {0}x{1}", this.width, this.height)); this.LoadRgba6666(serialise); return; case PALETTE8_RGB_888: Debug.WriteLine(string.Format("Image PALETTE8_RGB_888 {0}x{1}", this.width, this.height)); this.Load256ColourPalettised(serialise); return; default: throw new FormatException(string.Format(CultureInfo.CurrentCulture, "Unknown image format 0x{0:x}", this.format)); } data = new byte[width * height * 3]; format.OnPixel += SetPixelBySource; format.ReadData(serialise.Stream); }