diff options
Diffstat (limited to 'tools/asset_packer.cc')
| -rw-r--r-- | tools/asset_packer.cc | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/tools/asset_packer.cc b/tools/asset_packer.cc index 39169e4..04b74a4 100644 --- a/tools/asset_packer.cc +++ b/tools/asset_packer.cc @@ -31,8 +31,11 @@ static const std::map<std::string, ProcGenFunc> kAssetPackerProcGenFuncMap = { static bool HasImageExtension(const std::string& filename) { std::string ext = filename.substr(filename.find_last_of(".") + 1); - // simple case-insensitive check (assuming lowercase for simplicity or just basic checks) - if (ext == "png" || ext == "jpg" || ext == "jpeg" || ext == "tga" || ext == "bmp") return true; + // simple case-insensitive check (assuming lowercase for simplicity or just + // basic checks) + if (ext == "png" || ext == "jpg" || ext == "jpeg" || ext == "tga" || + ext == "bmp") + return true; return false; } @@ -190,7 +193,8 @@ int main(int argc, char* argv[]) { if (kAssetPackerProcGenFuncMap.find(info.proc_func_name) == kAssetPackerProcGenFuncMap.end()) { fprintf(stderr, - "Warning: Unknown procedural function: %s for asset: %s (Runtime error will occur)\n", + "Warning: Unknown procedural function: %s for asset: %s " + "(Runtime error will occur)\n", info.proc_func_name.c_str(), info.name.c_str()); // return 1; // Allow unknown functions for testing runtime handling } @@ -223,31 +227,35 @@ int main(int argc, char* argv[]) { std::string base_dir = assets_txt_path.substr(0, assets_txt_path.find_last_of("/\\") + 1); std::string full_path = base_dir + info.filename; - + std::vector<uint8_t> buffer; bool is_image = HasImageExtension(info.filename); if (is_image) { int w, h, channels; - unsigned char* img_data = stbi_load(full_path.c_str(), &w, &h, &channels, 4); // Force 4 channels (RGBA) + unsigned char* img_data = stbi_load( + full_path.c_str(), &w, &h, &channels, 4); // Force 4 channels (RGBA) if (!img_data) { - fprintf(stderr, "Error: Could not load image file: %s (Reason: %s)\n", full_path.c_str(), stbi_failure_reason()); + fprintf(stderr, "Error: Could not load image file: %s (Reason: %s)\n", + full_path.c_str(), stbi_failure_reason()); return 1; } - + // Format: [Width(4)][Height(4)][Pixels...] buffer.resize(sizeof(uint32_t) * 2 + w * h * 4); uint32_t* header = reinterpret_cast<uint32_t*>(buffer.data()); header[0] = (uint32_t)w; header[1] = (uint32_t)h; std::memcpy(buffer.data() + sizeof(uint32_t) * 2, img_data, w * h * 4); - + stbi_image_free(img_data); - printf("Processed image asset %s: %dx%d RGBA\n", info.name.c_str(), w, h); + printf("Processed image asset %s: %dx%d RGBA\n", info.name.c_str(), w, + h); } else { std::ifstream asset_file(full_path, std::ios::binary); if (!asset_file.is_open()) { - fprintf(stderr, "Error: Could not open asset file: %s\n", full_path.c_str()); + fprintf(stderr, "Error: Could not open asset file: %s\n", + full_path.c_str()); return 1; } buffer.assign((std::istreambuf_iterator<char>(asset_file)), |
