hello guys!
I'm just programming a big sprited game, and thus I need to make paletised sprites.
I did it one for one pixel/char, and like I'm using 16-colored sprites, I wanted to make a compressor for two pixels/char.
With the help from Ashbad, We edited a program from PierrotLL.
But, the second pixel i totally ignored...
input: short datas
"65535,45468,45468,65535" wille be taken for 2 pixels
output:
"0,0x1,0x1,0" //sprite
"655535,45468" // palette.
Code:
I'll thanks any help from your initative. Thanks!
I'm just programming a big sprited game, and thus I need to make paletised sprites.
I did it one for one pixel/char, and like I'm using 16-colored sprites, I wanted to make a compressor for two pixels/char.
With the help from Ashbad, We edited a program from PierrotLL.
But, the second pixel i totally ignored...
input: short datas
"65535,45468,45468,65535" wille be taken for 2 pixels
output:
"0,0x1,0x1,0" //sprite
"655535,45468" // palette.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int color_swatches[1024], nb_color=0;
int swatches(int color1, int color2)
{
int i, l = 0, j = 0;
for(i=0 ; i<nb_color ; i++) {
if(color1 == color_swatches[i]) {
j = (i&0x0F) << 4;
i = -1;
break;
}
}
if(i>=nb_color) {
color_swatches[i] = color1;
nb_color++;
j = (nb_color&0x0F) << 4;
}
for(l = 0; l < nb_color; l++) {
if(color2 == color_swatches[i])
j |= i&0x0F;
return j;
}
color_swatches[l] = color2;
nb_color++;
return j;
}
int main()
{
int c, n1=0, n2 = 0;
FILE *input, *output;
unsigned char resultname[] = "out\\Rpk000.c";
unsigned char inputname[] = "in\\Pk000.c";
for(int i = 1; i < 152; i++)
{
resultname[7] = '0' + i /100;
resultname[8] = '0' + (i/10)%10;
resultname[9] = '0' + i%10;
inputname[5] = resultname[7];
inputname[6] = resultname[8];
inputname[7] = resultname[9];
printf("N %i : %s ; %s ; ", i, inputname, resultname);
input = fopen(inputname, "r");
if(input != NULL)
printf("Ouverture bien faite; ");
else
{
printf("Ouverture failed; \n");
continue;
}
output = fopen(resultname, "w+");
if(output != NULL)
printf("Ouverture bien faite; ");
else
{
printf("Ouverture failed;\n");
continue;
}
printf("\n");
fprintf(output, "unsigned char m[] = {\n");
nb_color=-1;
for(int i = 0;i< 1024; i++)
color_swatches[i] = 65535;
int alignment_check = 0;
while((c = fgetc(input)) != EOF) {
switch(c) {
case '\t': fputc(c, output); break;
case '\n': fputc(c, output); break;
case EOF: break;
case ',':
if(!alignment_check) {
alignment_check = 1;
} else {
fprintf(output, "%p,", swatches(n1, n2));
n1=0; n2=0;
alignment_check = 0;
}
break;
default:
if(c>='0' && c<='9') {
if(!alignment_check) {
n1 = n1*10 + c-'0';
} else {
n2 = n2*10 + c-'0';
}
}
break;
}
}
fseek ( output , -3 , SEEK_CUR );
fprintf(output, " \n};");
fprintf(output, "\n\nunsigned short p[] = {", i);
for(int n=0 ; n<nb_color ; n++)
fprintf(output, "%p,", color_swatches[n]);
fseek ( output , -1 , SEEK_CUR );
fprintf(output, "};\n\n");
fclose(input);
fclose(output);
}
}
I'll thanks any help from your initative. Thanks!