示例#1
0
    public static Texture2D GifToTexture(Stream stream, int frameIndex)
    {
        Loader loader = new Loader();

        if (!loader.Load(stream))
        {
            return(null);
        }
        int image_width  = loader._logical_screen_desc.image_width;
        int image_height = loader._logical_screen_desc.image_height;
        int num          = image_width * image_height;

        UnityEngine.Color[] array   = new UnityEngine.Color[num];
        Gif.Color[]         array2  = loader._global_color_table;
        int  background_color       = loader._logical_screen_desc.background_color;
        bool transparent_color_flag = loader._frames.get_Item(0)._GCE_data.transparent_color_flag;

        UnityEngine.Color clear = UnityEngine.Color.clear;
        if (!transparent_color_flag && array2 != null && background_color < array2.Length)
        {
            clear.r = (float)array2[background_color].r / 255f;
            clear.g = (float)array2[background_color].g / 255f;
            clear.b = (float)array2[background_color].b / 255f;
            clear.a = 1f;
        }
        for (int i = 0; i < num; i++)
        {
            array[i] = clear;
        }
        GifFrame gifFrame      = loader._frames.get_Item(frameIndex);
        int      image_left    = gifFrame._image.desc.image_left;
        int      image_top     = gifFrame._image.desc.image_top;
        int      image_width2  = gifFrame._image.desc.image_width;
        int      image_height2 = gifFrame._image.desc.image_height;

        if (gifFrame._image.desc.local_color_table_flag)
        {
            array2 = gifFrame._image.desc.local_color_table;
        }
        int  num2 = gifFrame._image.data.Length;
        bool transparent_color_flag2 = gifFrame._GCE_data.transparent_color_flag;
        int  transparent_color       = gifFrame._GCE_data.transparent_color;

        for (int j = 0; j < num2; j++)
        {
            int num3 = (int)gifFrame._image.data[j];
            if (!transparent_color_flag2 || transparent_color != num3)
            {
                Gif.Color color = array2[num3];
                array[j].r = (float)color.r / 255f;
                array[j].g = (float)color.g / 255f;
                array[j].b = (float)color.b / 255f;
                array[j].a = 1f;
            }
        }
        Texture2D texture2D = new Texture2D(image_width, image_height, TextureFormat.RGBA32, false);

        texture2D.SetPixels(array);
        texture2D.Apply();
        return(texture2D);
    }
示例#2
0
    public static Texture2D GifToTexture(Stream stream, int frameIndex)
    {
        Loader loader = new Loader();

        if (!loader.Load(stream))
        {
            return(null);
        }
        int width  = loader._logical_screen_desc.image_width;
        int height = loader._logical_screen_desc.image_height;
        int num3   = width * height;

        UnityEngine.Color[] colors      = new UnityEngine.Color[num3];
        Gif.Color[]         colorArray2 = loader._global_color_table;
        int  index = loader._logical_screen_desc.background_color;
        bool flag  = loader._frames[0]._GCE_data.transparent_color_flag;

        UnityEngine.Color clear = UnityEngine.Color.clear;
        if ((!flag && (colorArray2 != null)) && (index < colorArray2.Length))
        {
            clear.r = ((float)colorArray2[index].r) / 255f;
            clear.g = ((float)colorArray2[index].g) / 255f;
            clear.b = ((float)colorArray2[index].b) / 255f;
            clear.a = 1f;
        }
        for (int i = 0; i < num3; i++)
        {
            colors[i] = clear;
        }
        GifFrame frame = loader._frames[frameIndex];
        int      num6  = frame._image.desc.image_left;
        int      num7  = frame._image.desc.image_top;
        int      num8  = frame._image.desc.image_width;
        int      num9  = frame._image.desc.image_height;

        if (frame._image.desc.local_color_table_flag)
        {
            colorArray2 = frame._image.desc.local_color_table;
        }
        int  length = frame._image.data.Length;
        bool flag2  = frame._GCE_data.transparent_color_flag;
        int  num11  = frame._GCE_data.transparent_color;

        for (int j = 0; j < length; j++)
        {
            int num13 = frame._image.data[j];
            if (!flag2 || (num11 != num13))
            {
                Gif.Color color2 = colorArray2[num13];
                colors[j].r = ((float)color2.r) / 255f;
                colors[j].g = ((float)color2.g) / 255f;
                colors[j].b = ((float)color2.b) / 255f;
                colors[j].a = 1f;
            }
        }
        Texture2D textured = new Texture2D(width, height, TextureFormat.RGBA32, false);

        textured.SetPixels(colors);
        textured.Apply();
        return(textured);
    }