/// <summary> /// Reads MatrixData from swf into a byte-array /// </summary> /// <remarks> /// Since were only interested in bytecode actions, theres no need to parse this data. /// </remarks> protected byte[] ReadMatrixData() { byte[] b = br.ReadBytes(27); // max. byte size of matrix record BitArray ba = BitParser.GetBitValues(b); int bitcount = 1; int Nbits; if (ba[bitcount - 1]) { Nbits = (int)BitParser.ReadUInt32(ba, bitcount, 5); bitcount += 5 + Nbits * 2; } bitcount += 1; if (ba[bitcount - 1]) { Nbits = (int)BitParser.ReadUInt32(ba, bitcount, 5); bitcount += 5 + Nbits * 2; } Nbits = (int)BitParser.ReadUInt32(ba, bitcount, 5); bitcount += 5 + Nbits * 2; int bytecount = Convert.ToInt32(Math.Ceiling((double)bitcount / 8.0)); byte[] matrix = new byte[bytecount]; for (int i = 0; i < bytecount; i++) { matrix[i] = b[i]; } br.BaseStream.Position -= b.Length - bytecount; return(matrix); }
/// <summary> /// Creates a new <see cref="Pix15"/> instance. /// </summary> /// <param name="bytes">Bytes.</param> public Pix15(byte[] bytes) { BitArray ba = BitParser.GetBitValues(bytes); this.red = (byte)BitParser.ReadUInt32(ba, 1, 5); this.green = (byte)BitParser.ReadUInt32(ba, 6, 5); this.blue = (byte)BitParser.ReadUInt32(ba, 11, 5); }
/// <summary> /// Reads the data from the binary reader. /// </summary> /// <param name="binaryReader">Binary reader.</param> public override void ReadData(BufferedBinaryReader binaryReader) { byte[] b = binaryReader.ReadBytes(4); BitArray ba = BitParser.GetBitValues(b); blockWidth = (int)BitParser.ReadUInt32(ba, 0, 4); imageWidth = (int)BitParser.ReadUInt32(ba, 4, 12); blockHeight = (int)BitParser.ReadUInt32(ba, 16, 4); imageHeight = (int)BitParser.ReadUInt32(ba, 20, 12); int nbWBlock = 0; int nbBlockWInt = imageWidth / blockWidth; float nbBlockWDec = imageWidth / blockWidth; if (nbBlockWInt == nbBlockWDec) { nbWBlock = nbBlockWInt; } else { nbWBlock = nbBlockWInt + 1; } int nbHBlock = 0; int nbBlockHInt = imageHeight / blockHeight; float nbBlockHDec = imageHeight / blockHeight; if (nbBlockHInt == nbBlockHDec) { nbHBlock = nbBlockHInt; } else { nbHBlock = nbBlockHInt + 1; } int nbBlock = nbWBlock * nbHBlock; if (nbBlock > 0) { blocks = new ImageBlock[nbBlock]; for (int i = 0; i < nbBlock; i++) { blocks[i] = new ImageBlock(); blocks[i].ReadData(binaryReader); } } }
/// <summary> /// Reads the data from a binary reader. /// </summary> /// <param name="binaryReader">Binary reader.</param> public void ReadData(BufferedBinaryReader binaryReader) { byte[] b = binaryReader.ReadBytes(2); BitArray ba = BitParser.GetBitValues(b); dataSize = (int)BitParser.ReadUInt32(ba, 0, 16); data = null; if (dataSize != 0) { data = new byte[dataSize]; for (int i = 0; i < dataSize; i++) { data[i] = binaryReader.ReadByte(); } } }
/// <summary> /// Reads RectData from swf into a byte-array. /// </summary> /// <remarks> /// Since were only interested in bytecode actions, theres no need to parse this data. /// </remarks> protected byte[] ReadRectData() { byte[] b = br.ReadBytes(17); // max. byte size of rect record BitArray ba = BitParser.GetBitValues(b); int Nbits = (int)BitParser.ReadUInt32(ba, 5); int bitcount = 5 + Nbits * 4; int bytecount = Convert.ToInt32(Math.Ceiling((double)bitcount / 8.0)); byte[] rect = new byte[bytecount]; for (int i = 0; i < bytecount; i++) { rect[i] = b[i]; } br.BaseStream.Position -= b.Length - bytecount; return(rect); }
private Rectangle GetSwfRect(byte[] bytes) { BitArray ba = BitParser.GetBitValues(bytes); int Nbits = (int)BitParser.ReadUInt32(ba, 5); int index = 5; int xmin = (int)BitParser.ReadUInt32(ba, index, Nbits) / 20; index += Nbits; int xmax = (int)BitParser.ReadUInt32(ba, index, Nbits) / 20; index += Nbits; int ymin = (int)BitParser.ReadUInt32(ba, index, Nbits) / 20; index += Nbits; int ymax = (int)BitParser.ReadUInt32(ba, index, Nbits) / 20; return(new Rectangle(xmin, ymin, xmax, ymax)); }
/// <summary> /// Reads RectData from swf into a byte-array /// </summary> /// <remarks> /// Since were only interested in bytecode actions, theres no need to parse this data. /// </remarks> protected byte[] ReadCXFormWithAlphaData() { byte[] b = br.ReadBytes(17); // max. byte size of transform record BitArray ba = BitParser.GetBitValues(b); bool hasAdd = ba[0]; bool hasMult = ba[1]; int Nbits = (int)BitParser.ReadUInt32(ba, 2, 4); int bitcount = 6 + (hasAdd ? Nbits * 4 : 0) + (hasMult ? Nbits * 4 : 0); int bytecount = Convert.ToInt32(Math.Ceiling((double)bitcount / 8.0)); byte[] cfa = new byte[bytecount]; for (int i = 0; i < bytecount; i++) { cfa[i] = b[i]; } br.BaseStream.Position -= b.Length - bytecount; return(cfa); }