Refactor for easier use in other projects
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include <ReTexture/flags.h>
|
||||
|
||||
namespace ReTexture {
|
||||
class Texture {
|
||||
class SoftwareTexture {
|
||||
private:
|
||||
unsigned int width = 0;
|
||||
unsigned int height = 0;
|
||||
@@ -17,10 +17,10 @@ namespace ReTexture {
|
||||
void invertY();
|
||||
public:
|
||||
std::vector<unsigned char> pixelData;
|
||||
explicit Texture(const std::string& file);
|
||||
Texture(const std::string& file, const TextureFlag& flags);
|
||||
Texture(const std::vector<unsigned char>& pixel_data, TextureFormat format, unsigned int width, unsigned int height);
|
||||
Texture downscale(unsigned int rhs);
|
||||
explicit SoftwareTexture(const std::string& file);
|
||||
SoftwareTexture(const std::string& file, const TextureFlag& flags);
|
||||
SoftwareTexture(const std::vector<unsigned char>& pixel_data, TextureFormat format, unsigned int width, unsigned int height);
|
||||
SoftwareTexture downscale(unsigned int rhs);
|
||||
[[nodiscard]] unsigned int getWidth() const;
|
||||
[[nodiscard]] unsigned int getHeight() const;
|
||||
TextureFormat getTextureFormat();
|
||||
|
4
main.cpp
4
main.cpp
@@ -3,7 +3,7 @@
|
||||
|
||||
using namespace ReTexture;
|
||||
int main() {
|
||||
auto* bmp = new Texture("testImages/1.bmp", {TextureFlag::INVERT_Y});
|
||||
auto* bmp = new SoftwareTexture("testImages/1.bmp", {TextureFlag::INVERT_Y});
|
||||
std::cout << "Bitmap Width: " << bmp->getWidth() << std::endl;
|
||||
std::cout << "Bitmap Height: " << bmp->getHeight() << std::endl;
|
||||
|
||||
@@ -14,7 +14,7 @@ int main() {
|
||||
std::cout << "Bitmap Format: RGBA" << std::endl;
|
||||
delete bmp;
|
||||
|
||||
auto* png = new Texture("testImages/1.png", TextureFlag::INVERT_Y);
|
||||
auto* png = new SoftwareTexture("testImages/1.png", TextureFlag::INVERT_Y);
|
||||
std::cout << "PNG width: " << png->getWidth() << std::endl;
|
||||
std::cout << "PNG height: " << png->getHeight() << std::endl;
|
||||
|
||||
|
@@ -8,7 +8,7 @@
|
||||
|
||||
namespace ReTexture {
|
||||
|
||||
Texture::Texture(const std::string &file, const TextureFlag& flags) {
|
||||
SoftwareTexture::SoftwareTexture(const std::string &file, const TextureFlag& flags) {
|
||||
load(file);
|
||||
if (flags & TextureFlag::INVERT_Y)
|
||||
invertY();
|
||||
@@ -16,11 +16,11 @@ namespace ReTexture {
|
||||
this->flags = flags;
|
||||
}
|
||||
|
||||
Texture::Texture(const std::string &file) {
|
||||
*this = Texture(file, {});
|
||||
SoftwareTexture::SoftwareTexture(const std::string &file) {
|
||||
*this = SoftwareTexture(file, {});
|
||||
}
|
||||
|
||||
Texture::Texture(const std::vector<unsigned char>& pixel_data, TextureFormat format, unsigned int width, unsigned int height) {
|
||||
SoftwareTexture::SoftwareTexture(const std::vector<unsigned char>& pixel_data, TextureFormat format, unsigned int width, unsigned int height) {
|
||||
pixelData = pixel_data;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
@@ -29,7 +29,7 @@ namespace ReTexture {
|
||||
}
|
||||
|
||||
|
||||
void Texture::load(const std::string &file) {
|
||||
void SoftwareTexture::load(const std::string &file) {
|
||||
std::ifstream ifStream(file, std::ios::in | std::ios::binary);
|
||||
unsigned char bmpFileHeader[14];
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace ReTexture {
|
||||
loadPNG(file);
|
||||
}
|
||||
|
||||
void Texture::loadBMP(const std::string &file) {
|
||||
void SoftwareTexture::loadBMP(const std::string &file) {
|
||||
std::ifstream bmpFile(file, std::ios::in | std::ios::binary);
|
||||
if (!bmpFile.is_open())
|
||||
return;
|
||||
@@ -75,7 +75,7 @@ namespace ReTexture {
|
||||
format = TextureFormat::RGB;
|
||||
}
|
||||
|
||||
void Texture::loadPNG(const std::string &file) {
|
||||
void SoftwareTexture::loadPNG(const std::string &file) {
|
||||
int channels, w, h;
|
||||
|
||||
unsigned char* imageData = stbi_load(file.c_str(), &w, &h, &channels, 0);
|
||||
@@ -95,7 +95,7 @@ namespace ReTexture {
|
||||
stbi_image_free(imageData);
|
||||
}
|
||||
|
||||
void Texture::invertY() {
|
||||
void SoftwareTexture::invertY() {
|
||||
unsigned int rowSize;
|
||||
if (format == TextureFormat::RGB)
|
||||
rowSize = width * 3;
|
||||
@@ -112,23 +112,23 @@ namespace ReTexture {
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int Texture::getWidth() const {
|
||||
unsigned int SoftwareTexture::getWidth() const {
|
||||
return width;
|
||||
}
|
||||
|
||||
unsigned int Texture::getHeight() const {
|
||||
unsigned int SoftwareTexture::getHeight() const {
|
||||
return height;
|
||||
}
|
||||
|
||||
TextureFormat Texture::getTextureFormat() {
|
||||
TextureFormat SoftwareTexture::getTextureFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
TextureFlag Texture::getFlags() {
|
||||
TextureFlag SoftwareTexture::getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
Texture Texture::downscale(unsigned int rhs) {
|
||||
SoftwareTexture SoftwareTexture::downscale(unsigned int rhs) {
|
||||
std::vector<unsigned char> result;
|
||||
|
||||
if (format == TextureFormat::RGB)
|
||||
@@ -139,6 +139,6 @@ namespace ReTexture {
|
||||
result.resize((width / rhs) * (height / rhs) * 4),
|
||||
stbir_resize_uint8_linear(pixelData.data(), width, height, 0, result.data(), (width / rhs), (height / rhs), 0, stbir_pixel_layout::STBIR_RGBA);
|
||||
|
||||
return Texture(result, format, (width / rhs), (height / rhs));
|
||||
return SoftwareTexture(result, format, (width / rhs), (height / rhs));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user