2 // The tool to enhance t-1 frames by remapping the palette
5 // Copyright (C) 2015 Balthasar SzczepaĆski
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 // Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/)
22 // on Pentium III libdevil must be recompiled with
23 // --disable-ssl2 --disable-ssl3
24 // (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954)
31 int mustard(const char *t,int m,int e);
32 int main(int argc, char *argv[]);
33 unsigned char b642d(char b64);
38 int main(int argc, char *argv[])
44 return mustard("remapt-1 inpix outpix palette [q]",0,1);
48 if(strlen(argv[3])<340)
49 return mustard("Palette too short.",0,1);
53 ilEnable(IL_ORIGIN_SET);
54 ilEnable(IL_FILE_OVERWRITE);
56 ilGenImages(1,&inpix);
59 if(!ilLoadImage(argv[1]))
60 return mustard("inpix load fail.",1,1);
62 if(ilGetInteger(IL_IMAGE_FORMAT)!=IL_COLOUR_INDEX)
63 return mustard("inpix not indexed.",1,1);
66 ilConvertPal(IL_PAL_RGB24);
67 if(ilGetInteger(IL_PALETTE_NUM_COLS)!=255)
68 return mustard("Wrong number of colors.",1,1);
72 if(strlen(argv[3])<340)
73 return mustard("Palette too short.",1,1);
77 argv[3][i]=b642d(argv[3][i]);
80 pal[3*i ]=( argv[3][4*i ] <<2)|
81 ((argv[3][4*i+1]&0x30) >>4);
83 pal[3*i+1]=((argv[3][4*i+1]&0x0f) <<4)|
84 ((argv[3][4*i+2]&0x3c) >>2);
86 pal[3*i+2]=((argv[3][4*i+2]&0x03) <<6)|
89 pal[3*i+255]=pal[3*i ];
90 pal[3*i+256]=pal[3*i+1];
91 pal[3*i+257]=pal[3*i+2];
93 pal[3*i+510]=pal[3*i ];
94 pal[3*i+511]=pal[3*i+1];
95 pal[3*i+512]=pal[3*i+2];
97 if(!ilSave(IL_PNG,argv[2]))
98 return mustard("outpix save fail",1,1);
100 return mustard("remapped",1,0);
103 unsigned char b642d(char b64)
105 if(b64 >='A' && b64 <='Z')
107 else if(b64 >= 'a' && b64 <= 'z')
109 else if(b64 >= '0' && b64 <= '9')
119 int mustard(const char *t, int m,int e)
126 ilDeleteImages(1,&inpix);