Change pixel to RGB format

TODO: update pixel decoder to 1byte gray to RGB gray value
This commit is contained in:
JackCarterSmith 2019-07-19 00:43:11 +02:00
parent 2934246375
commit a34a5d5337
4 changed files with 22 additions and 16 deletions

View File

@ -30,7 +30,7 @@ int saveToPNG(RS_IMAGE *img, char *tex_name) {
png_set_IHDR(png_ptr, info_ptr, img->width, img->height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
// Init PNG datas
row_ptrs = png_malloc(png_ptr, img->height * sizeof(png_byte));
row_ptrs = png_malloc(png_ptr, img->height * sizeof(png_byte *));
/*for (y=0; y<img->height; y++) {
png_byte *row = png_malloc(png_ptr, img->width*sizeof(unsigned char)*3);
row_ptrs[y] = row;
@ -38,7 +38,11 @@ int saveToPNG(RS_IMAGE *img, char *tex_name) {
unsigned char pixel[3] = pixelAt(img->pixels);
}
}*/
memcpy(row_ptrs, img->pixels, sizeof(unsigned char)*3*img->height*img->width);
if (img->paletteEntries == 0 || img->sampleBits == 32 || img->sampleBits == 16) {
memcpy(row_ptrs, img->pixels, sizeof(*img->pixels)*img->height*img->width);
} else {
memcpy(row_ptrs, img->pixels, sizeof(*img->pixels)*3*img->height*img->width);
}
png_init_io(png_ptr, _png_f);
png_set_rows(png_ptr, info_ptr, row_ptrs);

View File

@ -9,6 +9,8 @@ int getPaletteFromFile(RS_IMAGE *img, FILE *f) {
case 256:
fread(img->palette, sizeof(unsigned char), entries*3, f);
break;
default:
break;
}
return EXIT_SUCCESS;
@ -27,13 +29,6 @@ int getSamplesFromFile(RS_IMAGE *img, FILE *f) {
fread(img->samples, size, 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;
}
@ -81,6 +76,8 @@ void decodePixels(RS_IMAGE *img) {
img->pixels = calloc(1, size);
useOddBytes(img->samples, img->pixels, size);
break;
default:
break;
}
}
@ -150,6 +147,8 @@ RS_IMAGE_DESC getImageDescFromType(unsigned char type) {
desc.palette_enties = 0;
desc.sample_bits = 8;
break;
default:
break;
}
return desc;

View File

@ -17,6 +17,15 @@
///// Define new types //////
/////////////////////////////
/**
* @brief RGB pixel structure, used to store datas for implementation inside PNG files
*/
typedef struct PixelRGB {
char _red;
char _green;
char _blue;
}PIXEL;
/**
* @brief Image definition from Rogue Squadron HMT files
*/
@ -26,7 +35,7 @@ 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 sampleBits; /**< Bits per samble */
int paletteEntries;
unsigned char *pixels; /**< Image pixels list, managed like an array and declared as a pointer */
PIXEL *pixels; /**< Image pixels list, managed like an array and declared as a pointer */
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
}RS_IMAGE;

View File

@ -53,16 +53,10 @@ int exportTextures(HMT_FILE *hmt_f, char *filename) {
switch (hmt_f->textures_list[i].image.type_) {
case 0:
case 1:
saveToPNG(&(hmt_f->textures_list[i].image), hmt_f->textures_list[i].name);
//Write to PNM
break;
case 3:
//Write to TGA
break;
case 4:
case 5:
saveToPNG(&(hmt_f->textures_list[i].image), hmt_f->textures_list[i].name);
//Write to PGM
break;
default:
printf("[INFO] Image type %d not currently supported!\n", hmt_f->textures_list[i].image.type_);