From: b Date: Fri, 2 Dec 2022 10:16:04 +0000 (+0000) Subject: T-1 remap tool. debug needed! X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=4fd82fc67c74b4c0e50cea198eefa5b9d74e870d;p=ott%2Fenhance T-1 remap tool. debug needed! --- diff --git a/enhance.c b/enhance.c index 0daa9fb..1036266 100644 --- a/enhance.c +++ b/enhance.c @@ -37,6 +37,7 @@ on Pentium III libdevil must be recompiled with #include "npb.h" #include "pal_mix.h" #include "pal_unmix.h" +#include "remap_t_1.h" int main (int argc, char **argv) { @@ -68,6 +69,8 @@ int main (int argc, char **argv) f = &subtool_pal_mix; else if (strcmp(argv[1], "pal_unmix")==0) f = &subtool_pal_unmix; + else if (strcmp(argv[1], "remap_t_1")==0) + f = &subtool_remap_t_1; else finish(EINVAL, "Unknown mode.\n"); diff --git a/makefile b/makefile index f57b8ce..a257374 100644 --- a/makefile +++ b/makefile @@ -45,7 +45,8 @@ reveal\ diff\ npb\ pal_mix\ -pal_unmix +pal_unmix\ +remap_t_1 C_STANDALONE=\ standalone-nofading.c\ @@ -55,7 +56,8 @@ standalone-reveal.c\ standalone-diff.c\ standalone-npb.c\ standalone-pal_mix.c\ -standalone-pal_unmix.c +standalone-pal_unmix.c\ +standalone-remap_t_1.c C_SUBTOOL=\ nofading.c\ @@ -65,7 +67,8 @@ reveal.c\ diff.c\ npb.c\ pal_mix.c\ -pal_unmix.c +pal_unmix.c\ +remap_t_1.c H_SUBTOOL=\ nofading.h\ @@ -75,7 +78,8 @@ reveal.h\ diff.h\ npb.h\ pal_mix.h\ -pal_unmix.h +pal_unmix.h\ +remap_t_1.h H_PNG=\ npb0.h\ @@ -128,33 +132,15 @@ clean: PHONY: all clean -#npb-ong1: npb-ong1.cpp makefile -# $(CC) $(CF) $(LF) -o npb-ong1 npb-ong1.cpp -# -#npb: npb.cpp makefile -# $(CC) $(CF) $(LF) -o npb npb.cpp -# -#403: 403.cpp makefile -# $(CC) $(CF) $(LF) -o 403 403.cpp -# #npbd-ong1: npb npbd-ong1.cpp makefile # $(CC) $(CF) -o npbd-ong1 npbd-ong1.cpp $(LF2) # #npbd: npb npbd.cpp makefile # $(CC) $(CF) -o npbd npbd.cpp $(LF2) # -#bluenh: bluenh.cpp makefile -# $(CC) $(CF) $(LF) -o bluenh bluenh.cpp -# #bluenhd: bluenhd.cpp makefile # $(CC) $(CF) -o bluenhd bluenhd.cpp $(LF2) # -#insert: insert.c makefile -# $(CC) $(CF) $(LF) -o insert insert.c -# -#extract: extract.c makefile -# $(CC) $(CF) $(LF) -o extract extract.c -# #seediff: seediff.c makefile # $(CC) $(CF) $(LF) -o seediff seediff.c # @@ -167,9 +153,6 @@ PHONY: all clean #compare: compare.c makefile # $(CC) $(CF) $(LF) -o compare compare.c # -#nofading: nofading.c makefile -# $(CC) $(CF) $(LF) -o nofading nofading.c -# #nofadingd: nofadingd.c makefile # $(CC) $(CF) $(LF) -o nofadingd nofadingd.c # diff --git a/makefile.1.mak b/makefile.1.mak index 8dcc31a..103fdd2 100644 --- a/makefile.1.mak +++ b/makefile.1.mak @@ -45,7 +45,8 @@ reveal\ diff\ npb\ pal_mix\ -pal_unmix +pal_unmix\ +remap_t_1 C_STANDALONE=\ standalone-nofading.c\ @@ -55,7 +56,8 @@ standalone-reveal.c\ standalone-diff.c\ standalone-npb.c\ standalone-pal_mix.c\ -standalone-pal_unmix.c +standalone-pal_unmix.c\ +standalone-remap_t_1.c C_SUBTOOL=\ nofading.c\ @@ -65,7 +67,8 @@ reveal.c\ diff.c\ npb.c\ pal_mix.c\ -pal_unmix.c +pal_unmix.c\ +remap_t_1.c H_SUBTOOL=\ nofading.h\ @@ -75,7 +78,8 @@ reveal.h\ diff.h\ npb.h\ pal_mix.h\ -pal_unmix.h +pal_unmix.h\ +remap_t_1.h H_PNG=\ npb0.h\ @@ -128,33 +132,15 @@ clean: PHONY: all clean -#npb-ong1: npb-ong1.cpp makefile -# $(CC) $(CF) $(LF) -o npb-ong1 npb-ong1.cpp -# -#npb: npb.cpp makefile -# $(CC) $(CF) $(LF) -o npb npb.cpp -# -#403: 403.cpp makefile -# $(CC) $(CF) $(LF) -o 403 403.cpp -# #npbd-ong1: npb npbd-ong1.cpp makefile # $(CC) $(CF) -o npbd-ong1 npbd-ong1.cpp $(LF2) # #npbd: npb npbd.cpp makefile # $(CC) $(CF) -o npbd npbd.cpp $(LF2) # -#bluenh: bluenh.cpp makefile -# $(CC) $(CF) $(LF) -o bluenh bluenh.cpp -# #bluenhd: bluenhd.cpp makefile # $(CC) $(CF) -o bluenhd bluenhd.cpp $(LF2) # -#insert: insert.c makefile -# $(CC) $(CF) $(LF) -o insert insert.c -# -#extract: extract.c makefile -# $(CC) $(CF) $(LF) -o extract extract.c -# #seediff: seediff.c makefile # $(CC) $(CF) $(LF) -o seediff seediff.c # @@ -167,9 +153,6 @@ PHONY: all clean #compare: compare.c makefile # $(CC) $(CF) $(LF) -o compare compare.c # -#nofading: nofading.c makefile -# $(CC) $(CF) $(LF) -o nofading nofading.c -# #nofadingd: nofadingd.c makefile # $(CC) $(CF) $(LF) -o nofadingd nofadingd.c # \ No newline at end of file diff --git a/pal_unmix.c b/pal_unmix.c index 69b3f65..63461e4 100644 --- a/pal_unmix.c +++ b/pal_unmix.c @@ -31,7 +31,7 @@ on Pentium III libdevil must be recompiled with #include #include "core.h" -#include "pal_mix.h" +#include "pal_unmix.h" int palette_unmix_index (ILuint n, struct PixelInfo *p, void *data); ILuint tsqrt(ILuint s); @@ -65,8 +65,8 @@ int subtool_pal_unmix (int argc, char **argv, int argi, char **err) if (argc >= argi + 5) { - sscanf(argv[argi+3],"%u",&(n0)); - sscanf(argv[argi+4],"%u",&(n1)); + sscanf(argv[argi+3],"%u",&n0); + sscanf(argv[argi+4],"%u",&n1); n = n0 * n1; size_defined = 1; } diff --git a/remap_t_1.c b/remap_t_1.c new file mode 100644 index 0000000..1116fe7 --- /dev/null +++ b/remap_t_1.c @@ -0,0 +1,286 @@ +/* +remap_t_1.c +The tool to enhance t-1 frames by remapping the palette +02.12.2022 + +Copyright (C) 2015, 2022 Balthasar Szczepański + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . + + +Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/) +on Pentium III libdevil must be recompiled with +--disable-ssl2 --disable-ssl3 +(https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954) + +*/ + +#include +#include +#include + +#include "core.h" +#include "remap_t_1.h" + +#define N0 3 +#define N1 85 + +struct remap_data +{ + ILuint n0; + ILuint n1; + ILuint n; + struct ColorInfo new_pal[0x100]; +}; + +int palette_remap (ILuint n, struct PixelInfo *p, void *data); +ILubyte b642d(char c); + +char REMAPT1_MISSING_ARGS[] = "Missing parameters.\npremap_t_1 inPix outPix palette [n1 n2]\n"; + +int subtool_remap_t_1 (int argc, char **argv, int argi, char **err) +{ + struct IL_full_info info; + FLAG_TYPE flags = MUST_BE_INDEXED | CAN_BE_MULTIPLE | CANNOT_HAVE_ALPHA | OK_PALETTE_ONLY; + struct remap_data data; + ILuint i, j, k; + ILubyte v[4]; + uint_fast8_t eot = 0; + int r; + + if (argc < argi + 3) + { + *err = REMAPT1_MISSING_ARGS; + return EINVAL; + } + + if (argc >= argi + 5) + { + sscanf(argv[argi+3],"%u",&(data.n0)); + sscanf(argv[argi+4],"%u",&(data.n1)); + } + else + { + data.n0 = N0; + data.n1 = N1; + } + data.n = data.n0 * data.n1; + if (data.n>=0x100) + { + *err = BAD_PALETTE_SIZE; + return EINVAL; + } + + r = reserve_pictures(1); + if (r) + { + *err = CREATE_FAILED; + return r; + } + + r = load_picture(0, argv[argi], &info, &flags); + if (r) + { + *err = LOAD_FAILED; + return r; + } + + if (info.palette_num_cols != data.n) + { + *err = BAD_PALETTE_SIZE; + return EINVAL; + } + + for (i=0, k=0; i> 4); + data.new_pal[i].green = ((v[1] & 0x0f) << 4) | ((v[2] & 0x3c) >> 2); + data.new_pal[i].blue = ((v[3] & 0x03) << 6) | v[3] ; + ++data.n1; + } + + r = perform_action_1picture ( + 0, //id + 0, 0, 0, 0, 0, 0, //x y f w h f + &palette_remap, + flags, + &data + ); + if (r) + { + *err = CONVERT_FAILED; + return r; + } + + r = save_picture(0, argv[argi+1], flags); + if (r!=0) + { + *err = SAVE_FAILED; + return r; + } + + return 0; +} + +int palette_remap (ILuint n, struct PixelInfo *p, void *data) +{ + struct remap_data *d = data; + ILuint j; + + // i = p->index / d->n1; + j = p->index % d->n1; + + p->red = d->new_pal[j].red; + p->green = d->new_pal[j].green; + p->blue = d->new_pal[j].blue; + + return 0; +} + +ILubyte b642d(char c) +{ + if(c >='A' && c <='Z') + return c-'A'; + else if(c >= 'a' && c <= 'z') + return c-'a'+26; + else if(c >= '0' && c <= '9') + return c-'0'+52; + else if(c=='+') + return 62; + else if(c=='-') + return 63; + else + return 0; +} + +/* +//#include +#include +#include +#include "IL/il.h" + +int mustard(const char *t,int m,int e); +int main(int argc, char *argv[]); +unsigned char b642d(char b64); + +ILuint inpix; +unsigned char q =0; + +int main(int argc, char *argv[]) +{ + ILubyte *pal; + unsigned short i; + + if (argc<4) + return mustard("remapt-1 inpix outpix palette [q]",0,1); + else if(argc > 4) + q=1; + + if(strlen(argv[3])<340) + return mustard("Palette too short.",0,1); + + ilInit(); + + ilEnable(IL_ORIGIN_SET); + ilEnable(IL_FILE_OVERWRITE); + + ilGenImages(1,&inpix); + ilBindImage(inpix); + + if(!ilLoadImage(argv[1])) + return mustard("inpix load fail.",1,1); + + if(ilGetInteger(IL_IMAGE_FORMAT)!=IL_COLOUR_INDEX) + return mustard("inpix not indexed.",1,1); + + + ilConvertPal(IL_PAL_RGB24); + if(ilGetInteger(IL_PALETTE_NUM_COLS)!=255) + return mustard("Wrong number of colors.",1,1); + + pal=ilGetPalette(); + + if(strlen(argv[3])<340) + return mustard("Palette too short.",1,1); + + + for(i=0; i<340; ++i) + argv[3][i]=b642d(argv[3][i]); + for(i=0; i<85; ++i) + { + pal[3*i ]=( argv[3][4*i ] <<2)| + ((argv[3][4*i+1]&0x30) >>4); + + pal[3*i+1]=((argv[3][4*i+1]&0x0f) <<4)| + ((argv[3][4*i+2]&0x3c) >>2); + + pal[3*i+2]=((argv[3][4*i+2]&0x03) <<6)| + ( argv[3][4*i+3] ); + + pal[3*i+255]=pal[3*i ]; + pal[3*i+256]=pal[3*i+1]; + pal[3*i+257]=pal[3*i+2]; + + pal[3*i+510]=pal[3*i ]; + pal[3*i+511]=pal[3*i+1]; + pal[3*i+512]=pal[3*i+2]; + } + if(!ilSave(IL_PNG,argv[2])) + return mustard("outpix save fail",1,1); + + return mustard("remapped",1,0); +} + +unsigned char b642d(char b64) +{ + if(b64 >='A' && b64 <='Z') + return b64-'A'; + else if(b64 >= 'a' && b64 <= 'z') + return b64-'a'+26; + else if(b64 >= '0' && b64 <= '9') + return b64-'0'+52; + else if(b64=='+') + return 62; + else if(b64=='-') + return 63; + else + return 0; +} + +int mustard(const char *t, int m,int e) +{ + if(!q) + puts(t); + switch (m) + { + case 1: + ilDeleteImages(1,&inpix); + case 0: + default: + return e; + } +} +*/ \ No newline at end of file diff --git a/remapt-1.c b/remapt-1.c deleted file mode 100644 index 08b7c15..0000000 --- a/remapt-1.c +++ /dev/null @@ -1,131 +0,0 @@ -// remapt-1.c -// The tool to enhance t-1 frames by remapping the palette -// 16.09.2015 -// -// Copyright (C) 2015 Balthasar Szczepański -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . -// - -// Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/) -// on Pentium III libdevil must be recompiled with -// --disable-ssl2 --disable-ssl3 -// (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954) - -//#include -#include -#include -#include "IL/il.h" - -int mustard(const char *t,int m,int e); -int main(int argc, char *argv[]); -unsigned char b642d(char b64); - -ILuint inpix; -unsigned char q =0; - -int main(int argc, char *argv[]) -{ - ILubyte *pal; - unsigned short i; - - if (argc<4) - return mustard("remapt-1 inpix outpix palette [q]",0,1); - else if(argc > 4) - q=1; - - if(strlen(argv[3])<340) - return mustard("Palette too short.",0,1); - - ilInit(); - - ilEnable(IL_ORIGIN_SET); - ilEnable(IL_FILE_OVERWRITE); - - ilGenImages(1,&inpix); - ilBindImage(inpix); - - if(!ilLoadImage(argv[1])) - return mustard("inpix load fail.",1,1); - - if(ilGetInteger(IL_IMAGE_FORMAT)!=IL_COLOUR_INDEX) - return mustard("inpix not indexed.",1,1); - - - ilConvertPal(IL_PAL_RGB24); - if(ilGetInteger(IL_PALETTE_NUM_COLS)!=255) - return mustard("Wrong number of colors.",1,1); - - pal=ilGetPalette(); - - if(strlen(argv[3])<340) - return mustard("Palette too short.",1,1); - - - for(i=0; i<340; ++i) - argv[3][i]=b642d(argv[3][i]); - for(i=0; i<85; ++i) - { - pal[3*i ]=( argv[3][4*i ] <<2)| - ((argv[3][4*i+1]&0x30) >>4); - - pal[3*i+1]=((argv[3][4*i+1]&0x0f) <<4)| - ((argv[3][4*i+2]&0x3c) >>2); - - pal[3*i+2]=((argv[3][4*i+2]&0x03) <<6)| - ( argv[3][4*i+3] ); - - pal[3*i+255]=pal[3*i ]; - pal[3*i+256]=pal[3*i+1]; - pal[3*i+257]=pal[3*i+2]; - - pal[3*i+510]=pal[3*i ]; - pal[3*i+511]=pal[3*i+1]; - pal[3*i+512]=pal[3*i+2]; - } - if(!ilSave(IL_PNG,argv[2])) - return mustard("outpix save fail",1,1); - - return mustard("remapped",1,0); -} - -unsigned char b642d(char b64) -{ - if(b64 >='A' && b64 <='Z') - return b64-'A'; - else if(b64 >= 'a' && b64 <= 'z') - return b64-'a'+26; - else if(b64 >= '0' && b64 <= '9') - return b64-'0'+52; - else if(b64=='+') - return 62; - else if(b64=='-') - return 63; - else - return 0; -} - -int mustard(const char *t, int m,int e) -{ - if(!q) - puts(t); - switch (m) - { - case 1: - ilDeleteImages(1,&inpix); - case 0: - default: - return e; - } -} \ No newline at end of file diff --git a/testimg/remapt-1_0001.png b/testimg/remapt-1_0001.png new file mode 100644 index 0000000..1cfc269 Binary files /dev/null and b/testimg/remapt-1_0001.png differ diff --git a/testimg/t-1_0001.png b/testimg/t-1_0001.png new file mode 100644 index 0000000..abc34cd Binary files /dev/null and b/testimg/t-1_0001.png differ