First code release

This commit is contained in:
JackCarterSmith 2019-07-02 18:26:21 +02:00
parent 7380e19c69
commit a95e202f29
7 changed files with 2663 additions and 0 deletions

2492
Doxyfile Normal file

File diff suppressed because it is too large Load Diff

19
src/HMT-Extractor.c Normal file
View File

@ -0,0 +1,19 @@
/*
============================================================================
Name : HMT-Extractor.c
Author : JackCarterSmith
Version : 1.0
Copyright : LGPL
Description : HMT textures extractor with enhanced function in C
============================================================================
*/
#include "HMT_Parser.h"
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("No input file specified!\nCorrect syntax is:\n HMT-Extractor <texture_file_hmt>\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

13
src/HMT-Extractor.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef HMT_EXTRACTOR_H_
#define HMT_EXTRACTOR_H_
#include <stdio.h>
#include <stdlib.h>
#include <zlib.h>
#include <png.h>
#include "HMT_Parser.h"
#include "RS_images.h"
int exportToPNM(FILE *f, RS_IMAGE *img);
#endif

3
src/HMT_Parser.c Normal file
View File

@ -0,0 +1,3 @@
#include "HMT-Extractor.h"

97
src/HMT_Parser.h Normal file
View File

@ -0,0 +1,97 @@
#ifndef HMT_PARSER_H_
#define HMT_PARSER_H_
#include <stdio.h>
#include <stdlib.h>
#include "RS_images.h"
/////////////////////////////
///// Define HMT types //////
/////////////////////////////
/**
* @brief Material struct inside HMT file type
*
* Actual RE material struct:\n
* 4B material entry count MC\n
* 4B offset after material entries / offset to textures\n
* MC * material entry (36B)\n
* [\n
* 2B int material/texture type:\n
* 1 - material with texture\n
* 2 - material without texture\n
* 2B int texture index\n
* 4B float (scale factor?)\n
* 4B float (always 1.0)\n
* 4B int zero\n
* 4B int 0x0A\n
* 16B name\n
* ]\n
*
* @image html hmt_materialDef.png
*/
typedef struct HMTMaterial {
short type_; /**< Material type:\n 1 = Material with texture\n 2 = Material without texture */
short texture_index;
float unknow1,unknow2;
int zero;
int hex_a;
char *name[16];
}HMT_MATERIAL;
/**
* @brief Texture struct inside HMT file type
*
* Actual RE texture struct:\n
* 4B int texcount Tc\n
* TC * texture entry 52B\n
* [\n
* 4B int pixel offset\n
* 28B zero\n
* 4B int palette offset, 0 = no palette\n
* 4B int texname offset\n
* 2B int width\n
* 2B int height\n
* 8B texture format [\n
* 1B int : always 1?\n
* 1B int : bits per sample?\n
* 1B int : subtype:\n
* -0 - palette 16x3B RGB, 4bit per pixel\n
* -1 - 256x3B palette RGB, 8bit per pixel\n
* -3 - RGBA 32bpp\n
* -4 - greyscale, 4bpp\n
* -5 - grayscale, 8bpp\n
* 1B int ? 0, 0x40, 0x80\n
* 4B RGBA transparent color?\n
* ]\n
* ]\n
*
* @image html hmt_textureDef.png
*/
typedef struct HMTTexture {
int data_offset;
int palette_offset;
int textureName_offset;
unsigned long width, height;
char *name[16];
RS_IMAGE image;
}HMT_TEXTURE;
/**
* @brief HMT file struct
*/
typedef struct HMTFile {
int material_count;
int texture_offset;
int texture_count;
HMT_MATERIAL *materials_list;
HMT_TEXTURE *textures_list;
}HMT_FILE;
/////////////////////////////
///// Declare functions /////
/////////////////////////////
int exportToPNM(FILE *f, RS_IMAGE *img);
#endif

3
src/RS_images.c Normal file
View File

@ -0,0 +1,3 @@
#include "RS_images.h"

36
src/RS_images.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef RS_IMAGES_H_
#define RS_IMAGES_H_
#include <stdio.h>
#include <stdlib.h>
/////////////////////////////
///// Define new types //////
/////////////////////////////
/**
* @brief Image definition from Rogue Squadron HMT files
*/
typedef struct RSImage {
int data_size; /**< Image bytes size */
int width, height;
unsigned char type_; /**< Image type (0 = RBG/4bits per pixel, 1 = RBG/8bpp, 3 = RGBA/32bpp , 4 = grayscale/4bpp, 5 = grayscale/8bpp */
unsigned char sampleBits; /**< Bits per samble */
int paletteEntries;
unsigned char *pixels; /**< Image pixels list */
unsigned char *samples; /**< Image samples list */
unsigned char palette[256][3]; /**< Image palette definition */
}RS_IMAGE;
/////////////////////////////
///// Declare functions /////
/////////////////////////////
void Unpack4To8bit(unsigned char *src, unsigned char *dst, int sampling);
void Unpack4bitTo24bitRGB(unsigned char *src, unsigned char *dst, int size, unsigned char pal[256][3]);
void UseOddBytes(unsigned char *src, unsigned char *dst, int size);
void DecodePixel(RS_IMAGE img);
int WritePaletteToFile(RS_IMAGE img, FILE *f);
int WriteSamplesToFile(RS_IMAGE img, FILE *f);
#endif