char LOAD_FAILED[] = "Failed to load picture.\n";
char SAVE_FAILED[] = "Failed to save picture.\n";
char CREATE_FAILED[] = "Failed to create picture(s).\n";
-char CONVERT_FAILED[] = "Failed to convert picture.\n";
+char CONVERT_FAILED[]= "Failed to convert picture.\n";
+char SIZE_MISMATCH[] = "Pictures have different sizes.\n";
char NO_STR[] = "";
int init (void)
int build_picture (uint_fast16_t id, ILint width, ILint height, ILint frames, struct IL_full_info *info, FLAG_TYPE *flags)
{
- info->image_width = width;
- info->image_height = height;
+ struct IL_full_info reference_info;
+
+ reference_info.image_width = width;
+ reference_info.image_height = height;
if (*flags & CAN_BE_MULTIPLE)
- info->num_images = frames-1;
+ reference_info.num_images = frames-1;
else
- info->num_images = 0;
+ reference_info.num_images = 0;
if (*flags & MUST_BE_INDEXED)
{
- info->image_format = IL_COLOUR_INDEX;
- info->image_type = IL_UNSIGNED_BYTE;
- info->image_channels = 1;
+ reference_info.image_format = IL_COLOUR_INDEX;
+ reference_info.image_type = IL_UNSIGNED_BYTE;
+ reference_info.image_channels = 1;
}
else
{
{
if (*flags & MUST_HAVE_ALPHA)
{
- info->image_format = IL_LUMINANCE_ALPHA;
- info->image_channels = 2;
+ reference_info.image_format = IL_LUMINANCE_ALPHA;
+ reference_info.image_channels = 2;
}
else
{
- info->image_format = IL_LUMINANCE;
- info->image_channels = 1;
+ reference_info.image_format = IL_LUMINANCE;
+ reference_info.image_channels = 1;
}
}
else
{
if (*flags & MUST_HAVE_ALPHA)
{
- info->image_format = IL_RGBA;
- info->image_channels = 4;
+ reference_info.image_format = IL_RGBA;
+ reference_info.image_channels = 4;
}
else
{
- info->image_format = IL_RGB;
- info->image_channels = 3;
+ reference_info.image_format = IL_RGB;
+ reference_info.image_channels = 3;
}
}
if (*flags & CAN_BE_OVER_8BIT)
- info->image_type = IL_UNSIGNED_SHORT;
+ reference_info.image_type = IL_UNSIGNED_SHORT;
else
- info->image_type = IL_UNSIGNED_BYTE;
+ reference_info.image_type = IL_UNSIGNED_BYTE;
}
- return build_picture_from_info(id, info, flags);
+ return build_picture_from_info(id, &reference_info, info, flags);
}
-int build_picture_from_info (uint_fast16_t id, struct IL_full_info *info, FLAG_TYPE *flags)
+int build_picture_from_info (uint_fast16_t id, struct IL_full_info *reference_info, struct IL_full_info *info, FLAG_TYPE *flags)
{
ILint i;
int r;
create_picture(id);
ilBindImage(picture[id].handle);
- if (info->num_images > 0)
+ if (reference_info->num_images > 0)
{
- if (!ilCreateSubImage(IL_SUB_NEXT, info->num_images))
+ if (!ilCreateSubImage(IL_SUB_NEXT, reference_info->num_images))
return EIO;
}
- for (i=0; i<=info->num_images; ++i)
+ for (i=0; i<=reference_info->num_images; ++i)
{
ilBindImage(picture[id].handle);
ilActiveImage(i);
if (!ilTexImage(
- info->image_width,
- info->image_height,
+ reference_info->image_width,
+ reference_info->image_height,
0,
- info->image_channels,
- info->image_format,
- info->image_type,
+ reference_info->image_channels,
+ reference_info->image_format,
+ reference_info->image_type,
NULL
))
return EIO;
}
- r = get_info(id, info, 0);
- if (r!=0)
- return r;
- get_flags(info, flags);
-
- return 0;
+ return convert_picture (id, info, flags);
}
int save_picture (uint_fast16_t id, char *path, FLAG_TYPE flags)
extern char SAVE_FAILED[];
extern char CREATE_FAILED[];
extern char CONVERT_FAILED[];
+extern char SIZE_MISMATCH[];
struct Picture {
uint_fast8_t open;
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 build_picture (uint_fast16_t id, ILint width, ILint height, ILint frames, struct IL_full_info *info, FLAG_TYPE *flags);
-int build_picture_from_info (uint_fast16_t id, struct IL_full_info *info, FLAG_TYPE *flags);
+int build_picture_from_info (uint_fast16_t id, struct IL_full_info *reference_info, struct IL_full_info *info, FLAG_TYPE *flags);
int get_info (uint_fast16_t id, struct IL_full_info *info, ILint frame);
ILuint upscale_value (ILubyte x, ILint bytes);
--- /dev/null
+/*
+diff.c
+see the difference!
+15.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)
+
+*/
+
+#define RA 0x00
+#define GA 0x57
+#define BA 0xAF
+
+#define RB 0xBB
+#define GB 0x66
+#define BB 0x22
+
+#include <stdio.h>
+#include <errno.h>
+
+#include "bluenh.h"
+#include "core.h"
+
+struct diff_data
+{
+ ILuint r_a;
+ ILuint r_a;
+ ILuint r_a;
+ ILuint g_b;
+ ILuint g_b;
+ ILuint g_b;
+ ILuint max;
+};
+
+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)
+{
+ ILubyte v;
+ struct diff_data data;
+ struct IL_full_info info[3];
+ uint_fast16_t id[3] = {0, 1, 2};
+ ILint xyf0[3] = {0, 0, 0};
+ FLAG_TYPE flags[3] = {
+ CAN_BE_MULTIPLE | CAN_BE_OVER_8BIT | CANNOT_BE_GRAY | NOT_WRITABLE,
+ CAN_BE_MULTIPLE | CAN_BE_OVER_8BIT | CANNOT_BE_GRAY | NOT_WRITABLE,
+ CAN_BE_MULTIPLE | CAN_BE_OVER_8BIT | CANNOT_BE_GRAY | NOT_READABLE
+ };
+ uint_fast8_t palette_only;
+ uint_fast8_t i;
+ ILubyte new_pal[0x100 * 4];
+ ILubyte *pal[3];
+ ILuint handle;
+ int r;
+
+
+ if (argc < argi + 3)
+ {
+ *err = DIFF_MISSING_ARGS;
+ return EINVAL;
+ }
+
+ r = reserve_pictures(3);
+ if (r)
+ {
+ *err = CREATE_FAILED;
+ return r;
+ }
+
+ r = load_picture(0, argv[argi], &(info[0]), &(flags[0]));
+ if (r)
+ {
+ *err = LOAD_FAILED;
+ return r;
+ }
+
+ r = load_picture(1, argv[argi], &(info[1]), &(flags[1]));
+ if (r)
+ {
+ *err = LOAD_FAILED;
+ return r;
+ }
+
+ if ((info[0].image_height != info[1].image_height) || (info[0].image_width != info[1].image_width) || (info[0].num_images != info[1].num_images))
+ {
+ *err = SIZE_MISMATCH;
+ return r;
+ }
+
+ if ((info[0].image_bpc != info[1].image_bpc) || (!(flags[0] & IS_OVER_8BIT)) || (!(flags[0] & IS_OVER_8BIT)))
+ {
+ flags[0] &= ~CAN_BE_OVER_8BIT;
+ flags[1] &= ~CAN_BE_OVER_8BIT;
+ flags[2] &= ~CAN_BE_OVER_8BIT;
+ }
+
+ if ((flags[0] & HAS_ALPHA) || (flags[1] & HAS_ALPHA))
+ {
+ flags[0] |= MUST_HAVE_ALPHA;
+ flags[1] |= MUST_HAVE_ALPHA;
+ flags[2] |= MUST_HAVE_ALPHA;
+ }
+ else
+ flags[2] |= CANNOT_HAVE_ALPHA;
+
+ if ((flags[0] & IS_INDEXED) && (flags[1] & IS_INDEXED) && ((info[0].palette_num_cols * info[1].palette_num_cols) <= 0x100))
+ {
+ palette_only = 1;
+ flags[0] |= OK_PALETTE_ONLY;
+ flags[1] |= OK_PALETTE_ONLY;
+ flags[2] |= OK_PALETTE_ONLY;
+ flags[0] &= ~CAN_BE_OVER_8BIT;
+ flags[1] &= ~CAN_BE_OVER_8BIT;
+ flags[2] &= ~CAN_BE_OVER_8BIT;
+ flags[2] |= MUST_BE_INDEXED;
+ }
+ else
+ {
+ palette_only = 0;
+ flags[0] |= CANNOT_BE_INDEXED;
+ flags[1] |= CANNOT_BE_INDEXED;
+ flags[2] |= CANNOT_BE_INDEXED;
+ }
+
+ r = convert_picture(0, &(info[0]), &(flags[0]);
+ {
+ *err = CONVERT_FAILED;
+ return EIO;
+ }
+
+ r = convert_picture(1, &(info[1]), &(flags[1]);
+ {
+ *err = CONVERT_FAILED;
+ return EIO;
+ }
+
+ if (argc >= argi + 6)
+ {
+ sscanf(argv[argi+3],"%hhu",&v);
+ data.r_a = upscale_value(v, info[0].image_bpc);
+ sscanf(argv[argi+4],"%hhu",&v);
+ data.g_a = upscale_value(v, info[0].image_bpc);
+ sscanf(argv[argi+5],"%hhu",&v);
+ data.b_a = upscale_value(v, info[0].image_bpc);
+ }
+ else
+ {
+ data.r_a = upscale_value(RA, info[0].image_bpc);
+ data.g_a = upscale_value(GA, info[0].image_bpc);
+ data.b_a = upscale_value(BA, info[0].image_bpc);
+ }
+ if (argc >= argi + 9)
+ {
+ sscanf(argv[argi+6],"%hhu",&v);
+ data.r_b = upscale_value(v, info[0].image_bpc);
+ sscanf(argv[argi+7],"%hhu",&v);
+ data.g_b = upscale_value(v, info[0].image_bpc);
+ sscanf(argv[argi+8],"%hhu",&v);
+ data.b_b = upscale_value(v, info[0].image_bpc);
+ }
+ else
+ {
+ data.r_b = upscale_value(RB, info[0].image_bpc);
+ data.g_b = upscale_value(GB, info[0].image_bpc);
+ data.b_b = upscale_value(BB, info[0].image_bpc);
+ }
+
+ r = build_picture_from_info(2, &(info[0], &(info[2]), &(flags[2]));
+ if (r!=0)
+ {
+ *err = CREATE_FAILED;
+ return EIO;
+ }
+
+ if (palette_only)
+ {
+
+ ilRegisterPal
+
+
+ }
+ else
+ {
+ for (i=0; i<3; ++i)
+ {
+ 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,
+
+
+
+ }