RSE-Texture/src/Texture-Extractor.c
JackCarterSmith 7861c872fb Fixed some troubles with HMT_f management
TODO: Change code to implement chained list instead of array, issue with data extraction
2019-07-05 14:13:57 +02:00

74 lines
2.0 KiB
C

/*
================================================================================
Name : Texture-Extractor.c
Author : JackCarterSmith
Version : 0.1
License : GPL-v3.0
Description : DAT textures extractor to PNG format with enhanced function in C
================================================================================
*/
#include "Texture-Extractor.h"
int main(int argc, char *argv[]) {
// Init buffer vars
HMT_FILE *hmt_fdatas = NULL;
// Check if filenames arguments exist
if (argc < 2) {
printf("No input file specified!\nCorrect syntax is:\n HMT-Extractor <texture_file_hmt>\n");
return EXCEPTION_NONCONTINUABLE; //TODO: implement own error codes system
}
// Do the work
hmt_fdatas = extractDatasFromHMT(argv[1]); //TODO: Manage multi inputs files
if (hmt_fdatas == NULL) return EXIT_FAILURE;
exportTextures(hmt_fdatas, argv[1]);
purgeHMTFromMemory(hmt_fdatas); // Clean up memory (because I'm a good boy)
return EXIT_SUCCESS;
}
HMT_FILE *extractDatasFromHMT(char *hmt_filename) {
FILE *_hmtFile = NULL;
HMT_FILE *hmt_fdatas = NULL;
_hmtFile = fopen(hmt_filename, "rb");
if (_hmtFile != NULL) {
hmt_fdatas = parseHMTFile(_hmtFile);
if (hmt_fdatas == NULL) printf("[ERR] Failed to parse datas from %s\n", hmt_filename);
} else {
printf("[ERR] Input file not found!\n");
}
fclose(_hmtFile);
return hmt_fdatas;
}
int exportTextures(HMT_FILE *hmt_f, char *filename) {
int i;
for (i=0; i<hmt_f->texture_count; i++) {
switch (hmt_f->textures_list[i].image.type_) {
case 0:
case 1:
saveToPNG(&(hmt_f->textures_list[i].image), hmt_f->textures_list[i].name);
//Write to PNM
break;
case 3:
//Write to TGA
break;
case 4:
case 5:
saveToPNG(&(hmt_f->textures_list[i].image), hmt_f->textures_list[i].name);
//Write to PGM
break;
default:
printf("[INFO] Image type %d not currently supported!\n", hmt_f->textures_list[i].image.type_);
}
}
return EXIT_SUCCESS;
}