]> bicyclesonthemoon.info Git - ott/enhance/commitdiff
The reveal tool is ready.
authorb <rowerynaksiezycu@gmail.com>
Sun, 13 Nov 2022 17:39:24 +0000 (17:39 +0000)
committerb <rowerynaksiezycu@gmail.com>
Sun, 13 Nov 2022 17:39:24 +0000 (17:39 +0000)
bluenh.c
core.h
enhance.c
makefile
makefile.1.mak
reveal.c [moved from reveal.cpp with 53% similarity]
reveal.h [new file with mode: 0644]
testimg/gradient.png [new file with mode: 0644]

index 79dbd24dfed09a2cf290e8995f234196f45d68a7..3a99ba46e0bb908f0c3b9e123fe0f79572d9f430 100644 (file)
--- 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 <stdlib.h>
-#include <stdio.h>
-#include <IL/il.h>
-
-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<b)?(enhance(x,E-D,B-A,D*B-A*E)):e))));
-}
-
-ILubyte enhance3(ILubyte x, ILubyte a, ILubyte b, ILubyte c)
-{
-       return enhance(x,C-A,B-A,(B-C)*A);
-}
-
-int main (int argc, const char *argv[])
-{
-       ILubyte a,b,c,d,e,f,g;
-       ILubyte *h, *s, *l;
-       ILuint inX, inY;
-       ILubyte *newdata;
-       
-       if(argc<9)
-               mustard(ARGUMENT_MUSTARD);
-       if (argc>=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;i<inX;++i)
-       {
-               for(unsigned long j=0;j<inY;++j)
-               {
-                       if(CR==CG&&CG==CB)
-                               continue;
-                       //it'll stilll work correctly if two are equal.
-                       if(CR>CG)
-                       {
-                               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 43120ab0fa387d3f509c8b104fca74b6883713ea..94ca1977bfea5d6567c70571cce0767431c7231c 100644 (file)
--- a/core.h
+++ b/core.h
@@ -30,7 +30,7 @@ on Pentium III libdevil must be recompiled with
 // #include <stdio.h>
 // #include <errno.h>
 
-#include "IL/il.h"
+#include <IL/il.h>
 
 #define FLAG_TYPE uint_fast32_t
 
index 9df533279ad486eaadc95fa344598a912367e6cb..a1f21a89ebd0a6d276701e5776f3f2ed35b80094 100644 (file)
--- 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
index 603d6ed27522455201f6852a75ff4fffaa30e816..d71ecb63476cbaa4206fd4dd625051d48d8bed2a 100644 (file)
--- 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
index b05a9644f00c21eb03d9acec6d0314f987ddf597..16ccecc0848c91c15efeeac93be351b72ddc4f79 100644 (file)
@@ -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
similarity index 53%
rename from reveal.cpp
rename to reveal.c
index bb6b6157b17919474e813fc5510f43e0ab464678..5b411efae07fb5c7af1b0736b51ba2d6ceecbb1d 100644 (file)
+++ b/reveal.c
-// 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 <http://www.gnu.org/licenses/>.
-// 
-
-// 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 <http://www.gnu.org/licenses/>.
+
+
+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 <stdio.h>
+#include <errno.h>
+
+#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 (file)
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 <http://www.gnu.org/licenses/>.
+
+
+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 (file)
index 0000000..2a01a10
Binary files /dev/null and b/testimg/gradient.png differ