|
|
|
@ -13,6 +13,18 @@ |
|
|
|
const uint MAX_FILESIZE = 2 * 1024 * 1024; // 2MB
|
|
|
|
const uint MAX_FILESIZE = 2 * 1024 * 1024; // 2MB
|
|
|
|
const uint MAX_STRING_LENGTH = 1024; |
|
|
|
const uint MAX_STRING_LENGTH = 1024; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char* |
|
|
|
|
|
|
|
utilBaseName(const char* path_str) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
assert(std::strlen(path_str) < MAX_STRING_LENGTH); |
|
|
|
|
|
|
|
const char* output = std::strrchr(path_str, '/'); |
|
|
|
|
|
|
|
if (output) |
|
|
|
|
|
|
|
return output; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return path_str; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: don't use ftell() to get filesize
|
|
|
|
// TODO: don't use ftell() to get filesize
|
|
|
|
// https://wiki.sei.cmu.edu/confluence/display/c/FIO19-C.+Do+not+use+fseek%28%29+and+ftell%28%29+to+compute+the+size+of+a+regular+file
|
|
|
|
// https://wiki.sei.cmu.edu/confluence/display/c/FIO19-C.+Do+not+use+fseek%28%29+and+ftell%28%29+to+compute+the+size+of+a+regular+file
|
|
|
|
char * |
|
|
|
char * |
|
|
|
@ -64,15 +76,21 @@ void utilSafeFree(const void* mem) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
util_image |
|
|
|
util_image |
|
|
|
utilLoadImage(const char* filename) |
|
|
|
utilLoadImage(const char* base_dir, const char* filename) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOG(INFO) << "Loading Image: " << filename << "\n"; |
|
|
|
const uint max_path = 256; // NOTE: util_image.file_path is char[256]
|
|
|
|
assert(std::strlen(filename) < 256); |
|
|
|
const char* base_name = utilBaseName(filename); |
|
|
|
|
|
|
|
uint l = std::strlen(base_dir) + std::strlen(base_name) + 1; // NOTE: +1 for '/' char
|
|
|
|
|
|
|
|
assert(l < max_path); |
|
|
|
|
|
|
|
char full_path[l]; |
|
|
|
|
|
|
|
std::memcpy(full_path, base_dir, std::strlen(base_dir) + 1); |
|
|
|
|
|
|
|
std::strcat(std::strcat(full_path, "/"), base_name); |
|
|
|
|
|
|
|
LOG(INFO) << "Loading Image: " << full_path << "\n"; |
|
|
|
|
|
|
|
|
|
|
|
util_image image; |
|
|
|
util_image image; |
|
|
|
std::memcpy(image.file_path, filename, std::strlen(filename) + 1); |
|
|
|
std::memcpy(image.file_path, full_path, std::strlen(full_path) + 1); |
|
|
|
stbi_set_flip_vertically_on_load(1); |
|
|
|
stbi_set_flip_vertically_on_load(1); |
|
|
|
image.pixels = stbi_load(filename, &image.w, &image.h, &image.num_channels, 0); |
|
|
|
image.pixels = stbi_load(full_path, &image.w, &image.h, &image.num_channels, 0); |
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
if (image.pixels == 0) { |
|
|
|
if (image.pixels == 0) { |
|
|
|
|