internal override void ToSwf(SwfWriter w) { uint start = (uint)w.Position; w.AppendTagIDAndLength(this.TagType, 0, true); w.AppendUI16(CharacterId); if (!HasAlphaData) { if (!HasOwnTable) { w.AppendByte(0xFF); w.AppendByte(0xD8); w.AppendBytes(JpegData); w.AppendByte(0xFF); w.AppendByte(0xD9); } else { w.AppendBytes(JpegData); } } else { w.AppendUI32((uint)JpegData.Length); w.AppendBytes(JpegData); w.AppendBytes(CompressedAlphaData); } w.ResetLongTagLength(this.TagType, start, true); }
internal override void ToSwf(SwfWriter w) { uint start = (uint)w.Position; w.AppendTagIDAndLength(this.TagType, 0, true); w.AppendUI16(SampleCount); w.AppendBytes(SoundData); w.ResetLongTagLength(this.TagType, start); }
internal override void ToSwf(SwfWriter w) { uint start = (uint)w.Position; w.AppendTagIDAndLength(this.TagType, 0, true); if (JpegTable.Length > 0) { w.AppendByte(0xFF); w.AppendByte(0xD8); w.AppendBytes(JpegTable); w.AppendByte(0xFF); w.AppendByte(0xD9); } w.ResetLongTagLength(this.TagType, start, true); }
internal override void ToSwf(SwfWriter w) { uint start = (uint)w.Position; w.AppendTagIDAndLength(this.TagType, 0, true); w.AppendUI16(SoundId); w.AppendBits((uint)SoundFormat, 4); switch (SoundRate) { case 5512: w.AppendBits(0, 2); break; case 11025: w.AppendBits(1, 2); break; case 22050: w.AppendBits(2, 2); break; case 44100: w.AppendBits(3, 2); break; } w.AppendBit(SoundSize == 16U); w.AppendBit(IsStereo); w.Align(); w.AppendUI32(SoundSampleCount); w.AppendBytes(SoundData); w.ResetLongTagLength(this.TagType, start); }
internal override void ToSwf(SwfWriter w) { uint start = (uint)w.Position; w.AppendTagIDAndLength(this.TagType, 0, true); w.AppendUI16(CharacterId); w.AppendByte((byte)BitmapFormat); w.AppendUI16(Width); w.AppendUI16(Height); if (BitmapFormat == BitmapFormat.Colormapped8Bit) // 8-bit colormapped image { w.AppendByte((byte)(ColorCount - 1)); uint colorBytes = HasAlpha ? (uint)4 : (uint)3; uint padWidth = this.Width + (4 - (this.Width % 4)); uint unzippedSize = (this.ColorCount * colorBytes) + (padWidth * this.Height); byte[] mapData = new byte[unzippedSize]; for (int i = 0; i < this.ColorCount; i++) { mapData[i * colorBytes + 0] = ColorTable[i].R; mapData[i * colorBytes + 1] = ColorTable[i].G; mapData[i * colorBytes + 2] = ColorTable[i].B; if (HasAlpha) { mapData[i * colorBytes + 3] = ColorTable[i].A; } } int index = 0; int st = (int)(this.ColorCount * colorBytes); for (int i = st; i < unzippedSize; i++) { if (((i - st) % padWidth) < this.Width)// exclude padding { mapData[i] = (byte)this.ColorData[index++]; } else { mapData[i] = 0; } } byte[] zipped = ByteReader.Compress(mapData); if (OrgBitmapData != null) { w.AppendBytes(OrgBitmapData); } else { w.AppendBytes(zipped); } } else if (BitmapFormat == BitmapFormat.RGB15Bit) // rbg 15 { // todo: find a test file for rgb555 uint colorBytes = 2; uint padWidth = this.Width * colorBytes; padWidth += (4 - padWidth) % 4; uint unzippedSize = (padWidth * this.Height) * colorBytes; byte[] mapData = new byte[unzippedSize]; int index = 0; uint byteCount = padWidth * this.Height; for (uint i = 0; i < unzippedSize; i += colorBytes) { byte rd = this.BitmapData[index].R; byte gr = this.BitmapData[index].G; byte bl = this.BitmapData[index].B; byte b0 = 0; byte b1 = 0; b0 |= (byte)((rd & 0x7C) << 1); b0 |= (byte)((gr & 0x03) << 6); b1 |= (byte)((gr & 0xE0) >> 2); b1 |= (byte)((bl & 0x1F) << 3); mapData[i + 0] = b0; mapData[i + 1] = b1; index++; } byte[] zipped = ByteReader.Compress(mapData); if (OrgBitmapData != null) { w.AppendBytes(OrgBitmapData); } else { w.AppendBytes(zipped); } } else if (BitmapFormat == BitmapFormat.RGB24Bit) // RGB 24 { uint colorBytes = HasAlpha ? (uint)4 : (uint)3; uint unzippedSize = (this.Width * this.Height) * colorBytes; byte[] mapData = new byte[unzippedSize]; int index = 0; for (uint i = 0; i < unzippedSize; i += colorBytes) { mapData[i + 0] = this.BitmapData[index].A; mapData[i + 1] = this.BitmapData[index].R; mapData[i + 2] = this.BitmapData[index].G; if (HasAlpha) { mapData[i + 3] = this.BitmapData[index].B; } index++; } byte[] zipped = ByteReader.Compress(mapData); if (OrgBitmapData != null) { w.AppendBytes(OrgBitmapData); } else { w.AppendBytes(zipped); } } w.ResetLongTagLength(this.TagType, start, true); }