@@ -703,7 +703,8 @@ void Build(struct s_parameter *parameter)
703
703
int idata = 0 ; /* current output */
704
704
int pixrequested ; /* how many pix do we need for a byte? */
705
705
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 */
707
708
struct s_sprite_info * spinfo = NULL ; /* info about extracted sprites */
708
709
struct s_sprite_info curspi = {0 };
709
710
int ispi = 0 ,mspi = 0 ; /* fast counters for sprite info struct */
@@ -788,10 +789,11 @@ void Build(struct s_parameter *parameter)
788
789
}
789
790
790
791
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 ;
795
797
}
796
798
797
799
//*****************************************************
@@ -809,7 +811,7 @@ void Build(struct s_parameter *parameter)
809
811
if (parameter -> importpalettefilename ) {
810
812
/* load palette from a text file */
811
813
char separator ,* curchar ,* txtpalette ;
812
- int palsize ,curcoul , is_hsp ;
814
+ int palsize ,curcoul ;
813
815
int has_reduce = 0 ;
814
816
815
817
printf (KIO "Image %dx%d\n" ,photo -> width ,photo -> height );
@@ -831,16 +833,18 @@ void Build(struct s_parameter *parameter)
831
833
}
832
834
if (strstr (txtpalette ," HSP" )) is_hsp = 1 ; else is_hsp = 0 ;
833
835
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 " );
835
837
}
836
838
837
839
/* parse text */
838
840
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 ;
842
845
}
843
846
maxcoul = is_hsp ;
847
+ printf ("palette=[%s]\n" ,txtpalette );
844
848
while ((curchar = strchr (txtpalette ,separator ))!= NULL ) {
845
849
if (maxcoul == 16 ) {
846
850
printf (KERROR "\nERROR: invalid palette! too much colorz!\n" KNORMAL );
@@ -849,10 +853,15 @@ void Build(struct s_parameter *parameter)
849
853
* curchar = ' ' ;
850
854
curchar ++ ;
851
855
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
+ }
856
865
}
857
866
printf ("%d couleur%s importée%s\n" ,maxcoul - is_hsp ,maxcoul - is_hsp > 1 ?"s" :"" ,maxcoul - is_hsp > 1 ?"s" :"" );
858
867
@@ -925,6 +934,7 @@ void Build(struct s_parameter *parameter)
925
934
926
935
MemFree (txtpalette );
927
936
} else {
937
+ is_hsp = parameter -> hsp ;
928
938
/* as the bitmap is RGBA we must scan to find all colors */
929
939
maxcoul = 0 ;
930
940
png_has_transparency = 0 ;
@@ -1218,8 +1228,14 @@ printf(KBLUE"expand image to %d\n"KNORMAL,photo->height);
1218
1228
1219
1229
1220
1230
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
+ }
1223
1239
}
1224
1240
printf ("\n" );
1225
1241
@@ -1283,11 +1299,18 @@ printf(KBLUE"expand image to %d\n"KNORMAL,photo->height);
1283
1299
ticpack = 0 ; /* reset pixel counter */
1284
1300
for (xs = metax ;xs < 16 + metax ;xs ++ ) {
1285
1301
/* 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 ) {
1290
1306
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
+ }
1291
1314
}
1292
1315
/* output format */
1293
1316
switch (parameter -> packed ) {
0 commit comments