/*
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
}
}
-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; ++i)
create_picture(i);
+ return 0;
}
void close_picture (uint_fast16_t id)
return 0;
}
+
+int convert_picture (uint_fast16_t id, FLAG_TYPE flags)
+{
+ ILint current_format;
+ ILint final_format;
+ ILint current_type;
+ ILint final_type;
+ ILint current_palette_type;
+ ILint final_palette_type;
+ ILboolean r;
+
+ if (id >= 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<frames;
+ ++z, frame_offset += frame_bytes
+ ){
+ for (
+ y=y0, line_offset=frame_offset+line_start+(y0*line_bytes);
+ y < y0 + height;
+ ++y, line_offset += line_bytes;
+ ){
+ if ((y>=0)&&(y<info.image_height))
+ {
+ for (
+ x=x0, pixel_offset=line_offset+(x0*info.bytes_per_pixel);
+ x < x0 + width;
+ ++x
+ ){
+ if ((x>=0)&&(x<info.image_width))
+ {
+ if (flags & IS_INDEXED)
+ {
+
+ }
+ else
+ {
+ switch (info.image_type)
+ {
+ case IL_INT:
+ case IL_UNSIGNED_INT:
+ if(flags & IS_GRAY)
+ y = (ILuint)(*((ILuint*)(data+pixel_offset+y_offset)));
+ else
+ {
+ r = (ILuint)(*((ILuint*)(data+pixel_offset+r_offset)));
+ g = (ILuint)(*((ILuint*)(data+pixel_offset+g_offset)));
+ b = (ILuint)(*((ILuint*)(data+pixel_offset+b_offset)));
+ }
+ if(flags & HAS_ALPHA)
+ a = (ILuint)(*((ILuint*)(data+pixel_offset+a_offset)));
+ break;
+ case IL_SHORT:
+ case IL_UNSIGNED_SHORT:
+ if(flags & IS_GRAY)
+ y = (ILuint)(*((ILuint*)(data+pixel_offset+y_offset)));
+ else
+ {
+ r = (ILuint)(*((ILuint*)(data+pixel_offset+r_offset)));
+ g = (ILuint)(*((ILuint*)(data+pixel_offset+g_offset)));
+ b = (ILuint)(*((ILuint*)(data+pixel_offset+b_offset)));
+ }
+ if(flags & HAS_ALPHA)
+ a = (ILuint)(*((ILuint*)(data+pixel_offset+a_offset)));
+ break;
+ }
+
+
+
+ }
+ }
+ }
+ }
+ }
+ }
+
+void action(
+ ILint x, ILint y, ILint z,
+ ILuint *r, ILuint *g, ILuint *b, ILuint *a, ILuint *y, ILuint *i,
+ FLAG_TYPE flags,
+ void *data
\ No newline at end of file
/*
-enhance.c
+core.h
The tool with multiple enhancements and manipulations of pictures
-21.10.2022
+01.11.2022
Copyright (C) 2022 Balthasar Szczepański
#include "IL/il.h"
+#define FLAG_TYPE uint_fast16_t
+
+#define MUST_HAVE_ALPHA 0x0001
+#define CANNOT_HAVE_ALPHA 0x0002
+#define MUST_BE_GRAY 0x0004
+#define CANNOT_BE_GRAY 0x0008
+#define MUST_BE_INDEXED 0x0010
+#define CANNOT_BE_INDEXED 0x0020
+
+#define OK_PALETTE_ONLY 0x0040
+#define CAN_BE_MULTIPLE 0x0080
+#define CAN_BE_OVER_8BIT 0x0100
+
+#define IN_WINDOW 0x0200
+
+#define HAS_ALPHA 0x0400
+#define IS_GRAY 0x0800
+#define IS_INDEXED 0x1000
+#define IS_MULTIPLE 0x2000
+#define IS_OVER_8BIT 0x4000
+#define IS_PALETTE_ONLY 0x8000
+
+
struct Picture {
uint_fast8_t open;
ILuint handle;
};
+struct IL_full_info {
+ ILint active_image;
+ ILint active_layer;
+ ILint active_mipmap;
+ ILint conv_pal;
+ ILint cur_image;
+ ILint file_mode;
+ ILint format_mode;
+ ILint format_set;
+ ILint image_bits_per_pixel;
+ ILint image_bytes_per_pixel;
+ ILint image_format;
+ ILint image_height;
+ ILint image_type;
+ ILint image_width;
+ ILint num_images;
+ ILint num_mipmaps;
+ ILint origin_mode;
+ ILint origin_set;
+ ILint palette_bpp;
+ ILint palette_num_cols;
+ ILint palette_type;
+ ILint type_mode;
+ ILint type_set;
+ ILint use_key_colour;
+ ILint version_num;
+};
+
void finish (int const returnvalue, char const * const returntext);
void init (void);
void create_picture (uint_fast16_t id);
-void create_pictures (uint_fast16_t n);
+int create_pictures (uint_fast16_t n);
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_info (uint_fast16_t id, struct IL_full_info *info);
*/
#include <errno.h>
+#include <string.h>
+
#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
--- /dev/null
+/*
+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 <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 <stdint.h>
+#include <inttypes.h>
+#include <errno.h>
+
+#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<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);
+ 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 <stdlib.h>
+#include <stdio.h>
+#include <IL/il.h>
+
+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<inX-frame;++i)
+ {
+ for(unsigned long j=frame;j<inY-frame;++j)
+ {
+ if(CR<*ra)
+ *ra=CR;
+ if(CR>*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<inX-frame;++i)
+ {
+ for(unsigned long j=frame;j<inY-frame;++j)
+ {
+
+ CR=enhance(CR,RA,RB);
+ CG=enhance(CG,GA,GB);
+ CB=enhance(CB,BA,BB);
+ }
+ }
+ 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("nofadig inPix outPix [framesize] [q] [a]\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
+ /*
+info.h
+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 <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 info (int argc, char **argv, char **err);
#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
-// 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 <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)
+/*
+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 <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 <stdint.h>
+#include <inttypes.h>
+#include <errno.h>
+
+#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
ilDeleteImages(1, &pix);
exit(mustard);
}
-
+*/
--- /dev/null
+ /*
+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 <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 nofading (int argc, char **argv, char **err);