|
|
|
|
@ -8,27 +8,27 @@
|
|
|
|
|
#include "util_image.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
util_image parseSTBResult(util_image img); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
util_image |
|
|
|
|
utilLoadImage(const char* full_path) |
|
|
|
|
utilLoadImagePath(const char* full_path) |
|
|
|
|
{ |
|
|
|
|
LOG(Info) << "Loading Image: " << full_path << "\n"; |
|
|
|
|
|
|
|
|
|
util_image image; |
|
|
|
|
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; |
|
|
|
|
return parseSTBResult(image); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LOG(Info) << "Image properties, data_len: " << image.data_len |
|
|
|
|
<< ", width: " << image.w << ", height: " << image.h << "\n"; |
|
|
|
|
|
|
|
|
|
return 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 |
|
|
|
|
@ -41,3 +41,20 @@ utilFreeImage(util_image image)
|
|
|
|
|
utilSafeFree(image.pixels); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
util_image |
|
|
|
|
parseSTBResult(util_image image) |
|
|
|
|
{ |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|