Beispiel #1
0
    static public PalettizedImage LoadBMP(string _path, PalettizedImageConfig _config)
    {
        string filename = System.IO.Path.GetFileNameWithoutExtension(_path);

        byte[] imageFile = System.IO.File.ReadAllBytes(_path);
        //Debug.Log("Image header from file '"+filename+"': " + imageFile[ 0 ] + "," + imageFile[ 1 ] + "," + imageFile[ 2 ]);
        int pixelsOffset     = ReadInt(imageFile, 0x0a);
        int width            = ReadInt(imageFile, 0x12);
        int height           = ReadInt(imageFile, 0x16);
        int bpp              = ReadWord(imageFile, 0x1c);
        int coloursInPalette = ReadWord(imageFile, 0x2e);

        //Debug.Log ("width=" + width + ", height=" + height + ", bpp=" + bpp + " (pixels start=" + pixelsOffset + ") Colours in palette=" + coloursInPalette );

        if (coloursInPalette == 0)
        {
            coloursInPalette = 256;
        }
        PalettizedImage image = new PalettizedImage(width, height, coloursInPalette);

        image.SetConfig(_config);
        image.m_fileName = filename;
        if (image.ReadPalette(imageFile, 0x36) == false)
        {
            return(null);
        }

        if (image.ReadImage(imageFile, pixelsOffset, bpp) == false)
        {
            return(null);
        }

        return(image);
    }
    public static PalettizedImage LoadBMP( string _path, PalettizedImageConfig _config )
    {
        string filename = System.IO.Path.GetFileNameWithoutExtension( _path );

        byte[] imageFile = System.IO.File.ReadAllBytes( _path );
        //Debug.Log("Image header from file '"+filename+"': " + imageFile[ 0 ] + "," + imageFile[ 1 ] + "," + imageFile[ 2 ]);
        int pixelsOffset = ReadInt( imageFile, 0x0a );
        int width = ReadInt( imageFile, 0x12 );
        int height = ReadInt( imageFile, 0x16 );
        int bpp = ReadWord ( imageFile, 0x1c );
        int coloursInPalette = ReadWord ( imageFile, 0x2e );
        //Debug.Log ("width=" + width + ", height=" + height + ", bpp=" + bpp + " (pixels start=" + pixelsOffset + ") Colours in palette=" + coloursInPalette );

        if( coloursInPalette == 0 )
            coloursInPalette = 256;
        PalettizedImage image = new PalettizedImage( width, height, coloursInPalette );
        image.SetConfig( _config );
        image.m_fileName = filename;
        if( image.ReadPalette( imageFile, 0x36 ) == false )
            return null;

        if( image.ReadImage( imageFile, pixelsOffset, bpp ) == false )
            return null;

        return image;
    }
Beispiel #3
0
    static public PalettizedImage LoadPNG(string _path, PalettizedImageConfig _config)
    {
        PngReader pngr = FileHelper.CreatePngReader(_path);

        if (!pngr.ImgInfo.Indexed)
        {
            Debug.LogException(new UnityException("Image wasn't indexed"));
            return(null);
        }

        PngChunkPLTE palette = pngr.GetMetadata().GetPLTE();

        PalettizedImage image = new PalettizedImage(pngr.ImgInfo.Cols, pngr.ImgInfo.Rows, palette.GetNentries());

        image.SetConfig(_config);
        image.m_fileName = System.IO.Path.GetFileNameWithoutExtension(_path);

        image.ReadPalette(palette);
        image.ReadImage(pngr);

        return(image);
    }
    public static PalettizedImage LoadPNG( string _path, PalettizedImageConfig _config )
    {
        PngReader pngr = FileHelper.CreatePngReader( _path );
        if( !pngr.ImgInfo.Indexed )
        {
            Debug.LogException( new UnityException( "Image wasn't indexed" ));
            return null;
        }

        PngChunkPLTE palette = pngr.GetMetadata().GetPLTE();

        PalettizedImage image = new PalettizedImage( pngr.ImgInfo.Cols, pngr.ImgInfo.Rows, palette.GetNentries());
        image.SetConfig( _config );
        image.m_fileName = System.IO.Path.GetFileNameWithoutExtension( _path );

        image.ReadPalette( palette );
        image.ReadImage( pngr );

        return image;
    }