Fixed pixels not decoding correctly
TODO: Try to make first PNG file
This commit is contained in:
parent
7861c872fb
commit
2934246375
@ -13,7 +13,7 @@ HMT_FILE *parseHMTFile(FILE *hmt_src) {
|
|||||||
|
|
||||||
// Read materials
|
// Read materials
|
||||||
printf("\n\nMaterials detected: %d\n", _buff->material_count);
|
printf("\n\nMaterials detected: %d\n", _buff->material_count);
|
||||||
_buff->materials_list = calloc(_buff->material_count, sizeof(HMT_MATERIAL));
|
_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
|
||||||
if (readMaterial(&(_buff->materials_list[i]), hmt_src) != 0) {
|
if (readMaterial(&(_buff->materials_list[i]), hmt_src) != 0) {
|
||||||
@ -27,7 +27,7 @@ HMT_FILE *parseHMTFile(FILE *hmt_src) {
|
|||||||
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("\n\nTextures detected: %d\n", _buff->texture_count);
|
||||||
if (_buff->texture_count > 0) {
|
if (_buff->texture_count > 0) {
|
||||||
_buff->textures_list = calloc(_buff->texture_count, sizeof(HMT_TEXTURE));
|
_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++) {
|
||||||
// Extract textures datas
|
// Extract textures datas
|
||||||
if (readTexture(&(_buff->textures_list[i]), hmt_src) != 0) {
|
if (readTexture(&(_buff->textures_list[i]), hmt_src) != 0) {
|
||||||
|
@ -37,7 +37,6 @@ typedef struct HMTMaterial {
|
|||||||
int zero;
|
int zero;
|
||||||
int hex_a;
|
int hex_a;
|
||||||
char name[16];
|
char name[16];
|
||||||
struct HMTMaterial *_next;
|
|
||||||
}HMT_MATERIAL;
|
}HMT_MATERIAL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,18 +75,18 @@ typedef struct HMTTexture {
|
|||||||
unsigned long width, height;
|
unsigned long width, height;
|
||||||
char name[16];
|
char name[16];
|
||||||
RS_IMAGE image;
|
RS_IMAGE image;
|
||||||
struct HMTTexture *_next;
|
|
||||||
}HMT_TEXTURE;
|
}HMT_TEXTURE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief HMT file struct
|
* @brief Instance of HMTFile in memory
|
||||||
|
* This structure contain all parsed data for a single HMT file.
|
||||||
*/
|
*/
|
||||||
typedef struct HMTFile {
|
typedef struct HMTFile {
|
||||||
int material_count;
|
int material_count; /**< Number of materials registered inside HMTFile instance. */
|
||||||
int texture_offset;
|
int texture_offset; /**< Address from which texture data begins. */
|
||||||
int texture_count;
|
int texture_count; /**< Number of textures registered inside HMTFile instance. */
|
||||||
HMT_MATERIAL *materials_list;
|
HMT_MATERIAL *materials_list; /**< Starting pointer of the materials list. Managed like an array and declared as a pointer */
|
||||||
HMT_TEXTURE *textures_list;
|
HMT_TEXTURE *textures_list; /**< Starting pointer of the textures list. Managed like an array and declared as a pointer*/
|
||||||
}HMT_FILE;
|
}HMT_FILE;
|
||||||
|
|
||||||
|
|
||||||
@ -97,6 +96,10 @@ typedef struct HMTFile {
|
|||||||
HMT_FILE *parseHMTFile(FILE *hmt_src);
|
HMT_FILE *parseHMTFile(FILE *hmt_src);
|
||||||
int readMaterial(HMT_MATERIAL *mat, FILE *hmt_src);
|
int readMaterial(HMT_MATERIAL *mat, FILE *hmt_src);
|
||||||
int readTexture(HMT_TEXTURE *tex, FILE *hmt_src);
|
int readTexture(HMT_TEXTURE *tex, FILE *hmt_src);
|
||||||
|
HMT_MATERIAL *getMaterialFromIndex(int i);
|
||||||
|
HMT_MATERIAL *getMaterialFromName(char *matName);
|
||||||
|
HMT_TEXTURE *getTextureFromIndex(int i);
|
||||||
|
HMT_TEXTURE *getTextureFromMaterial(HMT_MATERIAL *mat);
|
||||||
void purgeHMTFromMemory(HMT_FILE *_f);
|
void purgeHMTFromMemory(HMT_FILE *_f);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,7 +16,7 @@ int getPaletteFromFile(RS_IMAGE *img, FILE *f) {
|
|||||||
|
|
||||||
int getSamplesFromFile(RS_IMAGE *img, FILE *f) {
|
int getSamplesFromFile(RS_IMAGE *img, FILE *f) {
|
||||||
int sample_bits = img->sampleBits;
|
int sample_bits = img->sampleBits;
|
||||||
int size = img->width*img->height*div(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("WARNING! Please fix size/sample.");
|
||||||
@ -27,6 +27,13 @@ int getSamplesFromFile(RS_IMAGE *img, FILE *f) {
|
|||||||
fread(img->samples, size, 1, f);
|
fread(img->samples, size, 1, f);
|
||||||
if (img->type_ == 2) fread(img->samples, div(size, 4).quot, 1, f);
|
if (img->type_ == 2) fread(img->samples, div(size, 4).quot, 1, f);
|
||||||
|
|
||||||
|
/*
|
||||||
|
unsigned char temp[size];
|
||||||
|
for (int i=0; i<size; i++) {
|
||||||
|
temp[i] = img->samples[i];
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,12 +41,12 @@ void decodePixels(RS_IMAGE *img) {
|
|||||||
int size;
|
int size;
|
||||||
|
|
||||||
img->pixels = NULL;
|
img->pixels = NULL;
|
||||||
if (img->type_ != 0 ||
|
if (!(img->type_ == 0 ||
|
||||||
img->type_ != 1 ||
|
img->type_ == 1 ||
|
||||||
img->type_ != 2 ||
|
img->type_ == 2 ||
|
||||||
img->type_ != 3 ||
|
img->type_ == 3 ||
|
||||||
img->type_ != 4 ||
|
img->type_ == 4 ||
|
||||||
img->type_ != 5) return;
|
img->type_ == 5)) return;
|
||||||
|
|
||||||
switch (img->sampleBits) {
|
switch (img->sampleBits) {
|
||||||
case 32:
|
case 32:
|
||||||
|
@ -26,8 +26,8 @@ typedef struct RSImage {
|
|||||||
unsigned char type_; /**< Image type (0 = RBG/4bits per pixel, 1 = RBG/8bpp, 3 = RGBA/32bpp , 4 = grayscale/4bpp, 5 = grayscale/8bpp */
|
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 */
|
unsigned char sampleBits; /**< Bits per samble */
|
||||||
int paletteEntries;
|
int paletteEntries;
|
||||||
unsigned char *pixels; /**< Image pixels list */
|
unsigned char *pixels; /**< Image pixels list, managed like an array and declared as a pointer */
|
||||||
unsigned char *samples; /**< Image samples list */
|
unsigned char *samples; /**< Image samples list managed like an array and declared as a pointer */
|
||||||
unsigned char palette[256][3]; /**< Image palette definition */ //TODO: Create union struct type instead
|
unsigned char palette[256][3]; /**< Image palette definition */ //TODO: Create union struct type instead
|
||||||
}RS_IMAGE;
|
}RS_IMAGE;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user