/// <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--;
}
if (_bitmapFormat == 3)
{
_colorMapData = new ColorMapData();
_colorMapData.ReadData(binaryReader, _bitmapColorTableSize, _bitmapWidth, _bitmapHeight, toReaded);
}
else if (_bitmapFormat == 4 || _bitmapFormat == 5)
{
int imageSize = _bitmapWidth * _bitmapHeight;
int uncompressedSize = imageSize;
if (_bitmapFormat == 4)
uncompressedSize *= 2;
else
uncompressedSize *= 4;
byte[] uncompressed = new byte[uncompressedSize];
byte[] compressed = binaryReader.ReadBytes(toReaded);
Inflater zipInflator = new Inflater();
zipInflator.SetInput(compressed);
zipInflator.Inflate(uncompressed, 0, uncompressedSize);
_bitmapColorData = null;
if (_bitmapFormat == 4)
{
Pix15[] bitmapPixelData = new Pix15[imageSize];
for (int i = 0, j = 0; i < imageSize; i++, j += 2)
{
byte[] data = new byte[2] {uncompressed[j], uncompressed[j+1]};
bitmapPixelData[i] = new Pix15(data);
}
_bitmapColorData = new BitmapColorData(bitmapPixelData);
}
else
{
Pix24[] bitmapPixelData = new Pix24[imageSize];
for (int i = 0, j = 0; i < imageSize; i++, j += 4)
{
byte reserved = uncompressed[j];
byte red = uncompressed[j + 1];
byte green = uncompressed[j + 2];
byte blue = uncompressed[j + 3];
bitmapPixelData[i] = new Pix24(red, green, blue);
}
_bitmapColorData = new BitmapColorData(bitmapPixelData);
}
}
}