From: b Date: Tue, 1 Nov 2022 20:22:31 +0000 (+0000) Subject: begin general mechanism, X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=31915231161a914fd81cd6ce7a6e8835c075ca2f;p=ott%2Fenhance begin general mechanism, info, test pictures, fading - start work. --- diff --git a/core.c b/core.c index 9eadad4..93d9714 100644 --- a/core.c +++ b/core.c @@ -1,7 +1,7 @@ /* core.c The tool with multiple enhancements and manipulations of pictures -21.10.2022 +01.11.2022 Copyright (C) 2014, 2015, 2022 Balthasar Szczepański @@ -60,13 +60,17 @@ void create_picture (uint_fast16_t id) } } -void create_pictures (uint_fast16_t n) +int create_pictures (uint_fast16_t n) { uint_fast16_t i; + int r; - reserve_pictures(n); + r = reserve_pictures(n); + if (r) + return r; for (i=0; i= n_pictures) + return EINVAL; + + ilBindImage(picture[id].handle); + current_format = ilGetInteger(IL_IMAGE_FORMAT); + final_format = current_format; + current_type = ilGetInteger(IL_IMAGE_TYPE); + final_type = current_type; + + if (!(flags & CAN_BE_MULTIPLE)) + { + if (ilGetInteger(IL_NUM_IMAGES) > 1) + { + fputs("Picture is not allowed to have multiple frames.\n", stderr); + return EINVAL; + } + } + + if (final_format == IL_COLOUR_INDEX) + { + current_palette_type = ilGetInteger(IL_PALETTE_TYPE); + final_palette_type = current_palette_type; + + if (flags & CANNOT_BE_INDEXED) + { + switch (final_palette_type) + { + case IL_PAL_BGR24: + final_format = IL_BGR; + final_type = IL_UNSIGNED_BYTE; + break; + case IL_PAL_BGR32: + final_format = IL_BGR; + final_type = IL_UNSIGNED_SHORT; + break; + case IL_PAL_BGRA32: + final_format = IL_BGRA; + final_type = IL_UNSIGNED_BYTE; + break; + case IL_PAL_RGBA32: + final_format = IL_RGBA; + final_type = IL_UNSIGNED_BYTE; + break; + case IL_PAL_RGB32: + final_format = IL_RGB; + final_type = IL_UNSIGNED_SHORT; + break; + case IL_PAL_RGB24: + default: + final_format = IL_RGB; + final_type = IL_UNSIGNED_BYTE; + break; + } + } + else + { + if (!(flags & CAN_BE_OVER_8BIT)) + { + switch (final_palette_type) + { + case IL_PAL_BGR32: + final_palette_type = IL_PAL_BGR24; + break; + case IL_PAL_RGB32: + final_palette_type = IL_PAL_RGB24; + break; + default: + break; + } + } + + if (flags & MUST_HAVE_ALPHA) + { + switch (final_palette_type) + { + case IL_PAL_BGR24: + case IL_PAL_BGR32: + final_palette_type = IL_PAL_BGRA32; + break; + case IL_PAL_RGB24: + case IL_PAL_RGB32: + final_palette_type = IL_PAL_RGBA32; + break; + default: + break; + } + } + else if (flags & CANNOT_HAVE_ALPHA) + { + switch (final_palette_type) + { + case IL_PAL_BGRA32: + final_palette_type = IL_PAL_BGR24; + break; + case IL_PAL_RGBA32: + final_palette_type = IL_PAL_RGB24; + break; + default: + break; + } + } + + /* TODO: GRAY */ + + if (final_palette_type != current_palette_type) + { + fputs("CONVERT PAL!\n", stderr); + r = ilConvertPal(final_palette_type); + if (!r) + { + fputs("Palette conversion failed.\n", stderr); + return EIO; + } + } + } + } + + if (final_format != IL_COLOUR_INDEX) /* might have changed */ + { + if (flags & MUST_BE_INDEXED) + { + fputs("Picture is not allowed to be indexed.\n", stderr); + return EINVAL; + } + + if (flags & MUST_HAVE_ALPHA) + { + switch (final_format) + { + case IL_RGB: + final_format = IL_RGBA; + break; + case IL_BGR: + final_format = IL_BGRA; + break; + case IL_LUMINANCE: + final_format = IL_LUMINANCE_ALPHA; + break; + default: + break; + } + } + else if (flags & CANNOT_HAVE_ALPHA) + { + switch (final_format) + { + case IL_RGBA: + final_format = IL_RGB; + break; + case IL_BGRA: + final_format = IL_BGR; + break; + case IL_LUMINANCE_ALPHA: + final_format = IL_LUMINANCE; + break; + default: + break; + } + } + + if (flags & MUST_BE_GRAY) + { + switch (final_format) + { + case IL_RGB: + case IL_BGR: + final_format = IL_LUMINANCE; + break; + case IL_RGBA: + case IL_BGRA: + final_format = IL_LUMINANCE_ALPHA; + break; + default: + break; + } + } + else if (flags & CANNOT_BE_GRAY) + { + switch (final_format) + { + case IL_LUMINANCE: + final_format = IL_RGB; + break; + case IL_LUMINANCE_ALPHA: + final_format = IL_RGB; + break; + default: + break; + } + } + + if (flags & CAN_BE_OVER_8BIT) + { + switch(final_type) + { + case IL_BYTE: + final_type = IL_UNSIGNED_BYTE; + break; + case IL_SHORT: + final_type = IL_UNSIGNED_SHORT; + break; + case IL_DOUBLE: + case IL_FLOAT: + case IL_INT: + final_type = IL_UNSIGNED_INT; + break; + default: + break; + } + } + else + final_type = IL_UNSIGNED_BYTE; + + if ((final_type != current_type) || (final_format != current_format)) + { + fputs("CONVERT IMG!\n", stderr); + r = ilConvertImage(final_format, final_type); + if (!r) + { + fputs("Image format conversion failed.\n", stderr); + return EIO; + } + } + } + return 0; +} + +int load_picture (uint_fast16_t id, char *path, FLAG_TYPE flags) +{ + ILboolean r; + + if (id >= n_pictures) + return EINVAL; + + ilBindImage(picture[id].handle); + r = ilLoadImage(path); + if (!r) + return EIO; + + return convert_picture(id, flags); +} + +void get_info (uint_fast16_t id, struct IL_full_info *info) +{ + if (id < n_pictures) + ilBindImage(picture[id].handle); + + info->active_image = ilGetInteger(IL_ACTIVE_IMAGE); + info->active_layer = ilGetInteger(IL_ACTIVE_LAYER); + info->active_mipmap = ilGetInteger(IL_ACTIVE_MIPMAP); + info->conv_pal = ilGetInteger(IL_CONV_PAL); + info->cur_image = ilGetInteger(IL_CUR_IMAGE); + info->file_mode = ilGetInteger(IL_FILE_MODE); + info->format_mode = ilGetInteger(IL_FORMAT_MODE); + info->format_set = ilGetInteger(IL_FORMAT_SET); + info->image_bits_per_pixel = ilGetInteger(IL_IMAGE_BITS_PER_PIXEL); + info->image_bytes_per_pixel = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL); + info->image_format = ilGetInteger(IL_IMAGE_FORMAT); + info->image_height = ilGetInteger(IL_IMAGE_HEIGHT); + info->image_type = ilGetInteger(IL_IMAGE_TYPE); + info->image_width = ilGetInteger(IL_IMAGE_WIDTH); + info->num_images = ilGetInteger(IL_NUM_IMAGES); + info->num_mipmaps = ilGetInteger(IL_NUM_MIPMAPS); + info->origin_mode = ilGetInteger(IL_ORIGIN_MODE); + info->origin_set = ilGetInteger(IL_ORIGIN_SET); + info->palette_bpp = ilGetInteger(IL_PALETTE_BPP); + info->palette_num_cols = ilGetInteger(IL_PALETTE_NUM_COLS); + info->palette_type = ilGetInteger(IL_PALETTE_TYPE); + info->type_mode = ilGetInteger(IL_TYPE_MODE); + info->type_set = ilGetInteger(IL_TYPE_SET); + info->use_key_colour = ilGetInteger(IL_USE_KEY_COLOUR); + info->version_num = ilGetInteger(IL_VERSION_NUM); +} + +int action_1picture ( + uint_fast16_t id, + ILint x0, ILint y0, ILint width, ILint height, + void *function, + FLAG_TYPE flags, + void *data +) +{ + ILint x, y, z; + ILint frames; + IL_full_info *info; + ILuint r, g, b, a, y, i; + ILint line_bytes, line_start, frame_bytes; + ILint frame_offset, line_offset, pixel_offset; + ILint r_offset, g_offset, b_offset, a_offset, y_offset, i_offset; + void *data; + + flags &= ~(IS_GRAY|IS_INDEXED|IS_MULTIPLE|IS_OVER_8BIT|IS_PALETTE_ONLY); + + if (id >= n_pictures) + return EINVAL; + ilBindImage(picture[id].handle); + + data = ilGetData; + + get_info(id, &info); + switch (info.image_format) + { + case IL_COLOUR_INDEX: + info_flag |= IS_INDEXED; + switch (info.palette_type) + { + case IL_PAL_BGR32: + case IL_PAL_RGB32: + info_flag |= IS_OVER_8BIT; + break; + case IL_PAL_BGRA32: + case IL_PAL_RGBA32: + info_flag |= HAS_ALPHA; + break; + case IL_PAL_BGR24: + case IL_PAL_RGB24: + default: + break; + } + } + case IL_LUMINANCE_ALPHA: + info_flag |= HAS_ALPHA; + case IL_LUMINANCE: + info_flag |= IS_GRAY; + break; + case IL_BGRA: + case IL_RGBA: + info_flag |= HAS_ALPHA; + case IL_BGR: + case IL_RGB: + default: + break; + } + switch(info.image_type) + { + case IL_BYTE: + case IL_UNSIGNED_BYTE: + break; + default: + info_flag |= IS_OVER_8BIT; + } + frames = info.num_images; + if (frames > 1) + info_flag |= IS_MULTIPLE; + else if (frames < 1) + frames = 1; + + if ((flags & IS_INDEXED) && (flags & OK_PALETTE_ONLY)) + flags |= IS_PALETTE_ONLY; + + if (!(flags & IN_WINDOW)) + { + x0 = 0; + y0 = 0; + width = info.image_width; + height = info.image_height; + } + + line_bytes = info.bytes_per_pixel * info.image_width; + frame_bytes = line_bytes * info.image_height; + + if (info.origin_mode == IL_ORIGIN_UPPER_LEFT) + { + line_start = frame_bytes; + line_bytes = 0 - line_bytes; + } + else + line_start = 0; + + if (flags & IS_PALETTE_ONLY) + { + + } + else + { + r_offset = -1; + g_offset = -1; + b_offset = -1; + a_offset = -1; + y_offset = -1; + i_offset = -1; + switch (info.image_type) + { + case IL_INT: + case IL_UNSIGNED_INT: + switch (info.image_format) + { + case IL_BGRA: + a_offset = 12; + case IL_BGR: + r_offset = 8; + g_offset = 4; + b_offset = 0; + break; + case IL_RGBA: + a_offset = 12; + case IL_RGB: + r_offset = 0; + g_offset = 4; + b_offset = 8; + break; + case IL_LUMINANCE_ALPHA: + a_offset = 4; + case IL_LUMINANCE: + y_offset = 0; + break; + case IL_COLOUR_INDEX: + i_offset = 0; + default: + break; + } + break; + case IL_SHORT: + case IL_UNSIGNED_SHORT: + switch (info.image_format) + { + case IL_BGRA: + a_offset = 6; + case IL_BGR: + r_offset = 4; + g_offset = 2; + b_offset = 0; + break; + case IL_RGBA: + a_offset = 6; + case IL_RGB: + r_offset = 0; + g_offset = 2; + b_offset = 8; + break; + case IL_LUMINANCE_ALPHA: + a_offset = 2; + case IL_LUMINANCE: + y_offset = 0; + break; + case IL_COLOUR_INDEX: + i_offset = 0; + default: + break; + } + break; + case IL_BYTE: + case IL_UNSIGNED_BYTE: + switch (info.image_format) + { + case IL_BGRA: + a_offset = 3; + case IL_BGR: + r_offset = 2; + g_offset = 1; + b_offset = 0; + break; + case IL_RGBA: + a_offset = 3; + case IL_RGB: + r_offset = 0; + g_offset = 1; + b_offset = 2; + break; + case IL_LUMINANCE_ALPHA: + a_offset = 1; + case IL_LUMINANCE: + y_offset = 0; + break; + case IL_COLOUR_INDEX: + i_offset = 0; + default: + break; + } + break; + default: + break; + } + + for ( + z=0, frame_offset=0; + z=0)&&(y=0)&&(x +#include + #include "core.h" +#include "info.h" +#include "nofading.h" + int main (int argc, char **argv) { + int r; + char *error_text; + if (argc < 2) finish(EINVAL, "No mode selected.\n"); init(); - finish(0, "Ok.\n"); + if (strcmp(argv[1], "nofading")==0) + r = nofading(argc-2, argv+2, &error_text); + else if (strcmp(argv[1], "info")==0) + r = info(argc-2, argv+2, &error_text); + else + finish(EINVAL, "Unknown mode.\n"); + + if (r!=0) + finish(r, error_text); + + + finish(0, ""); } \ No newline at end of file diff --git a/info.c b/info.c new file mode 100644 index 0000000..3c3060c --- /dev/null +++ b/info.c @@ -0,0 +1,390 @@ +/* +info.c +Get information +01.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) + +*/ + +#include +#include +#include + +#include "core.h" +#include "info.h" + +char INFO_MISSING_ARGS[] = "Missing parameters.\ninfo inPix\n"; +char INFO_LOAD_FAILED[] = "Failed to load picture.\n"; + +void print_info_uint (char *name, long unsigned value) +{ + fprintf(stdout, "%s: %lu\n", name, value); +} +void print_info_bool (char *name, long unsigned value) +{ + fprintf(stdout, "%s: %s\n", name, value?"TRUE":"FALSE"); +} +void print_info_datatype (char *name, long unsigned value) +{ + fprintf(stdout,"%s: ",name); + switch (value) + { + case IL_BYTE: + fputs("BYTE", stdout); + break; + case IL_DOUBLE: + fputs("DOUBLE", stdout); + break; + case IL_FLOAT: + fputs("FLOAT", stdout); + break; + case IL_INT: + fputs("INT", stdout); + break; + case IL_SHORT: + fputs("SHORT", stdout); + break; + case IL_UNSIGNED_INT: + fputs("UNSIGNED INT", stdout); + break; + case IL_UNSIGNED_BYTE: + fputs("UNSIGNED BYTE", stdout); + break; + case IL_UNSIGNED_SHORT: + fputs("UNSIGNED SHORT", stdout); + break; + default: + fprintf(stdout, "? %ld", value); + break; + } + fputs("\n", stdout); +} + +void print_info_dataformat (char *name, long unsigned value) +{ + fprintf(stdout,"%s: ",name); + switch (value) + { + case IL_BGR: + fputs("BGR", stdout); + break; + case IL_BGRA: + fputs("BGRA", stdout); + break; + case IL_COLOUR_INDEX: + fputs("COLOUR INDEX", stdout); + break; + case IL_LUMINANCE: + fputs("LUMINANCE", stdout); + break; + case IL_LUMINANCE_ALPHA: + fputs("LUMINANCE ALPHA", stdout); + break; + case IL_RGB: + fputs("RGB", stdout); + break; + case IL_RGBA: + fputs("RGBA", stdout); + break; + default: + fprintf(stdout, "? %ld", value); + break; + } + fputs("\n", stdout); +} + +void print_info_originmode (char *name, long unsigned value) +{ + fprintf(stdout,"%s: ",name); + switch (value) + { + case IL_ORIGIN_LOWER_LEFT: + fputs("LOWER LEFT", stdout); + break; + case IL_ORIGIN_UPPER_LEFT: + fputs("UPPER LEFT", stdout); + break; + default: + fprintf(stdout, "? %ld", value); + break; + } + fputs("\n", stdout); +} + +void print_info_palettetype (char *name, long unsigned value) +{ + fprintf(stdout,"%s: ",name); + switch (value) + { + case IL_PAL_BGR24: + fputs("BGR24", stdout); + break; + case IL_PAL_BGR32: + fputs("BGR32", stdout); + break; + case IL_PAL_BGRA32: + fputs("BGRA32", stdout); + break; + case IL_PAL_RGB24: + fputs("RGB24", stdout); + break; + case IL_PAL_RGB32: + fputs("RGB32", stdout); + break; + case IL_PAL_RGBA32: + fputs("RGBA32", stdout); + break; + default: + fprintf(stdout, "? %ld", value); + break; + } + fputs("\n", stdout); +} + +int info (int argc, char **argv, char **err) +{ + int r; + int i; + struct IL_full_info info; + + if (argc<1) + { + *err = INFO_MISSING_ARGS; + return EINVAL; + } + + r = create_pictures(1); + if (r) + { + *err = INFO_LOAD_FAILED; + return r; + } + + for (i=0; i>> %s <<<\n",argv[i]); + r = load_picture(0, argv[i], + OK_PALETTE_ONLY | CAN_BE_MULTIPLE | CAN_BE_OVER_8BIT); + if (r) + { + fputs("FAIL\n",stdout); + continue; + } + + get_info(0, &info); + print_info_uint ("active_image", info.active_image); + print_info_uint ("active_layer", info.active_layer); + print_info_uint ("active_mipmap", info.active_mipmap); + print_info_bool ("conv_pal", info.conv_pal); + print_info_uint ("cur_image", info.cur_image); + print_info_bool ("file_mode", info.file_mode); + print_info_dataformat ("format_mode", info.format_mode); + print_info_bool ("format_set", info.format_set); + print_info_uint ("image_bits_per_pixel", info.image_bits_per_pixel); + print_info_uint ("image_bytes_per_pixel", info.image_bytes_per_pixel); + print_info_dataformat ("image_format", info.image_format); + print_info_uint ("image_height", info.image_height); + print_info_datatype ("image_type", info.image_type); + print_info_uint ("image_width", info.image_width); + print_info_uint ("num_images", info.num_images); + print_info_uint ("num_mipmaps", info.num_mipmaps); + print_info_originmode ("origin_mode", info.origin_mode); + print_info_bool ("origin_set", info.origin_set); + print_info_uint ("palette_bpp", info.palette_bpp); + print_info_uint ("palette_num_cols", info.palette_num_cols); + print_info_palettetype("palette_type", info.palette_type); + print_info_datatype ("type_mode", info.type_mode); + print_info_bool ("type_set", info.type_set); + print_info_bool ("use_key_colour", info.use_key_colour); + print_info_uint ("version_num", info.palette_num_cols); + } + return 0; +} + +/* + +#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 RA ((long)(*ra)) +#define RB ((long)(*rb)) +#define GA ((long)(*ga)) +#define GB ((long)(*gb)) +#define BA ((long)(*ba)) +#define BB ((long)(*bb)) + +#include +#include +#include + +void mustard(int mustard); + +ILubyte enhance(ILubyte x, long r, long s, long t); +int main (int argc, const char *argv[]); + +ILuint pix; +ILboolean q=true; +ILboolean pixOpen=false; +ILboolean allchannels=false; + +ILubyte enhance(ILubyte x, long A, long B) +{ + if(A==B) + return x; + long y=(((long)x)-A)*255/(B-A); + return (ILubyte)((y>255)?255:((y<0)?0:y)); +} + +int main (int argc, const char *argv[]) +{ + ILubyte rav, rbv, gav, gbv, bav, bbv; + ILubyte *ra, *rb, *ga, *gb, *ba, *bb; + ILuint inX, inY, frame; + ILubyte *newdata; + + if(argc<3) + mustard(ARGUMENT_MUSTARD); + if (argc>=4) + { + sscanf(argv[3],"%u",&frame); + } + else + frame=0; + if (argc>=5) + { + if (argv[4][0]=='q' || argv[4][0]=='Q') + q=false; + } + if (argc>=6) + { + if (argv[5][0]=='a' || argv[5][0]=='A') + allchannels=true; + } + + ra=&rav; + rb=&rbv; + if(allchannels) + { + ga=&gav; + gb=&gbv; + ba=&bav; + bb=&bbv; + } + else + { + ga=&rav; + gb=&rbv; + ba=&rav; + bb=&rbv; + } + + 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(); + + *ra=255; + *ga=255; + *ba=255; + *rb=0; + *gb=0; + *bb=0; + + for(unsigned long i=frame;i*rb) + *rb=CR; + if(CG<*ga) + *ga=CG; + if(CG>*gb) + *gb=CG; + if(CB<*ba) + *ba=CB; + if(CB>*bb) + *bb=CB; + } + } + + for(unsigned long i=frame;i. + + +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 info (int argc, char **argv, char **err); diff --git a/makefile b/makefile index 7566ab3..41cc765 100644 --- a/makefile +++ b/makefile @@ -6,8 +6,8 @@ LF=-lIL #all: 403 npb npbd npb-ong1 npbd-ong1 bluenh bluenhd insert extract seediff insertframe mremapt-1 compare nofading nofadingd all: enhance -enhance: enhance.c core.h core.c - $(CC) $(CF) -o enhance enhance.c core.c $(LF) +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 $(LF) #npb-ong1: npb-ong1.cpp makefile # $(CC) $(CF) $(LF) -o npb-ong1 npb-ong1.cpp diff --git a/nofading.cpp b/nofading.c similarity index 56% rename from nofading.cpp rename to nofading.c index 333165f..2079ce6 100644 --- a/nofading.cpp +++ b/nofading.c @@ -1,27 +1,98 @@ -// nofading.cpp -// The tool to remove fading from an image -// 04.03.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) +/* +nofading.c +The tool to remove fading from an image +01.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 . + + +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 "nofading.h" + +char NOFADING_MISSING_ARGS[] = "Missing parameters.\nnofading inPix outPix [a] [framesize]\n"; + +int nofading (int argc, char **argv, char **err) +{ + uint_fast8_t individual_channels; + uint_fast16_t frame_t = 0; + uint_fast16_t frame_b = 0; + uint_fast16_t frame_l = 0; + uint_fast16_t frame_r = 0; + uint_fast8_t palette_only = 0; + + if (argc<2) + { + *err = NOFADING_MISSING_ARGS; + return EINVAL; + } + if (argc>=3) + { + if(argv[2][0]=='a' || argv[3][0]=='A') + individual_channels = 1; + } + + if (argc>=7) + { + sscanf(argv[3], "%"SCNuFAST16, &frame_t); + sscanf(argv[4], "%"SCNuFAST16, &frame_b); + sscanf(argv[5], "%"SCNuFAST16, &frame_l); + sscanf(argv[6], "%"SCNuFAST16, &frame_r); + } + else if (argc>=5) + { + sscanf(argv[3], "%"SCNuFAST16, &frame_t); + frame_b = frame_t; + sscanf(argv[4], "%"SCNuFAST16, &frame_l); + frame_r = frame_l; + } + else if (argc>=4) + { + sscanf(argv[3], "%"SCNuFAST16, &frame_t); + frame_b = frame_t; + frame_l = frame_t; + frame_r = frame_t; + } + else + { + frame_t = 0; + frame_b = 0; + frame_l = 0; + frame_r = 0; + } + + if ((frame_t==0) && (frame_b==0) && (frame_l==0) && (frame_r==0)) + palette_only = OK_PALETTE_ONLY; + + create_pictures(2); + + return 0; +} + +/* #define INPIX_MUSTARD 1 #define OUTPIX_MUSTARD 2 @@ -187,4 +258,4 @@ void mustard(int mustard) ilDeleteImages(1, &pix); exit(mustard); } - +*/ diff --git a/nofading.h b/nofading.h new file mode 100644 index 0000000..56f4a98 --- /dev/null +++ b/nofading.h @@ -0,0 +1,28 @@ + /* +nofading.h +The tool with multiple enhancements and manipulations of pictures +01.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 nofading (int argc, char **argv, char **err); diff --git a/testimg/bmp_16_A1_R5_G5_B5.bmp b/testimg/bmp_16_A1_R5_G5_B5.bmp new file mode 100644 index 0000000..91fc250 Binary files /dev/null and b/testimg/bmp_16_A1_R5_G5_B5.bmp differ diff --git a/testimg/bmp_16_R5_G6_ B5.bmp b/testimg/bmp_16_R5_G6_ B5.bmp new file mode 100644 index 0000000..e03cf51 Binary files /dev/null and b/testimg/bmp_16_R5_G6_ B5.bmp differ diff --git a/testimg/bmp_16_X1_R5_G5_B5.bmp b/testimg/bmp_16_X1_R5_G5_B5.bmp new file mode 100644 index 0000000..1e46a1e Binary files /dev/null and b/testimg/bmp_16_X1_R5_G5_B5.bmp differ diff --git a/testimg/bmp_24_R8_G8_B8.bmp b/testimg/bmp_24_R8_G8_B8.bmp new file mode 100644 index 0000000..df07c39 Binary files /dev/null and b/testimg/bmp_24_R8_G8_B8.bmp differ diff --git a/testimg/bmp_32_A8_R8_G8_B8.bmp b/testimg/bmp_32_A8_R8_G8_B8.bmp new file mode 100644 index 0000000..a3b354e Binary files /dev/null and b/testimg/bmp_32_A8_R8_G8_B8.bmp differ diff --git a/testimg/bmp_32_X8_R8_G8_B8.bmp b/testimg/bmp_32_X8_R8_G8_B8.bmp new file mode 100644 index 0000000..4bbccaf Binary files /dev/null and b/testimg/bmp_32_X8_R8_G8_B8.bmp differ diff --git a/testimg/bmp_GR.bmp b/testimg/bmp_GR.bmp new file mode 100644 index 0000000..c9bcbd5 Binary files /dev/null and b/testimg/bmp_GR.bmp differ diff --git a/testimg/bmp_I16.bmp b/testimg/bmp_I16.bmp new file mode 100644 index 0000000..15dcc66 Binary files /dev/null and b/testimg/bmp_I16.bmp differ diff --git a/testimg/bmp_I2.bmp b/testimg/bmp_I2.bmp new file mode 100644 index 0000000..daaec63 Binary files /dev/null and b/testimg/bmp_I2.bmp differ diff --git a/testimg/bmp_I256.bmp b/testimg/bmp_I256.bmp new file mode 100644 index 0000000..11ee889 Binary files /dev/null and b/testimg/bmp_I256.bmp differ diff --git a/testimg/bmp_I4.bmp b/testimg/bmp_I4.bmp new file mode 100644 index 0000000..2fa5054 Binary files /dev/null and b/testimg/bmp_I4.bmp differ diff --git a/testimg/jpg.jpg b/testimg/jpg.jpg new file mode 100644 index 0000000..1fbdef2 Binary files /dev/null and b/testimg/jpg.jpg differ diff --git a/testimg/png_16_gray.png b/testimg/png_16_gray.png new file mode 100644 index 0000000..1c77d59 Binary files /dev/null and b/testimg/png_16_gray.png differ diff --git a/testimg/png_16_graya.png b/testimg/png_16_graya.png new file mode 100644 index 0000000..a206009 Binary files /dev/null and b/testimg/png_16_graya.png differ diff --git a/testimg/png_16_rgb.png b/testimg/png_16_rgb.png new file mode 100644 index 0000000..22d081c Binary files /dev/null and b/testimg/png_16_rgb.png differ diff --git a/testimg/png_16_rgba.png b/testimg/png_16_rgba.png new file mode 100644 index 0000000..49f8828 Binary files /dev/null and b/testimg/png_16_rgba.png differ diff --git a/testimg/png_8_gray.png b/testimg/png_8_gray.png new file mode 100644 index 0000000..07e4bff Binary files /dev/null and b/testimg/png_8_gray.png differ diff --git a/testimg/png_8_graya.png b/testimg/png_8_graya.png new file mode 100644 index 0000000..d6f5fe0 Binary files /dev/null and b/testimg/png_8_graya.png differ diff --git a/testimg/png_8_rgb.png b/testimg/png_8_rgb.png new file mode 100644 index 0000000..f7136d4 Binary files /dev/null and b/testimg/png_8_rgb.png differ diff --git a/testimg/png_8_rgba.png b/testimg/png_8_rgba.png new file mode 100644 index 0000000..1424923 Binary files /dev/null and b/testimg/png_8_rgba.png differ diff --git a/testimg/png_p.png b/testimg/png_p.png new file mode 100644 index 0000000..e07548e Binary files /dev/null and b/testimg/png_p.png differ diff --git a/testimg/png_p_16_gray.png b/testimg/png_p_16_gray.png new file mode 100644 index 0000000..34bfeb0 Binary files /dev/null and b/testimg/png_p_16_gray.png differ diff --git a/testimg/png_p_16_graya.png b/testimg/png_p_16_graya.png new file mode 100644 index 0000000..e2a0766 Binary files /dev/null and b/testimg/png_p_16_graya.png differ diff --git a/testimg/png_p_16_rgb.png b/testimg/png_p_16_rgb.png new file mode 100644 index 0000000..dcdc611 Binary files /dev/null and b/testimg/png_p_16_rgb.png differ diff --git a/testimg/png_p_16_rgba.png b/testimg/png_p_16_rgba.png new file mode 100644 index 0000000..c94f00d Binary files /dev/null and b/testimg/png_p_16_rgba.png differ diff --git a/testimg/png_p_8_gray.png b/testimg/png_p_8_gray.png new file mode 100644 index 0000000..2b69591 Binary files /dev/null and b/testimg/png_p_8_gray.png differ diff --git a/testimg/png_p_8_graya.png b/testimg/png_p_8_graya.png new file mode 100644 index 0000000..1bdedb7 Binary files /dev/null and b/testimg/png_p_8_graya.png differ diff --git a/testimg/png_p_8_rgb.png b/testimg/png_p_8_rgb.png new file mode 100644 index 0000000..96dfb10 Binary files /dev/null and b/testimg/png_p_8_rgb.png differ diff --git a/testimg/png_p_8_rgba.png b/testimg/png_p_8_rgba.png new file mode 100644 index 0000000..c9895d3 Binary files /dev/null and b/testimg/png_p_8_rgba.png differ