You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.0 KiB
44 lines
1.0 KiB
|
|
#include <cstring> |
|
|
|
#define STB_IMAGE_IMPLEMENTATION |
|
#include "stb_image.h" |
|
|
|
#include "dumbLog.h" |
|
#include "util_image.h" |
|
|
|
|
|
util_image |
|
utilLoadImage(const char* full_path) |
|
{ |
|
LOG(Info) << "Loading Image: " << full_path << "\n"; |
|
|
|
util_image image; |
|
std::memcpy(image.file_path, full_path, std::strlen(full_path) + 1); |
|
stbi_set_flip_vertically_on_load(1); |
|
image.pixels = stbi_load(full_path, &image.w, &image.h, &image.num_channels, 0); |
|
image.bits_per_channel = 8; |
|
image.data_len = image.w * image.h * image.num_channels; // NOTE: assumes 8 bits per channel |
|
|
|
if (image.pixels == 0) { |
|
LOG(Error) << stbi_failure_reason() << "\n"; |
|
utilFreeImage(image); |
|
return image; |
|
} |
|
|
|
LOG(Info) << "Image properties, data_len: " << image.data_len |
|
<< ", width: " << image.w << ", height: " << image.h << "\n"; |
|
|
|
return image; |
|
} |
|
|
|
void |
|
utilFreeImage(util_image image) |
|
{ |
|
image.w = image.h = image.data_len = 0; |
|
image.bits_per_channel = 8; |
|
image.num_channels = 4; |
|
std::memset(image.file_path, 0, std::strlen(image.file_path) + 1); |
|
utilSafeFree(image.pixels); |
|
} |
|
|
|
|