Skip to content

Commit fa2e298

Browse files
author
roudoudou
committed
palette fixes, handling short bit depth in palette mode...
1 parent 4b18e3f commit fa2e298

File tree

2 files changed

+45
-21
lines changed

2 files changed

+45
-21
lines changed

convgeneric.c

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,8 @@ void Build(struct s_parameter *parameter)
703703
int idata=0; /* current output */
704704
int pixrequested; /* how many pix do we need for a byte? */
705705
int limitcolors=16; /* max number of colors regarding the options */
706-
int hasblack; /* index of black color if any, else -1 */
706+
int hasblack,is_hsp; /* index of black color if any, else -1 */
707+
int hsptr=-1,hsptv=-1,hsptb=-1; /* transparency color */
707708
struct s_sprite_info *spinfo=NULL; /* info about extracted sprites */
708709
struct s_sprite_info curspi={0};
709710
int ispi=0,mspi=0; /* fast counters for sprite info struct */
@@ -788,10 +789,11 @@ void Build(struct s_parameter *parameter)
788789
}
789790

790791
if (parameter->search_transparency) {
791-
// on va prendre la couleur à la con qu'on retrouve partout, en particulier dans les coin...
792-
r=photo->data[photo->width*4+0]&0xF0;
793-
v=photo->data[photo->width*4+1]&0xF0;
794-
b=photo->data[photo->width*4+2]&0xF0;
792+
// on va prendre la couleur à la con qu'on retrouve partout, en particulier dans les coins...
793+
// à faire évoluer avec un forcage RGB...
794+
hsptr=photo->data[photo->width*4+0]&0xF0;
795+
hsptv=photo->data[photo->width*4+1]&0xF0;
796+
hsptb=photo->data[photo->width*4+2]&0xF0;
795797
}
796798

797799
//*****************************************************
@@ -809,7 +811,7 @@ void Build(struct s_parameter *parameter)
809811
if (parameter->importpalettefilename) {
810812
/* load palette from a text file */
811813
char separator,*curchar,*txtpalette;
812-
int palsize,curcoul,is_hsp;
814+
int palsize,curcoul;
813815
int has_reduce=0;
814816

815817
printf(KIO"Image %dx%d\n",photo->width,photo->height);
@@ -831,16 +833,18 @@ void Build(struct s_parameter *parameter)
831833
}
832834
if (strstr(txtpalette," HSP")) is_hsp=1; else is_hsp=0;
833835
if (parameter->hsp!=is_hsp) {
834-
printf(KWARNING"Warning, palette mode is different from output mode!\n");
836+
printf(KWARNING"Warning, palette [%s] mode is different from output mode!\n",is_hsp?"HSP":"legacy");
835837
}
836838

