rename ImageFormat enum items

This commit is contained in:
MihailRis 2025-12-21 19:05:14 +03:00
parent 1940fa7fa4
commit 163a0a8c93
18 changed files with 58 additions and 58 deletions

View file

@ -251,13 +251,13 @@ std::unique_ptr<ImageData> png::load_image(const ubyte* bytes, size_t size) {
}
png_read_image(pngPtr, rowPointers.get());
ImageFormat format = ImageFormat::rgba8888;
ImageFormat format = ImageFormat::RGBA8888;
switch (colorType) {
case PNG_COLOR_TYPE_RGBA:
format = ImageFormat::rgba8888;
format = ImageFormat::RGBA8888;
break;
case PNG_COLOR_TYPE_RGB:
format = ImageFormat::rgb888;
format = ImageFormat::RGB888;
break;
default:
png_destroy_read_struct(&pngPtr, &infoPtr, nullptr);
@ -296,7 +296,7 @@ void png::write_image(const std::string& filename, const ImageData* image) {
image->getWidth(),
image->getHeight(),
(const ubyte*)image->getData(),
image->getFormat() == ImageFormat::rgba8888
image->getFormat() == ImageFormat::RGBA8888
);
}
@ -306,6 +306,6 @@ util::Buffer<ubyte> png::encode_image(const ImageData& image) {
image.getWidth(),
image.getHeight(),
image.getData(),
format == ImageFormat::rgba8888
format == ImageFormat::RGBA8888
);
}

View file

@ -157,7 +157,7 @@ Hud::Hud(Engine& engine, LevelFrontend& frontend, Player& player)
frontend(frontend),
player(player),
debugImgWorldGen(std::make_unique<ImageData>(
ImageFormat::rgba8888, WORLDGEN_IMG_SIZE, WORLDGEN_IMG_SIZE
ImageFormat::RGBA8888, WORLDGEN_IMG_SIZE, WORLDGEN_IMG_SIZE
)) {
contentAccess = createContentAccess();
contentAccess->setId("hud.content-access");

View file

@ -95,7 +95,7 @@ std::unique_ptr<Atlas> AtlasBuilder::build(uint extrusion, bool prepare, uint ma
}
}
auto canvas = std::make_unique<ImageData>(ImageFormat::rgba8888, width, height);
auto canvas = std::make_unique<ImageData>(ImageFormat::RGBA8888, width, height);
std::unordered_map<std::string, UVRegion> regions;
std::vector<rectangle> rects = packer.getResult();
for (uint i = 0; i < entries.size(); i++) {

View file

@ -15,7 +15,7 @@ Batch2D::Batch2D(size_t capacity) : capacity(capacity), color(1.0f){
const ubyte pixels[] = {
0xFF, 0xFF, 0xFF, 0xFF
};
ImageData image(ImageFormat::rgba8888, 1, 1, pixels);
ImageData image(ImageFormat::RGBA8888, 1, 1, pixels);
blank = Texture::from(&image);
currentTexture = nullptr;
}

View file

@ -20,7 +20,7 @@ Batch3D::Batch3D(size_t capacity)
const ubyte pixels[] = {
255, 255, 255, 255,
};
ImageData image(ImageFormat::rgba8888, 1, 1, pixels);
ImageData image(ImageFormat::RGBA8888, 1, 1, pixels);
blank = Texture::from(&image);
currentTexture = nullptr;
}

View file

@ -260,7 +260,7 @@ std::unique_ptr<ImageData> GBuffer::toImage() const {
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, data.get());
glBindTexture(GL_TEXTURE_2D, 0);
return std::make_unique<ImageData>(
ImageFormat::rgb888, width, height, std::move(data)
ImageFormat::RGB888, width, height, std::move(data)
);
}

View file

