Exemplo n.º 1
0
        public Texture2D GetFrame(int index)
        {
            Frame frame = Frames[index];

            Texture2D texture = Texture2DUtil.CreateTransparentTexture(Header.Width, Header.Height);


            List <LayerChunk> layers = GetChunks <LayerChunk>();
            List <CelChunk>   cels   = frame.GetChunks <CelChunk>();

            cels.Sort((ca, cb) => ca.LayerIndex.CompareTo(cb.LayerIndex));

            for (int i = 0; i < cels.Count; i++)
            {
                LayerChunk layer = layers[cels[i].LayerIndex];

                LayerBlendMode blendMode = layer.BlendMode;
                float          opacity   = Mathf.Min(layer.Opacity / 255f, cels[i].Opacity / 255f);

                bool visibility = layer.Visible;


                LayerChunk parent = GetParentLayer(layer);
                while (parent != null)
                {
                    visibility &= parent.Visible;
                    if (visibility == false)
                    {
                        break;
                    }

                    parent = GetParentLayer(parent);
                }

                if (visibility == false || layer.LayerType == LayerType.Group)
                {
                    continue;
                }

                Texture2D celTex = GetTextureFromCel(cels[i]);

                switch (blendMode)
                {
                case LayerBlendMode.Normal: texture = Texture2DBlender.Normal(texture, celTex); break;

                case LayerBlendMode.Multiply: texture = Texture2DBlender.Multiply(texture, celTex, opacity); break;

                case LayerBlendMode.Screen: texture = Texture2DBlender.Screen(texture, celTex); break;

                case LayerBlendMode.Overlay: texture = Texture2DBlender.Overlay(texture, celTex); break;

                case LayerBlendMode.Darken: texture = Texture2DBlender.Darken(texture, celTex); break;

                case LayerBlendMode.Lighten: texture = Texture2DBlender.Lighten(texture, celTex); break;

                case LayerBlendMode.ColorDodge: texture = Texture2DBlender.ColorDodge(texture, celTex); break;

                case LayerBlendMode.ColorBurn: texture = Texture2DBlender.ColorBurn(texture, celTex); break;

                case LayerBlendMode.HardLight: texture = Texture2DBlender.HardLight(texture, celTex); break;

                case LayerBlendMode.SoftLight: texture = Texture2DBlender.SoftLight(texture, celTex); break;

                case LayerBlendMode.Difference: texture = Texture2DBlender.Difference(texture, celTex); break;

                case LayerBlendMode.Exclusion: texture = Texture2DBlender.Exclusion(texture, celTex); break;

                case LayerBlendMode.Hue: texture = Texture2DBlender.Hue(texture, celTex); break;

                case LayerBlendMode.Saturation: texture = Texture2DBlender.Saturation(texture, celTex); break;

                case LayerBlendMode.Color: texture = Texture2DBlender.Color(texture, celTex); break;

                case LayerBlendMode.Luminosity: texture = Texture2DBlender.Luminosity(texture, celTex); break;

                case LayerBlendMode.Addition: texture = Texture2DBlender.Addition(texture, celTex); break;

                case LayerBlendMode.Subtract: texture = Texture2DBlender.Subtract(texture, celTex); break;

                case LayerBlendMode.Divide: texture = Texture2DBlender.Divide(texture, celTex); break;
                }
            }



            return(texture);
        }
Exemplo n.º 2
0
        public Texture2D GetFrame(int index)
        {
            Frame frame = Frames[index];


            Texture2D texture = Texture2DUtil.CreateTransparentTexture(Header.Width, Header.Height);


            List <LayerChunk> layers = GetChunks <LayerChunk>();
            List <CelChunk>   cels   = frame.GetChunks <CelChunk>();

            cels.Sort((ca, cb) => ca.LayerIndex.CompareTo(cb.LayerIndex));

            for (int i = 0; i < cels.Count; i++)
            {
                LayerBlendMode blendMode = layers[cels[i].LayerIndex].BlendMode;
                float          opacity   = layers[cels[i].LayerIndex].Opacity / 255f;

                Texture2D celTex = GetTextureFromCel(cels[i]);

                switch (blendMode)
                {
                case LayerBlendMode.Normal: texture = Texture2DBlender.Normal(texture, celTex); break;

                case LayerBlendMode.Multiply: texture = Texture2DBlender.Multiply(texture, celTex, opacity); break;

                case LayerBlendMode.Screen: texture = Texture2DBlender.Screen(texture, celTex); break;

                case LayerBlendMode.Overlay: texture = Texture2DBlender.Overlay(texture, celTex); break;

                case LayerBlendMode.Darken: texture = Texture2DBlender.Darken(texture, celTex); break;

                case LayerBlendMode.Lighten: texture = Texture2DBlender.Lighten(texture, celTex); break;

                case LayerBlendMode.ColorDodge: texture = Texture2DBlender.ColorDodge(texture, celTex); break;

                case LayerBlendMode.ColorBurn: texture = Texture2DBlender.ColorBurn(texture, celTex); break;

                case LayerBlendMode.HardLight: texture = Texture2DBlender.HardLight(texture, celTex); break;

                case LayerBlendMode.SoftLight: texture = Texture2DBlender.SoftLight(texture, celTex); break;

                case LayerBlendMode.Difference: texture = Texture2DBlender.Difference(texture, celTex); break;

                case LayerBlendMode.Exclusion: texture = Texture2DBlender.Exclusion(texture, celTex); break;

                case LayerBlendMode.Hue: texture = Texture2DBlender.Hue(texture, celTex); break;

                case LayerBlendMode.Saturation: texture = Texture2DBlender.Saturation(texture, celTex); break;

                case LayerBlendMode.Color: texture = Texture2DBlender.Color(texture, celTex); break;

                case LayerBlendMode.Luminosity: texture = Texture2DBlender.Luminosity(texture, celTex); break;

                case LayerBlendMode.Addition: texture = Texture2DBlender.Addition(texture, celTex); break;

                case LayerBlendMode.Subtract: texture = Texture2DBlender.Subtract(texture, celTex); break;

                case LayerBlendMode.Divide: texture = Texture2DBlender.Divide(texture, celTex); break;
                }
            }



            return(texture);
        }