Example #1
0
 public new static void LoadTexture(Texture2D texture, byte[] bytes)
 {
     if (bytes[0] == 0xFF)
     {
         Color32[] colors = OnlineMapsJPEGDecoder.GetColors(bytes);
         texture.SetPixels32(colors);
         texture.Apply();
     }
     else
     {
         texture.LoadImage(bytes);
     }
 }
    /// <summary>
    /// Loads JPEG and returns the array colors of the image.
    /// </summary>
    /// <param name="bytes">JPEG file data.</param>
    /// <returns>Array of colors.</returns>
    public static Color32[] GetColors(byte[] bytes)
    {
        OnlineMapsJPEGDecoder jpeg = new OnlineMapsJPEGDecoder();
        jpeg.Decode(bytes);

        Color32[] colors = new Color32[jpeg.context.rgb.Length / 3];
        int w = jpeg.context.width;
        int h = jpeg.context.height;

        for (int i = 0; i < colors.Length; i++)
        {
            int i3 = i * 3;
            int cx = i % w;
            int cy = h - i / w - 1;

            colors[cx + cy * w] = new Color32(jpeg.context.rgb[i3], jpeg.context.rgb[i3 + 1], jpeg.context.rgb[i3 + 2], 255);
        }

        return colors;
    }
Example #3
0
    /// <summary>
    /// Loads JPEG and returns the array colors of the image.
    /// </summary>
    /// <param name="bytes">JPEG file data.</param>
    /// <returns>Array of colors.</returns>
    public static Color32[] GetColors(byte[] bytes)
    {
        OnlineMapsJPEGDecoder jpeg = new OnlineMapsJPEGDecoder();

        jpeg.Decode(bytes);

        Color32[] colors = new Color32[jpeg.context.rgb.Length / 3];
        int       w      = jpeg.context.width;
        int       h      = jpeg.context.height;

        for (int i = 0; i < colors.Length; i++)
        {
            int i3 = i * 3;
            int cx = i % w;
            int cy = h - i / w - 1;

            colors[cx + cy * w] = new Color32(jpeg.context.rgb[i3], jpeg.context.rgb[i3 + 1], jpeg.context.rgb[i3 + 2], 255);
        }

        return(colors);
    }