Finished HMT_parser

This commit is contained in:
JackCarterSmith 2019-07-03 01:02:50 +02:00
parent de8c52e290
commit 2d7d2156ff
3 changed files with 85 additions and 1 deletions

View File

@ -6,7 +6,7 @@ int parseHMTFile(FILE *hmt_src, HMT_FILE *dst) {
if (hmt_src == NULL) return -1;
fseek(hmt_src, 0, SEEK_SET); //Rewind file at the start
rewind(hmt_src); //Rewind file at the start
fread(&(dst->material_count), 4, 1, hmt_src); // Extract first usefull datas
fread(&(dst->texture_offset), 4, 1, hmt_src);
@ -48,6 +48,52 @@ int readMaterial(HMT_MATERIAL *mat, FILE *hmt_src) {
int readTexture(HMT_TEXTURE *tex, FILE *hmt_src) {
int result = 0;
char u0,u1,bpp;
int color_rgba;
long pos;
RS_IMAGE_DESC desc;
fread(&(tex->data_offset), 4, 1, hmt_src);
fseek(hmt_src, 28, SEEK_CUR); // Skip zeros area
fread(&(tex->palette_offset), 4, 1, hmt_src);
fread(&(tex->textureName_offset), 4, 1, hmt_src);
fread(&(tex->width), 2, 1, hmt_src);
fread(&(tex->height), 2, 1, hmt_src);
fread(&u0, 1, 1, hmt_src);
fread(&bpp, 1, 1, hmt_src);
fread(&(tex->image.type_), 1, 1, hmt_src);
fread(&u1, 1, 1, hmt_src);
fread(&color_rgba, 4, 1, hmt_src);
pos = ftell(hmt_src);
fseek(hmt_src, tex->textureName_offset, SEEK_SET);
fread(&(tex->name), 16, 1, hmt_src);
fseek(hmt_src, pos, SEEK_SET);
desc = getImageDescFromType(tex->image.type_);
tex->image.paletteEntries = desc.palette_enties;
tex->image.sampleBits = desc.sample_bits;
tex->image.width = tex->width;
tex->image.height = tex->height;
printf("Texture name: %s\n", tex->name);
printf("Size w: %ld h: %ld\n", tex->width, tex->height);
printf("Texture subtype: %d\n", tex->image.type_);
printf("Palette offset: %d\n", tex->palette_offset);
printf("Data offset: %d\n", tex->data_offset);
printf("u0: %d u1: %d\n", u0, u1);
if (tex->palette_offset > 0) {
printf("\nPalette entries: %d\n", tex->image.paletteEntries);
fseek(hmt_src, tex->palette_offset, SEEK_SET);
//loadPalette(&(tex->image), stream);
}
fseek(hmt_src, tex->data_offset, SEEK_SET);
//loadSamples(&(tex->image), stream);
//decodePixels(&(tex->image));
fseek(hmt_src, pos, SEEK_SET);
return result;
}

View File

@ -1,3 +1,34 @@
#include "RS_images.h"
RS_IMAGE_DESC getImageDescFromType(unsigned char type) {
RS_IMAGE_DESC desc;
switch(type) {
case 0:
desc.palette_enties = 16;
desc.sample_bits = 4;
break;
case 1:
desc.palette_enties = 256;
desc.sample_bits = 8;
break;
case 2:
desc.palette_enties = 0;
desc.sample_bits = 16;
break;
case 3:
desc.palette_enties = 0;
desc.sample_bits = 32;
break;
case 4:
desc.palette_enties = 0;
desc.sample_bits = 4;
break;
case 5:
desc.palette_enties = 0;
desc.sample_bits = 8;
break;
}
return desc;
}

View File

@ -22,10 +22,17 @@ typedef struct RSImage {
unsigned char palette[256][3]; /**< Image palette definition */
}RS_IMAGE;
typedef struct RSImage_desc {
int palette_enties;
int sample_bits;
//char alpha;
}RS_IMAGE_DESC;
/////////////////////////////
///// Declare functions /////
/////////////////////////////
RS_IMAGE_DESC getImageDescFromType(unsigned char type);
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);