AddIndex() public method

public AddIndex ( uint dwOffset, uint dwSize ) : void
dwOffset uint
dwSize uint
return void
コード例 #1
0
        /// <summary>
        /// aviファイルにフレームを1つ追加します.
        /// </summary>
        /// <param name="bmp"></param>
        public void AddFrame(Bitmap bmp)
        {
            int i, width, height, lineSize;

            if (bmp.Width != m_width || bmp.Height != m_height)
            {
                throw new Exception("bitmap size mismatch");
            }

            // BitmapDataからビットマップデータと、BITMPAINFOHEADERを取り出す
            BitmapData bmpDat = bmp.LockBits(
                new Rectangle(0, 0, (int)bmp.Width, (int)bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
            int address = bmpDat.Scan0.ToInt32();

            byte[] bitmapData = new byte[bmpDat.Stride * bmpDat.Height];
            Marshal.Copy(new IntPtr(address), bitmapData, 0, bitmapData.Length);

            if (m_is_first)    //then
            {
                m_is_first = false;
                this.m_main_header.dwWidth               = (uint)m_width;
                this.m_main_header.dwHeight              = (uint)m_height;
                this.m_main_header.dwMaxBytesPerSec      = (uint)(bmpDat.Stride * bmpDat.Height * this.frameRate); // bmp%infoHeader%SizeImage * avi%frameRate
                this.m_main_header.dwStreams             = 1;
                this.m_main_header.dwSuggestedBufferSize = (uint)(bmpDat.Stride * bmpDat.Height);                  // bmp.infoHeader%SizeImage
                m_linesize = bmpDat.Stride;

                this.m_stream_header.fccType               = Util.mmioFOURCC("vids");
                this.m_stream_header.fccHandler            = 0;
                this.m_stream_header.dwFlags               = 0;
                this.m_stream_header.dwReserved1           = 0;
                this.m_stream_header.dwInitialFrames       = 0;
                this.m_stream_header.dwScale               = m_scale;
                this.m_stream_header.dwRate                = m_rate;
                this.m_stream_header.dwStart               = 0;
                this.m_stream_header.dwSuggestedBufferSize = this.m_main_header.dwSuggestedBufferSize;
                this.m_stream_header.dwQuality             = 0;
                this.m_stream_header.dwSampleSize          = 0;

                Util.aviWriteMainHeader(m_main_header, m_stream);

                Util.fwrite("LIST", this.m_stream);                                  // i = fwrite( 'LIST', 1, 4, avi%fp )
                Util.WriteDWORD(0x874, this.m_stream);                               // call bmpQWordWrite( 130, avi%fp )
                Util.fwrite("strl", this.m_stream);                                  // i = fwrite( 'strl', 1, 4, avi%fp )

                Util.aviWriteStreamHeader(m_stream_header, m_main_header, m_stream); // avi )

                Util.fwrite("strf", this.m_stream);                                  // i = fwrite( 'strf', 1, 4, avi%fp )
                Util.WriteDWORD(0x28, this.m_stream);                                //call bmpQWordWrite( 40, avi%fp )    !// infoHeaderのサイズ
                BITMAPINFOHEADER bih = new BITMAPINFOHEADER();
                bih.biSize          = (uint)(Marshal.SizeOf(bih));
                bih.biWidth         = bmpDat.Width;
                bih.biHeight        = bmpDat.Height;
                bih.biPlanes        = 1;
                bih.biBitCount      = 24;
                bih.biCompression   = 0;//BI_RGB
                bih.biSizeImage     = (uint)(bmpDat.Stride * bmpDat.Height);
                bih.biXPelsPerMeter = 0;
                bih.biYPelsPerMeter = 0;
                bih.biClrUsed       = 0;
                bih.biClrImportant  = 0;
                bih.Write(m_stream);

                /*fwrite( "strn", this.fp );
                 * WriteDWORD( 6, this.fp );
                 * fwrite( "VIDEO", this.fp );
                 * WriteBYTE( 0, this.fp );*/
                Util.fwrite("indx", this.m_stream);                       //fcc
                Util.WriteDWORD(0x7f8, this.m_stream);                    // cb
                Util.WriteWORD((byte)0x4, this.m_stream);                 // wLongsPerEntry
                Util.WriteBYTE(0x0, this.m_stream);                       // bIndexSubType
                Util.WriteBYTE(Util.AVI_INDEX_OF_INDEXES, this.m_stream); // bIndexType
                Util.WriteDWORD(0x0, this.m_stream);                      // nEntriesInUse
                Util.fwrite("00db", this.m_stream);                       // dwChunkId
                Util.WriteDWORD(0x0, this.m_stream);
                Util.WriteDWORD(0x0, this.m_stream);
                Util.WriteDWORD(0x0, this.m_stream);
                for (int ii = 1; ii <= 126; ii++)
                {
                    Util.WriteQWORD(0x0, this.m_stream);
                    Util.WriteDWORD(0x0, this.m_stream);
                    Util.WriteDWORD(0x0, this.m_stream);
                }

                Util.fwrite("LIST", this.m_stream);
                Util.WriteDWORD(0x104, m_stream);
                Util.fwrite("odml", this.m_stream);
                Util.fwrite("dmlh", m_stream);
                Util.WriteDWORD(0xf8, m_stream);
                Util.WriteDWORD(0x0, m_stream);  //ここ後で更新するべき
                for (int ii = 1; ii <= 61; ii++)
                {
                    Util.WriteDWORD(0x0, m_stream);
                }

                Util.fwrite("JUNK", this.m_stream); // i = fwrite( 'JUNK', 1, 4, avi%fp )
                Util.WriteDWORD(0x60c, m_stream);
                Util.WriteDWORD(0, m_stream);       //"This"が将来登録されたらやばいので
                Util.fwrite("This file was generated by RawAvi@LipSync", this.m_stream);
                //WriteDWORD( 1503, this.fp );// call bmpQWordWrite( 1802, avi%fp )
                for (i = 1; i <= 1503; i++)       //do i = 1, 1802
                {
                    this.m_stream.Write((byte)0); // call fputc( 0, avi%fp )
                }//end do
                m_junk_length = 0xff4;

                Util.fwrite("LIST", this.m_stream); //      i = fwrite( 'LIST', 1, 4, avi%fp )
                m_movi_position = m_stream.BaseStream.Position;
                Util.WriteDWORD(0, this.m_stream);  // call bmpQWordWrite( 0, avi%fp )     !// ******************ココの数字は一番最後に書き換える必要あり2040~2043あとdwTotalFrames(48~51)も
                Util.fwrite("movi", this.m_stream); // i = fwrite( 'movi', 1, 4, avi%fp )
                m_next_framedata_position = m_stream.BaseStream.Position;

                m_std_index.SetBaseOffset((ulong)m_next_framedata_position);
                m_super_index.nEntriesInUse++;
            }//end if

            if (m_next_framedata_position != m_stream.BaseStream.Position)
            {
                m_stream.BaseStream.Seek(m_next_framedata_position, SeekOrigin.Begin);
            }

            long chunk_size = m_next_framedata_position - m_riff_position;

#if DEBUG
//            MessageBox.Show( "chunk_size=" + chunk_size );
#endif
            if ((m_current_chunk == 0 && chunk_size > m_split_sreshold) ||
                (m_current_chunk > 0 && chunk_size > SRESHOLD))
            {
                // AVIXリストへの書き込みに移行
                UpdateIndex();
                m_stream.BaseStream.Seek(m_avix_position, SeekOrigin.Begin);
                Util.fwrite("RIFF", m_stream);
                m_riff_position = m_stream.BaseStream.Position;
#if DEBUG
//                fp.Flush();
//                MessageBox.Show( "m_riff_position=" + m_riff_position );
#endif
                Util.WriteDWORD(0, m_stream);
                Util.fwrite("AVIX", m_stream);
                long current = m_stream.BaseStream.Position;
                if ((current + 12) % 0x800 != 0)
                {
                    long additional = (current + 20) % 0x800;
                    additional    = 0x800 - ((current + 20) % 0x800);
                    m_junk_length = (int)additional + 20;
                    Util.fwrite("JUNK", m_stream);
                    Util.WriteDWORD((uint)additional, m_stream);
                    for (long ii = 0; ii < additional; ii++)
                    {
                        Util.WriteBYTE((byte)0, m_stream);
                    }
                }
                else
                {
                    m_junk_length = 0;
                }
                m_junk_length = 0;

                Util.fwrite("LIST", m_stream);
                m_movi_position = m_stream.BaseStream.Position;
                Util.WriteDWORD(0, m_stream);  //後で更新するべき
                Util.fwrite("movi", m_stream);
                m_next_framedata_position = m_stream.BaseStream.Position;
                m_std_index.aIndex.Clear();
                m_std_index.SetBaseOffset((ulong)m_next_framedata_position);
                m_current_chunk++;
                m_super_index.nEntriesInUse++;
            }

            // フレームを書き込む処理
            width  = (int)this.m_main_header.dwWidth;
            height = (int)this.m_main_header.dwHeight;
            if (width != bmpDat.Width)    //then
            //aviAddFrame = -1
            {
                return;
            }//end if
            if (height != bmpDat.Height)    //then
            //aviAddframe = -1
            {
                return;
            }//end if
            lineSize = bmpDat.Stride;// int( (width * 24 + 31) / 32 ) * 4

            m_std_index.AddIndex((uint)((ulong)m_stream.BaseStream.Position - m_std_index.qwBaseOffset) + 8, (uint)(lineSize * height));
            Util.fwrite("00db", this.m_stream);                             //    i = fwrite( '00db', 1, 4, avi%fp )
            Util.WriteDWORD(m_main_header.dwSuggestedBufferSize, m_stream); // call bmpQWordWrite( avi%mainHeader%dwSuggestedBufferSize, avi%fp )
            m_stream.Write(bitmapData);
            m_next_framedata_position = m_stream.BaseStream.Position;
            _avisuperindex_entry entry = m_super_index.aIndex[m_current_chunk];
            entry.dwDuration++;
            m_super_index.aIndex[m_current_chunk] = entry; //    avi%noOfFrame = avi%noOfFrame + 1
            this.m_stream.Flush();                         // aviAddFrame = fflush( avi%fp )
            bmp.UnlockBits(bmpDat);
        }//  end function
コード例 #2
0
        /// <summary>
        /// aviファイルにフレームを1つ追加します.
        /// </summary>
        /// <param name="bmp"></param>
        public unsafe void AddFrame(Bitmap bmp)
        {
            int        width, height, lineSize;
            BitmapData bmpDat;

            if (m_is_transparent)
            {
                bmpDat = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
                                      ImageLockMode.ReadOnly,
                                      PixelFormat.Format32bppArgb);
            }
            else
            {
                bmpDat = bmp.LockBits(new Rectangle(0, 0, (int)bmp.Width, (int)bmp.Height),
                                      ImageLockMode.ReadOnly,
                                      PixelFormat.Format24bppRgb);
            }

            if (m_next_framedata_position != m_stream.BaseStream.Position)
            {
                m_stream.BaseStream.Seek(m_next_framedata_position, SeekOrigin.Begin);
            }

            long chunk_size = m_next_framedata_position - m_riff_position;

            if ((m_current_chunk == 0 && chunk_size > m_split_sreshold) ||
                (m_current_chunk > 0 && chunk_size > _THRESHOLD))
            {
                // AVIXリストへの書き込みに移行
                UpdateIndex();
                m_stream.BaseStream.Seek(m_avix_position, SeekOrigin.Begin);
                Util.fwrite("RIFF", m_stream);
                m_riff_position = m_stream.BaseStream.Position;
                Util.WriteDWORD(0, m_stream);
                Util.fwrite("AVIX", m_stream);
                long current = m_stream.BaseStream.Position;
                if ((current + 12) % 0x800 != 0)
                {
                    long additional = (current + 20) % 0x800;
                    additional    = 0x800 - ((current + 20) % 0x800);
                    m_junk_length = (int)additional + 20;
                    Util.fwrite("JUNK", m_stream);
                    Util.WriteDWORD((uint)additional, m_stream);
                    for (long ii = 0; ii < additional; ii++)
                    {
                        Util.WriteBYTE((byte)0, m_stream);
                    }
                }
                else
                {
                    m_junk_length = 0;
                }
                m_junk_length = 0;

                Util.fwrite("LIST", m_stream);
                m_movi_position = m_stream.BaseStream.Position;
                Util.WriteDWORD(0, m_stream);//後で更新するべき
                Util.fwrite("movi", m_stream);
                m_next_framedata_position = m_stream.BaseStream.Position;
                m_std_index.aIndex.Clear();
                m_std_index.SetBaseOffset((ulong)m_next_framedata_position);
                m_current_chunk++;
                m_super_index.nEntriesInUse++;
            }

            // フレームを書き込む処理
            width  = (int)m_main_header.dwWidth;
            height = (int)m_main_header.dwHeight;
            if (width != bmpDat.Width)
            {
                return;
            }
            if (height != bmpDat.Height)
            {
                return;
            }
            lineSize = bmpDat.Stride;

            if (m_compressed)
            {
                int is_key_frame = 0;
                int size         = bmpDat.Stride * bmpDat.Height;
                try {
                    IntPtr dat = VCM.ICSeqCompressFrame(m_compvar, 0, bmpDat.Scan0, &is_key_frame, &size);
                    if (!dat.Equals(IntPtr.Zero))
                    {
                        byte[] ndat = new byte[size];
                        Marshal.Copy(dat, ndat, 0, size);
                        m_std_index.AddIndex((uint)((ulong)m_stream.BaseStream.Position - m_std_index.qwBaseOffset) + 8, (uint)size);
                        Util.fwrite("00db", m_stream);
                        Util.WriteDWORD((uint)size, m_stream);
                        m_stream.Write(ndat, 0, size);
                        m_this_movi_size += size;
                    }
                } catch {
                }
            }
            else
            {
                m_std_index.AddIndex((uint)((ulong)m_stream.BaseStream.Position - m_std_index.qwBaseOffset) + 8, (uint)(lineSize * height));
                Util.fwrite("00db", m_stream);
                int    address    = bmpDat.Scan0.ToInt32();
                byte[] bitmapData = new byte[bmpDat.Stride * bmpDat.Height];
                Marshal.Copy(new IntPtr(address), bitmapData, 0, bitmapData.Length);
                Util.WriteDWORD(m_main_header.dwSuggestedBufferSize, m_stream);
                m_stream.Write(bitmapData);
                m_this_movi_size += bitmapData.Length;
            }
            m_next_framedata_position = m_stream.BaseStream.Position;
            _avisuperindex_entry entry = m_super_index.aIndex[m_current_chunk];

            entry.dwDuration++;
            m_super_index.aIndex[m_current_chunk] = entry;
            m_stream.Flush();
            bmp.UnlockBits(bmpDat);
        }