| 5214 | {} |
| 5215 | |
| 5216 | olc::rcode LoadImageResource(olc::Sprite* spr, const std::string& sImageFile, olc::ResourcePack* pack) override |
| 5217 | { |
| 5218 | UNUSED(pack); |
| 5219 | // clear out existing sprite |
| 5220 | spr->pColData.clear(); |
| 5221 | // Open file |
| 5222 | stbi_uc* bytes = nullptr; |
| 5223 | int w = 0, h = 0, cmp = 0; |
| 5224 | if (pack != nullptr) |
| 5225 | { |
| 5226 | ResourceBuffer rb = pack->GetFileBuffer(sImageFile); |
| 5227 | bytes = stbi_load_from_memory((unsigned char*)rb.vMemory.data(), int(rb.vMemory.size()), &w, &h, &cmp, 4); |
| 5228 | } |
| 5229 | else |
| 5230 | { |
| 5231 | // Check file exists |
| 5232 | if (!_gfs::exists(sImageFile)) return olc::rcode::NO_FILE; |
| 5233 | bytes = stbi_load(sImageFile.c_str(), &w, &h, &cmp, 4); |
| 5234 | } |
| 5235 | |
| 5236 | if (!bytes) return olc::rcode::FAIL; |
| 5237 | spr->width = w; spr->height = h; |
| 5238 | spr->pColData.resize(spr->width * spr->height); |
| 5239 | std::memcpy(spr->pColData.data(), bytes, spr->width * spr->height * 4); |
| 5240 | delete[] bytes; |
| 5241 | return olc::rcode::OK; |
| 5242 | } |
| 5243 | |
| 5244 | olc::rcode SaveImageResource(olc::Sprite* spr, const std::string& sImageFile) override |
| 5245 | { |
no test coverage detected