2024-07-12 19:48:34 +02:00
|
|
|
#include <pd/external/stb_image.h>
|
|
|
|
|
|
|
|
#include <pd/Image.hpp>
|
|
|
|
#include <pd/internal_db.hpp>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Palladium {
|
|
|
|
|
|
|
|
void Image::Load(const std::string &path) {
|
|
|
|
// Make sure to cleanup
|
|
|
|
Delete();
|
2024-08-02 13:50:36 +02:00
|
|
|
if (!img) img = Texture::New();
|
|
|
|
img->LoadFile(path);
|
2024-07-12 19:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Image::From_NIMG(const nimg &image) {
|
|
|
|
// Make sure to cleanup
|
|
|
|
Delete();
|
2024-08-02 13:50:36 +02:00
|
|
|
if (!img) img = Texture::New();
|
|
|
|
img->LoadPixels(image.pixel_buffer, image.width, image.height);
|
2024-07-12 19:48:34 +02:00
|
|
|
}
|
|
|
|
|
2024-08-02 13:50:36 +02:00
|
|
|
Texture::Ref Image::Get() {
|
2024-07-12 19:48:34 +02:00
|
|
|
if (!Loadet()) {
|
2024-08-30 14:54:49 +02:00
|
|
|
return nullptr;
|
2024-07-12 19:48:34 +02:00
|
|
|
}
|
|
|
|
return img;
|
|
|
|
}
|
|
|
|
|
2024-08-02 13:50:36 +02:00
|
|
|
void Image::Set(Texture::Ref i, NVec4 uvs) {
|
2024-07-12 19:48:34 +02:00
|
|
|
Delete();
|
2024-12-08 19:26:21 +01:00
|
|
|
if (uvs.x() != -1) custom_uvs = uvs;
|
2024-07-12 19:48:34 +02:00
|
|
|
img = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
NVec2 Image::GetSize() {
|
2024-08-02 13:50:36 +02:00
|
|
|
if (!img) return NVec2(0, 0);
|
|
|
|
return img->GetSize();
|
2024-07-12 19:48:34 +02:00
|
|
|
}
|
|
|
|
|
2024-08-02 13:50:36 +02:00
|
|
|
void Image::Delete() { img = nullptr; }
|
2024-07-12 19:48:34 +02:00
|
|
|
|
2024-08-02 13:50:36 +02:00
|
|
|
bool Image::Loadet() { return img != nullptr; }
|
2024-07-12 19:48:34 +02:00
|
|
|
} // namespace Palladium
|