1 /*
2     This file is part of darktable,
3     Copyright (C) 2009-2021 darktable developers.
4 
5     darktable is free software: you can redistribute it and/or modify
6     it under the terms of the GNU 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 General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with darktable.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 
21 #include "common/darktable.h"
22 #include "common/iop_profile.h"
23 #include "views/view.h"
24 #include <gmodule.h>
25 #include <gtk/gtk.h>
26 #include <glib.h>
27 
28 #ifdef USE_LUA
29 #include "lua/call.h"
30 #include "lua/events.h"
31 #include "lua/lib.h"
32 #include "lua/modules.h"
33 #include "lua/types.h"
34 #endif
35 
36 struct dt_lib_module_t;
37 struct dt_colorpicker_sample_t;
38 
39 /** struct responsible for all library related shared routines and plugins. */
40 typedef struct dt_lib_t
41 {
42   GList *plugins;
43   struct dt_lib_module_t *gui_module;
44 
45   /** Proxy functions for communication with views */
46   struct
47   {
48     /** Colorpicker plugin hooks */
49     struct
50     {
51       struct dt_lib_module_t *module;
52       float *picked_color_rgb_mean;
53       float *picked_color_rgb_min;
54       float *picked_color_rgb_max;
55       float *picked_color_lab_mean;
56       float *picked_color_lab_min;
57       float *picked_color_lab_max;
58       GSList *live_samples;
59       struct dt_colorpicker_sample_t *selected_sample;
60       int size;
61       int display_samples;
62       int restrict_histogram;
63       void (*update_panel)(struct dt_lib_module_t *self);
64       void (*update_samples)(struct dt_lib_module_t *self);
65       void (*set_sample_area)(struct dt_lib_module_t *self, float size);
66       void (*set_sample_box_area)(struct dt_lib_module_t *self, const float *const size);
67       void (*set_sample_point)(struct dt_lib_module_t *self, float x, float y);
68     } colorpicker;
69 
70     /** Histogram processing hooks */
71     struct
72     {
73       struct dt_lib_module_t *module;
74       void (*process)(struct dt_lib_module_t *self, const float *const input,
75                       int width, int height,
76                       const dt_iop_order_iccprofile_info_t *const profile_info_from,
77                       const dt_iop_order_iccprofile_info_t *const profile_info_to);
78       // FIXME: now that PR #5532 is merged, define this as dt_atomic_int and include "common/atomic.h" and use dt_atomic_set_int() and dt_atomic_get_int()
79       gboolean is_linear;
80     } histogram;
81   } proxy;
82 } dt_lib_t;
83 
84 typedef struct dt_lib_module_t
85 {
86 #define INCLUDE_API_FROM_MODULE_H
87 #include "libs/lib_api.h"
88 
89   /** opened module. */
90   GModule *module;
91   /** other stuff that may be needed by the module, not only in gui mode. */
92   void *data;
93   /** string identifying this operation. */
94   char plugin_name[128];
95   /** child widget which is added to the GtkExpander. */
96   GtkWidget *widget;
97   /** expander containing the widget. */
98   GtkWidget *expander;
99   /** callback for delayed update after user interaction */
100   void (*_postponed_update)(struct dt_lib_module_t *self);
101   /** ID of timer for delayed callback */
102   guint timeout_handle;
103 
104   GSList *accel_closures;
105   GtkWidget *reset_button;
106   GtkWidget *presets_button;
107 } dt_lib_module_t;
108 
109 void dt_lib_init(dt_lib_t *lib);
110 void dt_lib_cleanup(dt_lib_t *lib);
111 
112 /** creates a label widget for the expander, with callback to enable/disable this module. */
113 GtkWidget *dt_lib_gui_get_expander(dt_lib_module_t *module);
114 /** set a expand/collaps plugin expander */
115 void dt_lib_gui_set_expanded(dt_lib_module_t *module, gboolean expanded);
116 /** get the expanded state of a plugin */
117 gboolean dt_lib_gui_get_expanded(dt_lib_module_t *module);
118 
119 /** connects the reset and presets shortcuts to a lib */
120 void dt_lib_connect_common_accels(dt_lib_module_t *module);
121 
122 /** return the plugin with the given name */
123 dt_lib_module_t *dt_lib_get_module(const char *name);
124 
125 /** get the visible state of a plugin */
126 gboolean dt_lib_is_visible(dt_lib_module_t *module);
127 /** set the visible state of a plugin */
128 void dt_lib_set_visible(dt_lib_module_t *module, gboolean visible);
129 /** check if a plugin is to be shown in a given view */
130 gboolean dt_lib_is_visible_in_view(dt_lib_module_t *module, const dt_view_t *view);
131 
132 /** returns the localized plugin name for a given plugin_name. must not be freed. */
133 gchar *dt_lib_get_localized_name(const gchar *plugin_name);
134 
135 /** preset stuff for lib */
136 
137 /** add or replace a preset for this operation. */
138 void dt_lib_presets_add(const char *name, const char *plugin_name, const int32_t version, const void *params,
139                         const int32_t params_size, gboolean readonly);
140 
141 /** queue a delayed call of update function after user interaction */
142 void dt_lib_queue_postponed_update(dt_lib_module_t *mod, void (*update_fn)(dt_lib_module_t *self));
143 /** cancel any previously-queued callback */
144 void dt_lib_cancel_postponed_update(dt_lib_module_t *mod);
145 
146 // apply a preset to the given module
147 gboolean dt_lib_presets_apply(const gchar *preset, gchar *module_name, int module_version);
148 // duplicate a preset
149 gchar *dt_lib_presets_duplicate(const gchar *preset, gchar *module_name, int module_version);
150 // remove a preset
151 void dt_lib_presets_remove(const gchar *preset, gchar *module_name, int module_version);
152 // update a preset
153 void dt_lib_presets_update(const gchar *preset, gchar *module_name, int module_version, const gchar *newname,
154                            const gchar *desc, const void *params, const int32_t params_size);
155 // know if the module can autoapply presets
156 gboolean dt_lib_presets_can_autoapply(dt_lib_module_t *mod);
157 
158 /*
159  * Proxy functions
160  */
161 
162 /** set the colorpicker area selection tool and size, size 0.0 - 1.0 */
163 void dt_lib_colorpicker_set_area(dt_lib_t *lib, float size);
164 /** set the colorpicker area selection tool and size, box[k] 0.0 - 1.0 */
165 void dt_lib_colorpicker_set_box_area(dt_lib_t *lib, const float *const box);
166 
167 /** set the colorpicker point selection tool and position */
168 void dt_lib_colorpicker_set_point(dt_lib_t *lib, float x, float y);
169 
170 /** sorter callback to add a lib in the list of libs after init */
171 gint dt_lib_sort_plugins(gconstpointer a, gconstpointer b);
172 /** init presets for a newly created lib */
173 void dt_lib_init_presets(dt_lib_module_t *module);
174 
175 // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
176 // vim: shiftwidth=2 expandtab tabstop=2 cindent
177 // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
178