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"
extern int _options; // Global options settings variable
HMT_FILE *parseHMTFile(FILE *hmt_src) {
int i;
HMT_FILE *_buff = NULL;
@ -12,7 +15,7 @@ HMT_FILE *parseHMTFile(FILE *hmt_src) {
fread(&(_buff->texture_offset), 4, 1, hmt_src);
// 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
for (i=0; i<_buff->material_count; i++) {
// Extract materials datas
@ -25,7 +28,7 @@ HMT_FILE *parseHMTFile(FILE *hmt_src) {
// Read textures
fseek(hmt_src, _buff->texture_offset, SEEK_SET);
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) {
_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++) {
@ -45,8 +48,10 @@ int readMaterial(HMT_MATERIAL *mat, FILE *hmt_src) {
fread(mat, sizeof(HMT_MATERIAL), 1, hmt_src);
if (_options & 0x1) {
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;
}
@ -83,6 +88,7 @@ int readTexture(HMT_TEXTURE *tex, FILE *hmt_src) {
tex->image.width = tex->width;
tex->image.height = tex->height;
if (_options & VERBOSE_ENABLED) {
printf("\n");
printf("Texture name: %s\n", tex->name);
printf("Size w: %ld h: %ld\n", tex->width, tex->height);
@ -91,9 +97,10 @@ int readTexture(HMT_TEXTURE *tex, FILE *hmt_src) {
printf("Data offset: %d\n", tex->data_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("u0: %d u1: %d\n", u0, u1);
}
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);
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;
if (f->_bufsiz >= ftell(f)+size) {
printf("WARNING! Please fix size/sample.");
printf("[ERR] WARNING! Please fix size/sample.");
return EXIT_FAILURE;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,13 +10,11 @@
#include <sys/types.h>
#include <sys/stat.h>
#endif
#include "options.h"
#include "HMT_Parser.h"
#include "RS_images.h"
#include "Image_Exporter.h"
#define VERBOSE_ENABLED 0x0001
#define NO_OUTPUT_DIR 0x0002
void createSubDir(char *dirName);
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