1 Commits

Author SHA1 Message Date
e161d0d9a0 Downscale 2024-08-03 17:40:33 -04:00
4 changed files with 10602 additions and 3 deletions

View File

@@ -19,6 +19,8 @@ namespace ReTexture {
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);
[[nodiscard]] unsigned int getWidth() const;
[[nodiscard]] unsigned int getHeight() const;
TextureFormat getTextureFormat();

View File

@@ -2,8 +2,9 @@
namespace ReTexture {
enum TextureFlag {
INVERT_Y = 0,
INVERT_X = 1,
NONE = 0,
INVERT_Y = 1,
INVERT_X = 2,
};
inline TextureFlag operator|(TextureFlag a, TextureFlag b) {

10572
include/stb_image_resize2.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,10 @@
#include <fstream>
#include <algorithm>
#include <ReTexture/Texture.h>
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include <stb_image_resize2.h>
namespace ReTexture {
@@ -19,6 +20,15 @@ namespace ReTexture {
*this = Texture(file, {});
}
Texture::Texture(const std::vector<unsigned char>& pixel_data, TextureFormat format, unsigned int width, unsigned int height) {
pixelData = pixel_data;
this->width = width;
this->height = height;
this->format = format;
this->flags = TextureFlag::NONE;
}
void Texture::load(const std::string &file) {
std::ifstream ifStream(file, std::ios::in | std::ios::binary);
unsigned char bmpFileHeader[14];
@@ -117,4 +127,18 @@ namespace ReTexture {
TextureFlag Texture::getFlags() {
return flags;
}
Texture Texture::downscale(unsigned int rhs) {
std::vector<unsigned char> result;
if (format == TextureFormat::RGB)
result.resize((width / rhs) * (height / rhs) * 3),
stbir_resize_uint8_linear(pixelData.data(), width, height, 0, result.data(), (width / rhs), (height / rhs), 0, stbir_pixel_layout::STBIR_RGB);
else if (format == TextureFormat::RGBA)
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));
}
}