palladium/source/Image.cpp

44 lines
898 B
C++
Raw Normal View History

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();
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();
if (!img) img = Texture::New();
img->LoadPixels(image.pixel_buffer, image.width, image.height);
2024-07-12 19:48:34 +02:00
}
Texture::Ref Image::Get() {
2024-07-12 19:48:34 +02:00
if (!Loadet()) {
return nullptr;
2024-07-12 19:48:34 +02:00
}
return img;
}
void Image::Set(Texture::Ref i, NVec4 uvs) {
2024-07-12 19:48:34 +02:00
Delete();
if (uvs.x() != -1) custom_uvs = uvs;
2024-07-12 19:48:34 +02:00
img = i;
}
NVec2 Image::GetSize() {
if (!img) return NVec2(0, 0);
return img->GetSize();
2024-07-12 19:48:34 +02:00
}
void Image::Delete() { img = nullptr; }
2024-07-12 19:48:34 +02:00
bool Image::Loadet() { return img != nullptr; }
2024-07-12 19:48:34 +02:00
} // namespace Palladium