#include "pch.h" #include "log.h" #include "image.h" #include "asset.h" #include using namespace ui; bool Image::load(std::string filename) { stbi_set_flip_vertically_on_load(false); Asset file; if (!(file.open(filename.c_str()) && file.read_all())) { file.close(); return false; } uint8_t* buffer = stbi_load_from_memory(file.m_data, file.m_len, &width, &height, nullptr, 4); file.close(); comp = 4; m_data = std::unique_ptr(buffer); return true; } bool Image::load_file(std::string filename) { stbi_set_flip_vertically_on_load(false); uint8_t* buffer = stbi_load(filename.c_str(), &width, &height, nullptr, 4); comp = 4; m_data = std::unique_ptr(buffer); return true; } void Image::flip() { auto flipped = std::make_unique(width*height*4); int line_size = width * 4; const uint8_t* src = m_data.get(); uint8_t* dst = flipped.get() + line_size * (height - 1); for (int y = 0; y < height; y++) { std::copy(src, src+line_size, dst); src += line_size; dst -= line_size; } std::swap(m_data, flipped); }