6 Copyright (C) 2022 Balthasar SzczepaĆski
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as
10 published by the Free Software Foundation, either version 3 of the
11 License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Affero General Public License for more details.
18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/)
23 on Pentium III libdevil must be recompiled with
24 --disable-ssl2 --disable-ssl3
25 (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954)
54 char DIFF_MISSING_ARGS[] = "Missing parameters.\ndiff inPixA inPixB outPix [RA GA BA [RB GB BB]]\n";
56 int subtool_diff (int argc, char **argv, int argi, char **err)
59 struct diff_data data;
60 struct IL_full_info info[3];
61 uint_fast16_t id[3] = {0, 1, 2};
62 ILint xyf0[3] = {0, 0, 0};
63 FLAG_TYPE flags[3] = {
64 CAN_BE_MULTIPLE | CAN_BE_OVER_8BIT | CANNOT_BE_GRAY | NOT_WRITABLE,
65 CAN_BE_MULTIPLE | CAN_BE_OVER_8BIT | CANNOT_BE_GRAY | NOT_WRITABLE,
66 CAN_BE_MULTIPLE | CAN_BE_OVER_8BIT | CANNOT_BE_GRAY | NOT_READABLE
68 uint_fast8_t palette_only;
70 ILubyte new_pal[0x100 * 4];
78 *err = DIFF_MISSING_ARGS;
82 r = reserve_pictures(3);
89 r = load_picture(0, argv[argi], &(info[0]), &(flags[0]));
96 r = load_picture(1, argv[argi], &(info[1]), &(flags[1]));
103 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))
105 *err = SIZE_MISMATCH;
109 if ((info[0].image_bpc != info[1].image_bpc) || (!(flags[0] & IS_OVER_8BIT)) || (!(flags[0] & IS_OVER_8BIT)))
111 flags[0] &= ~CAN_BE_OVER_8BIT;
112 flags[1] &= ~CAN_BE_OVER_8BIT;
113 flags[2] &= ~CAN_BE_OVER_8BIT;
116 if ((flags[0] & HAS_ALPHA) || (flags[1] & HAS_ALPHA))
118 flags[0] |= MUST_HAVE_ALPHA;
119 flags[1] |= MUST_HAVE_ALPHA;
120 flags[2] |= MUST_HAVE_ALPHA;
123 flags[2] |= CANNOT_HAVE_ALPHA;
125 if ((flags[0] & IS_INDEXED) && (flags[1] & IS_INDEXED) && ((info[0].palette_num_cols * info[1].palette_num_cols) <= 0x100))
128 flags[0] |= OK_PALETTE_ONLY;
129 flags[1] |= OK_PALETTE_ONLY;
130 flags[2] |= OK_PALETTE_ONLY;
131 flags[0] &= ~CAN_BE_OVER_8BIT;
132 flags[1] &= ~CAN_BE_OVER_8BIT;
133 flags[2] &= ~CAN_BE_OVER_8BIT;
134 flags[2] |= MUST_BE_INDEXED;
139 flags[0] |= CANNOT_BE_INDEXED;
140 flags[1] |= CANNOT_BE_INDEXED;
141 flags[2] |= CANNOT_BE_INDEXED;
144 r = convert_picture(0, &(info[0]), &(flags[0]);
146 *err = CONVERT_FAILED;
150 r = convert_picture(1, &(info[1]), &(flags[1]);
152 *err = CONVERT_FAILED;
156 if (argc >= argi + 6)
158 sscanf(argv[argi+3],"%hhu",&v);
159 data.r_a = upscale_value(v, info[0].image_bpc);
160 sscanf(argv[argi+4],"%hhu",&v);
161 data.g_a = upscale_value(v, info[0].image_bpc);
162 sscanf(argv[argi+5],"%hhu",&v);
163 data.b_a = upscale_value(v, info[0].image_bpc);
167 data.r_a = upscale_value(RA, info[0].image_bpc);
168 data.g_a = upscale_value(GA, info[0].image_bpc);
169 data.b_a = upscale_value(BA, info[0].image_bpc);
171 if (argc >= argi + 9)
173 sscanf(argv[argi+6],"%hhu",&v);
174 data.r_b = upscale_value(v, info[0].image_bpc);
175 sscanf(argv[argi+7],"%hhu",&v);
176 data.g_b = upscale_value(v, info[0].image_bpc);
177 sscanf(argv[argi+8],"%hhu",&v);
178 data.b_b = upscale_value(v, info[0].image_bpc);
182 data.r_b = upscale_value(RB, info[0].image_bpc);
183 data.g_b = upscale_value(GB, info[0].image_bpc);
184 data.b_b = upscale_value(BB, info[0].image_bpc);
187 r = build_picture_from_info(2, &(info[0], &(info[2]), &(flags[2]));
190 *err = CREATE_FAILED;
205 handle = get_handle(i);
211 ((flags[0] & HAS_ALPHA)?4:3) * info[0].palette_num_cols * info[1].palette_num_cols,