示例#1
0
        public static AviMainHeader Read(FourCCHeader fcc, BinaryReader br)
        {
            var r = new AviMainHeader();

            r.fcc = fcc.fourcc;
            r.cb  = fcc.bytes;

            if (0 != r.fcc.CompareTo("avih") ||
                56 != r.cb)
            {
                throw new ArgumentException("AviMainHeader fourcc/size mismatch");
            }

            r.dwMicroSecPerFrame   = br.ReadUInt32();
            r.dwMaxBytesPersec     = br.ReadUInt32();
            r.dwPaddingGranularity = br.ReadUInt32();
            r.dwFlags = br.ReadUInt32();

            r.dwTotalFrames         = br.ReadUInt32();
            r.dwInitialFrames       = br.ReadUInt32();
            r.dwStreams             = br.ReadUInt32();
            r.dwSuggestedBufferSize = br.ReadUInt32();
            r.dwWidth = br.ReadUInt32();

            r.dwHeight    = br.ReadUInt32();
            r.dwReserved0 = br.ReadUInt32();
            r.dwReserved1 = br.ReadUInt32();
            r.dwReserved2 = br.ReadUInt32();
            r.dwReserved3 = br.ReadUInt32();
            return(r);
        }
示例#2
0
        public static BitmapInfoHeader Read(FourCCHeader fcc, BinaryReader br)
        {
            if (0 != fcc.fourcc.CompareTo("strf") ||
                40 != fcc.bytes)
            {
                throw new ArgumentException("BitmapInfoHeader fourcc/size mismatch");
            }

            var r = new BitmapInfoHeader();

            r.biSize     = br.ReadUInt32();
            r.biWidth    = br.ReadInt32();
            r.biHeight   = br.ReadInt32();
            r.biPlanes   = br.ReadInt16();
            r.biBitCount = br.ReadInt16();

            r.biCompression   = br.ReadUInt32();
            r.biSizeImage     = br.ReadUInt32();
            r.biXPelsPerMeter = br.ReadInt32();
            r.biYPelsPerMeter = br.ReadInt32();
            r.biClrUsed       = br.ReadUInt32();

            r.biClrImportant = br.ReadUInt32();
            return(r);
        }
示例#3
0
        public static FourCCHeader Read(BinaryReader br)
        {
            var fh = new FourCCHeader();

            fh.fourcc = Common.ReadFourCC(br);
            fh.bytes  = br.ReadUInt32();
            return(fh);
        }
示例#4
0
        public void ReadOneImage(FourCCHeader fcc)
        {
            PositionAndSize ps = new PositionAndSize();

            ps.bytes    = fcc.bytes;
            ps.position = mBr.BaseStream.Position;
            mImagePos.Add(ps);

            mBr.BaseStream.Seek(fcc.bytes, SeekOrigin.Current);
        }
示例#5
0
        public static ListHeader Read(FourCCHeader fcc, BinaryReader br)
        {
            var r = new ListHeader();

            if (0 != fcc.fourcc.CompareTo("LIST"))
            {
                throw new ArgumentException("LIST header mismatch");
            }

            r.fcc   = fcc.fourcc;
            r.bytes = fcc.bytes;
            r.type  = Common.ReadFourCC(br);

            return(r);
        }
示例#6
0
        public static AviStreamHeader Read(FourCCHeader fcc, BinaryReader br)
        {
            var r = new AviStreamHeader();

            r.fcc = fcc.fourcc;
            r.cb  = fcc.bytes;

            if (0 != r.fcc.CompareTo("strh") ||
                56 != r.cb)
            {
                throw new ArgumentException("AviStreamHeader fourcc/size mismatch");
            }

            r.fccType    = Common.ReadFourCC(br);
            r.fccHandler = Common.ReadFourCC(br);
            r.dwFlags    = br.ReadUInt32();
            r.wPriority  = br.ReadUInt16();
            r.wLanguage  = br.ReadUInt16();

            r.dwInitialFrames = br.ReadUInt32();
            r.dwScale         = br.ReadUInt32();
            r.dwRate          = br.ReadUInt32();
            r.dwStart         = br.ReadUInt32();
            r.dwLength        = br.ReadUInt32();

            r.dwSuggestedBufferSize = br.ReadUInt32();
            r.dwQuality             = br.ReadUInt32();
            r.dwSampleSize          = br.ReadUInt32();

            r.left = br.ReadInt16();
            r.top  = br.ReadInt16();

            r.right  = br.ReadInt16();
            r.bottom = br.ReadInt16();

            return(r);
        }
示例#7
0
        /* RIFF "AVI "
         *   LIST "hdrl"
         *     avih AviMainHeader
         *     LIST "strl"
         *       strh AviStreamHeader
         *       strf BitmapInfoHeader
         *   LIST "movi"
         *     00db
         *     00db
         *     ...
         * RIFF "AVIX"
         *   LIST "movi"
         *     00db
         *     00db
         *     ...
         */

        public bool Open(string path)
        {
            mImagePos.Clear();

            mBr = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read));

            var riffHeader = RiffHeader.Read(mBr);

            if (0 != riffHeader.riff.CompareTo("RIFF") ||
                0 != riffHeader.type.CompareTo("AVI "))
            {
                Console.WriteLine("E: this is not AVI");
                return(false);
            }

            try {
                do
                {
                    var fcc = FourCCHeader.Read(mBr);
                    Console.WriteLine("{0}", fcc.fourcc);
                    switch (fcc.fourcc)
                    {
                    case "RIFF":
                        var riffType = Common.ReadFourCC(mBr);
                        if (0 != riffType.CompareTo("AVIX"))
                        {
                            Console.WriteLine("D: Unknown Riff {0}", riffType);
                        }
                        break;

                    case "LIST":
                        var lst = ListHeader.Read(fcc, mBr);
                        break;

                    case "avih":
                        mAviMainHeader = AviMainHeader.Read(fcc, mBr);
                        break;

                    case "strh":
                        mAviStreamHeader = AviStreamHeader.Read(fcc, mBr);
                        break;

                    case "strf":
                        if (0 == mAviStreamHeader.fccType.CompareTo("vids"))
                        {
                            mBmpih = BitmapInfoHeader.Read(fcc, mBr);
                        }
                        else
                        {
                            SkipUnknownHeader(fcc);
                        }
                        break;

                    case "00db":
                    case "00dc":
                        ReadOneImage(fcc);
                        break;

                    default:
                        SkipUnknownHeader(fcc);
                        break;
                    }
                } while (true);
            } catch (EndOfStreamException) {
                // OK
            }

            Console.WriteLine("Total {0} images", mImagePos.Count);

            if (mImagePos.Count == 0)
            {
                Close();
                return(false);
            }

            return(true);
        }
示例#8
0
 public void SkipUnknownHeader(FourCCHeader fcc)
 {
     mBr.BaseStream.Seek(fcc.bytes, SeekOrigin.Current);
 }