--- /dev/null
+/*
+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);
+}
+*/
+++ /dev/null
- // //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);
-}
-
--- /dev/null
+/*
+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);
/*
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
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;
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)
{
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)
{
}
else
{
- if (!(flags & CAN_BE_OVER_8BIT))
+ if (!(*flags & CAN_BE_OVER_8BIT))
{
switch (final_palette_type)
{
}
}
- if (flags & MUST_HAVE_ALPHA)
+ if (*flags & MUST_HAVE_ALPHA)
{
switch (final_palette_type)
{
break;
}
}
- else if (flags & CANNOT_HAVE_ALPHA)
+ else if (*flags & CANNOT_HAVE_ALPHA)
{
switch (final_palette_type)
{
}
}
- /* 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;
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)
{
break;
}
}
- else if (flags & CANNOT_HAVE_ALPHA)
+ else if (*flags & CANNOT_HAVE_ALPHA)
{
switch (final_format)
{
}
}
- if (flags & MUST_BE_GRAY)
+ if (*flags & MUST_BE_GRAY)
{
switch (final_format)
{
break;
}
}
- else if (flags & CANNOT_BE_GRAY)
+ else if (*flags & CANNOT_BE_GRAY)
{
switch (final_format)
{
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)
{
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;
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)
return EINVAL;
ilBindImage(picture[id].handle);
- r = convert_picture(id, flags);
+ r = convert_picture(id, NULL, &flags);
if (r)
return r;
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
// )
/*
core.h
The tool with multiple enhancements and manipulations of pictures
-12.11.2022
+13.11.2022
Copyright (C) 2022 Balthasar Szczepański
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,
/*
enhance.c
The tool with multiple enhancements and manipulations of pictures
-12.11.2022
+13.11.2022
Copyright (C) 2022 Balthasar Szczepański
#include "core.h"
#include "info.h"
#include "nofading.h"
+#include "bluenh.h"
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");
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)
{
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);
- /*
+/*
info.h
Get information
-12.11.2022
+13.11.2022
Copyright (C) 2022 Balthasar Szczepański
(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);
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)
$(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)
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)
$(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)
/*
nofading.c
The tool to remove fading from an image
-12.11.2022
+13.11.2022
Copyright (C) 2015, 2022 Balthasar Szczepański
(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
{
return r;
}
- r = load_picture(0, argv[optind], flags);
+ r = load_picture(0, argv[optind], &info, &flags);
if (r)
{
*err = LOAD_FAILED;
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)
- /*
+/*
nofading.h
The tool with multiple enhancements and manipulations of pictures
-12.11.2022
+13.11.2022
Copyright (C) 2022 Balthasar Szczepański
(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);