From: b Date: Sun, 13 Nov 2022 17:39:24 +0000 (+0000) Subject: The reveal tool is ready. X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=67e95f07f4a483abdb5313976f9c13524449805e;p=ott%2Fenhance The reveal tool is ready. --- diff --git a/bluenh.c b/bluenh.c index 79dbd24..3a99ba4 100644 --- a/bluenh.c +++ b/bluenh.c @@ -63,7 +63,7 @@ int subtool_bluenh (int argc, char **argv, int argi, char **err) ILubyte v; struct bluenh_data data; struct IL_full_info info; - FLAG_TYPE flags = CAN_BE_MULTIPLE | CAN_BE_OVER_8BIT; + FLAG_TYPE flags = CAN_BE_MULTIPLE | CAN_BE_OVER_8BIT | OK_PALETTE_ONLY; int r; if (argc < argi + 8) @@ -229,175 +229,3 @@ static inline ILuint bluenh_mid (ILuint x, ILuint low, ILuint high_old, ILuint h max ); } - -/* -#define INPIX_MUSTARD 1 -#define OUTPIX_MUSTARD 2 - -#define ARGUMENT_MUSTARD 4 - -#define ANIMATED_MUSTARD 6 -#define FAIL 900 -#define OK 0 - -#define CR newdata[4*(i+inX*j)+0] -#define CG newdata[4*(i+inX*j)+1] -#define CB newdata[4*(i+inX*j)+2] - -#define A ((long)(a)) -#define B ((long)(b)) -#define C ((long)(c)) -#define D ((long)(d)) -#define E ((long)(e)) -#define F ((long)(f)) - -#include -#include -#include - -void mustard(int mustard); -ILubyte enhance(ILubyte x, long r, long s, long t); -ILubyte enhance2(ILubyte x, ILubyte a, ILubyte b, ILubyte c, ILubyte d, ILubyte e, ILubyte f); -ILubyte enhance3(ILubyte x, ILubyte a, ILubyte b, ILubyte c); -int main (int argc, const char *argv[]); - -ILuint pix; -ILboolean q=true; -ILboolean pixOpen=false; - - -ILubyte enhance(ILubyte x, long r, long s, long t) -{ - long y=(r*x+t)/s; - return (ILubyte)((y>255)?255:((y<0)?0:y)); -} - -ILubyte enhance2(ILubyte x, ILubyte a, ILubyte b, ILubyte c, ILubyte d, ILubyte e, ILubyte f) -{ - return ((x<=a)?d:((x>=c)?f:((x>b)?(enhance(x,F-E,C-B,E*C-B*F)):((x=10) - { - if (argv[9][0]=='q' || argv[9][0]=='Q') - q=false; - } - - sscanf(argv[3],"%hhu",&a); - sscanf(argv[4],"%hhu",&b); - sscanf(argv[5],"%hhu",&c); - sscanf(argv[6],"%hhu",&d); - sscanf(argv[7],"%hhu",&e); - sscanf(argv[8],"%hhu",&f); - - ilInit(); - if(!ilEnable(IL_ORIGIN_SET))mustard(FAIL); - if(!ilEnable(IL_FILE_OVERWRITE))mustard(FAIL); - ilClearColour(255,255,0,0); - ilGenImages(1, &pix); - pixOpen=true; - ilBindImage(pix); - if(!ilLoadImage(argv[1]))mustard(INPIX_MUSTARD); - if(!ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE))mustard(INPIX_MUSTARD); - - inX=ilGetInteger(IL_IMAGE_WIDTH); - inY=ilGetInteger(IL_IMAGE_HEIGHT); - if(ilGetInteger(IL_NUM_IMAGES)>1) - mustard(ANIMATED_MUSTARD); - - newdata=ilGetData(); - for(unsigned long i=0;iCG) - { - if(CG>CB) - { - h=&(CR); - s=&(CG); - l=&(CB); - } - else if(CB>CR) - { - h=&(CB); - s=&(CR); - l=&(CG); - } - else - { - h=&(CR); - s=&(CB); - l=&(CG); - } - } - else - { - if(CR>CB) - { - h=&(CG); - s=&(CR); - l=&(CB); - } - else if(CB>CG) - { - h=&(CB); - s=&(CG); - l=&(CR); - } - else - { - h=&(CG); - s=&(CB); - l=&(CR); - } - } - g=*h; - *h=enhance2(*h,a,b,c,d,e,f); - *s=enhance3(*s,*l,g,*h); - } - } - if(!ilSave(IL_PNG,argv[2]))mustard(OUTPIX_MUSTARD); - // no mustard - mustard(0); -} - -void mustard(int mustard) -{ - switch(mustard) - { - case 0: - if(q) printf("ENHANCED!\n");break; - case ARGUMENT_MUSTARD: - if(q) printf("bluenhanced inPix outPix a b c d e f [q]\n");break; - case INPIX_MUSTARD: - if(q) printf("inPIX mustard.\n");break; - case OUTPIX_MUSTARD: - if(q) printf("outPIX mustard.\n");break; - case ANIMATED_MUSTARD: - if(q) printf("Animation is mustard.\n");break; - default: - if (q) printf("Ch*rpin* mustard mustaard!\n"); - } - if(pixOpen) - ilDeleteImages(1, &pix); - exit(mustard); -} -*/ diff --git a/core.h b/core.h index 43120ab..94ca197 100644 --- a/core.h +++ b/core.h @@ -30,7 +30,7 @@ on Pentium III libdevil must be recompiled with // #include // #include -#include "IL/il.h" +#include #define FLAG_TYPE uint_fast32_t diff --git a/enhance.c b/enhance.c index 9df5332..a1f21a8 100644 --- a/enhance.c +++ b/enhance.c @@ -32,6 +32,7 @@ on Pentium III libdevil must be recompiled with #include "info.h" #include "nofading.h" #include "bluenh.h" +#include "reveal.h" int main (int argc, char **argv) { @@ -53,6 +54,8 @@ int main (int argc, char **argv) f = &subtool_info; else if (strcmp(argv[1], "bluenh")==0) f = &subtool_bluenh; + else if (strcmp(argv[1], "reveal")==0) + f = &subtool_reveal; else finish(EINVAL, "Unknown mode.\n"); @@ -61,6 +64,5 @@ int main (int argc, char **argv) if (r!=0) finish(r, error_text); - finish(0, ""); } \ No newline at end of file diff --git a/makefile b/makefile index 603d6ed..d71ecb6 100644 --- a/makefile +++ b/makefile @@ -40,22 +40,26 @@ RM =/usr/bin/rm STANDALONE=\ nofading\ info\ -bluenh +bluenh\ +reveal C_STANDALONE=\ standalone-nofading.c\ standalone-info.c\ -standalone-bluenh.c +standalone-bluenh.c\ +standalone-reveal.c C_SUBTOOL=\ nofading.c\ info.c\ -bluenh.c +bluenh.c\ +reveal.c H_SUBTOOL=\ nofading.h\ info.h\ -bluenh.h +bluenh.h\ +reveal.h #all: 403 npb npbd npb-ong1 npbd-ong1 bluenh bluenhd insert extract seediff insertframe mremapt-1 compare nofading nofadingd diff --git a/makefile.1.mak b/makefile.1.mak index b05a964..16ccecc 100644 --- a/makefile.1.mak +++ b/makefile.1.mak @@ -40,22 +40,26 @@ CONFIGURE_CMD = $(PERL) $(CONFIGURE) $(CONFIGFILE) STANDALONE=\ nofading\ info\ -bluenh +bluenh\ +reveal C_STANDALONE=\ standalone-nofading.c\ standalone-info.c\ -standalone-bluenh.c +standalone-bluenh.c\ +standalone-reveal.c C_SUBTOOL=\ nofading.c\ info.c\ -bluenh.c +bluenh.c\ +reveal.c H_SUBTOOL=\ nofading.h\ info.h\ -bluenh.h +bluenh.h\ +reveal.h #all: 403 npb npbd npb-ong1 npbd-ong1 bluenh bluenhd insert extract seediff insertframe mremapt-1 compare nofading nofadingd diff --git a/reveal.cpp b/reveal.c similarity index 53% rename from reveal.cpp rename to reveal.c index bb6b615..5b411ef 100644 --- a/reveal.cpp +++ b/reveal.c @@ -1,28 +1,169 @@ -// enhance.cpp -// The enhancement software - reveal hidden details -// 9.06.2019 -// -// Copyright (C) 2014 - 2019 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) +/* +reveal.c +reveal hidden details +13.11.2022 +Copyright (C) 2014 - 2019, 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 "reveal.h" +#include "core.h" + +char REVEAL_MISSING_ARGS[] = "Missing parameters.\nreveal inPix outPix\n"; + +int reveal (ILuint n, struct PixelInfo *p, void *data); +static inline ILubyte reveal_swap1(ILubyte x); +static inline ILubyte reveal_swap2(ILubyte x); +static inline ILubyte reveal_swap4(ILubyte x); + + +int subtool_reveal (int argc, char **argv, int argi, char **err) +{ + struct IL_full_info info; + FLAG_TYPE flags = CAN_BE_MULTIPLE | OK_PALETTE_ONLY; + int r; + + if (argc < argi + 2) + { + *err = REVEAL_MISSING_ARGS; + return EINVAL; + } + + r = create_pictures(1); + if (r) + { + *err = CREATE_FAILED; + return r; + } + + r = load_picture(0, argv[argi], &info, &flags); + if (r) + { + *err = LOAD_FAILED; + return r; + } + + r = action_1picture ( + 0, + 0, 0, 0, 0, 0, 0, + &reveal, + flags, + NULL + ); + if (r) + { + *err = CONVERT_FAILED; + return r; + } + + r = save_picture (0, argv[argi+1], flags); + if (r) + { + *err = SAVE_FAILED; + return r; + } + + return 0; +} + +int reveal (ILuint n, struct PixelInfo *p, void *data) +{ + if (p->flags & IS_GRAY) + p->value = reveal_swap2(p->value); + else + { + p->red = reveal_swap4(p->red); + p->green = reveal_swap2(p->green); + p->blue = reveal_swap1(p->blue); + } + + return 0; +} + +static inline ILubyte reveal_swap1(ILubyte x) +{ + ILubyte y = 0x00; + + y |= x&0x01; + x >>= 1; + y <<= 1; + y |= x&0x01; + x >>= 1; + y <<= 1; + y |= x&0x01; + x >>= 1; + y <<= 1; + y |= x&0x01; + x >>= 1; + y <<= 1; + y |= x&0x01; + x >>= 1; + y <<= 1; + y |= x&0x01; + x >>= 1; + y <<= 1; + y |= x&0x01; + x >>= 1; + y <<= 1; + y |= x&0x01; + + return y; +} + +static inline ILubyte reveal_swap2(ILubyte x) +{ + ILubyte y = 0x00; + + y |= x&0x03; + x >>= 2; + y <<= 2; + y |= x&0x03; + x >>= 2; + y <<= 2; + y |= x&0x03; + x >>= 2; + y <<= 2; + y |= x&0x03; + + return y; +} + +static inline ILubyte reveal_swap4(ILubyte x) +{ + ILubyte y = 0x00; + + y |= x&0x0f; + x >>= 4; + y <<= 4; + y |= x&0x0f; + + return y; +} + +/* #define INPIX_MUSTARD 1 #define OUTPIX_MUSTARD 2 @@ -215,4 +356,4 @@ void mustard(int mustard) ilDeleteImages(1, &pix); exit(mustard); } - +*/ diff --git a/reveal.h b/reveal.h new file mode 100644 index 0000000..45672c4 --- /dev/null +++ b/reveal.h @@ -0,0 +1,28 @@ +/* +reveal.h +reveal hidden details +13.11.2022 + +Copyright (C) 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) +*/ + +int subtool_reveal (int argc, char **argv, int argi, char **err); diff --git a/testimg/gradient.png b/testimg/gradient.png new file mode 100644 index 0000000..2a01a10 Binary files /dev/null and b/testimg/gradient.png differ