|
|
|
@ -8,14 +8,42 @@ |
|
|
|
#include "util_image.h" |
|
|
|
#include "util_image.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
util_image parseSTBResult(util_image img); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
util_image |
|
|
|
util_image |
|
|
|
utilLoadImage(const char* full_path) |
|
|
|
utilLoadImagePath(const char* full_path) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOG(Info) << "Loading Image: " << full_path << "\n"; |
|
|
|
LOG(Info) << "Loading Image: " << full_path << "\n"; |
|
|
|
|
|
|
|
|
|
|
|
util_image image; |
|
|
|
util_image image; |
|
|
|
stbi_set_flip_vertically_on_load(1); |
|
|
|
stbi_set_flip_vertically_on_load(1); |
|
|
|
image.pixels = stbi_load(full_path, &image.w, &image.h, &image.num_channels, 0); |
|
|
|
return parseSTBResult(image); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
util_image |
|
|
|
|
|
|
|
utilLoadImageBytes(const uint8* bytes, uint length) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LOG(Info) << "Loading binary image data\n"; |
|
|
|
|
|
|
|
util_image image; |
|
|
|
|
|
|
|
stbi_set_flip_vertically_on_load(1); |
|
|
|
|
|
|
|
image.pixels = stbi_load_from_memory(bytes, length, &image.w, &image.h, &image.num_channels, 0); |
|
|
|
|
|
|
|
return parseSTBResult(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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
util_image |
|
|
|
|
|
|
|
parseSTBResult(util_image image) |
|
|
|
|
|
|
|
{ |
|
|
|
image.bits_per_channel = 8; |
|
|
|
image.bits_per_channel = 8; |
|
|
|
image.data_len = image.w * image.h * image.num_channels; // NOTE: assumes 8 bits per channel
|
|
|
|
image.data_len = image.w * image.h * image.num_channels; // NOTE: assumes 8 bits per channel
|
|
|
|
|
|
|
|
|
|
|
|
@ -30,14 +58,3 @@ utilLoadImage(const char* full_path) |
|
|
|
|
|
|
|
|
|
|
|
return image; |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|