]> bicyclesonthemoon.info Git - ott/enhance/blob - core.h
diff online
[ott/enhance] / core.h
1  /*
2 core.h
3 The tool with multiple enhancements and manipulations of pictures
4 03.12.2022
5
6 Copyright (C) 2022  Balthasar SzczepaƄski
7
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.
12
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.
17
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/>.
20
21
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)
26 */
27
28 // #include <stdlib.h>
29 #include <stdint.h>
30 // #include <stdio.h>
31 // #include <errno.h>
32
33 #include <IL/il.h>
34
35 #define FLAG_TYPE uint_fast32_t
36
37 #define   MUST_HAVE_ALPHA   0x000001
38 #define CANNOT_HAVE_ALPHA   0x000002
39 #define   MUST_BE_GRAY      0x000004
40 #define CANNOT_BE_GRAY      0x000008
41 #define   MUST_BE_INDEXED   0x000010
42 #define CANNOT_BE_INDEXED   0x000020
43
44 #define     OK_PALETTE_ONLY 0x000040
45 #define    CAN_BE_MULTIPLE  0x000080
46 #define    CAN_BE_OVER_8BIT 0x000100
47
48 #define     IN_WINDOW       0x000200
49
50 #define    HAS_ALPHA        0x000400
51 #define     IS_GRAY         0x000800
52 #define     IS_INDEXED      0x001000
53 #define     IS_MULTIPLE     0x002000
54 #define     IS_OVER_8BIT    0x004000
55 #define     IS_PALETTE_ONLY 0x008000
56
57 #define    NOT_WRITABLE     0x010000
58 #define    NOT_READABLE     0x020000
59
60 #define    EFF_ALPHA        0x040000
61 #define    EFF_GRAY         0x080000
62 #define    EFF_INDEXED      0x100000
63
64 extern char NO_STR[];
65 extern char INIT_FAILED[];
66 extern char LOAD_FAILED[];
67 extern char SAVE_FAILED[];
68 extern char CREATE_FAILED[];
69 extern char CONVERT_FAILED[];
70 extern char SIZE_MISMATCH[];
71 extern char MULTIPLE_FORBIDDEN[];
72 extern char INDEXED_REQUIRED[];
73 extern char PALETTE_ONLY_REQUIRED[];
74 extern char BAD_PALETTE_SIZE[];
75
76 struct Picture {
77         uint_fast8_t open;
78         ILuint handle;
79 };
80
81 struct IL_full_info {
82         ILint active_image;
83         ILint active_layer;
84         ILint active_mipmap;
85         ILint blit_blend; //b
86         ILint compress_mode; //
87         ILint conv_pal;
88         ILint cur_image;
89         ILint default_on_fail; //b
90         ILint dxtc_data_format; //
91         ILint file_mode;
92         ILint format_mode;
93         ILint format_set;
94         ILint image_bits_per_pixel;
95         ILint image_bpc; //
96         ILint image_bytes_per_pixel;
97         ILint image_channels; //
98         ILint image_cubeflags; //
99         ILint image_depth; //
100         ILint image_duration; //
101         ILint image_format;
102         ILint image_height;
103         ILint image_offx; //
104         ILint image_offy; //
105         ILint image_origin; //
106         ILint image_planesize; //
107         ILint image_size_of_data; //
108         ILint image_type;
109         ILint image_width;
110         ILint keep_dxtc_data; //
111         ILint num_faces; //
112         ILint num_images;
113         ILint num_layers; //
114         ILint num_mipmaps;
115         ILint origin_mode;
116         ILint origin_set;
117         ILint palette_base_type; //
118         ILint palette_bpp;
119         ILint palette_num_cols;
120         ILint palette_type;
121         ILint type_mode;
122         ILint type_set;
123         ILint use_key_colour;
124         ILint version_num;
125 };
126
127 struct PixelInfo
128 {
129         uint_fast16_t id;
130         ILuint handle;
131         ILuint frames;
132         
133         ILint x0;
134         ILint y0;
135         ILint f0;
136         
137         ILint x_window;
138         ILint y_window;
139         ILint f_window;
140         
141         ILint x_pict;
142         ILint y_pict;
143         ILint f_pict;
144         
145         ILuint red;
146         ILuint green;
147         ILuint blue;
148         ILuint value;
149         ILuint alpha;
150         ILuint index;
151         
152         ILint red_offset;
153         ILint green_offset;
154         ILint blue_offset;
155         ILint value_offset;
156         ILint alpha_offset;
157         ILint index_offset;
158         
159         ILint line_start;
160         ILint line_bytes;
161         ILint frame_bytes;
162         
163         ILint line_offset;
164         ILint pixel_offset;
165         ILint pal_offset;
166         
167         FLAG_TYPE flags;
168         void *data;
169         void *palette;
170         
171         struct IL_full_info info;
172 };
173
174 struct ColorInfo
175 {
176         ILuint red;
177         ILuint green;
178         ILuint blue;
179         ILuint value;
180         ILuint alpha;
181         ILuint index;
182 };
183
184
185 typedef int (ACTION_F)(ILuint n, struct PixelInfo *info, void *data);
186 typedef int (SUBTOOL_F)(int argc, char **argv, int argi, char **err);
187
188
189 void finish (int const returnvalue, char const * const returntext);
190 int init (void);
191 ILuint get_handle (uint_fast16_t id);
192 int get_data (uint_fast16_t id, void **data, ILuint frame);
193 int get_palette (uint_fast16_t id, void *palette, ILuint frame);
194 int set_palette (uint_fast16_t id, void *palette, ILuint size, ILenum type, ILuint frame);
195 void create_picture (uint_fast16_t id);
196 int create_pictures (uint_fast16_t n);
197 void close_picture (uint_fast16_t id);
198 void close_pictures (void);
199 void clear_pictures (void);
200 int reserve_pictures (uint_fast16_t n);
201 void get_flags (struct IL_full_info *info, FLAG_TYPE *flags);
202 int convert_picture (uint_fast16_t id, struct IL_full_info *info, FLAG_TYPE *flags);
203 int load_picture (uint_fast16_t id, char *path, struct IL_full_info *info, FLAG_TYPE *flags);
204 int load_picture_mem (uint_fast16_t id, const void *address, ILuint size, struct IL_full_info *info, FLAG_TYPE *flags);
205 int save_picture (uint_fast16_t id, char *path, FLAG_TYPE flags);
206 int build_picture (uint_fast16_t id, ILint width, ILint height, ILint frames, struct IL_full_info *info, FLAG_TYPE *flags);
207 int build_picture_from_info (uint_fast16_t id, struct IL_full_info *reference_info, struct IL_full_info *info, FLAG_TYPE *flags);
208 int get_info (uint_fast16_t id, struct IL_full_info *info, ILint frame);
209
210 ILuint upscale_value (ILubyte x, ILint bytes);
211 ILubyte downscale_value (ILuint x, ILint bytes);
212
213 int perform_action_1picture_1pixel (
214         uint_fast16_t id,
215         ILint x, ILint y, ILint f,
216         ACTION_F *function,
217         FLAG_TYPE flags,
218         void *data
219 );
220
221 int perform_action_1picture (
222         uint_fast16_t id,
223         ILint x0, ILint y0, ILint f0,
224         ILint width, ILint height, ILint frames,
225         ACTION_F *function,
226         FLAG_TYPE flags,
227         void *f_data
228 );
229
230 int perform_action (
231         uint_fast16_t n,
232         uint_fast16_t *id,
233         ILint *x0, ILint *y0, ILint *f0,
234         ILint width, ILint height, ILint frames,
235         ACTION_F *function,
236         FLAG_TYPE *flags,
237         void *data
238 );
239
240 int perform_action_palette_mix (
241         uint_fast16_t *id,
242         ACTION_F *function,
243         FLAG_TYPE *flags,
244         void *data
245 );
246
247
248
249 int copy_pixels (ILuint n, struct PixelInfo *p, void *data);
250 ILuint copy_1p_alpha (ILint64 src, ILint64 dst, ILint64 alpha, ILint64 max);
251 int fill_color (ILuint n, struct PixelInfo *p, void *data);
252 int palette_mix_index (ILuint n, struct PixelInfo *p, void *data);
253 ILuint tsqrt(ILuint s);