837839
/* parse text */
838840
if (is_hsp) {
839-
palette[0]=1;
840-
palette[1]=2;
841-
palette[2]=3;
841+
// la couleur de la transparence
842+
palette[0]=hsptr;
843+
palette[1]=hsptv;
844+
palette[2]=hsptb;
842845
}
843846
maxcoul=is_hsp;
847+
printf("palette=[%s]\n",txtpalette);
844848
while ((curchar=strchr(txtpalette,separator))!=NULL) {
845849
if (maxcoul==16) {
846850
printf(KERROR"\nERROR: invalid palette! too much colorz!\n"KNORMAL);
@@ -849,10 +853,15 @@ void Build(struct s_parameter *parameter)
849853
*curchar=' ';
850854
curchar++;
851855
curcoul=strtol(curchar,NULL,16);
852-
palette[maxcoul*3+0]=curcoul&0xF0;
853-
palette[maxcoul*3+1]=(curcoul&0xF00)>>4;
854-
palette[maxcoul*3+2]=(curcoul&0xF)<<4;
855-
maxcoul++;
856+
r=curcoul&0xF0;
857+
v=(curcoul&0xF00)>>4;
858+
b=(curcoul&0xF)<<4;
859+
if (r!=hsptr || v!=hsptv || b!=hsptb) {
860+
palette[maxcoul*3+0]=curcoul&0xF0;
861+
palette[maxcoul*3+1]=(curcoul&0xF00)>>4;
862+
palette[maxcoul*3+2]=(curcoul&0xF)<<4;
863+
maxcoul++;
864+
}
856865
}
857866
printf("%d couleur%s importée%s\n",maxcoul-is_hsp,maxcoul-is_hsp>1?"s":"",maxcoul-is_hsp>1?"s":"");
858867

@@ -925,6 +934,7 @@ void Build(struct s_parameter *parameter)
925934

926935
MemFree(txtpalette);
927936
} else {
937+
is_hsp=parameter->hsp;
928938
/* as the bitmap is RGBA we must scan to find all colors */
929939
maxcoul=0;
930940
png_has_transparency=0;
@@ -1218,8 +1228,14 @@ printf(KBLUE"expand image to %d\n"KNORMAL,photo->height);
12181228

12191229

12201230
printf("paletteplus: defw ");
1221-
for (i=parameter->hsp;i<maxcoul+parameter->hsp;i++) {
1222-
printf("%s#%03X",i-parameter->hsp?",":"",(palette[i*3+0]&0xF0)|((palette[i*3+1]>>4)<<8)|(palette[i*3+2]>>4));
1231+
if (parameter->importpalettefilename) {
1232+
for (i=parameter->hsp;i<maxcoul+parameter->hsp-(1-is_hsp);i++) {
1233+
printf("%s#%03X",i-parameter->hsp?",":"",(palette[i*3+0]&0xF0)|((palette[i*3+1]>>4)<<8)|(palette[i*3+2]>>4));
1234+
}
1235+
} else {
1236+
for (i=parameter->hsp;i<maxcoul+parameter->hsp;i++) {
1237+
printf("%s#%03X",i-parameter->hsp?",":"",(palette[i*3+0]&0xF0)|((palette[i*3+1]>>4)<<8)|(palette[i*3+2]>>4));
1238+
}
12231239
}
12241240
printf("\n");
12251241

@@ -1283,11 +1299,18 @@ printf(KBLUE"expand image to %d\n"KNORMAL,photo->height);
12831299
ticpack=0; /* reset pixel counter */
12841300
for (xs=metax;xs<16+metax;xs++) {
12851301
/* transparency */
1286-
if (photo->data[(i+xs+(j+ys)*photo->width)*4+3]>0) {
1287-
zepix=GetIDXFromPixel(palette,&photo->data[(i+xs+(j+ys)*photo->width)*4+0]);
1288-
// RIEN A FAIRE!!! if (!parameter->black) zepix++;
1289-
} else {
1302+
if (parameter->search_transparency
1303+
&& photo->data[(i+xs+(j+ys)*photo->width)*4+0]==hsptr
1304+
&& photo->data[(i+xs+(j+ys)*photo->width)*4+1]==hsptv
1305+
&& photo->data[(i+xs+(j+ys)*photo->width)*4+2]==hsptb ) {
12901306
zepix=0;
1307+
} else {
1308+
if (photo->data[(i+xs+(j+ys)*photo->width)*4+3]>0) {
1309+
zepix=GetIDXFromPixel(palette,&photo->data[(i+xs+(j+ys)*photo->width)*4+0]);
1310+
// RIEN A FAIRE!!! if (!parameter->black) zepix++;
1311+
} else {
1312+
zepix=0;
1313+
}
12911314
}
12921315
/* output format */
12931316
switch (parameter->packed) {

minilib.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ printf("PNG opening [%s]\n",filename);
354354
pixel_size=3;
355355
}
356356
png_set_palette_to_rgb(png_ptr);
357+
png_info->bit_depth=8;
357358
break;
358359
case PNG_COLOR_TYPE_GRAY:
359360
pixel_size=3;
@@ -454,7 +455,7 @@ printf("PNG read OK\n");
454455
png_info->color_type=PNG_COLOR_TYPE_RGBA;
455456
png_info->data=ImageFreeRRGGBBToRRGGBBAA(png_info->data,png_info->width,png_info->height);
456457
} else {
457-
logerr("INTERNAL ERROR - cannot process PNG BD:%d CT:%d",png_info->bit_depth,png_info->color_type);
458+
logerr("INTERNAL ERROR - cannot process PNG BitDepth:%d ColType:%d",png_info->bit_depth,png_info->color_type);
458459
exit(INTERNAL_ERROR);
459460
}
460461
}

0 commit comments

Comments
 (0)