| 6489 | {} |
| 6490 | |
| 6491 | olc::rcode LoadImageResource(olc::Sprite* spr, const std::string& sImageFile, olc::ResourcePack* pack) override |
| 6492 | { |
| 6493 | // clear out existing sprite |
| 6494 | spr->pColData.clear(); |
| 6495 | |
| 6496 | // Open file |
| 6497 | UNUSED(pack); |
| 6498 | Gdiplus::Bitmap* bmp = nullptr; |
| 6499 | if (pack != nullptr) |
| 6500 | { |
| 6501 | // Load sprite from input stream |
| 6502 | ResourceBuffer rb = pack->GetFileBuffer(sImageFile); |
| 6503 | bmp = Gdiplus::Bitmap::FromStream(SHCreateMemStream((BYTE*)rb.vMemory.data(), UINT(rb.vMemory.size()))); |
| 6504 | } |
| 6505 | else |
| 6506 | { |
| 6507 | // Check file exists |
| 6508 | if (!_gfs::exists(sImageFile)) return olc::rcode::NO_FILE; |
| 6509 | |
| 6510 | // Load sprite from file |
| 6511 | bmp = Gdiplus::Bitmap::FromFile(ConvertS2W(sImageFile).c_str()); |
| 6512 | } |
| 6513 | |
| 6514 | if (bmp->GetLastStatus() != Gdiplus::Ok) return olc::rcode::FAIL; |
| 6515 | spr->width = bmp->GetWidth(); |
| 6516 | spr->height = bmp->GetHeight(); |
| 6517 | |
| 6518 | spr->pColData.resize(spr->width * spr->height); |
| 6519 | |
| 6520 | for (int y = 0; y < spr->height; y++) |
| 6521 | for (int x = 0; x < spr->width; x++) |
| 6522 | { |
| 6523 | Gdiplus::Color c; |
| 6524 | bmp->GetPixel(x, y, &c); |
| 6525 | spr->SetPixel(x, y, olc::Pixel(c.GetRed(), c.GetGreen(), c.GetBlue(), c.GetAlpha())); |
| 6526 | } |
| 6527 | delete bmp; |
| 6528 | return olc::rcode::OK; |
| 6529 | } |
| 6530 | |
| 6531 | olc::rcode SaveImageResource(olc::Sprite* spr, const std::string& sImageFile) override |
| 6532 | { |