⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tagparser.java

📁 java版本的flash文件(swf)播放器
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        
        //--MP3 Streams sometimes have an extra word here...
        //if( format == SWFConstants.SOUND_FORMAT_MP3 )
        //{
        //    int unknown = in.readUI16();
        //}
        //--but other SDK's don't know about this so we can't assume it
        //  will always be present in a SWF.
        
        if( adpcmOnly )
        {
            mTagtypes.tagSoundStreamHead( playbackFreq, playback16bits, playbackStereo,
                                         format, streamFreq, stream16bits, streamStereo,
                                         avgSampleCount );
        }
        else
        {
            mTagtypes.tagSoundStreamHead2( playbackFreq, playback16bits, playbackStereo,
                                          format, streamFreq, stream16bits, streamStereo,
                                          avgSampleCount );
        }
    }
    
    protected void parseSoundStreamBlock( InStream in ) throws IOException
    {
        mTagtypes.tagSoundStreamBlock( in.read() );
    }

    protected void parseDefineBits( InStream in ) throws IOException
    {
        mTagtypes.tagDefineBits( in.readUI16(), in.read() );
    }
    
    protected void parseDefineJPEGTables( InStream in ) throws IOException
    {
        mTagtypes.tagJPEGTables( in.read() );
    }
    
    protected void parseDefineBitsJPEG3( InStream in ) throws IOException
    {
        int id   = in.readUI16();
        int size = (int)in.readUI32();
        
        byte[] imageData = in.read( size );
        byte[] alphaData = in.read();
        
        mTagtypes.tagDefineBitsJPEG3( id, imageData, alphaData );
    }    
    
    protected void parseMorphShape( InStream in ) throws IOException
    {
        int id = in.readUI16();
        
        Rect startBounds = new Rect( in );
        Rect endBounds   = new Rect( in );
        
        int edgeOffset = (int)in.readUI32();
        
        SWFShape shape = mTagtypes.tagDefineMorphShape( id, startBounds, endBounds );
        
        if( shape == null ) return;
        
        //--Read the Fill Styles
        int fillCount = in.readUI8();
        if( fillCount == 0xff ) fillCount = in.readUI16();
        
        for( int i = 0; i < fillCount; i++ )
        {
            parseMorphFillStyle( in, shape );
        }
        
        //--Read the Line Styles
        int lineCount = in.readUI8();
        if( lineCount == 0xff ) lineCount = in.readUI16();
        
        for( int i = 0; i < lineCount; i++ )
        {
            parseMorphLineStyle( in, shape );
        }

        //--read the start shape
        parseShape( in, shape, false, true );

        //--read the end shape
        parseShape( in, shape, false, true );        
    }
 
    protected void parseMorphLineStyle( InStream in, SWFShape shape ) throws IOException
    {
        int startWidth = in.readUI16();        
        int endWidth   = in.readUI16();
        
        AlphaColor startColor = new AlphaColor(in);
        AlphaColor endColor   = new AlphaColor(in);

        shape.defineLineStyle( startWidth, startColor );        
        shape.defineLineStyle( endWidth,   endColor   );        
    }
    
    protected void parseMorphFillStyle( InStream in, SWFShape shape ) throws IOException
    {
        int fillType = in.readUI8();
        
        if( fillType == FILL_SOLID )
        {
            AlphaColor startColor = new AlphaColor(in);
            AlphaColor endColor   = new AlphaColor(in);
                        
            shape.defineFillStyle( startColor );
            shape.defineFillStyle( endColor   );
        }
        else if( fillType == FILL_LINEAR_GRADIENT 
              || fillType == FILL_RADIAL_GRADIENT )
        {
            Matrix startMatrix = new Matrix( in );
            Matrix endMatrix   = new Matrix( in );
            
            int numRatios = in.readUI8();
            
            int[]        startRatios = new int[ numRatios ];
            AlphaColor[] startColors = new AlphaColor[ numRatios ];

            int[]        endRatios = new int[ numRatios ];
            AlphaColor[] endColors = new AlphaColor[ numRatios ];
                        
            for( int i = 0; i < numRatios; i++ )
            {
                startRatios[i] = in.readUI8();
                startColors[i] = new AlphaColor(in);
                endRatios[i]   = in.readUI8();
                endColors[i]   = new AlphaColor(in);
            }            
            
            shape.defineFillStyle( startMatrix, startRatios, startColors, 
                                   fillType == FILL_RADIAL_GRADIENT );

            shape.defineFillStyle( endMatrix, endRatios, endColors, 
                                   fillType == FILL_RADIAL_GRADIENT );
        }
        else if( fillType == FILL_TILED_BITMAP 
              || fillType == FILL_CLIPPED_BITMAP )
        {
            int bitmapId = in.readUI16();
            Matrix startMatrix = new Matrix( in );
            Matrix endMatrix   = new Matrix( in );
            
            shape.defineFillStyle( bitmapId, startMatrix, 
                                   fillType == FILL_CLIPPED_BITMAP );

            shape.defineFillStyle( bitmapId, endMatrix, 
                                   fillType == FILL_CLIPPED_BITMAP );
        }                            
    }
    
    protected void parseDefineJPEG2( InStream in, int length ) throws IOException
    {
        int id = in.readUI16();        
        
        //--read the image data
        byte[] image = in.read( length - 2 );
        
        mTagtypes.tagDefineBitsJPEG2( id, image );
    }
    
    protected void parseDefineBitsLossless( InStream in, int length, 
                                            boolean hasAlpha )
        throws IOException
    {
        int id     = in.readUI16();        
        int format = in.readUI8();
        int width  = in.readUI16();
        int height = in.readUI16();
        
        int size = 0;
        
        switch( format )
        {
            case BITMAP_FORMAT_8_BIT:  size = in.readUI8() + 1; break;
            case BITMAP_FORMAT_16_BIT: size = in.readUI16() + 1; break;
            case BITMAP_FORMAT_32_BIT: size = 0; break;
            default: throw new IOException( "unknown bitmap format: " + format );
        }                
        
        byte[] data = in.read( length - (int)in.getBytesRead() );
        
        //--unzip the data
        ByteArrayInputStream bin = new ByteArrayInputStream(data);
        InflaterInputStream inflater = new InflaterInputStream( bin );
        InStream dataIn = new InStream( inflater );
        
        Color[] colors = hasAlpha ? new AlphaColor[ size ] : new Color[ size ];
        
        for( int i = 0; i < size; i++ )
        {
            colors[i] = hasAlpha ? new AlphaColor( dataIn ) : new Color( dataIn );
        }
        
        byte[] imageData = dataIn.read();
        
        if( hasAlpha )
        {
            mTagtypes.tagDefineBitsLossless2( id, format, width, height, 
                                             (AlphaColor[])colors, imageData );
        }
        else
        {
            mTagtypes.tagDefineBitsLossless( id, format, width, height, colors, imageData );
        }
    }
    
    protected void parseExport( InStream in ) throws IOException
    {
        int count     = in.readUI16();
        
        String[] exportNames = new String[ count ];
        int[]    exportIds   = new int[ count ];
        
        for( int i = 0; i < count; i++ )
        {
            exportIds[i]   = in.readUI16();
            exportNames[i] = in.readString( mStringEncoding );
        }        
        
        mTagtypes.tagExport( exportNames, exportIds );
    }
    
    protected void parseImport( InStream in ) throws IOException
    {
        String movieName     = in.readString( mStringEncoding );
        int count     = in.readUI16();
        
        String[] importNames = new String[ count ];
        int[]    importIds   = new int[ count ];
        
        for( int i = 0; i < count; i++ )
        {
            importIds[i]   = in.readUI16();
            importNames[i] = in.readString( mStringEncoding );
        }
        
        mTagtypes.tagImport( movieName, importNames, importIds );
    }
    
    protected void parseDefineButton2( InStream in ) throws IOException
    {
        int id = in.readUI16();
                
        boolean trackAsMenu = ( in.readUI8() != 0 );
        
        int actionOffset = in.readUI16();  //skip first offset
        
        //--Read multiple button records
        Vector buttonRecords = ButtonRecord2.read( in );
               
        SWFActions actions = mTagtypes.tagDefineButton2( id, trackAsMenu, buttonRecords );
        
        if( actions == null ) return;
        
        //--Read multiple action records        
        while( actionOffset != 0 )
        {
            actionOffset = in.readUI16();                
                        
            //--Read the condition flags for this action array
            int actionConditions = in.readUI16();
                        
            actions.start( actionConditions );
            
            ActionParser parser = new ActionParser( actions, mFlashVersion );
            parser.parse( in );
        }                
        
        actions.done();
    }    
    
    protected void parseButtonCXForm( InStream in ) throws IOException
    {
        int buttonId = in.readUI16();
        ColorTransform transform = new ColorTransform( in );
        
        mTagtypes.tagButtonCXForm( buttonId, transform );
    }
    
    protected void parseDefineButton( InStream in ) throws IOException
    {
        int id = in.readUI16();
        Vector buttonRecords = ButtonRecord.read( in );
        
        SWFActions actions = mTagtypes.tagDefineButton( id, buttonRecords );
        
        if( actions == null ) return;
        
        actions.start( 0 );  //no conditions
        ActionParser parser = new ActionParser( actions, mFlashVersion );
        parser.parse( in );
        actions.done();        
    }
    
    protected void parseDefineText( int type, InStream in ) throws IOException
    {
        int    id     = in.readUI16();        
        Rect   bounds = new Rect( in );
        Matrix matrix = new Matrix( in );
        
        SWFText text = ( type == TAG_DEFINETEXT ) ? 
                           mTagtypes.tagDefineText( id, bounds, matrix ) :
                           mTagtypes.tagDefineText2( id, bounds, matrix );
        
        if( text == null ) return;
        
        int glyphBits   = in.readUI8();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -