Ejemplo n.º 1
0
    private void Start()
    {
        //Create the header struct
        ImageHeader header = new ImageHeader();

        header.Setup(File.OpenRead(Application.dataPath + path));

        //Create the palette, image and colors arrays
        byte[]  palette = GetPalette(File.OpenRead(Application.dataPath + path));
        byte[]  image   = DecodeImage(header.bytesPerLine, header.yEnd + 1, path);
        Pixel[] colors  = new Pixel[256];

        int index = 0;        //index of each RGB tuple

        //Get the pixels from the pallette
        for (int i = 0; i < colors.Length; i++)
        {
            colors[i] = new Pixel(palette[index], palette[index + 1], palette[index + 2]);
            index    += 3;
        }

        //There is no padding in this file, so i'll leave this out
        //int padding = ((header.bytesPerLine * header.numBitPlanes) * (8 / header.bitsPerPixel)) - ((header.xEnd - header.xStart) + 1);

        //Create a texture from the pixels
        Texture2D tex = new Texture2D(header.bytesPerLine, header.bytesPerLine);

        CreateTextureOptimized(image, colors, tex);

        //Set the texture to the renderer
        meshRendererComponent.material.mainTexture = tex;
    }