Finish add verbose option

This commit is contained in:
JackCarterSmith 2019-07-21 17:20:22 +02:00
parent 9999530948
commit f70f4a698b
9 changed files with 44 additions and 21 deletions

View File

@ -1,5 +1,8 @@
#include "HMT_Parser.h" #include "HMT_Parser.h"
extern int _options; // Global options settings variable
HMT_FILE *parseHMTFile(FILE *hmt_src) { HMT_FILE *parseHMTFile(FILE *hmt_src) {
int i; int i;
HMT_FILE *_buff = NULL; HMT_FILE *_buff = NULL;
@ -12,7 +15,7 @@ HMT_FILE *parseHMTFile(FILE *hmt_src) {
fread(&(_buff->texture_offset), 4, 1, hmt_src); fread(&(_buff->texture_offset), 4, 1, hmt_src);
// Read materials // Read materials
printf("\n\nMaterials detected: %d\n", _buff->material_count); printf("[INFO] Materials detected: %d\n", _buff->material_count);
_buff->materials_list = calloc(_buff->material_count, sizeof(HMT_MATERIAL)); // Create a big list of materials entries _buff->materials_list = calloc(_buff->material_count, sizeof(HMT_MATERIAL)); // Create a big list of materials entries
for (i=0; i<_buff->material_count; i++) { for (i=0; i<_buff->material_count; i++) {
// Extract materials datas // Extract materials datas
@ -25,7 +28,7 @@ HMT_FILE *parseHMTFile(FILE *hmt_src) {
// Read textures // Read textures
fseek(hmt_src, _buff->texture_offset, SEEK_SET); fseek(hmt_src, _buff->texture_offset, SEEK_SET);
fread(&(_buff->texture_count), 4, 1, hmt_src); fread(&(_buff->texture_count), 4, 1, hmt_src);
printf("\n\nTextures detected: %d\n", _buff->texture_count); printf("[INFO] Textures detected: %d\n\n", _buff->texture_count);
if (_buff->texture_count > 0) { if (_buff->texture_count > 0) {
_buff->textures_list = calloc(_buff->texture_count, sizeof(HMT_TEXTURE)); // Create a big list of textures entries _buff->textures_list = calloc(_buff->texture_count, sizeof(HMT_TEXTURE)); // Create a big list of textures entries
for (i=0; i<_buff->texture_count; i++) { for (i=0; i<_buff->texture_count; i++) {
@ -45,8 +48,10 @@ int readMaterial(HMT_MATERIAL *mat, FILE *hmt_src) {
fread(mat, sizeof(HMT_MATERIAL), 1, hmt_src); fread(mat, sizeof(HMT_MATERIAL), 1, hmt_src);
if (mat->zero != 0 || mat->hex_a != 0x0A) printf("\n Uncommon file detected!\n"); if (_options & 0x1) {
printf("Material type: %d\nTexture index: %d\n", mat->type_, mat->texture_index); if (mat->zero != 0 || mat->hex_a != 0x0A) printf("\n Uncommon file detected!\n");
printf("Material type: %d\nTexture index: %d\n", mat->type_, mat->texture_index);
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
@ -83,17 +88,19 @@ int readTexture(HMT_TEXTURE *tex, FILE *hmt_src) {
tex->image.width = tex->width; tex->image.width = tex->width;
tex->image.height = tex->height; tex->image.height = tex->height;
printf("\n"); if (_options & VERBOSE_ENABLED) {
printf("Texture name: %s\n", tex->name); printf("\n");
printf("Size w: %ld h: %ld\n", tex->width, tex->height); printf("Texture name: %s\n", tex->name);
printf("Texture subtype: %d\n", tex->image.type_); printf("Size w: %ld h: %ld\n", tex->width, tex->height);
printf("Palette offset: %d\n", tex->palette_offset); printf("Texture subtype: %d\n", tex->image.type_);
printf("Data offset: %d\n", tex->data_offset); printf("Palette offset: %d\n", tex->palette_offset);
printf("Transparent color (RGB): %X %X %X\n", tex->image.alpha_color._red, tex->image.alpha_color._green, tex->image.alpha_color._blue); printf("Data offset: %d\n", tex->data_offset);
printf("u0: %d u1: %d\n", u0, u1); printf("Transparent color (RGB): %X %X %X\n", tex->image.alpha_color._red, tex->image.alpha_color._green, tex->image.alpha_color._blue);
printf("u0: %d u1: %d\n", u0, u1);
}
if (tex->palette_offset > 0) { if (tex->palette_offset > 0) {
printf("\nPalette entries: %d\n", tex->image.paletteEntries); if (_options & VERBOSE_ENABLED) printf("\nPalette entries: %d\n", tex->image.paletteEntries);
fseek(hmt_src, tex->palette_offset, SEEK_SET); fseek(hmt_src, tex->palette_offset, SEEK_SET);
getPaletteFromFile(&(tex->image), hmt_src); getPaletteFromFile(&(tex->image), hmt_src);
} }
@ -126,7 +133,7 @@ int getSamplesFromFile(RS_IMAGE *img, FILE *f) {
int size = div(img->width*img->height*sample_bits, 8).quot; int size = div(img->width*img->height*sample_bits, 8).quot;
if (f->_bufsiz >= ftell(f)+size) { if (f->_bufsiz >= ftell(f)+size) {
printf("WARNING! Please fix size/sample."); printf("[ERR] WARNING! Please fix size/sample.");
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -3,6 +3,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "options.h"
#include "RS_images.h" #include "RS_images.h"
///////////////////////////// /////////////////////////////

View File

@ -1,6 +1,8 @@
#include "Image_Exporter.h" #include "Image_Exporter.h"
//extern int _options; // Global options settings variable
int saveToPNG(RS_IMAGE *img, char *tex_path, char *hmt_fileName) { int saveToPNG(RS_IMAGE *img, char *tex_path, char *hmt_fileName) {
if (tex_path == NULL || img == NULL) return EXIT_FAILURE; if (tex_path == NULL || img == NULL) return EXIT_FAILURE;
char export_path[128]; char export_path[128];

View File

@ -1,6 +1,7 @@
#ifndef IMAGE_EXPORTER_H_ #ifndef IMAGE_EXPORTER_H_
#define IMAGE_EXPORTER_H_ #define IMAGE_EXPORTER_H_
//#include "options.h"
#include "RS_images.h" #include "RS_images.h"
#include <zlib.h> #include <zlib.h>
#include <png.h> #include <png.h>

View File

@ -1,6 +1,8 @@
#include "RS_images.h" #include "RS_images.h"
//extern int _options; // Global options settings variable
void decodePixels(RS_IMAGE *img) { void decodePixels(RS_IMAGE *img) {
int size; int size;

View File

@ -4,6 +4,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
//#include "options.h"
/** /**
* @brief Constant contain the number of channel inside a PIXEL definition. * @brief Constant contain the number of channel inside a PIXEL definition.
*/ */

View File

@ -2,7 +2,7 @@
================================================================================ ================================================================================
Name : Texture-Extractor.c Name : Texture-Extractor.c
Author : JackCarterSmith Author : JackCarterSmith
Version : 1.0 Version : 1.0a
License : GPL-v3.0 License : GPL-v3.0
Description : DAT textures extractor to PNG format with enhanced function in C Description : DAT textures extractor to PNG format with enhanced function in C
================================================================================ ================================================================================
@ -11,7 +11,7 @@
#include "Texture-Extractor.h" #include "Texture-Extractor.h"
int _options = 0x0000; // Global options settings variable extern int _options; // Global options settings variable
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
// Init buffer vars // Init buffer vars
@ -27,7 +27,7 @@ int main(int argc, char *argv[]) {
if (_options == -1) return EXIT_SUCCESS; if (_options == -1) return EXIT_SUCCESS;
// Do the work // Do the work
for (file_index=(_options >> 8) & 0xFF; file_index<argc; file_index++) { for (file_index=(_options >> 8) & 0xFF; file_index<argc; file_index++) { // Manage multiple inputs files
hmt_fdatas = extractDatasFromHMT(argv[file_index]); hmt_fdatas = extractDatasFromHMT(argv[file_index]);
if (hmt_fdatas == NULL) return EXIT_FAILURE; if (hmt_fdatas == NULL) return EXIT_FAILURE;
if (exportTextures(hmt_fdatas, argv[file_index]) == EXIT_FAILURE) return EXIT_FAILURE; if (exportTextures(hmt_fdatas, argv[file_index]) == EXIT_FAILURE) return EXIT_FAILURE;
@ -56,7 +56,7 @@ int checkArgs(char *args[], int arg_nbr) {
_o |= NO_OUTPUT_DIR; _o |= NO_OUTPUT_DIR;
printf("[INFO] Extract to current directory.\n"); printf("[INFO] Extract to current directory.\n");
} else { } else {
printf("[INFO] Unknow option: %s\n", args[i]); printf("[INFO] Unknown option: %s\n", args[i]);
} }
} }
_o = (i << 8) | (_o & 0x00FF); _o = (i << 8) | (_o & 0x00FF);
@ -84,6 +84,7 @@ HMT_FILE *extractDatasFromHMT(char *hmt_filename) {
_hmtFile = fopen(hmt_filename, "rb"); _hmtFile = fopen(hmt_filename, "rb");
if (_hmtFile != NULL) { if (_hmtFile != NULL) {
printf("\n[INFO] - Parsing file: %s\n", hmt_filename);
hmt_fdatas = parseHMTFile(_hmtFile); hmt_fdatas = parseHMTFile(_hmtFile);
if (hmt_fdatas == NULL) printf("[ERR] Failed to parse datas from %s\n", hmt_filename); if (hmt_fdatas == NULL) printf("[ERR] Failed to parse datas from %s\n", hmt_filename);
} else { } else {

View File

@ -10,13 +10,11 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
#include "options.h"
#include "HMT_Parser.h" #include "HMT_Parser.h"
#include "RS_images.h" #include "RS_images.h"
#include "Image_Exporter.h" #include "Image_Exporter.h"
#define VERBOSE_ENABLED 0x0001
#define NO_OUTPUT_DIR 0x0002
void createSubDir(char *dirName); void createSubDir(char *dirName);
int checkArgs(char *args[], int arg_nbr); int checkArgs(char *args[], int arg_nbr);

9
src/options.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef OPTIONS_H_
#define OPTIONS_H_
#define VERBOSE_ENABLED 0x0001
#define NO_OUTPUT_DIR 0x0002
int _options;
#endif