29 this->pixels.resize(size.x * size.y);
30 for (uint32_t y = 0; y < size.y; ++y)
32 for (uint32_t x = 0; x < size.x; ++x)
35 this->pixels[y * size.x + x] = callback(pos);
40 explicit Image(
const std::filesystem::path &filepath)
43 if (std::filesystem::exists(filepath) ==
false)
49 unsigned char *data = stbi_load(filepath.string().c_str(), &width_, &height_, &channels_, 4);
51 if (!data || width_ <= 0 || height_ <= 0 || channels_ <= 0)
54 this->width =
static_cast<uint32_t
>(width_);
55 this->height =
static_cast<uint32_t
>(height_);
58 this->pixels.resize(width_ * height_);
59 for (uint32_t y = 0; y < this->height; ++y)
61 for (uint32_t x = 0; x < this->width; ++x)
63 size_t index = y * this->width + x;
65 glm::u8vec4(data[index * 4 + 0], data[index * 4 + 1], data[index * 4 + 2], data[index * 4 + 3]);
69 stbi_image_free(data);