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

📄 fscolortransform.java

📁 利用opensource的开源jar实现生成flash文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

        @return the value that will be multiplied with the red colour channel's value.
        */
    public float getMultiplyRed() { return multiplyRed; }    

    /** Gets the value of the multiply term for the green channel. 

        @return the value that will be multiplied with the green colour channel's value.
        */
    public float getMultiplyGreen() { return multiplyGreen; }

    /** Gets the value of the multiply term for the blue channel. 

        @return the value that will be multiplied with the blue colour channel's value.
        */
    public float getMultiplyBlue() { return multiplyBlue; }

    /** Gets the value of the multiply term for the alpha channel. 

        @return the value that will be multiplied with the alpha colour channel's value.
        */
    public float getMultiplyAlpha() { return multiplyAlpha; }

    /** Gets the value of the add term for the red channel. 

        @return the value that will be added to the red colour channel's value.
        */
    public int getAddRed() { return addRed; }

    /** Gets the value of the add term for the green channel. 

        @return the value that will be added to the green colour channel's value.
        */
    public int getAddGreen() { return addGreen; }

    /** Gets the value of the add term for the blue channel. 

        @return the value that will be added to the blue colour channel's value.
        */
    public int getAddBlue() { return addBlue; }

    /** Gets the value of the add term for the alpha channel. 

        @return the value that will be added to the alpha colour channel's value.
        */
    public int getAddAlpha() { return addAlpha; }

    /** Sets the value for the multiplyTerm which will be applied to the red colour channel.

        @param aNumber the value to be multiplied with the red colour channel's value.
        */
    public void setMultiplyRed(float aNumber) 
    {
        multiplyRed = aNumber;
    }

    /** Sets the value for the multiplyTerm which will be applied to the green colour channel.

        @param aNumber the value to be multiplied with the green colour channel's value.
        */
    public void setMultiplyGreen(float aNumber) 
    {
        multiplyGreen = aNumber;
    }

    /** Sets the value for the multiplyTerm which will be applied to the blue colour channel.

        @param aNumber the value to be multiplied with the blue colour channel's value.
        */
    public void setMultiplyBlue(float aNumber) 
    {
        multiplyBlue = aNumber;
    }

    /** Sets the value for the multiplyTerm which will be applied to the alpha colour channel.

        @param aNumber the value to be multiplied with the alpha colour channel's value.
        */     
    public void setMultiplyAlpha(float aNumber) 
    {
        multiplyAlpha = aNumber;
    }

    /** Sets the values for the multiply terms for the red, green and blue colour channels

        @param redTerm value to multiply the red colour channel by.
        @param greenTerm value to multiply the green colour channel by.
        @param blueTerm value to multiply the blue colour channel by.
        */
    public void setMultiplyTerms(float redTerm, float greenTerm, float blueTerm)
    {
        setMultiplyRed(redTerm);
        setMultiplyGreen(greenTerm);
        setMultiplyBlue(blueTerm);
    }

    /** Sets the values for the multiply terms for each of the colour channels

        @param redTerm value to multiply the red colour channel by.
        @param greenTerm value to multiply the green colour channel by.
        @param blueTerm value to multiply the blue colour channel by.
        @param alphaTerm value to multiply the alpha colour channel by.
        */
    public void setMultiplyTerms(float redTerm, float greenTerm, float blueTerm, float alphaTerm)
    {
        setMultiplyRed(redTerm);
        setMultiplyGreen(greenTerm);
        setMultiplyBlue(blueTerm);
        setMultiplyAlpha(alphaTerm);
    }

    /** Sets the value for the addTerm which will be applied to the red colour channel.

        @param aNumber the value to be added to the red colour channel's value.
        */
    public void setAddRed(int aNumber) 
    {
        addRed = aNumber;
    }

    /** Sets the value for the addTerm which will be applied to the green colour channel.

        @param aNumber the value to be added to the green colour channel's value.
        */
    public void setAddGreen(int aNumber) 
    {
        addGreen = aNumber;
    }

    /** Sets the value for the addTerm which will be applied to the blue colour channel.

        @param aNumber the value to be added to the blue colour channel's value.
        */
    public void setAddBlue(int aNumber) 
    {
        addBlue = aNumber;
    }

    /** Sets the value for the addTerm which will be applied to the alpha colour channel.

        @param aNumber the value to be added to the alpha colour channel's value.
        */
    public void setAddAlpha(int aNumber) 
    {
        addAlpha = aNumber;
    }

    /** Sets the values for the add terms for each of the colour channels.

        @param redTerm value to add to the red colour channel.
        @param greenTerm value to add to the green colour channel.
        @param blueTerm value to add to the blue colour channel.
        @param alphaTerm value to add to the alpha colour channel.
        */
    public void setAddTerms(int redTerm, int greenTerm, int blueTerm, int alphaTerm)
    {
        setAddRed(redTerm);
        setAddGreen(greenTerm);
        setAddBlue(blueTerm);
        setAddAlpha(alphaTerm);
    }

    /** Sets the values for the add terms for the red, green and blue colour channels.

        @param redTerm value to add to the red colour channel.
        @param greenTerm value to add to the green colour channel.
        @param blueTerm value to add to the blue colour channel.
        */
    public void setAddTerms(int redTerm, int greenTerm, int blueTerm)
    {
        setAddRed(redTerm);
        setAddGreen(greenTerm);
        setAddBlue(blueTerm);
    }

    /** 
     * Returns true if anObject is equal to this one. Objects are considered 
     * equal if they would generate identical binary data when they are encoded 
     * to a Flash file.
     *
     * @return true if this object would be identical to anObject when encoded.
     */
    public boolean equals(Object anObject)
    {
        boolean result = false;
        
        if (super.equals(anObject))
        {
            FSColorTransform typedObject = (FSColorTransform)anObject;
            
            result = multiplyRed == typedObject.multiplyRed;
            result = result && multiplyGreen == typedObject.multiplyGreen;
            result = result && multiplyBlue == typedObject.multiplyBlue;
            result = result && multiplyAlpha == typedObject.multiplyAlpha;
            result = result && addRed == typedObject.addRed;
            result = result && addGreen == typedObject.addGreen;
            result = result && addBlue == typedObject.addBlue;
            result = result && addAlpha == typedObject.addAlpha;
        }
        return result;
    }

    public void appendDescription(StringBuffer buffer, int depth)
    {
        buffer.append(name());

        if (depth > 0)
        {
            buffer.append(": { ");
            buffer.append("multiply = [" + multiplyRed + ", " + multiplyGreen + ", " + multiplyBlue + ", " + multiplyAlpha + "]; ");
            buffer.append("add = [" + addRed + ", " + addGreen + ", " + addBlue + ", " + addAlpha + "]; ");
            buffer.append("}");
        }
    }

    public int length(FSCoder coder)
    {
        int numberOfBits = 6;
        int fieldSize = fieldSize(coder);
        boolean containsMultiplyTerms = containsMultiplyTerms(coder);
        boolean containsAddTerms = containsAddTerms(coder);
    
        if (containsMultiplyTerms)
            numberOfBits += fieldSize * ((coder.context[FSCoder.TransparentColors] != 0) ? 4 : 3);
            
        if (containsAddTerms)
            numberOfBits += fieldSize * ((coder.context[FSCoder.TransparentColors] != 0) ? 4 : 3);

        numberOfBits += (numberOfBits % 8 > 0) ? 8 - (numberOfBits % 8) : 0;
    
        return numberOfBits>>3;
    }
    
    public void encode(FSCoder coder)
    {
        int numberOfBits = fieldSize(coder);
        boolean containsMultiplyTerms = containsMultiplyTerms(coder);
        boolean containsAddTerms = containsAddTerms(coder);
        
        coder.alignToByte();
        
        coder.writeBits(containsAddTerms ? 1 : 0, 1);
        coder.writeBits(containsMultiplyTerms ? 1 : 0, 1);
        coder.writeBits(numberOfBits, 4);
    
        if (containsMultiplyTerms)
        {
            coder.writeFixedBits(multiplyRed, numberOfBits, 8);
            coder.writeFixedBits(multiplyGreen, numberOfBits, 8);
            coder.writeFixedBits(multiplyBlue, numberOfBits, 8);
    
            if (coder.context[FSCoder.TransparentColors] != 0)
                coder.writeFixedBits(multiplyAlpha, numberOfBits, 8);
        }
        if (containsAddTerms)
        {
            coder.writeBits(addRed, numberOfBits);
            coder.writeBits(addGreen, numberOfBits);
            coder.writeBits(addBlue, numberOfBits);
    
            if (coder.context[FSCoder.TransparentColors] != 0)
                coder.writeBits(addAlpha, numberOfBits);
        }
        coder.alignToByte();
    }
     
    public void decode(FSCoder coder)
    {
        boolean containsAddTerms = false;
        boolean containsMultiplyTerms = false;
        int fieldSize = 0;
                
        coder.alignToByte();

        containsAddTerms = coder.readBits(1, false) != 0 ? true : false;
        containsMultiplyTerms = coder.readBits(1, false) != 0 ? true : false;
        fieldSize = coder.readBits(4, false);
        
        if (containsMultiplyTerms)
        {
            multiplyRed = coder.readFixedBits(fieldSize, 8);
            multiplyGreen = coder.readFixedBits(fieldSize, 8);
            multiplyBlue = coder.readFixedBits(fieldSize, 8);
            
            if (coder.context[FSCoder.TransparentColors] != 0)
                multiplyAlpha = coder.readFixedBits(fieldSize, 8);
        }
        
        if (containsAddTerms)
        {
            addRed = coder.readBits(fieldSize, true);
            addGreen = coder.readBits(fieldSize, true);
            addBlue = coder.readBits(fieldSize, true);
            
            if (coder.context[FSCoder.TransparentColors] != 0)
                addAlpha = coder.readBits(fieldSize, true);
        }
        coder.alignToByte();
    }

    /** Returns true if the values for the add and multiply terms represent a unity transform - one which will not change the colour of a shape. Whether the alpha channel is included is determined by the context associated with the FSCoder object.
    
        @param coder the FSCoder used to encoded the transform.
        @return true if the object represents a unity transform, false otherwise.
        */
    public boolean isUniyTransform(FSCoder coder)
    {
        return ! (containsAddTerms(coder) || containsMultiplyTerms(coder));
    }

    private boolean containsAddTerms(FSCoder coder) 
    {
        boolean containsTerms = addRed != 0 || addGreen != 0 || addBlue != 0;
        
        if (coder.context[FSCoder.TransparentColors] != 0)
            containsTerms = containsTerms || addAlpha != 0;
            
        return containsTerms;
    }

    private boolean containsMultiplyTerms(FSCoder coder) 
    {
        boolean containsTerms = multiplyRed != 1.0 || multiplyGreen != 1.0 || multiplyBlue != 1.0;
        
        if (coder.context[FSCoder.TransparentColors] != 0)
            containsTerms = containsTerms || multiplyAlpha != 1.0;
        
        return containsTerms;
    }

    private int addFieldSize(FSCoder coder)
    {
        int[] values;
        int size = 0;

        if (coder.context[FSCoder.TransparentColors] != 0)
            values = new int[] { addRed, addGreen, addBlue, addAlpha };
        else
            values = new int[] { addRed, addGreen, addBlue };

        size = FSCoder.size(values, true);
        
        return size;
    }

    private int multiplyFieldSize(FSCoder coder)
    {
        float[] values;
        int size = 0;

        if (coder.context[FSCoder.TransparentColors] != 0)
            values = new float[] { multiplyRed, multiplyGreen, multiplyBlue, multiplyAlpha };
        else
            values = new float[] { multiplyRed, multiplyGreen, multiplyBlue };

        size = FSCoder.fixedShortSize(values);
        
        return size;
    }

    private int fieldSize(FSCoder coder)
    {
        boolean containsMultiplyTerms = containsMultiplyTerms(coder);
        boolean containsAddTerms = containsAddTerms(coder);
        int numberOfBits = 0;

        if (containsAddTerms && !containsMultiplyTerms)
            numberOfBits = addFieldSize(coder);
        else if (!containsAddTerms && containsMultiplyTerms)
            numberOfBits = multiplyFieldSize(coder);
        else if (containsAddTerms && containsMultiplyTerms)
            numberOfBits = Math.max(addFieldSize(coder), multiplyFieldSize(coder));
        else
            numberOfBits = 1;

        return numberOfBits;
    }    
}

⌨️ 快捷键说明

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