private void LoadPaletteABGR1555(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) { ushort r = 0; serialise.UInt16(ref r); this.palette[i] = Color.FromArgb( (byte)(((r >> 10) & 0x1F) << 3), (byte)(((r >> 5) & 0x1F) << 3), (byte)(((r >> 0) & 0x1F) << 3)); } 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; }
private void LoadRgba6666(IwSerialise serialise) { uint[] d = new uint[this.width * this.height]; for (int i = 0; i < d.Length; ++i) { serialise.UInt24(ref d[i]); } this.data = new byte[this.height * this.pitch * 3]; }
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"); ////} }
private void LoadABGR1555(IwSerialise serialise) { var d = new ushort[this.height * this.pitch / 2]; serialise.Serialise(ref d); this.data = new byte[this.width * this.height * 3]; int dst = 0, src = 0; for (int y = 0; y < this.height; ++y) { for (int x = 0; x < this.width; ++x) { var r = d[src]; ++src; this.data[dst] = (byte)(((r >> 0) & 0x1F) << 3); ++dst; this.data[dst] = (byte)(((r >> 5) & 0x1F) << 3); ++dst; this.data[dst] = (byte)(((r >> 10) & 0x1F) << 3); ++dst; } } }
/// <summary> /// Initializes a new instance of the <see cref="IwSerialiseBinaryBlock"/> class. /// </summary> /// <param name="serialise"> /// The serialise. /// </param> public IwSerialiseBinaryBlock(IwSerialise serialise) { this.serialise = serialise; }
/// <summary> /// Initializes a new instance of the <see cref="BinaryBlockEventArgs"/> class. /// </summary> /// <param name="hash"> /// The hash. /// </param> /// <param name="iwSerialise"> /// The iw serialise. /// </param> /// <param name="len"> /// The len. /// </param> public BinaryBlockEventArgs(uint hash, IwSerialise iwSerialise, uint len) { this.hash = hash; this.iwSerialise = iwSerialise; this.len = len; }
/// <summary> /// The serialise. /// </summary> /// <param name="serialise"> /// The serialise. /// </param> public virtual void Serialise(IwSerialise serialise) { serialise.UInt32(ref this.hash); }
private void LoadUncompressed(IwSerialise serialise) { this.data = new byte[this.height * this.pitch]; serialise.Serialise(ref this.data); }
/// <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); }
/// <summary> /// The serialise. /// </summary> /// <param name="serialise"> /// The serialise. /// </param> public override void Serialise(IwSerialise serialise) { base.Serialise(serialise); }