@ -11,8 +11,8 @@ ImageData::ImageData(ImageFormat format, uint width, uint height)
: format(format), width(width), height(height) {
size_t pixsize;
switch (format) {
case ImageFormat::rgb888: pixsize = 3; break;
case ImageFormat::rgba8888: pixsize = 4; break;
case ImageFormat::RGB888: pixsize = 3; break;
case ImageFormat::RGBA8888: pixsize = 4; break;
default:
throw std::runtime_error("format is not supported");
}
@ -27,8 +27,8 @@ ImageData::ImageData(ImageFormat format, uint width, uint height, const ubyte* d
: format(format), width(width), height(height) {
size_t pixsize;
switch (format) {
case ImageFormat::rgb888: pixsize = 3; break;
case ImageFormat::rgba8888: pixsize = 4; break;
case ImageFormat::RGB888: pixsize = 3; break;
case ImageFormat::RGBA8888: pixsize = 4; break;
default:
throw std::runtime_error("format is not supported");
}
@ -40,9 +40,9 @@ ImageData::~ImageData() = default;
void ImageData::flipX() {
switch (format) {
case ImageFormat::rgb888:
case ImageFormat::rgba8888: {
uint size = (format == ImageFormat::rgba8888) ? 4 : 3;
case ImageFormat::RGB888:
case ImageFormat::RGBA8888: {
uint size = (format == ImageFormat::RGBA8888) ? 4 : 3;
for (uint y = 0; y < height; y++) {
for (uint x = 0; x < width / 2; x++) {
for (uint c = 0; c < size; c++) {
@ -62,9 +62,9 @@ void ImageData::flipX() {
void ImageData::flipY() {
switch (format) {
case ImageFormat::rgb888:
case ImageFormat::rgba8888: {
uint size = (format == ImageFormat::rgba8888) ? 4 : 3;
case ImageFormat::RGB888:
case ImageFormat::RGBA8888: {
uint size = (format == ImageFormat::RGBA8888) ? 4 : 3;
for (uint y = 0; y < height/2; y++) {
for (uint x = 0; x < width; x++) {
for (uint c = 0; c < size; c++) {
@ -87,8 +87,8 @@ void ImageData::blit(const ImageData& image, int x, int y) {
blitMatchingFormat(image, x, y);
return;
}
if (format == ImageFormat::rgba8888 &&
image.format == ImageFormat::rgb888) {
if (format == ImageFormat::RGBA8888 &&
image.format == ImageFormat::RGB888) {
blitRGB_on_RGBA(image, x, y);
return;
}
@ -188,10 +188,10 @@ static void draw_line(ImageData& image, int x1, int y1, int x2, int y2, const gl
void ImageData::drawLine(int x1, int y1, int x2, int y2, const glm::ivec4& color) {
switch (format) {
case ImageFormat::rgb888:
case ImageFormat::RGB888:
draw_line<3>(*this, x1, y1, x2, y2, color);
break;
case ImageFormat::rgba8888:
case ImageFormat::RGBA8888:
draw_line<4>(*this, x1, y1, x2, y2, color);
break;
default:
@ -223,10 +223,10 @@ static void draw_rect(ImageData& image, int dstX, int dstY, int width, int heigh
void ImageData::drawRect(int x, int y, int width, int height, const glm::ivec4& color) {
switch (format) {
case ImageFormat::rgb888:
case ImageFormat::RGB888:
draw_rect<3>(*this, x, y, width, height, color);
break;
case ImageFormat::rgba8888:
case ImageFormat::RGBA8888:
draw_rect<4>(*this, x, y, width, height, color);
break;
default:
@ -260,8 +260,8 @@ void ImageData::blitRGB_on_RGBA(const ImageData& image, int x, int y) {
void ImageData::blitMatchingFormat(const ImageData& image, int x, int y) {
uint comps;
switch (format) {
case ImageFormat::rgb888: comps = 3; break;
case ImageFormat::rgba8888: comps = 4; break;
case ImageFormat::RGB888: comps = 3; break;
case ImageFormat::RGBA8888: comps = 4; break;
default:
throw std::runtime_error("only unsigned byte formats supported");
}
@ -295,8 +295,8 @@ void ImageData::blitMatchingFormat(const ImageData& image, int x, int y) {
void ImageData::extrude(int x, int y, int w, int h) {
uint comps;
switch (format) {
case ImageFormat::rgb888: comps = 3; break;
case ImageFormat::rgba8888: comps = 4; break;
case ImageFormat::RGB888: comps = 3; break;
case ImageFormat::RGBA8888: comps = 4; break;
default:
throw std::runtime_error("only unsigned byte formats supported");
}
@ -431,8 +431,8 @@ static void check_matching(const ImageData& a, const ImageData& b) {
void ImageData::mulColor(const glm::ivec4& color) {
uint comps;
switch (format) {
case ImageFormat::rgb888: comps = 3; break;
case ImageFormat::rgba8888: comps = 4; break;
case ImageFormat::RGB888: comps = 3; break;
case ImageFormat::RGBA8888: comps = 4; break;
default:
throw std::runtime_error("only unsigned byte formats supported");
}
@ -453,8 +453,8 @@ void ImageData::addColor(const ImageData& other, int multiplier) {
uint comps;
switch (format) {
case ImageFormat::rgb888: comps = 3; break;
case ImageFormat::rgba8888: comps = 4; break;
case ImageFormat::RGB888: comps = 3; break;
case ImageFormat::RGBA8888: comps = 4; break;
default:
throw std::runtime_error("only unsigned byte formats supported");
}
@ -473,8 +473,8 @@ void ImageData::addColor(const ImageData& other, int multiplier) {
void ImageData::extend(int newWidth, int newHeight) {
size_t comps;
switch (format) {
case ImageFormat::rgb888: comps = 3; break;
case ImageFormat::rgba8888: comps = 4; break;
case ImageFormat::RGB888: comps = 3; break;
case ImageFormat::RGBA8888: comps = 4; break;
default:
throw std::runtime_error("only unsigned byte formats supported");
}
@ -499,8 +499,8 @@ void ImageData::extend(int newWidth, int newHeight) {
void ImageData::addColor(const glm::ivec4& color, int multiplier) {
uint comps;
switch (format) {
case ImageFormat::rgb888: comps = 3; break;
case ImageFormat::rgba8888: comps = 4; break;
case ImageFormat::RGB888: comps = 3; break;
case ImageFormat::RGBA8888: comps = 4; break;
default:
throw std::runtime_error("only unsigned byte formats supported");
}
@ -521,8 +521,8 @@ void ImageData::mulColor(const ImageData& other) {
uint comps;
switch (format) {
case ImageFormat::rgb888: comps = 3; break;
case ImageFormat::rgba8888: comps = 4; break;
case ImageFormat::RGB888: comps = 3; break;
case ImageFormat::RGBA8888: comps = 4; break;
default:
throw std::runtime_error("only unsigned byte formats supported");
}
@ -541,7 +541,7 @@ void ImageData::mulColor(const ImageData& other) {
std::unique_ptr<ImageData> add_atlas_margins(ImageData* image, int grid_size) {
// RGBA is only supported
assert(image->getFormat() == ImageFormat::rgba8888);
assert(image->getFormat() == ImageFormat::RGBA8888);
assert(image->getWidth() == image->getHeight());
int srcwidth = image->getWidth();

View file

@ -6,8 +6,8 @@
#include <memory>
enum class ImageFormat {
rgb888,
rgba8888
RGB888,
RGBA8888
};
class ImageData {
@ -57,7 +57,7 @@ public:
}
size_t getDataSize() const {
size_t channels = 3 + (format == ImageFormat::rgba8888);
size_t channels = 3 + (format == ImageFormat::RGBA8888);
return width * height * channels;
}
};

View file

@ -68,7 +68,7 @@ std::unique_ptr<ImageData> Texture::readData() {
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data.get());
glBindTexture(GL_TEXTURE_2D, 0);
return std::make_unique<ImageData>(
ImageFormat::rgba8888, width, height, std::move(data)
ImageFormat::RGBA8888, width, height, std::move(data)
);
}

View file

@ -9,8 +9,8 @@
namespace gl {
inline GLenum to_glenum(ImageFormat imageFormat) {
switch (imageFormat) {
case ImageFormat::rgb888: return GL_RGB;
case ImageFormat::rgba8888: return GL_RGBA;
case ImageFormat::RGB888: return GL_RGB;
case ImageFormat::RGBA8888: return GL_RGBA;
default:
return 0;
}

View file

@ -1,10 +1,7 @@
#pragma once
#include <memory>
#include <glm/glm.hpp>
#include "voxels/voxel.hpp"
#include "typedefs.hpp"
#include "voxels/voxel.hpp"
#include "voxels/Block.hpp"
#include "voxels/Chunk.hpp"
#include "voxels/VoxelsVolume.hpp"
@ -12,6 +9,9 @@
#include "commons.hpp"
#include "settings.hpp"
#include <memory>
#include <glm/glm.hpp>
template<typename VertexStructure> class Mesh;
class Content;
class Block;

View file

@ -16,7 +16,7 @@ MainBatch::MainBatch(size_t capacity)
const ubyte pixels[] = {
255, 255, 255, 255,
};
ImageData image(ImageFormat::rgba8888, 1, 1, pixels);
ImageData image(ImageFormat::RGBA8888, 1, 1, pixels);
blank = Texture::from(&image);
}

View file

@ -28,7 +28,7 @@ Skybox::Skybox(uint size, Shader& shader)
shader(shader),
batch3d(std::make_unique<Batch3D>(4096))
{
auto cubemap = std::make_unique<Cubemap>(size, size, ImageFormat::rgb888);
auto cubemap = std::make_unique<Cubemap>(size, size, ImageFormat::RGB888);
uint fboid;
glGenFramebuffers(1, &fboid);

View file

@ -650,7 +650,7 @@ static std::shared_ptr<UINode> read_canvas(
size = element.attr("size").asVec2();
}
auto image =
std::make_shared<Canvas>(reader.getGUI(), ImageFormat::rgba8888, size);
std::make_shared<Canvas>(reader.getGUI(), ImageFormat::RGBA8888, size);
read_uinode(reader, element, *image);
return image;
}

View file

@ -401,7 +401,7 @@ static int l_meta_meta_call(lua::State* L) {
return newuserdata<LuaCanvas>(
L,
nullptr,
std::make_shared<ImageData>(ImageFormat::rgba8888, size.x, size.y)
std::make_shared<ImageData>(ImageFormat::RGBA8888, size.x, size.y)
);
}

View file

@ -56,7 +56,7 @@ static int l_dump(lua::State* L) {
io::path file = require_string(L, 2);
uint w = heightmap->getWidth();
uint h = heightmap->getHeight();
ImageData image(ImageFormat::rgb888, w, h);
ImageData image(ImageFormat::RGB888, w, h);
auto heights = heightmap->getValues();
auto raster = image.getData();
for (uint y = 0; y < h; y++) {

View file

@ -561,7 +561,7 @@ public:
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, size.x, size.y, GL_RGB, GL_UNSIGNED_BYTE, data.get());
return std::make_unique<ImageData>(
ImageFormat::rgb888, size.x, size.y, data.release()
ImageFormat::RGB888, size.x, size.y, data.release()
);
}

View file

@ -46,7 +46,7 @@ void visualize(const SurroundMap& map, int mul, int max) {
int ox = areaMap.getOffsetX();
int oy = areaMap.getOffsetY();
ImageData image(ImageFormat::rgb888, w, h);
ImageData image(ImageFormat::RGB888, w, h);
ubyte* bytes = image.getData();
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {