Adding an image library because i apparently need TGAs
This commit is contained in:
38
src/image_utils.cpp
Normal file
38
src/image_utils.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
// image_utils.cpp
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "../vendor/stb/stb_image.h"
|
||||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "../vendor/stb/stb_image_write.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
bool ConvertToThumbnailTGA(const std::string& input_path, const std::string& output_tga_path) {
|
||||
int width, height, channels;
|
||||
|
||||
stbi_uc* data = stbi_load(input_path.c_str(), &width, &height, &channels, 4);
|
||||
if (!data) {
|
||||
std::cout << "[ERROR] Failed to decode image: " << input_path << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
int result = stbi_write_tga(output_tga_path.c_str(), width, height, 4, data);
|
||||
|
||||
stbi_image_free(data);
|
||||
|
||||
if (!result) {
|
||||
std::cout << "[ERROR] Failed to save TGA thumbnail to: " << output_tga_path << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ProcessUserThumbnail(int critter_id, const std::string& user_selected_file_path) {
|
||||
std::string target_tga_path = "./data/thumbnails/" + std::to_string(critter_id) + ".tga";
|
||||
|
||||
if (ConvertToThumbnailTGA(user_selected_file_path, target_tga_path)) {
|
||||
std::cout << "[INFO] Thumbnail successfully generated for Critter #" << critter_id << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "critter.hpp"
|
||||
#include "database.hpp"
|
||||
#include "ui.hpp"
|
||||
#include "../vendor/stb/stb_image.h"
|
||||
#include "../vendor/stb/stb_image_write.h"
|
||||
|
||||
#include <RmlUi/Core.h>
|
||||
#include <RmlUi/Debugger/Debugger.h>
|
||||
@@ -55,6 +57,8 @@ bool initialize() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
std::cout << "[INFO] Starting CritterFolio...\n";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user