/*
core.c
The tool with multiple enhancements and manipulations of pictures
-28.11.2022
+26.11.2022
Copyright (C) 2014, 2015, 2022 Balthasar Szczepański
return 0;
}
+int set_palette (uint_fast16_t id, void *palette, ILuint size, ILenum type, ILuint frame)
+{
+ if (id >= n_pictures)
+ return EINVAL;
+ if (!(picture[id].open))
+ return EIO;
+ ilBindImage(picture[id].handle);
+ if (frame > ilGetInteger(IL_NUM_IMAGES))
+ return EINVAL;
+ ilActiveImage(frame);
+ if (ilGetInteger(IL_IMAGE_FORMAT) != IL_COLOUR_INDEX)
+ return EINVAL;
+ ilRegisterPal(palette, size, type);
+ return 0;
+}
+
void create_picture (uint_fast16_t id)
{
if (id<n_pictures)
return r;
}
-
int perform_action_palette_mix (
uint_fast16_t *id,
- ILint *f0,
- ILint frames,
ACTION_F *function,
FLAG_TYPE *flags,
void *data
else
actual_frames = 1;
- if (*flags & IN_WINDOW) /* check first flags only! */
- p[i].f0 = f0[i];
- else
- p[i].f0 = f0[i];
+ p[i].f0 = 0;
}
n_colors = p[0].info.palette_num_cols * p[1].info.palette_num_cols;
return EINVAL;
}
- if (!(*flags & IN_WINDOW)) /* check first flags only! */
- frames = actual_frames;
-
- for (f = 0; (f < frames) && (r == 0); ++f)
+ for (f = 0; (f < actual_frames) && (r == 0); ++f)
{
skip_frame = 0;
for (i=0; i<3; ++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
-28.11.2022
+29.11.2022
Copyright (C) 2022 Balthasar Szczepański
int init (void);
ILuint get_handle (uint_fast16_t id);
int get_data (uint_fast16_t id, void **data, ILuint frame);
+int get_palette (uint_fast16_t id, void **palette, ILuint frame);
+int set_palette (uint_fast16_t id, void *palette, ILuint size, ILenum type, ILuint frame);
void create_picture (uint_fast16_t id);
int create_pictures (uint_fast16_t n);
void close_picture (uint_fast16_t id);
int perform_action_palette_mix (
uint_fast16_t *id,
- ILint *f0,
- ILint frames,
ACTION_F *function,
FLAG_TYPE *flags,
void *data
/*
diff.c
see the difference!
-15.11.2022
+29.11.2022
Copyright (C) 2022 Balthasar Szczepański
struct diff_data
{
ILuint r_a;
- ILuint r_a;
- ILuint r_a;
- ILuint g_b;
- ILuint g_b;
+ ILuint g_a;
+ ILuint b_a;
+ ILuint r_b;
ILuint g_b;
+ ILuint b_b;
ILuint max;
};
+int difference (ILuint n, struct PixelInfo *p, void *data);
+static inline ILuint diff_1ch (ILint64 x, ILint64 y, ILint64 A, ILint64 B, ILint64 F);
+
char DIFF_MISSING_ARGS[] = "Missing parameters.\ndiff inPixA inPixB outPix [RA GA BA [RB GB BB]]\n";
int subtool_diff (int argc, char **argv, int argi, char **err)
CAN_BE_MULTIPLE | CAN_BE_OVER_8BIT | CANNOT_BE_GRAY | NOT_READABLE
};
uint_fast8_t palette_only;
- uint_fast8_t i;
+ ILuint i;
ILubyte new_pal[0x100 * 4];
- ILubyte *pal[3];
- ILuint handle;
int r;
-
if (argc < argi + 3)
{
*err = DIFF_MISSING_ARGS;
return r;
}
- r = load_picture(1, argv[argi], &(info[1]), &(flags[1]));
+ r = load_picture(1, argv[argi+1], &(info[1]), &(flags[1]));
if (r)
{
*err = LOAD_FAILED;
flags[2] |= CANNOT_BE_INDEXED;
}
- r = convert_picture(0, &(info[0]), &(flags[0]);
+ r = convert_picture(0, &(info[0]), &(flags[0]));
{
*err = CONVERT_FAILED;
return EIO;
}
- r = convert_picture(1, &(info[1]), &(flags[1]);
+ r = convert_picture(1, &(info[1]), &(flags[1]));
{
*err = CONVERT_FAILED;
return EIO;
data.b_b = upscale_value(BB, info[0].image_bpc);
}
- r = build_picture_from_info(2, &(info[0], &(info[2]), &(flags[2]));
+ r = build_picture_from_info(2, &(info[0]), &(info[2]), &(flags[2]));
if (r!=0)
{
*err = CREATE_FAILED;
if (palette_only)
{
+ for (i=0; i<=info[2].num_images; ++i)
+ {
+ set_palette (
+ 2,
+ new_pal,
+ info[0].palette_num_cols * info[1].palette_num_cols * info[0].palette_bpp,
+ info[0].palette_type,
+ i
+ );
+ }
- ilRegisterPal
-
-
+ r = perform_action_palette_mix(
+ id,
+ &difference,
+ flags,
+ &data
+ );
+ if (r)
+ {
+ *err = CONVERT_FAILED;
+ return r;
+ }
}
else
{
- for (i=0; i<3; ++i)
+ r = perform_action(
+ 3,
+ id,
+ xyf0, xyf0, xyf0,
+ 0, 0, 0,
+ &difference,
+ flags,
+ &data
+ );
+ if (r)
{
- handle = get_handle(i);
- ilBindImage(handle);
- if (i==2)
- {
- ilRegisterPal(
- new_pal,
- ((flags[0] & HAS_ALPHA)?4:3) * info[0].palette_num_cols * info[1].palette_num_cols,
-
-
-
+ *err = CONVERT_FAILED;
+ return r;
+ }
}
+
+ r = save_picture(2, argv[argi+2], flags[2]);
+ if (r!=0)
+ {
+ *err = SAVE_FAILED;
+ return r;
+ }
+
+ return 0;
+}
+
+int difference (ILuint n, struct PixelInfo *p, void *data)
+{
+ struct diff_data *d;
+ d = data;
+
+ if (n != 3)
+ return EIO;
+
+ p[2].red = diff_1ch(p[0].red, p[1].red, d->r_a, d->r_b, d->max);
+ p[2].green = diff_1ch(p[0].green, p[1].green, d->g_a, d->g_b, d->max);
+ p[2].blue = diff_1ch(p[0].blue, p[1].blue, d->b_a, d->b_b, d->max);
+ if (p[2].flags & HAS_ALPHA)
+ p[2].alpha = (p[0].alpha + p[1].alpha) / 2; /* no better idea */
+
+ return 0;
+}
+
+static inline ILuint diff_1ch (ILint64 x, ILint64 y, ILint64 A, ILint64 B, ILint64 F)
+{
+ ILint64 v;
+
+ if (x == y)
+ return (ILuint) x;
+ else if (x > y)
+ v = (A * (x - y)) / F;
+ else
+ v = (B * (y - x)) / F;
+
+ return (ILuint) v;
+}
--- /dev/null
+/*
+diff.h
+see the difference!
+29.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_diff (int argc, char **argv, int argi, char **err);
/*
enhance.c
The tool with multiple enhancements and manipulations of pictures
-13.11.2022
+29.11.2022
Copyright (C) 2022 Balthasar Szczepański
#include "nofading.h"
#include "bluenh.h"
#include "reveal.h"
+#include "diff.h"
int main (int argc, char **argv)
{
f = &subtool_bluenh;
else if (strcmp(argv[1], "reveal")==0)
f = &subtool_reveal;
+ else if (strcmp(argv[1], "diff")==0)
+ f = &subtool_diff;
else
finish(EINVAL, "Unknown mode.\n");
# "makefile" is automatically generated from "makefile.1.mak"
-# 12.11.2022
+# 29.11.2022
#
# Copyright (C) 2022 Balthasar Szczepański
#
nofading\
info\
bluenh\
-reveal
+reveal\
+diff
C_STANDALONE=\
standalone-nofading.c\
standalone-info.c\
standalone-bluenh.c\
-standalone-reveal.c
+standalone-reveal.c\
+standalone-diff.c
C_SUBTOOL=\
nofading.c\
info.c\
bluenh.c\
-reveal.c
+reveal.c\
+diff.c
H_SUBTOOL=\
nofading.h\
info.h\
bluenh.h\
-reveal.h
+reveal.h\
+diff.h
#all: 403 npb npbd npb-ong1 npbd-ong1 bluenh bluenhd insert extract seediff insertframe mremapt-1 compare nofading nofadingd
# "makefile" is automatically generated from "makefile.1.mak"
-# 12.11.2022
+# 29.11.2022
#
# Copyright (C) 2022 Balthasar Szczepański
#
nofading\
info\
bluenh\
-reveal
+reveal\
+diff
C_STANDALONE=\
standalone-nofading.c\
standalone-info.c\
standalone-bluenh.c\
-standalone-reveal.c
+standalone-reveal.c\
+standalone-diff.c
C_SUBTOOL=\
nofading.c\
info.c\
bluenh.c\
-reveal.c
+reveal.c\
+diff.c
H_SUBTOOL=\
nofading.h\
info.h\
bluenh.h\
-reveal.h
+reveal.h\
+diff.h
#all: 403 npb npbd npb-ong1 npbd-ong1 bluenh bluenhd insert extract seediff insertframe mremapt-1 compare nofading nofadingd