public RCode LoadFromPGESprFile(string sImageFile, ResourcePack pack) { if (pColData != null) { pColData = null; } Func <FileStream, RCode> readData = (ifs) => { BinaryReader reader = new BinaryReader(ifs); width = reader.ReadInt32(); height = reader.ReadInt32(); byte[] pixels = reader.ReadBytes(width * height * sizeof(UInt32)); if (pixels.Length % sizeof(UInt32) > 0) { return(RCode.FAIL); } pColData = new Pixel[width * height]; for (int i = 0, p = 0; i < pixels.Length; i += sizeof(UInt32), p++) { pColData[p] = new Pixel(pixels[i + 0], pixels[i + 1], pixels[i + 2], pixels[i + 3]); } return(RCode.OK); }; // These are essentially Memory Surfaces represented by olc::Sprite // which load very fast, but are completely uncompressed if (pack == null) { try { using FileStream ifs = File.Open(sImageFile, FileMode.Open); return(readData.Invoke(ifs)); } catch (IOException) { return(RCode.FAIL); } } /*else * { * ResourceBuffer rb = pack->GetFileBuffer(sImageFile); * std::istream is(&rb); * ReadData(is); * return olc::OK; * }*/ return(RCode.FAIL); }
public Sprite(string sImageFile, ResourcePack pack) { PixelGameEngine.Instance.Platform.LoadFromFile(sImageFile, ref pColData, ref width, ref height, pack); }