]> bicyclesonthemoon.info Git - ott/enhance/commitdiff
bluenhance! but something fail
authorb <rowerynaksiezycu@gmail.com>
Sun, 13 Nov 2022 14:07:40 +0000 (14:07 +0000)
committerb <rowerynaksiezycu@gmail.com>
Sun, 13 Nov 2022 14:07:40 +0000 (14:07 +0000)
13 files changed:
bluenh.c [new file with mode: 0644]
bluenh.cpp [deleted file]
bluenh.h [new file with mode: 0644]
core.c
core.h
enhance.c
info.c
info.h
makefile
makefile.1.mak
nofading.c
nofading.h
testimg/blue.png [new file with mode: 0644]

diff --git a/bluenh.c b/bluenh.c
new file mode 100644 (file)
index 0000000..79dbd24
--- /dev/null
+++ b/bluenh.c
@@ -0,0 +1,403 @@
+/*
+bluenh.c
+ENHANCE the bluepix!
+13.11.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 <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 "bluenh.h"
+#include "core.h"
+
+char BLUENH_MISSING_ARGS[] = "Missing parameters.\nbluenh inPix outPix a b c d e f\n";
+
+struct bluenh_data
+{
+       ILuint a;
+       ILuint b;
+       ILuint c;
+       ILuint d;
+       ILuint e;
+       ILuint f;
+       ILint64 r_high;
+       ILint64 s_high;
+       ILint64 t_high;
+       ILint64 r_low;
+       ILint64 s_low;
+       ILint64 t_low;
+       ILint64 max;
+};
+
+int bluenhance (ILuint n, struct PixelInfo *p, void *data);
+void calculate_bluenh_parameters (struct bluenh_data *data);
+static inline ILuint bluenh_linear (ILuint x, ILint64 r, ILint64 s, ILint64 t, ILuint max);
+static inline ILuint bluenh_top (ILuint x, struct bluenh_data *data);
+static inline ILuint bluenh_mid (ILuint x, ILuint low, ILuint high_old, ILuint high_new, ILuint max);
+
+
+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;
+       int r;
+       
+       if (argc < argi + 8)
+       {
+               *err = BLUENH_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;
+       }
+       
+       if (!(flags & IS_GRAY))
+       {
+               sscanf(argv[argi+2],"%hhu",&v);
+               data.a = upscale_value(v, info.image_bpc);
+               sscanf(argv[argi+3],"%hhu",&v);
+               data.b = upscale_value(v, info.image_bpc);
+               sscanf(argv[argi+4],"%hhu",&v);
+               data.c = upscale_value(v, info.image_bpc);
+               sscanf(argv[argi+5],"%hhu",&v);
+               data.d = upscale_value(v, info.image_bpc);
+               sscanf(argv[argi+6],"%hhu",&v);
+               data.e = upscale_value(v, info.image_bpc);
+               sscanf(argv[argi+7],"%hhu",&v);
+               data.f = upscale_value(v, info.image_bpc);
+               data.max = upscale_value(0xFF, info.image_bpc);
+               calculate_bluenh_parameters (&data);
+               
+               r = action_1picture (
+                       0,
+                       0, 0, 0, 0, 0, 0,
+                       &bluenhance,
+                       flags,
+                       &data
+               );
+               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 bluenhance (ILuint n, struct PixelInfo *p, void *data)
+{
+       struct bluenh_data *d;
+       ILuint *high, *mid, *low;
+       ILuint high_old;
+       
+       /* known to be RGB at this point*/
+       
+       d = data;
+       
+       if ((p->red == p->green) && (p->green == p->blue))
+               return 0; /* nothing to do here */
+       
+       if(p->red > p->green)
+       {
+               if(p->green > p->blue)
+               {
+                       high= &(p->red);
+                       mid = &(p->green);
+                       low = &(p->blue);
+               }
+               else if(p->blue > p->red)
+               {
+                       high= &(p->blue);
+                       mid = &(p->red);
+                       low = &(p->green);
+               }
+               else
+               {
+                       high = &(p->red);
+                       mid  = &(p->blue);
+                       low  = &(p->green);
+               }
+       }
+       else
+       {
+               if(p->red > p->blue)
+               {
+                       high= &(p->green);
+                       mid = &(p->red);
+                       low = &(p->blue);
+               }
+               else if(p->blue > p->green)
+               {
+                       high= &(p->blue);
+                       mid = &(p->green);
+                       low = &(p->red);
+               }
+               else
+               {
+                       high= &(p->green);
+                       mid = &(p->blue);
+                       low = &(p->red);
+               }
+       }
+       high_old = *high;
+       *high = bluenh_top(*high, d);
+       *mid  = bluenh_mid(*mid, *low, high_old, *high, d->max);
+       
+       return 0;
+}
+
+void calculate_bluenh_parameters (struct bluenh_data *data)
+{
+       data->r_high = (ILint64)(data->f) - (ILint64)(data->e);
+       data->s_high = (ILint64)(data->c) - (ILint64)(data->b);
+       data->t_high =((ILint64)(data->e))*((ILint64)(data->c))-((ILint64)(data->b))*((ILint64)(data->f));
+       data->r_high = (ILint64)(data->e) - (ILint64)(data->d);
+       data->s_high = (ILint64)(data->b) - (ILint64)(data->a);
+       data->t_high =((ILint64)(data->d))*((ILint64)(data->b))-((ILint64)(data->a))*((ILint64)(data->e));
+}
+
+static inline ILuint bluenh_linear (ILuint x, ILint64 r, ILint64 s, ILint64 t, ILuint max)
+{
+       ILint64 y = (r*x + t)/s;
+       return (ILuint)((y>max)?max:((y<0)?0:y));
+}
+
+static inline ILuint bluenh_top (ILuint x, struct bluenh_data *data)
+{
+               if (x <= data->a)
+                       return data->d;
+               else if (x >= data->c)
+                       return data->f;
+               else if (x > data->b)
+                       return bluenh_linear(x, data->r_high, data->s_high, data->t_high, data->max);
+               else if (x < data->b)
+                       return bluenh_linear(x, data->r_low, data->s_low, data->t_low, data->max);
+               else
+                       return data->e;
+}
+
+static inline ILuint bluenh_mid (ILuint x, ILuint low, ILuint high_old, ILuint high_new, ILuint max)
+{
+       return bluenh_linear(
+               x,
+               ((ILuint64)high_new) - ((ILuint64)low),
+               ((ILuint64)high_old) - ((ILuint64)low),
+               (((ILuint64)high_old) - ((ILuint64)high_new)) * ((ILuint64)low),
+               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/bluenh.cpp b/bluenh.cpp
deleted file mode 100644 (file)
index 13de6b6..0000000
+++ /dev/null
@@ -1,179 +0,0 @@
-    //  //bluenhance
-   //  // ENHANCE the bluepix!
-  //  //  
- //  //   Requires Dev Image Library,
-//  //  //on Pentium III libdevil must be
-   //  // recompiled with --disable-ssl2 --disable-ssl3
-  //  //
- //  //   ~~bicyclesonthemoon
-
-#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/bluenh.h b/bluenh.h
new file mode 100644 (file)
index 0000000..0925ab9
--- /dev/null
+++ b/bluenh.h
@@ -0,0 +1,28 @@
+/*
+bluenh.h
+ENHANCE the bluepix!
+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_bluenh (int argc, char **argv, int argi, char **err);
diff --git a/core.c b/core.c
index a146279b194d9e11e2554a1e0a7c550a283d9f04..fc3ddf6cd6b06204f1b252af536ac92d221f3834 100644 (file)
--- a/core.c
+++ b/core.c
@@ -1,7 +1,7 @@
 /*
 core.c
 The tool with multiple enhancements and manipulations of pictures
-12.11.2022
+13.11.2022
 
 Copyright (C) 2014, 2015, 2022  Balthasar Szczepański
 
@@ -148,7 +148,52 @@ int reserve_pictures (uint_fast16_t n)
        return 0;
 }
 
-int convert_picture (uint_fast16_t id, FLAG_TYPE flags)
+void get_flags (struct IL_full_info *info, FLAG_TYPE *flags)
+{
+       *flags &= ~(HAS_ALPHA | IS_GRAY | IS_INDEXED | IS_MULTIPLE | IS_OVER_8BIT);
+       
+       if (info->num_images > 0)
+               *flags |= IS_MULTIPLE;
+       
+       if (info->image_bpc > 1)
+               *flags |= IS_OVER_8BIT;
+       
+       switch (info->image_format)
+       {
+       case IL_COLOUR_INDEX:
+               *flags |= IS_INDEXED;
+               switch (info->palette_type)
+               {
+               case IL_PAL_BGR32:
+               case IL_PAL_RGB32:
+                       *flags |= IS_OVER_8BIT;
+                       break;
+               case IL_PAL_BGRA32:
+               case IL_PAL_RGBA32:
+                       *flags |= HAS_ALPHA;
+                       break;
+               case IL_PAL_RGB24:
+               case IL_PAL_BGR24:
+               default:
+                       break;
+               }
+               break;
+       case IL_LUMINANCE_ALPHA:
+               *flags |= HAS_ALPHA;
+       case IL_LUMINANCE:
+               *flags |= IS_GRAY;
+               break;
+       case IL_RGBA:
+       case IL_BGRA:
+               *flags |= HAS_ALPHA;
+       case IL_RGB:
+       case IL_BGR:
+       default:
+               break;
+       }
+}
+
+int convert_picture (uint_fast16_t id, struct IL_full_info *info, FLAG_TYPE *flags)
 {
        ILint current_format;
        ILint final_format;
@@ -156,18 +201,23 @@ int convert_picture (uint_fast16_t id, FLAG_TYPE flags)
        ILint final_type;
        ILint current_palette_type;
        ILint final_palette_type;
-       ILboolean r;
+       struct IL_full_info info_c;
+       int r;
        
        if (id >= n_pictures)
                return EINVAL;
        
+       r = get_info (id, &info_c, 0);
+       if (r!=0)
+               return r;
+       
        ilBindImage(picture[id].handle);
-       current_format = ilGetInteger(IL_IMAGE_FORMAT);
+       current_format = info_c.image_format;
        final_format = current_format;
-       current_type = ilGetInteger(IL_IMAGE_TYPE);
+       current_type = info_c.image_type;
        final_type = current_type;
        
-       if (!(flags & CAN_BE_MULTIPLE))
+       if (!(*flags & CAN_BE_MULTIPLE))
        {
                if (ilGetInteger(IL_NUM_IMAGES) > 0)
                {
@@ -178,10 +228,10 @@ int convert_picture (uint_fast16_t id, FLAG_TYPE flags)
        
        if (final_format == IL_COLOUR_INDEX)
        {
-               current_palette_type = ilGetInteger(IL_PALETTE_TYPE);
+               current_palette_type = info_c.palette_type;
                final_palette_type = current_palette_type;
                
-               if (flags & CANNOT_BE_INDEXED)
+               if (*flags & (CANNOT_BE_INDEXED | MUST_BE_GRAY))
                {
                        switch (final_palette_type)
                        {
@@ -214,7 +264,7 @@ int convert_picture (uint_fast16_t id, FLAG_TYPE flags)
                }
                else
                {
-                       if (!(flags & CAN_BE_OVER_8BIT))
+                       if (!(*flags & CAN_BE_OVER_8BIT))
                        {
                                switch (final_palette_type)
                                {
@@ -229,7 +279,7 @@ int convert_picture (uint_fast16_t id, FLAG_TYPE flags)
                                }
                        }
                        
-                       if (flags & MUST_HAVE_ALPHA)
+                       if (*flags & MUST_HAVE_ALPHA)
                        {
                                switch (final_palette_type)
                                {
@@ -245,7 +295,7 @@ int convert_picture (uint_fast16_t id, FLAG_TYPE flags)
                                        break;
                                }
                        }
-                       else if (flags & CANNOT_HAVE_ALPHA)
+                       else if (*flags & CANNOT_HAVE_ALPHA)
                        {
                                switch (final_palette_type)
                                {
@@ -260,13 +310,10 @@ int convert_picture (uint_fast16_t id, FLAG_TYPE flags)
                                }
                        }
                        
-                       /* TODO: GRAY */
-                       
                        if (final_palette_type != current_palette_type)
                        {
-                               fputs("CONVERT PAL!\n", stderr);
-                               r = ilConvertPal(final_palette_type);
-                               if (!r)
+                               fputs("Palette was converted!\n", stderr);
+                               if (!(ilConvertPal(final_palette_type)))
                                {
                                        fputs("Palette conversion failed.\n", stderr);
                                        return EIO;
@@ -277,13 +324,13 @@ int convert_picture (uint_fast16_t id, FLAG_TYPE flags)
        
        if (final_format != IL_COLOUR_INDEX) /* might have changed */
        {
-               if (flags & MUST_BE_INDEXED)
+               if (*flags & MUST_BE_INDEXED)
                {
-                       fputs("Picture is not allowed to be indexed.\n", stderr);
+                       fputs("Picture must be indexed.\n", stderr);
                        return EINVAL;
                }
                
-               if (flags & MUST_HAVE_ALPHA)
+               if (*flags & MUST_HAVE_ALPHA)
                {
                        switch (final_format)
                        {
@@ -300,7 +347,7 @@ int convert_picture (uint_fast16_t id, FLAG_TYPE flags)
                                break;
                        }
                }
-               else if (flags & CANNOT_HAVE_ALPHA)
+               else if (*flags & CANNOT_HAVE_ALPHA)
                {
                        switch (final_format)
                        {
@@ -318,7 +365,7 @@ int convert_picture (uint_fast16_t id, FLAG_TYPE flags)
                        }
                }
                
-               if (flags & MUST_BE_GRAY)
+               if (*flags & MUST_BE_GRAY)
                {
                        switch (final_format)
                        {
@@ -334,7 +381,7 @@ int convert_picture (uint_fast16_t id, FLAG_TYPE flags)
                                break;
                        }
                }
-               else if (flags & CANNOT_BE_GRAY)
+               else if (*flags & CANNOT_BE_GRAY)
                {
                        switch (final_format)
                        {
@@ -342,14 +389,14 @@ int convert_picture (uint_fast16_t id, FLAG_TYPE flags)
                                final_format = IL_RGB;
                                break;
                        case IL_LUMINANCE_ALPHA:
-                               final_format = IL_RGB;
+                               final_format = IL_RGBA;
                                break;
                        default:
                                break;
                        }
                }
                
-               if (flags & CAN_BE_OVER_8BIT)
+               if (*flags & CAN_BE_OVER_8BIT)
                {
                        switch(final_type)
                        {
@@ -373,19 +420,32 @@ int convert_picture (uint_fast16_t id, FLAG_TYPE flags)
                
                if ((final_type != current_type) || (final_format != current_format))
                {
-                       fputs("CONVERT IMG!\n", stderr);
-                       r = ilConvertImage(final_format, final_type);
-                       if (!r)
+                       fputs("Picture is converted!\n", stderr);
+                       if (!(ilConvertImage(final_format, final_type)))
                        {
                                fputs("Image format conversion failed.\n", stderr);
                                return EIO;
                        }
                }
        }
+       if (info == NULL)
+       {
+               r = get_info (id, &info_c, 0);
+               if (r!=0)
+                       return r;
+               get_flags(&info_c, flags);
+       }
+       else
+       {
+               r = get_info (id, info, 0);
+               if (r!=0)
+                       return r;
+               get_flags(info, flags);
+       }
        return 0;
 }
 
-int load_picture (uint_fast16_t id, char *path, FLAG_TYPE flags)
+int load_picture (uint_fast16_t id, char *path, struct IL_full_info *info, FLAG_TYPE *flags)
 {
        if (id >= n_pictures)
                return EINVAL;
@@ -394,7 +454,7 @@ int load_picture (uint_fast16_t id, char *path, FLAG_TYPE flags)
        if (!ilLoadImage(path))
                return EIO;
        
-       return convert_picture(id, flags);
+       return convert_picture(id, info, flags);
 }
 
 int save_picture (uint_fast16_t id, char *path, FLAG_TYPE flags)
@@ -405,7 +465,7 @@ int save_picture (uint_fast16_t id, char *path, FLAG_TYPE flags)
                return EINVAL;
        
        ilBindImage(picture[id].handle);
-       r = convert_picture(id, flags);
+       r = convert_picture(id, NULL, &flags);
        if (r)
                return r;
        
@@ -864,6 +924,29 @@ int action_1picture (
        return r;
 }
 
+ILuint upscale_value (ILubyte x, ILint bytes)
+{
+       ILint i;
+       ILuint y = 0;
+       
+       for (i=0; i<bytes; ++i)
+       {
+               y <<= 8;
+               y |= x;
+       }
+}
+
+ILubyte downscale_value (ILuint x, ILint bytes)
+{
+       ILint i;
+       
+       return (ILubyte)(x >> (8 * (bytes-1)));
+}
+
+
+
+
+
 // int action(
        // ILuint n, struct PixelInfo *info, void *data
 // )
diff --git a/core.h b/core.h
index 726ff3a1d68b238f34a56f9439900e9efe4d057f..43120ab0fa387d3f509c8b104fca74b6883713ea 100644 (file)
--- a/core.h
+++ b/core.h
@@ -1,7 +1,7 @@
  /*
 core.h
 The tool with multiple enhancements and manipulations of pictures
-12.11.2022
+13.11.2022
 
 Copyright (C) 2022  Balthasar Szczepański
 
@@ -172,11 +172,15 @@ void close_picture (uint_fast16_t id);
 void close_pictures (void);
 void clear_pictures (void);
 int reserve_pictures (uint_fast16_t n);
-int convert_picture (uint_fast16_t id, FLAG_TYPE flags);
-int load_picture (uint_fast16_t id, char *path, FLAG_TYPE flags);
+void get_flags (struct IL_full_info *info, FLAG_TYPE *flags);
+int convert_picture (uint_fast16_t id, struct IL_full_info *info, FLAG_TYPE *flags);
+int load_picture (uint_fast16_t id, char *path, struct IL_full_info *info, FLAG_TYPE *flags);
 int save_picture (uint_fast16_t id, char *path, FLAG_TYPE flags);
 int get_info (uint_fast16_t id, struct IL_full_info *info, ILint frame);
 
+ILuint upscale_value (ILubyte x, ILint bytes);
+ILubyte downscale_value (ILuint x, ILint bytes);
+
 int action_1picture (
        uint_fast16_t id,
        ILint x0, ILint y0, ILint f0, ILint width, ILint height, ILint frames,
index 0808b9dbff111962645d8eb771922862ed48de9d..9df533279ad486eaadc95fa344598a912367e6cb 100644 (file)
--- a/enhance.c
+++ b/enhance.c
@@ -1,7 +1,7 @@
 /*
 enhance.c
 The tool with multiple enhancements and manipulations of pictures
-12.11.2022
+13.11.2022
 
 Copyright (C) 2022  Balthasar Szczepański
 
@@ -31,6 +31,7 @@ on Pentium III libdevil must be recompiled with
 #include "core.h"
 #include "info.h"
 #include "nofading.h"
+#include "bluenh.h"
 
 int main (int argc, char **argv)
 {
@@ -50,6 +51,8 @@ int main (int argc, char **argv)
                f = &subtool_nofading;
        else if (strcmp(argv[1], "info")==0)
                f = &subtool_info;
+       else if (strcmp(argv[1], "bluenh")==0)
+               f = &subtool_bluenh;
        else
                finish(EINVAL, "Unknown mode.\n");
        
diff --git a/info.c b/info.c
index 05a40d4efd108ff8178db76572cbeaf75755748a..0fa6d36f7a59159a6a10eedc186cebefb0f55f9a 100644 (file)
--- a/info.c
+++ b/info.c
@@ -167,6 +167,7 @@ int subtool_info (int argc, char **argv, int argi, char **err)
        ILint j;
        ILint frames=1;
        struct IL_full_info info;
+       FLAG_TYPE flags = OK_PALETTE_ONLY | CAN_BE_MULTIPLE | CAN_BE_OVER_8BIT;
        
        if (argc <= argi)
        {
@@ -184,8 +185,7 @@ int subtool_info (int argc, char **argv, int argi, char **err)
        for (i=argi; i<argc; ++i)
        {
                fprintf(stdout,"\n>>> %s <<<\n",argv[i]);
-               r = load_picture(0, argv[i],
-                       OK_PALETTE_ONLY | CAN_BE_MULTIPLE | CAN_BE_OVER_8BIT);
+               r = load_picture(0, argv[i], &info, &flags);
                if (r)
                {
                        fputs("FAIL\n",stdout);
diff --git a/info.h b/info.h
index 86110b508400688043a6e6c31289914edbcbbb4f..8c93d3af87f4f7430ef54624738f950fd5470ea9 100644 (file)
--- a/info.h
+++ b/info.h
@@ -1,7 +1,7 @@
- /*
+/*
 info.h
 Get information
-12.11.2022
+13.11.2022
 
 Copyright (C) 2022  Balthasar Szczepański
 
@@ -25,4 +25,4 @@ on Pentium III libdevil must be recompiled with
 (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954)
 */
 
-SUBTOOL_F subtool_info;
+int subtool_info (int argc, char **argv, int argi, char **err);
index ebbf22fb8ad83b1f33d4b22c9193ca2b50f85bd5..e16336850cd57d35652fd7a82db6b357635e0841 100644 (file)
--- a/makefile
+++ b/makefile
@@ -39,11 +39,24 @@ RM   =/usr/bin/rm
 
 STANDALONE=\
 nofading\
-info
+info\
+bluenh
 
 C_STANDALONE=\
 standalone-nofading.c\
-standalone-info.c
+standalone-info.c\
+standalone-bluenh.c
+
+C_SUBTOOL=\
+nofading.c\
+info.c\
+bluenh.c
+
+H_SUBTOOL=\
+nofading.h\
+info.h\
+bluenh.h
+
 
 #all: 403 npb npbd npb-ong1 npbd-ong1 bluenh bluenhd insert extract seediff insertframe mremapt-1 compare nofading nofadingd
 all: enhance $(STANDALONE)
@@ -53,8 +66,8 @@ makefile: makefile.1.mak $(CONFIGFILE)
        $(CONFIGURE_CMD) < makefile.1.mak > makefile 
 
 
-enhance: enhance.c core.h core.c nofading.h nofading.c info.h info.c
-       $(CC) $(CF) -o enhance enhance.c core.c nofading.c info.c $(L_IL)
+enhance: enhance.c core.h core.c $(H_SUBTOOL) $(C_SUBTOOL)
+       $(CC) $(CF) -o enhance enhance.c core.c $(C_SUBTOOL) $(L_IL)
 
 $(STANDALONE): %: standalone-%.c %.c %.h core.c core.h
        $(CC) $(CF) -o $@ standalone-$*.c $*.c core.c $(L_IL)
index 5e34c8e058550a82ebb721b054b6058aedde93bb..9f6b54dff22be55f5fff8f7b90ad3997b303c632 100644 (file)
@@ -39,11 +39,24 @@ CONFIGURE_CMD = $(PERL) $(CONFIGURE) $(CONFIGFILE)
 
 STANDALONE=\
 nofading\
-info
+info\
+bluenh
 
 C_STANDALONE=\
 standalone-nofading.c\
-standalone-info.c
+standalone-info.c\
+standalone-bluenh.c
+
+C_SUBTOOL=\
+nofading.c\
+info.c\
+bluenh.c
+
+H_SUBTOOL=\
+nofading.h\
+info.h\
+bluenh.h
+
 
 #all: 403 npb npbd npb-ong1 npbd-ong1 bluenh bluenhd insert extract seediff insertframe mremapt-1 compare nofading nofadingd
 all: enhance $(STANDALONE)
@@ -53,8 +66,8 @@ makefile: makefile.1.mak $(CONFIGFILE)
        $(CONFIGURE_CMD) < makefile.1.mak > makefile 
 
 
-enhance: enhance.c core.h core.c nofading.h nofading.c info.h info.c
-       $(CC) $(CF) -o enhance enhance.c core.c nofading.c info.c $(L_IL)
+enhance: enhance.c core.h core.c $(H_SUBTOOL) $(C_SUBTOOL)
+       $(CC) $(CF) -o enhance enhance.c core.c $(C_SUBTOOL) $(L_IL)
 
 $(STANDALONE): %: standalone-%.c %.c %.h core.c core.h
        $(CC) $(CF) -o $@ standalone-$*.c $*.c core.c $(L_IL)
index d37f16d62c83ec144cad2c1324737060cbc127bb..9343e1a42fb34f4da445f1f0b9ef7684d8809b32 100644 (file)
@@ -1,7 +1,7 @@
 /*
 nofading.c
 The tool to remove fading from an image
-12.11.2022
+13.11.2022
 
 Copyright (C) 2015, 2022  Balthasar Szczepański
 
@@ -43,7 +43,7 @@ on Pentium III libdevil must be recompiled with
                (high) = (val); \
 }
 
-char NOFADING_MISSING_ARGS[] = "Missing parameters.\nnofading [-a -c -f] [framesize]\n";
+char NOFADING_MISSING_ARGS[] = "Missing parameters.\nnofading [-a -c -f] inPix outPix [framesize]\n";
 
 struct nofading_data
 {
@@ -172,7 +172,7 @@ int subtool_nofading (int argc, char **argv, int argi, char **err)
                return r;
        }
        
-       r = load_picture(0, argv[optind], flags);
+       r = load_picture(0, argv[optind], &info, &flags);
        if (r)
        {
                *err = LOAD_FAILED;
@@ -202,7 +202,7 @@ int subtool_nofading (int argc, char **argv, int argi, char **err)
                data.alpha_high= 0x00000000;
                
                get_info(0, &info, f);
-               data.max = (1<<(info.image_bpc<<3))-1;
+               data.max = upscale_value(0xFF,info.image_bpc);
                if (f==0)
                {
                        if (flags & IN_WINDOW) 
index dc13e79c2d335b2ca5ff7393f575ae7ccff6c241..982f224146e462c7c85b5d805a81ede0bf7e91e1 100644 (file)
@@ -1,7 +1,7 @@
- /*
+/*
 nofading.h
 The tool with multiple enhancements and manipulations of pictures
-12.11.2022
+13.11.2022
 
 Copyright (C) 2022  Balthasar Szczepański
 
@@ -25,4 +25,4 @@ on Pentium III libdevil must be recompiled with
 (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954)
 */
 
-SUBTOOL_F subtool_nofading;
+int subtool_nofading (int argc, char **argv, int argi, char **err);
diff --git a/testimg/blue.png b/testimg/blue.png
new file mode 100644 (file)
index 0000000..0657e97
Binary files /dev/null and b/testimg/blue.png differ