/// <summary> /// Creates a new <see cref="DefineBitsLossLess2Tag"/> instance. /// </summary> /// <param name="characterId">id for this character</param> /// <param name="bitmapFormat">Format of compressed data</param> /// <param name="bitmapWidth">Width of bitmap image</param> /// <param name="bitmapHeight">Height of bitmap image</param> /// <param name="bitmapColorTableSize">actual number of colors in the color table</param> /// <param name="zlibBitmapData">zlib compressed bitmap data</param> public DefineBitsLossLess2Tag(ushort characterId, byte bitmapFormat, ushort bitmapWidth, ushort bitmapHeight, ushort bitmapColorTableSize, AlphaBitmapData zlibBitmapData) { _characterId = characterId; _bitmapFormat = bitmapFormat; _bitmapWidth = bitmapWidth; _bitmapHeight = bitmapHeight; _bitmapColorTableSize = bitmapColorTableSize; _alphaBitmapData = zlibBitmapData; _tagCode = (int)TagCodeEnum.DefineBitsLossLess2; }
/// <summary> /// Decompiles to stream. /// </summary> /// <param name="stream">Stream.</param> private void DecompileToStream(Stream stream) { if (BitmapFormat == 3) { //AlphaColorMapData AlphaColorMapData mapData = AlphaColorMapData; Bitmap bmp = new Bitmap((int)BitmapWidth, (int)BitmapHeight); int k = 0; for (int i = 0; i < (int)BitmapHeight; i++) { for (int j = 0; j < (int)BitmapWidth; j++) { int index = (int)mapData.ColorMapPixelData[k]; if (index >= 0 && index < mapData.ColorTableRgb.Length) { bmp.SetPixel(j, i, mapData.ColorTableRgb[index].ToWinColor()); } else { bmp.SetPixel(j, i, Color.Black); } k++; } } bmp.Save(stream, ImageFormat.Bmp); } else { //AlphaBitmapData AlphaBitmapData bitmapData = AlphaBitmapData; RGBA[] data = data = bitmapData.BitmapPixelData; Bitmap bmp = new Bitmap((int)BitmapWidth, (int)BitmapHeight); int k = 0; for (int i = 0; i < (int)BitmapHeight; i++) { for (int j = 0; j < (int)BitmapWidth; j++) { if (k < data.Length) { bmp.SetPixel(j, i, data[k].ToWinColor()); } else { bmp.SetPixel(j, i, Color.Black); } k++; } } bmp.Save(stream, ImageFormat.Bmp); } }
/// <summary> /// see <see cref="SwfDotNet.IO.Tags.BaseTag">base class</see> /// </summary> public override void ReadData(byte version, BufferedBinaryReader binaryReader) { RecordHeader rh = new RecordHeader(); rh.ReadData(binaryReader); int beforePos = (int)binaryReader.BaseStream.Position; int toReaded = (int)rh.TagLength - 7; _characterId = binaryReader.ReadUInt16(); _bitmapFormat = binaryReader.ReadByte(); _bitmapWidth = binaryReader.ReadUInt16(); _bitmapHeight = binaryReader.ReadUInt16(); _bitmapColorTableSize = 0; if (_bitmapFormat == 3) { _bitmapColorTableSize = binaryReader.ReadByte(); toReaded--; } int imageSize = _bitmapWidth * _bitmapHeight; if (_bitmapFormat == 3) { int uncompressedSize = imageSize + ((_bitmapColorTableSize + 1) * 4); byte[] uncompressed = new byte[uncompressedSize]; byte[] compressed = binaryReader.ReadBytes(toReaded); uncompressed = DeflatorWraper.Decompress(compressed); _alphaColorMapData = new AlphaColorMapData(); _alphaColorMapData.ColorTableRgb = new RGBA[_bitmapColorTableSize + 1]; int offset = 0; for (int i = 0; i < _bitmapColorTableSize + 1; i++, offset += 4) { byte red = uncompressed[offset]; byte green = uncompressed[offset + 1]; byte blue = uncompressed[offset + 2]; byte alpha = uncompressed[offset + 3]; _alphaColorMapData.ColorTableRgb[i] = new RGBA(red, green, blue, alpha); } _alphaColorMapData.ColorMapPixelData = new byte[uncompressedSize - offset]; for (int i = 0; i < uncompressedSize - offset; i++, offset++) { _alphaColorMapData.ColorMapPixelData[i] = uncompressed[offset]; } } else if (_bitmapFormat == 4 || _bitmapFormat == 5) { int uncompressedSize = imageSize * 4; byte[] uncompressed = new byte[uncompressedSize]; byte[] compressed = binaryReader.ReadBytes(toReaded); uncompressed = DeflatorWraper.Decompress(compressed); _alphaBitmapData = new AlphaBitmapData(); _alphaBitmapData.BitmapPixelData = new RGBA[imageSize]; for (int i = 0, j = 0; i < imageSize; i++, j += 4) { byte red = uncompressed[j]; byte green = uncompressed[j + 1]; byte blue = uncompressed[j + 2]; byte alpha = uncompressed[j + 3]; _alphaBitmapData.BitmapPixelData[i] = new RGBA(red, green, blue, alpha); } } }