diff --git a/HMT-Extractor Debug.launch b/HMT-Extractor Debug.launch
index 002bef1..e69de29 100644
--- a/HMT-Extractor Debug.launch
+++ b/HMT-Extractor Debug.launch
@@ -1,39 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/HMT-Extractor Release.launch b/HMT-Extractor Release.launch
index 10e9c9b..e69de29 100644
--- a/HMT-Extractor Release.launch
+++ b/HMT-Extractor Release.launch
@@ -1,36 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/RS_images.c b/src/RS_images.c
index a29a080..fbb81da 100644
--- a/src/RS_images.c
+++ b/src/RS_images.c
@@ -1,7 +1,7 @@
#include "RS_images.h"
-void getPaletteFromFile(RS_IMAGE *img, FILE *f) {
+int getPaletteFromFile(RS_IMAGE *img, FILE *f) {
int entries = img->paletteEntries;
switch (entries) {
@@ -10,20 +10,24 @@ void getPaletteFromFile(RS_IMAGE *img, FILE *f) {
fread(img->palette, sizeof(unsigned char), entries*3, f);
break;
}
+
+ return EXIT_SUCCESS;
}
-void getSamplesFromFile(RS_IMAGE *img, FILE *f) {
+int getSamplesFromFile(RS_IMAGE *img, FILE *f) {
int sample_bits = img->sampleBits;
int size = img->width*img->height*div(sample_bits, 8).quot;
if (f->_bufsiz >= ftell(f)+size) {
printf("WARNING! Please fix size/sample.");
- abort();
+ return EXCEPTION_DATATYPE_MISALIGNMENT;
}
img->samples = calloc(1, size);
fread(img->samples, size, 1, f);
if (img->type_ == 2) fread(img->samples, div(size, 4).quot, 1, f);
+
+ return EXIT_SUCCESS;
}
void decodePixels(RS_IMAGE *img) {
diff --git a/src/RS_images.h b/src/RS_images.h
index 3c703c5..851aa59 100644
--- a/src/RS_images.h
+++ b/src/RS_images.h
@@ -26,7 +26,7 @@ typedef struct RSImage {
int paletteEntries;
unsigned char *pixels; /**< Image pixels list */
unsigned char *samples; /**< Image samples list */
- unsigned char palette[256][3]; /**< Image palette definition */
+ unsigned char palette[256][3]; /**< Image palette definition */ //TODO: Create union struct type instead
}RS_IMAGE;
typedef struct RSImage_desc {
@@ -45,7 +45,7 @@ void unpack4To24bitsRGB(unsigned char *samples_tab, unsigned char *pixels_tab, i
void unpack8To24bitsRGB(unsigned char *samples_tab, unsigned char *pixels_tab, int size, unsigned char pal[256][3]);
void useOddBytes(unsigned char *src, unsigned char *dst, int size);
void decodePixels(RS_IMAGE *img);
-void getPaletteFromFile(RS_IMAGE *img, FILE *f);
-void getSamplesFromFile(RS_IMAGE *img, FILE *f);
+int getPaletteFromFile(RS_IMAGE *img, FILE *f);
+int getSamplesFromFile(RS_IMAGE *img, FILE *f);
#endif
diff --git a/src/Texture-Extractor.c b/src/Texture-Extractor.c
index 46c7745..04eb911 100644
--- a/src/Texture-Extractor.c
+++ b/src/Texture-Extractor.c
@@ -1,35 +1,57 @@
/*
- ============================================================================
- Name : HMT-Extractor.c
+ ================================================================================
+ Name : Texture-Extractor.c
Author : JackCarterSmith
Version : 0.1
- Copyright : LGPL
- Description : HMT textures extractor with enhanced function in C
- ============================================================================
+ 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[]) {
- char *filename = NULL;
- FILE *testfile = NULL;
- HMT_FILE *testhmt = calloc(1, sizeof(HMT_FILE));
+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 \n");
- return EXIT_FAILURE;
+ return EXCEPTION_NONCONTINUABLE; //TODO: implement own error codes system
}
- filename = argv[1];
- testfile = fopen(filename, "rb");
- int op_result = parseHMTFile(testfile, testhmt);
- fclose(testfile);
-
- switch (op_result) {
- case -1:
- printf("[ERR] Wrong inputs values!\n");
- break;
- }
+ // Do the work
+ hmt_fdatas = extractDatasFromHMT(argv[1]); //TODO: Manage multi inputs files
+ exportTextures(hmt_fdatas, argv[1]);
+ purgeHMTFromMemory(hmt_fdatas); // Clean up memory (because I'm a good boy)
return EXIT_SUCCESS;
}
+
+void purgeHMTFromMemory(HMT_FILE *_f) {
+ free(_f->textures_list->image.pixels);
+ free(_f->textures_list->image.samples);
+ free(_f->materials_list);
+ free(_f->textures_list);
+ free(_f);
+}
+
+HMT_FILE *extractDatasFromHMT(char *hmt_filename) {
+ FILE *_hmtFile = fopen(hmt_filename, "rb");
+ HMT_FILE *hmt_fdatas = calloc(1, sizeof(HMT_FILE));
+
+ if (parseHMTFile(_hmtFile, hmt_fdatas) != EXIT_SUCCESS) purgeHMTFromMemory(hmt_fdatas);
+
+ fclose(_hmtFile);
+
+ return hmt_fdatas;
+}
+
+int exportTextures(HMT_FILE *hmt_f, char *filename) {
+ return EXIT_SUCCESS;
+}
+
+int saveToPNG(RS_IMAGE *img, char *tex_name) {
+ return EXIT_SUCCESS;
+}
diff --git a/src/Texture-Extractor.h b/src/Texture-Extractor.h
index 32c1f58..fe8d398 100644
--- a/src/Texture-Extractor.h
+++ b/src/Texture-Extractor.h
@@ -4,11 +4,14 @@
#include
#include
#include
-#include
+//#include
#include
#include "HMT_Parser.h"
#include "RS_images.h"
-int exportToPNM(FILE *f, RS_IMAGE *img);
+void purgeHMTFromMemory(HMT_FILE *_f);
+HMT_FILE *extractDatasFromHMT(char* hmt_filename);
+int exportTextures(HMT_FILE *hmt_f, char *filename);
+int saveToPNG(RS_IMAGE *img, char *tex_name);
#endif