1 /*
2     This file is part of darktable,
3     Copyright (C) 2016-2021 darktable developers.
4 
5     darktable is free software: you can redistribute it and/or modify
6     it under the terms of the GNU Lesser General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9 
10     darktable is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU Lesser General Public License for more details.
14 
15     You should have received a copy of the GNU Lesser General Public License
16     along with darktable.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "common/module_api.h"
20 
21 #ifdef FULL_API_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #include "common/introspection.h"
28 
29 #include <cairo/cairo.h>
30 #include <gtk/gtk.h>
31 #include <glib.h>
32 #include <stdint.h>
33 
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
37 
38 #ifdef HAVE_OPENCL
39 #include <CL/cl.h>
40 #endif
41 
42 struct dt_iop_module_so_t;
43 struct dt_iop_module_t;
44 struct dt_dev_pixelpipe_t;
45 struct dt_dev_pixelpipe_iop_t;
46 struct dt_iop_roi_t;
47 struct dt_develop_tiling_t;
48 struct dt_iop_buffer_dsc_t;
49 struct _GtkWidget;
50 
51 #ifndef DT_IOP_PARAMS_T
52 #define DT_IOP_PARAMS_T
53 typedef void dt_iop_params_t;
54 #endif
55 
56 /* early definition of modules to do type checking */
57 
58 #pragma GCC visibility push(default)
59 
60 #endif // FULL_API_H
61 
62 /** this initializes static, hardcoded presets for this module and is called only once per run of dt. */
63 OPTIONAL(void, init_presets, struct dt_iop_module_so_t *self);
64 /** called once per module, at startup. */
65 OPTIONAL(void, init_global, struct dt_iop_module_so_t *self);
66 /** called once per module, at shutdown. */
67 OPTIONAL(void, cleanup_global, struct dt_iop_module_so_t *self);
68 
69 /** get name of the module, to be translated. */
70 REQUIRED(const char *, name, void);
71 /** get the alternative names or keywords of the module, to be translated. Separate variants by a pipe | */
72 DEFAULT(const char *, aliases, void);
73 /** get the default group this module belongs to. */
74 DEFAULT(int, default_group, void);
75 /** get the iop module flags. */
76 DEFAULT(int, flags, void);
77 /** get the deprecated message if needed, to be translated. */
78 DEFAULT(const char *, deprecated_msg, void);
79 
80 /** get a descriptive text used for example in a tooltip in more modules */
81 DEFAULT(const char *, description, struct dt_iop_module_t *self);
82 
83 DEFAULT(int, operation_tags, void);
84 DEFAULT(int, operation_tags_filter, void);
85 
86 /** what do the iop want as an input? */
87 DEFAULT(void, input_format, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_t *pipe,
88                              struct dt_dev_pixelpipe_iop_t *piece, struct dt_iop_buffer_dsc_t *dsc);
89 /** what will it output? */
90 DEFAULT(void, output_format, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_t *pipe,
91                               struct dt_dev_pixelpipe_iop_t *piece, struct dt_iop_buffer_dsc_t *dsc);
92 
93 /** what default colorspace this iop use? */
94 REQUIRED(int, default_colorspace, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_t *pipe,
95                                   struct dt_dev_pixelpipe_iop_t *piece);
96 /** what input colorspace it expects? */
97 DEFAULT(int, input_colorspace, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_t *pipe,
98                                 struct dt_dev_pixelpipe_iop_t *piece);
99 /** what will it output? */
100 DEFAULT(int, output_colorspace, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_t *pipe,
101                                  struct dt_dev_pixelpipe_iop_t *piece);
102 /** what colorspace the blend module operates with? */
103 DEFAULT(int, blend_colorspace, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_t *pipe,
104                                 struct dt_dev_pixelpipe_iop_t *piece);
105 
106 /** report back info for tiling: memory usage and overlap. Memory usage: factor * input_size + overhead */
107 DEFAULT(void, tiling_callback, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece,
108                                 const struct dt_iop_roi_t *roi_in, const struct dt_iop_roi_t *roi_out,
109                                 struct dt_develop_tiling_t *tiling);
110 
111 /** callback methods for gui. */
112 /** synch gtk interface with gui params, if necessary. */
113 OPTIONAL(void, gui_update, struct dt_iop_module_t *self);
114 /** reset ui to defaults */
115 OPTIONAL(void, gui_reset, struct dt_iop_module_t *self);
116 /** construct widget. */
117 OPTIONAL(void, gui_init, struct dt_iop_module_t *self);
118 /** apply color picker results */
119 OPTIONAL(void, color_picker_apply, struct dt_iop_module_t *self, struct _GtkWidget *picker, struct dt_dev_pixelpipe_iop_t *piece);
120 /** called by standard widget callbacks after value changed */
121 OPTIONAL(void, gui_changed, struct dt_iop_module_t *self, GtkWidget *widget, void *previous);
122 /** destroy widget. */
123 DEFAULT(void, gui_cleanup, struct dt_iop_module_t *self);
124 /** optional method called after darkroom expose. */
125 OPTIONAL(void, gui_post_expose, struct dt_iop_module_t *self, cairo_t *cr, int32_t width, int32_t height,
126                                 int32_t pointerx, int32_t pointery);
127 /** optional callback to be notified if the module acquires gui focus/loses it. */
128 OPTIONAL(void, gui_focus, struct dt_iop_module_t *self, gboolean in);
129 
130 /** Optional callback for keyboard accelerators */
131 OPTIONAL(void, init_key_accels, struct dt_iop_module_so_t *so);
132 OPTIONAL(void, original_init_key_accels, struct dt_iop_module_so_t *so);
133 /** Key accelerator registration callbacks */
134 OPTIONAL(void, connect_key_accels, struct dt_iop_module_t *self);
135 OPTIONAL(void, disconnect_key_accels, struct dt_iop_module_t *self);
136 OPTIONAL(GSList *, mouse_actions, struct dt_iop_module_t *self);
137 
138 /** optional event callbacks */
139 OPTIONAL(int, mouse_leave, struct dt_iop_module_t *self);
140 OPTIONAL(int, mouse_moved, struct dt_iop_module_t *self, double x, double y, double pressure, int which);
141 OPTIONAL(int, button_released, struct dt_iop_module_t *self, double x, double y, int which, uint32_t state);
142 OPTIONAL(int, button_pressed, struct dt_iop_module_t *self, double x, double y, double pressure, int which, int type,
143                               uint32_t state);
144 
145 OPTIONAL(int, scrolled, struct dt_iop_module_t *self, double x, double y, int up, uint32_t state);
146 OPTIONAL(void, configure, struct dt_iop_module_t *self, int width, int height);
147 
148 OPTIONAL(void, init, struct dt_iop_module_t *self); // this MUST set params_size!
149 DEFAULT(void, cleanup, struct dt_iop_module_t *self);
150 
151 /** this inits the piece of the pipe, allocing piece->data as necessary. */
152 DEFAULT(void, init_pipe, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_t *pipe,
153                           struct dt_dev_pixelpipe_iop_t *piece);
154 /** this resets the params to factory defaults. used at the beginning of each history synch. */
155 /** this commits (a mutex will be locked to synch pipe/gui) the given history params to the pixelpipe piece.
156  */
157 DEFAULT(void, commit_params, struct dt_iop_module_t *self, dt_iop_params_t *params, struct dt_dev_pixelpipe_t *pipe,
158                               struct dt_dev_pixelpipe_iop_t *piece);
159 /** this is the chance to update default parameters, after the full raw is loaded. */
160 OPTIONAL(void, reload_defaults, struct dt_iop_module_t *self);
161 /** called after the image has changed in darkroom */
162 OPTIONAL(void, change_image, struct dt_iop_module_t *self);
163 
164 /** this destroys all resources needed by the piece of the pixelpipe. */
165 DEFAULT(void, cleanup_pipe, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_t *pipe,
166                              struct dt_dev_pixelpipe_iop_t *piece);
167 OPTIONAL(void, modify_roi_in, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece,
168                               const struct dt_iop_roi_t *roi_out, struct dt_iop_roi_t *roi_in);
169 OPTIONAL(void, modify_roi_out, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece,
170                                struct dt_iop_roi_t *roi_out, const struct dt_iop_roi_t *roi_in);
171 OPTIONAL(int, legacy_params, struct dt_iop_module_t *self, const void *const old_params, const int old_version,
172                              void *new_params, const int new_version);
173 // allow to select a shape inside an iop
174 OPTIONAL(void, masks_selection_changed, struct dt_iop_module_t *self, const int form_selected_id);
175 
176 /** this is the temp homebrew callback to operations.
177   * x,y, and scale are just given for orientation in the framebuffer. i and o are
178   * scaled to the same size width*height and contain a max of 3 floats. other color
179   * formats may be filled by this callback, if the pipeline can handle it. */
180 /** the simplest variant of process(). you can only use OpenMP SIMD here, no intrinsics */
181 /** must be provided by each IOP. */
182 REQUIRED(void, process, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i,
183                         void *const o, const struct dt_iop_roi_t *const roi_in,
184                         const struct dt_iop_roi_t *const roi_out);
185 /** a tiling variant of process(). */
186 DEFAULT(void, process_tiling, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i,
187                                void *const o, const struct dt_iop_roi_t *const roi_in,
188                                const struct dt_iop_roi_t *const roi_out, const int bpp);
189 
190 #if defined(__SSE__)
191 /** a variant process(), that can contain SSE2 intrinsics. */
192 /** can be provided by each IOP. */
193 OPTIONAL(void, process_sse2, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i,
194                              void *const o, const struct dt_iop_roi_t *const roi_in,
195                              const struct dt_iop_roi_t *const roi_out);
196 #endif
197 
198 #ifdef HAVE_OPENCL
199 /** the opencl equivalent of process(). */
200 OPTIONAL(int, process_cl, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in,
201                           cl_mem dev_out, const struct dt_iop_roi_t *const roi_in,
202                           const struct dt_iop_roi_t *const roi_out);
203 /** a tiling variant of process_cl(). */
204 OPTIONAL(int, process_tiling_cl, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i,
205                                  void *const o, const struct dt_iop_roi_t *const roi_in,
206                                  const struct dt_iop_roi_t *const roi_out, const int bpp);
207 #endif
208 
209 /** this functions are used for distort iop
210  * points is an array of float {x1,y1,x2,y2,...}
211  * size is 2*points_count */
212 /** points before the iop is applied => point after processed */
213 DEFAULT(int, distort_transform, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, float *points,
214                                  size_t points_count);
215 /** reverse points after the iop is applied => point before process */
216 DEFAULT(int, distort_backtransform, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, float *points,
217                                      size_t points_count);
218 
219 OPTIONAL(void, distort_mask, struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const float *const in,
220                              float *const out, const struct dt_iop_roi_t *const roi_in, const struct dt_iop_roi_t *const roi_out);
221 
222 // introspection related callbacks, will be auto-implemented if DT_MODULE_INTROSPECTION() is used,
223 OPTIONAL(int, introspection_init, struct dt_iop_module_so_t *self, int api_version);
224 DEFAULT(dt_introspection_t *, get_introspection, void);
225 DEFAULT(dt_introspection_field_t *, get_introspection_linear, void);
226 DEFAULT(void *, get_p, const void *param, const char *name);
227 DEFAULT(dt_introspection_field_t *, get_f, const char *name);
228 
229 // optional preference entry to add at the bottom of the preset menu
230 OPTIONAL(void, set_preferences, void *menu, struct dt_iop_module_t *self);
231 
232 #ifdef FULL_API_H
233 
234 #pragma GCC visibility pop
235 
236 #ifdef __cplusplus
237 }
238 #endif
239 
240 #endif // FULL_API_H
241 
242 // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
243 // vim: shiftwidth=2 expandtab tabstop=2 cindent
244 // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
245