Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
pixelpipe_raster_masks.c
Go to the documentation of this file.
1
26 dt_dev_pixelpipe_iop_t *current_piece,
27 const dt_iop_module_t *target_module)
28{
29 gboolean success = TRUE;
30 gchar *clean_target_name = delete_underscore(target_module->name());
31 gchar *target_name = g_strdup_printf("%s (%s)", clean_target_name, target_module->multi_name);
32
33 if(source_piece == NULL || current_piece == NULL)
34 {
35 fprintf(stderr,"[raster masks] ERROR: source: %s, current: %s\n",
36 (source_piece != NULL) ? "is defined" : "is undefined",
37 (current_piece != NULL) ? "is definded" : "is undefined");
38
39 gchar *hint = NULL;
40 if(source_piece == NULL)
41 {
42 hint = g_strdup_printf(
43 _("- Check if the module providing the masks for the module %s has not been deleted.\n"),
44 target_name);
45 }
46 else if(current_piece == NULL)
47 {
48 hint = g_strdup_printf(_("- Check if the module %s (%s) providing the masks has not been moved above %s.\n"),
49 delete_underscore(source_piece->module->name()),
50 source_piece->module->multi_name, clean_target_name);
51 }
52
53 dt_control_log(_("The %s module is trying to reuse a mask from a module but it can't be found.\n"
54 "\n%s"),
55 target_name, hint ? hint : "");
56 dt_free(hint);
57
58 fprintf(stderr, "[raster masks] no source module for module %s could be found\n", target_name);
59 success = FALSE;
60 }
61
62 if(success && !source_piece->enabled)
63 {
64 gchar *clean_source_name = delete_underscore(source_piece->module->name());
65 gchar *source_name = g_strdup_printf("%s (%s)", clean_source_name, source_piece->module->multi_name);
66 dt_control_log(_("The `%s` module is trying to reuse a mask from disabled module `%s`.\n"
67 "Disabled modules cannot provide their masks to other modules.\n"
68 "\n- Please enable `%s` or change the raster mask in `%s`."),
69 target_name, source_name, source_name, target_name);
70
71 fprintf(stderr, "[raster masks] module %s trying to reuse a mask from disabled instance of %s\n",
72 target_name, source_name);
73
74 dt_free(clean_source_name);
75 dt_free(source_name);
76 success = FALSE;
77 }
78
79 dt_free(clean_target_name);
80 dt_free(target_name);
81 return success;
82}
83
84float *dt_dev_get_raster_mask(dt_dev_pixelpipe_t *pipe, const dt_iop_module_t *raster_mask_source,
85 const int raster_mask_id, const dt_iop_module_t *target_module,
86 gboolean *free_mask, int *error)
87{
88 if(!error) return NULL;
89 *error = 0;
90
91 gchar *clean_target_name = delete_underscore(target_module->name());
92 gchar *target_name = g_strdup_printf("%s (%s)", clean_target_name, target_module->multi_name);
93
94 if(!raster_mask_source)
95 {
96 fprintf(stderr, "[raster masks] The source module of the mask for %s was not found\n", target_name);
97 dt_free(clean_target_name);
98 dt_free(target_name);
99 return NULL;
100 }
101
102 *free_mask = FALSE;
103 float *raster_mask = NULL;
104
105 dt_dev_pixelpipe_iop_t *source_piece = NULL;
106 dt_dev_pixelpipe_iop_t *current_piece = NULL;
107 GList *source_iter = NULL;
108 for(source_iter = g_list_last(pipe->nodes); source_iter; source_iter = g_list_previous(source_iter))
109 {
110 dt_dev_pixelpipe_iop_t *candidate = (dt_dev_pixelpipe_iop_t *)source_iter->data;
111 if(candidate->module == target_module)
112 current_piece = candidate;
113 else if(candidate->module == raster_mask_source)
114 {
115 source_piece = candidate;
116 break;
117 }
118 }
119
120 const int err_ret = !_dt_dev_raster_mask_check(source_piece, current_piece, target_module);
121 *error = err_ret;
122
123 if(!err_ret)
124 {
125 const uint64_t raster_hash = current_piece->global_mask_hash;
126
127 gchar *clean_source_name = delete_underscore(source_piece->module->name());
128 gchar *source_name = g_strdup_printf("%s (%s)", clean_source_name, source_piece->module->multi_name);
129 raster_mask = dt_pixelpipe_raster_get(source_piece->raster_masks, raster_mask_id);
130
131 gchar *type = dt_pixelpipe_get_pipe_name(pipe->type);
132 if(raster_mask)
133 {
135 "[raster masks] found in %s mask id %i from %s for module %s in pipe %s with hash %" PRIu64 "\n",
136 "internal", raster_mask_id, source_name, target_name, type, raster_hash);
137 dt_dev_pixelpipe_unset_reentry(pipe, raster_hash);
138 }
139 else
140 {
141 fprintf(stderr,
142 "[raster masks] mask id %i from %s for module %s could not be found in pipe %s. Pipe re-entry will be attempted.\n",
143 raster_mask_id, source_name, target_name, type);
144
145 if(dt_dev_pixelpipe_set_reentry(pipe, raster_hash))
146 pipe->flush_cache = TRUE;
147
148 if(error) *error = 1;
149
150 dt_free(clean_target_name);
151 dt_free(target_name);
152 return NULL;
153 }
154
155 for(GList *iter = g_list_next(source_iter); iter; iter = g_list_next(iter))
156 {
157 dt_dev_pixelpipe_iop_t *module = (dt_dev_pixelpipe_iop_t *)iter->data;
158
159 if(module->enabled
160 && !dt_dev_pixelpipe_activemodule_disables_currentmodule(module->module->dev, module->module))
161 {
162 if(module->module->distort_mask
163 && !(!strcmp(module->module->op, "finalscale")
164 && module->roi_in.width == 0
165 && module->roi_in.height == 0))
166 {
167 float *transformed_mask = dt_pixelpipe_cache_alloc_align_float_cache(
168 (size_t)module->roi_out.width * module->roi_out.height, 0);
169 if(!transformed_mask)
170 {
171 fprintf(stderr, "[raster masks] could not allocate memory for transformed mask\n");
172 if(error) *error = 1;
173 dt_free(clean_target_name);
174 dt_free(target_name);
175 return NULL;
176 }
177
178 module->module->distort_mask(module->module, pipe, module, raster_mask, transformed_mask,
179 &module->roi_in, &module->roi_out);
180 if(*free_mask) dt_pixelpipe_cache_free_align(raster_mask);
181 *free_mask = TRUE;
182 raster_mask = transformed_mask;
183 dt_print(DT_DEBUG_MASKS, "[raster masks] doing transform\n");
184 }
185 else if(!module->module->distort_mask
186 && (module->roi_in.width != module->roi_out.width
187 || module->roi_in.height != module->roi_out.height
188 || module->roi_in.x != module->roi_out.x
189 || module->roi_in.y != module->roi_out.y))
190 fprintf(stderr, "FIXME: module `%s' changed the roi from %d x %d @ %d / %d to %d x %d | %d / %d but doesn't have "
191 "distort_mask() implemented!\n", module->module->op, module->roi_in.width,
192 module->roi_in.height, module->roi_in.x, module->roi_in.y,
193 module->roi_out.width, module->roi_out.height, module->roi_out.x,
194 module->roi_out.y);
195 }
196
197 if(module->module == target_module)
198 {
199 dt_print(DT_DEBUG_MASKS, "[raster masks] found mask id %i from %s for module %s (%s) in pipe %s\n",
200 raster_mask_id, source_name, delete_underscore(module->module->name()),
201 module->module->multi_name, dt_pixelpipe_get_pipe_name(pipe->type));
202 break;
203 }
204 }
205 }
206
207 dt_free(clean_target_name);
208 dt_free(target_name);
209 return raster_mask;
210}
static void error(char *msg)
Definition ashift_lsd.c:202
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
int type
Definition common/metadata.c:62
void dt_control_log(const char *msg,...)
Definition control.c:530
void dt_print(dt_debug_thread_t thread, const char *msg,...)
Definition darktable.c:1530
@ DT_DEBUG_MASKS
Definition darktable.h:647
#define dt_pixelpipe_cache_alloc_align_float_cache(pixels, id)
Definition darktable.h:371
#define dt_free(ptr)
Definition darktable.h:380
static gchar * delete_underscore(const char *s)
Definition darktable.h:1015
#define dt_pixelpipe_cache_free_align(mem)
Definition darktable.h:377
gboolean dt_dev_pixelpipe_activemodule_disables_currentmodule(struct dt_develop_t *dev, struct dt_iop_module_t *current_module)
Definition dev_pixelpipe.c:212
float * dt_pixelpipe_raster_get(GHashTable *raster_masks, const int raster_mask_id)
Get the raster mask with given id from the raster masks hashtable of the pixelpipe.
Definition pixelpipe.c:71
char * dt_pixelpipe_get_pipe_name(dt_dev_pixelpipe_type_t pipe_type)
Definition pixelpipe_hb.c:259
gboolean dt_dev_pixelpipe_unset_reentry(dt_dev_pixelpipe_t *pipe, uint64_t hash)
Remove the re-entry pipeline flag, only if the object identifier is the one that set it....
Definition pixelpipe_hb.c:549
gboolean dt_dev_pixelpipe_set_reentry(dt_dev_pixelpipe_t *pipe, uint64_t hash)
Set the re-entry pipeline flag, only if no object is already capturing it. Re-entered pipelines run w...
Definition pixelpipe_hb.c:535
static gboolean _dt_dev_raster_mask_check(dt_dev_pixelpipe_iop_t *source_piece, dt_dev_pixelpipe_iop_t *current_piece, const dt_iop_module_t *target_module)
Check that the raster-mask provider/consumer relation is still valid in the current pipe.
Definition pixelpipe_raster_masks.c:25
float * dt_dev_get_raster_mask(dt_dev_pixelpipe_t *pipe, const dt_iop_module_t *raster_mask_source, const int raster_mask_id, const dt_iop_module_t *target_module, gboolean *free_mask, int *error)
Definition pixelpipe_raster_masks.c:84
unsigned __int64 uint64_t
Definition strptime.c:74
Definition pixelpipe_hb.h:95
gboolean enabled
Definition pixelpipe_hb.h:110
uint64_t global_mask_hash
Definition pixelpipe_hb.h:126
struct dt_iop_module_t *void * data
Definition pixelpipe_hb.h:96
GHashTable * raster_masks
Definition pixelpipe_hb.h:159
Definition pixelpipe_hb.h:216
gboolean flush_cache
Definition pixelpipe_hb.h:335
GList * nodes
Definition pixelpipe_hb.h:237
dt_dev_pixelpipe_type_t type
Definition pixelpipe_hb.h:284
Definition imageop.h:216
char multi_name[128]
Definition imageop.h:328