Done textures decoder
Next step, convert to PNG format
This commit is contained in:
parent
1c12db0eae
commit
93d9689cfe
@ -8,6 +8,7 @@ void getPaletteFromFile(RS_IMAGE *img, FILE *f) {
|
|||||||
case 16:
|
case 16:
|
||||||
case 256:
|
case 256:
|
||||||
fread(img->palette, sizeof(unsigned char), entries*3, f);
|
fread(img->palette, sizeof(unsigned char), entries*3, f);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,60 +45,61 @@ void decodePixels(RS_IMAGE *img) {
|
|||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
if (img->paletteEntries == 0) {
|
if (img->paletteEntries == 0) {
|
||||||
|
size = img->width * img->height;
|
||||||
img->pixels = calloc(1, size);
|
img->pixels = calloc(1, size);
|
||||||
unpack4To8bits(img->samples, img->pixels, size);
|
unpack4To8bits(img->samples, img->pixels, size);
|
||||||
} else if (img->paletteEntries == 16) {
|
} else if (img->paletteEntries == 16) {
|
||||||
|
size = img->width * img->height;
|
||||||
img->pixels = calloc(1, size*3);
|
img->pixels = calloc(1, size*3);
|
||||||
unpack4To24bitsRGB(img->samples, img->pixels, size, img->palette);
|
unpack4To24bitsRGB(img->samples, img->pixels, size, img->palette);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
if (img->paletteEntries == 0) {
|
if (img->paletteEntries == 0) {
|
||||||
|
size = img->width * img->height;
|
||||||
img->pixels = calloc(1, size);
|
img->pixels = calloc(1, size);
|
||||||
memcpy(img->pixels, img->samples, size);
|
memcpy(img->pixels, img->samples, size);
|
||||||
} else if (img->paletteEntries == 256) {
|
} else if (img->paletteEntries == 256) {
|
||||||
|
size = img->width * img->height;
|
||||||
img->pixels = calloc(1, size*3);
|
img->pixels = calloc(1, size*3);
|
||||||
unpack8To24bitsRGB(img->samples, img->pixels, size, img->palette);
|
unpack8To24bitsRGB(img->samples, img->pixels, size, img->palette);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
|
size = img->width * img->height;
|
||||||
img->pixels = calloc(1, size);
|
img->pixels = calloc(1, size);
|
||||||
useOddBytes(img->samples, img->pixels, size);
|
useOddBytes(img->samples, img->pixels, size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void unpack4To8bits(unsigned char *src, unsigned char *dst, int sampling) {
|
void unpack4To8bits(unsigned char *samples_tab, unsigned char *pixels_tab, int sampling) {
|
||||||
int i;
|
int i;
|
||||||
char v;
|
char v;
|
||||||
|
|
||||||
for(i=0; i<div(sampling,2).quot; i++) {
|
for(i=0; i<div(sampling,2).quot; i++) {
|
||||||
v = src[i];
|
v = samples_tab[i];
|
||||||
dst[i*2] = ((v >> 4) & 0xF) << 4;
|
pixels_tab[i*2] = ((v >> 4) & 0xF) << 4;
|
||||||
dst[i*2+1] = (v & 0xF) << 4;
|
pixels_tab[i*2+1] = (v & 0xF) << 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void unpack4To24bitsRGB(unsigned char *src, unsigned char *dst, int size, unsigned char pal[256][3]) {
|
void unpack4To24bitsRGB(unsigned char *samples_tab, unsigned char *pixels_tab, int size, unsigned char pal[256][3]) {
|
||||||
int i,index;
|
int i,index;
|
||||||
//unsigned char _pRGB[3]; //TODO: Can be remove and use 'dst' directly
|
|
||||||
|
|
||||||
//_pRGB = dst;
|
|
||||||
for(i=0; i<div(size,2).quot; i++) {
|
for(i=0; i<div(size,2).quot; i++) {
|
||||||
index = src[i];
|
index = samples_tab[i];
|
||||||
dst[i*2] = pal[(index >> 4) & 0xF];
|
memcpy(&(pixels_tab[i*2]), pal[(index >> 4) & 0xF], sizeof(unsigned char)*3);
|
||||||
dst[i*2+1] = pal[index & 0xF];
|
memcpy(&(pixels_tab[i*2+1]), pal[index & 0xF], sizeof(unsigned char)*3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void unpack8To24bitsRGB(unsigned char *src, unsigned char *dst, int size, unsigned char pal[256][3]) {
|
void unpack8To24bitsRGB(unsigned char *samples_tab, unsigned char *pixels_tab, int size, unsigned char pal[256][3]) {
|
||||||
int i,index;
|
int i,index;
|
||||||
unsigned char _pRGB[3]; //TODO: Can be remove and use 'dst' directly
|
|
||||||
|
|
||||||
_pRGB = dst;
|
|
||||||
for(i=0; i<size; i++) {
|
for(i=0; i<size; i++) {
|
||||||
index = src[i];
|
index = samples_tab[i];
|
||||||
_pRGB[i] = pal[index];
|
memcpy(&(pixels_tab[i]), pal[index], sizeof(unsigned char)*3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,9 +40,9 @@ typedef struct RSImage_desc {
|
|||||||
///// Declare functions /////
|
///// Declare functions /////
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
RS_IMAGE_DESC getImageDescFromType(unsigned char type); //TODO: Optimise function
|
RS_IMAGE_DESC getImageDescFromType(unsigned char type); //TODO: Optimise function
|
||||||
void unpack4To8bits(unsigned char *src, unsigned char *dst, int sampling);
|
void unpack4To8bits(unsigned char *samples_tab, unsigned char *pixels_tab, int sampling);
|
||||||
void unpack4To24bitsRGB(unsigned char *src, unsigned char *dst, int size, unsigned char pal[256][3]);
|
void unpack4To24bitsRGB(unsigned char *samples_tab, unsigned char *pixels_tab, int size, unsigned char pal[256][3]);
|
||||||
void unpack8To24bitsRGB(unsigned char *src, unsigned char *dst, int size, unsigned char pal[256][3]);
|
void unpack8To24bitsRGB(unsigned char *samples_tab, unsigned char *pixels_tab, int size, unsigned char pal[256][3]);
|
||||||
void useOddBytes(unsigned char *src, unsigned char *dst, int size);
|
void useOddBytes(unsigned char *src, unsigned char *dst, int size);
|
||||||
void decodePixels(RS_IMAGE *img);
|
void decodePixels(RS_IMAGE *img);
|
||||||
void getPaletteFromFile(RS_IMAGE *img, FILE *f);
|
void getPaletteFromFile(RS_IMAGE *img, FILE *f);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user