public JPEGTables(SwfReader r, uint curTagLen) { if (curTagLen > 8) { r.GetBytes(2); //jpg SOI Marker JpegTable = r.GetBytes(curTagLen - 4); r.GetBytes(2); //jpg EOI Marker } else { JpegTable = new byte[0]; } }
public JPEGTables(SwfReader r, uint curTagLen) { if(curTagLen > 8) { r.GetBytes(2); //jpg SOI Marker JpegTable = r.GetBytes(curTagLen - 4); r.GetBytes(2); //jpg EOI Marker } else { JpegTable = new byte[0]; } }
public DefineSoundTag(SwfReader r, uint tagLen) { SoundId = r.GetUI16(); SoundFormat = (SoundCompressionType)r.GetBits(4); uint sr = r.GetBits(2); switch (sr) { case 0: SoundRate = 5512; // ? break; case 1: SoundRate = 11025; break; case 2: SoundRate = 22050; break; case 3: SoundRate = 44100; break; } SoundSize = r.GetBit() ? 16U : 8U; IsStereo = r.GetBit(); r.Align(); SoundSampleCount = r.GetUI32(); // todo: this needs to decompress if mp3 etc SoundData = r.GetBytes(tagLen - 7); }
public DefineSoundTag(SwfReader r, uint tagLen) { SoundId = r.GetUI16(); SoundFormat = (SoundCompressionType)r.GetBits(4); uint sr = r.GetBits(2); switch (sr) { case 0: SoundRate = 5512; // ? break; case 1: SoundRate = 11025; break; case 2: SoundRate = 22050; break; case 3: SoundRate = 44100; break; } SoundSize = r.GetBit() ? 16U : 8U; IsStereo = r.GetBit(); r.Align(); SoundSampleCount = r.GetUI32(); // todo: this needs to decompress if mp3 etc SoundData = r.GetBytes(tagLen - 7); }
public SoundStreamBlockTag(SwfReader r, uint tagLen) { SampleCount = r.GetUI16(); SoundData = r.GetBytes(tagLen - 2); // assume mp3 for now //SoundData = new Mp3SoundData[SampleCount]; //for (int i = 0; i < SampleCount; i++) //{ // SoundData[i] = new Mp3SoundData(r); //} }
public SoundStreamBlockTag(SwfReader r, uint tagLen) { SampleCount = r.GetUI16(); SoundData = r.GetBytes(tagLen - 2); // assume mp3 for now //SoundData = new Mp3SoundData[SampleCount]; //for (int i = 0; i < SampleCount; i++) //{ // SoundData[i] = new Mp3SoundData(r); //} }
// this needs to combine with the jpegTables in the swfCompilationUnit to make an image public DefineBitsTag(SwfReader r, uint curTagLen, bool hasOwnTable, bool hasAlphaData) { this.HasOwnTable = hasOwnTable; this.HasAlphaData = hasAlphaData; if (hasOwnTable && !hasAlphaData) { tagType = TagType.DefineBitsJPEG2; } else if (hasOwnTable && hasAlphaData) { tagType = TagType.DefineBitsJPEG3; } CharacterId = r.GetUI16(); if (!hasAlphaData) { if (!hasOwnTable) { r.GetBytes(2); // SOI JpegData = r.GetBytes(curTagLen - 6); r.GetBytes(2); // EOI } else { JpegData = r.GetBytes(curTagLen - 2); CleanData(); } } else { uint jpgDataSize = r.GetUI32(); JpegData = r.GetBytes(jpgDataSize); // ignore alpha for now CompressedAlphaData = r.GetBytes(curTagLen - 6 - jpgDataSize); CleanData(); } }
// this needs to combine with the jpegTables in the swfCompilationUnit to make an image public DefineBitsTag(SwfReader r, uint curTagLen, bool hasOwnTable, bool hasAlphaData) { this.HasOwnTable = hasOwnTable; this.HasAlphaData = hasAlphaData; if (hasOwnTable && !hasAlphaData) { tagType = TagType.DefineBitsJPEG2; } else if(hasOwnTable && hasAlphaData) { tagType = TagType.DefineBitsJPEG3; } CharacterId = r.GetUI16(); if (!hasAlphaData) { if(!hasOwnTable) { r.GetBytes(2); // SOI JpegData = r.GetBytes(curTagLen - 6); r.GetBytes(2); // EOI } else { JpegData = r.GetBytes(curTagLen - 2); CleanData(); } } else { uint jpgDataSize = r.GetUI32(); JpegData = r.GetBytes(jpgDataSize); // ignore alpha for now CompressedAlphaData = r.GetBytes(curTagLen - 6 - jpgDataSize); CleanData(); } }
public DefineBitsLosslessTag(SwfReader r, uint curTagLen, bool hasAlpha) { HasAlpha = hasAlpha; if (hasAlpha) { tagType = TagType.DefineBitsLossless2; } CharacterId = r.GetUI16(); BitmapFormat = (BitmapFormat)r.GetByte(); this.Width = r.GetUI16(); this.Height = r.GetUI16(); if (BitmapFormat == BitmapFormat.Colormapped8Bit) // 8-bit colormapped image { this.ColorCount = (uint)r.GetByte() + 1; this.isIndexedColors = true; uint colorBytes = hasAlpha ? (uint)4 : (uint)3; uint padWidth = this.Width + (4 - (this.Width % 4)); // temp for debugging uint pos = r.Position; OrgBitmapData = r.GetBytes(curTagLen - 8); r.Position = pos; // end temp uint unzippedSize = (this.ColorCount * colorBytes) + (padWidth * this.Height); byte[] mapData = r.Decompress(curTagLen - 8, unzippedSize); uint index = 0; this.ColorTable = new RGBA[this.ColorCount]; for (int i = 0; i < this.ColorCount; i++) { if (hasAlpha) { this.ColorTable[i] = new RGBA(mapData[index], mapData[index + 1], mapData[index + 2], mapData[index + 3]); } else { this.ColorTable[i] = new RGBA(mapData[index], mapData[index + 1], mapData[index + 2]); } index += colorBytes; } this.ColorData = new uint[this.Width * this.Height]; index = 0; int offset = (int)(this.ColorCount * colorBytes); for (int i = 0; i < padWidth * this.Height; i++) { if ((i % padWidth) < this.Width)// exclude padding { this.ColorData[index++] = mapData[i + offset]; } } } else if (BitmapFormat == BitmapFormat.RGB15Bit) // RGBx555 { // todo: find a test file for rgb555 uint colorBytes = 2; uint padWidth = this.Width * colorBytes; padWidth += (4 - padWidth) % 4; // temp for debugging uint pos = r.Position; OrgBitmapData = r.GetBytes(curTagLen - 7); r.Position = pos; // end temp uint unzippedSize = (padWidth * this.Height) * colorBytes; byte[] mapData = r.Decompress(curTagLen - 7, unzippedSize); int index = 0; this.BitmapData = new RGBA[this.Width * this.Height]; for (uint i = 0; i < unzippedSize; i += colorBytes) { if ((i % padWidth) < (this.Width * colorBytes)) // exclude padding { byte b0 = mapData[i]; byte b1 = mapData[i + 1]; byte rd = (byte)((b0 & 0x7C) << 1); byte gr = (byte)(((b0 & 0x03) << 6) | ((b1 & 0xE0) >> 2)); byte bl = (byte)((b1 & 0x1F) << 3); this.BitmapData[index++] = new RGBA(rd, gr, bl); } } } else if (BitmapFormat == BitmapFormat.RGB24Bit) // RGB 24 { // temp for debugging uint pos = r.Position; OrgBitmapData = r.GetBytes(curTagLen - 7); r.Position = pos; // end temp uint colorBytes = 4; // 4 bytes will always be byte aligned uint unzippedSize = (this.Width * this.Height) * colorBytes; byte[] mapData = r.Decompress(curTagLen - 7, unzippedSize); int index = 0; this.BitmapData = new RGBA[this.Width * this.Height]; for (uint i = 0; i < unzippedSize; i += colorBytes) { if (hasAlpha) { this.BitmapData[index++] = new RGBA(mapData[i + 1], mapData[i + 2], mapData[i + 3], mapData[i]); } else { this.BitmapData[index++] = new RGBA(mapData[i + 1], mapData[i + 2], mapData[i + 3]); } } } }
public DefineBitsLosslessTag(SwfReader r, uint curTagLen, bool hasAlpha) { HasAlpha = hasAlpha; if (hasAlpha) { tagType = TagType.DefineBitsLossless2; } CharacterId = r.GetUI16(); BitmapFormat = (BitmapFormat)r.GetByte(); this.Width = r.GetUI16(); this.Height = r.GetUI16(); if (BitmapFormat == BitmapFormat.Colormapped8Bit) // 8-bit colormapped image { this.ColorCount = (uint)r.GetByte() + 1; this.isIndexedColors = true; uint colorBytes = hasAlpha ? (uint)4 : (uint)3; uint padWidth = this.Width + (4 - (this.Width % 4)); // temp for debugging uint pos = r.Position; OrgBitmapData = r.GetBytes(curTagLen - 8); r.Position = pos; // end temp uint unzippedSize = (this.ColorCount * colorBytes) + (padWidth * this.Height); byte[] mapData = r.Decompress(curTagLen - 8, unzippedSize); uint index = 0; this.ColorTable = new RGBA[this.ColorCount]; for (int i = 0; i < this.ColorCount; i++) { if (hasAlpha) { this.ColorTable[i] = new RGBA(mapData[index], mapData[index + 1], mapData[index + 2], mapData[index + 3]); } else { this.ColorTable[i] = new RGBA(mapData[index], mapData[index + 1], mapData[index + 2]); } index += colorBytes; } this.ColorData = new uint[this.Width * this.Height]; index = 0; int offset = (int)(this.ColorCount * colorBytes); for (int i = 0; i < padWidth * this.Height; i++) { if ((i % padWidth) < this.Width) // exclude padding { this.ColorData[index++] = mapData[i + offset]; } } } else if (BitmapFormat == BitmapFormat.RGB15Bit) // RGBx555 { // todo: find a test file for rgb555 uint colorBytes = 2; uint padWidth = this.Width * colorBytes; padWidth += (4 - padWidth) % 4; // temp for debugging uint pos = r.Position; OrgBitmapData = r.GetBytes(curTagLen - 7); r.Position = pos; // end temp uint unzippedSize = (padWidth * this.Height) * colorBytes; byte[] mapData = r.Decompress(curTagLen - 7, unzippedSize); int index = 0; this.BitmapData = new RGBA[this.Width * this.Height]; for (uint i = 0; i < unzippedSize; i += colorBytes) { if ((i % padWidth) < (this.Width * colorBytes)) // exclude padding { byte b0 = mapData[i]; byte b1 = mapData[i + 1]; byte rd = (byte)((b0 & 0x7C) << 1); byte gr = (byte)(((b0 & 0x03) << 6) | ((b1 & 0xE0) >> 2)); byte bl = (byte)((b1 & 0x1F) << 3); this.BitmapData[index++] = new RGBA(rd, gr, bl); } } } else if (BitmapFormat == BitmapFormat.RGB24Bit) // RGB 24 { // temp for debugging uint pos = r.Position; OrgBitmapData = r.GetBytes(curTagLen - 7); r.Position = pos; // end temp uint colorBytes = 4; // 4 bytes will always be byte aligned uint unzippedSize = (this.Width * this.Height) * colorBytes; byte[] mapData = r.Decompress(curTagLen - 7, unzippedSize); int index = 0; this.BitmapData = new RGBA[this.Width * this.Height]; for (uint i = 0; i < unzippedSize; i += colorBytes) { if (hasAlpha) { this.BitmapData[index++] = new RGBA(mapData[i + 1], mapData[i + 2], mapData[i + 3], mapData[i]); } else { this.BitmapData[index++] = new RGBA(mapData[i + 1], mapData[i + 2], mapData[i + 3]); } } } }