- 论坛徽章:
- 14
|
当年写过,贴给你参考一下。因为后来没用过,所以不知道是否有错误- bool CflashplayerApp::GetParam( CString& filename, bool& bTransparent, unsigned long& width, unsigned long& height, DWORD& ParentPID )
- {
- CString flashfilename;
- CString flashvmode;
- DWORD dwProcessId = 0;
- if( __argc > 1 )
- flashfilename = __targv[1];
- if( __argc > 2 )
- flashvmode = __targv[2];
- ParentPID = 0;
- if( __argc > 3 )
- {
- int r = _stscanf_s( __targv[3], _T("PID=%lu"), &dwProcessId );
- if( r == 1 )
- ParentPID = dwProcessId;
- }
- //MessageBox( NULL, __targv[2], __targv[1], 0 );
- CString CurrentDirectory;
- GetModuleFileName( NULL, CurrentDirectory.GetBuffer(MAX_PATH*2), MAX_PATH*2 );
- CurrentDirectory.ReleaseBuffer();
- int pos = CurrentDirectory.ReverseFind( _T('\\') );
- CurrentDirectory.Delete( pos+1, CurrentDirectory.GetLength()-(pos+1) );
- SetCurrentDirectory( CurrentDirectory );
- flashfilename.Trim();
- flashvmode.Trim();
- if( flashfilename.IsEmpty() )
- {
- flashfilename = _T("flash_begin.swf");
- }
- if( flashvmode.CompareNoCase(_T("transparent")) == 0 )
- bTransparent = true;
- else
- bTransparent = false;
- CFile flashfile;
- if( flashfile.Open(flashfilename,CFile::modeRead|CFile::typeBinary) )
- {
- flashfilename = flashfile.GetFilePath();
- char id[3];
- if( sizeof(id) != flashfile.Read(id,sizeof(id)) )
- {
- return false;
- }
- BYTE buf[17]; // (5 + 4*31)/8 = 17
- if( id[0]=='C' && id[1]=='W' && id[2]=='S' ) // 带压缩
- {
- try {
- flashfile.Seek( 8, CFile::begin );
- } catch( CFileException* e ) {
- e->Delete();
- return false;
- }
- BYTE tmp[128];
- UINT tmplen = flashfile.Read( tmp, sizeof(tmp) );
-
- int err = 0;
- z_stream d_stream;
- d_stream.zalloc = (alloc_func)0;
- d_stream.zfree = (free_func)0;
- d_stream.opaque = (voidpf)0;
- d_stream.next_in = tmp;
- d_stream.avail_in = tmplen;
- d_stream.next_out = buf;
- if( inflateInit(&d_stream) != Z_OK )
- return false;
- while( d_stream.total_out<sizeof(buf) && d_stream.total_in<tmplen )
- {
- d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
- if( (err = inflate(&d_stream,Z_NO_FLUSH)) == Z_STREAM_END )
- break;
- if( err != Z_OK )
- return false;
- }
- if( d_stream.total_out != sizeof(buf) )
- return false;
- //uLongf buflen = sizeof(buf);
- //int err = uncompress( buf, &buflen, tmp, tmplen );
- //if( Z_OK!=err && Z_BUF_ERROR!=err )
- // return false;
- }
- else if( id[0]=='F' && id[1]=='W' && id[2]=='S' )
- {
- try {
- flashfile.Seek( 8, CFile::begin );
- } catch( CFileException* e ) {
- e->Delete();
- return false;
- }
- if( sizeof(buf) != flashfile.Read(buf,sizeof(buf)) )
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- struct BitStream
- {
- BitStream( const BYTE* bs_, size_t len_ ) : bs(bs_), len(len_), offset(0)
- {
- }
- unsigned long GetULONG( size_t n )
- {
- if( len*8 - offset < n )
- return 0; // false;
- if( n > sizeof(unsigned long)*8 )
- return 0; // false;
- unsigned long ret = 0;
- size_t a = offset%8;
- if( a != 0 )
- {
- ret = BYTE(bs[offset/8] << a);
- if( n < 8-a )
- {
- ret >>= (8-n);
- offset += n;
- return ret;
- }
- ret >>= a;
- offset += 8-a;
- n -= 8-a;
- }
- for( ; n>=8; )
- {
- ret = ret*256 + bs[offset/8];
- offset += 8;
- n -= 8;
- }
- ret = ret*(1<<n) + (bs[offset/8] >> (8-n));
- offset += n;
- return ret;
- }
- long GetLONG( size_t n )
- {
- if( n==0 )
- return 0;
- unsigned long tmp = GetULONG(n);
- if( (tmp & (1ul<<(n-1))) == 0 ) // 正
- return long(tmp);
- tmp |= ~((1ul<<n)-1);
- return long(tmp); // 负
- }
- private:
- const BYTE* bs;
- size_t len;
- size_t offset;
- };
-
- BitStream bitstream( buf, sizeof(buf) );
- unsigned long len = bitstream.GetULONG(5);
- long xmin = bitstream.GetLONG(len);
- long xmax = bitstream.GetLONG(len);
- long ymin = bitstream.GetLONG(len);
- long ymax = bitstream.GetLONG(len);
- long w = xmax-xmin;
- long h = ymax-ymin;
- //if( w%20!=0 || h%20!=0 )
- // return false;
- width = abs(w/20);
- height = abs(h/20);
- filename = flashfilename;
- return true;
- }
- return false;
- }
- /*
- FWS,CWS
- 如果是CWS格式,从第8字节处还需要用zlib解压
- 第8字节开始
- 01111000 00000000 00000111 10011001 00000000 00000000 00000111 11111000 0
- -----___ ________ ____---- -------- ---_____ ________ __------ -------- -
- 15 778*20 204*20
- 01111000 00000000 00000101 01011111 00000000 00000000 00001111 10100000 00000000
- _____~~~ ~~~~~~~~ ~~~~____ ________ ___~~~~~ ~~~~~~~~ ~~______ ________ _
- 15 11000 8000
- 01111100 11100111 00000010 11000110 11111010 01110000 11000011 01010101 1
- ~~~~~___ ________ ____~~~~ ~~~~~~~~ ~~~_____ ________ __~~~~~~ ~~~~~~~~ ~
- 15 -12688 5687 -5693 1707
- 5687 - -12688 = 18375/20 = 918.75
- 1707 - -5693 = 370*20
- */
复制代码 |
|