Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
pixelpipe_rawdetail.c
Go to the documentation of this file.
1
12
13float *dt_dev_retrieve_rawdetail_mask(const dt_dev_pixelpipe_t *pipe, const dt_iop_module_t *target_module)
14{
15 const dt_dev_pixelpipe_iop_t *detailmask_piece = NULL;
16 for(GList *iter = g_list_first(pipe->nodes); iter; iter = g_list_next(iter))
17 {
18 const dt_dev_pixelpipe_iop_t *candidate = (const dt_dev_pixelpipe_iop_t *)iter->data;
19 if(!candidate) continue;
20 if(candidate->module == target_module) break;
21 if(candidate->enabled && !strcmp(candidate->module->op, "detailmask"))
22 detailmask_piece = candidate;
23 }
24
25 dt_dev_pixelpipe_t *mutable_pipe = (dt_dev_pixelpipe_t *)pipe;
26 const uint64_t mask_hash = detailmask_piece ? dt_dev_pixelpipe_rawdetail_mask_hash(detailmask_piece)
28
29 if(mask_hash == DT_PIXELPIPE_CACHE_HASH_INVALID) return NULL;
30
31 if(pipe->rawdetail_mask_hash != mask_hash)
32 {
34 if(IS_NULL_PTR(entry)) return NULL;
35
36 dt_dev_clear_rawdetail_mask(mutable_pipe);
38 mutable_pipe->rawdetail_mask_hash = mask_hash;
39 memcpy(&mutable_pipe->rawdetail_mask_roi, &detailmask_piece->roi_out, sizeof(dt_iop_roi_t));
40 }
41
42 void *mask = NULL;
44 return NULL;
45
46 return (float *)mask;
47}
48
49float *dt_dev_distort_detail_mask(const dt_dev_pixelpipe_t *pipe, float *src,
50 const dt_iop_module_t *target_module)
51{
52 if(dt_dev_retrieve_rawdetail_mask(pipe, target_module) == NULL) return NULL;
53 gboolean valid = FALSE;
54 const dt_dev_pixelpipe_iop_t *target_piece = NULL;
55 GList *source_iter = NULL;
56 for(GList *iter = g_list_first(pipe->nodes); iter; iter = g_list_next(iter))
57 {
58 const dt_dev_pixelpipe_iop_t *candidate = (dt_dev_pixelpipe_iop_t *)iter->data;
59 if(candidate->module == target_module) target_piece = candidate;
60 if((IS_NULL_PTR(source_iter)) && (!strcmp(candidate->module->op, "detailmask")) && candidate->enabled)
61 {
62 valid = TRUE;
63 source_iter = iter;
64 }
65 }
66
67 if(!valid) return NULL;
68 dt_vprint(DT_DEBUG_MASKS, "[dt_dev_distort_detail_mask] (%ix%i) for module %s\n",
69 pipe->rawdetail_mask_roi.width, pipe->rawdetail_mask_roi.height, target_module->op);
70
71 float *resmask = src;
72 float *inmask = src;
73 dt_iop_roi_t current_roi = pipe->rawdetail_mask_roi;
74 if(source_iter)
75 {
76 /* The side-band detail mask is stored in the output geometry of the
77 * hidden `detailmask` stage. Start warping at the next node exactly like
78 * raster masks do, otherwise we would re-apply the source transform to a
79 * buffer that is already expressed in source output coordinates. */
80 for(GList *iter = g_list_next(source_iter); iter; iter = g_list_next(iter))
81 {
82 dt_dev_pixelpipe_iop_t *module = (dt_dev_pixelpipe_iop_t *)iter->data;
83 if(module->enabled
84 && !dt_dev_pixelpipe_activemodule_disables_currentmodule(module->module->dev, module->module))
85 {
86 if(module->module->distort_mask
87 && !(!strcmp(module->module->op, "finalscale")
88 && module->roi_in.width == 0
89 && module->roi_in.height == 0))
90 {
92 (size_t)module->roi_out.width * module->roi_out.height, 0);
93 dt_vprint(DT_DEBUG_MASKS, " %s %ix%i -> %ix%i\n", module->module->op,
94 module->roi_in.width, module->roi_in.height,
95 module->roi_out.width, module->roi_out.height);
96 module->module->distort_mask(module->module, (dt_dev_pixelpipe_t *)pipe, module, inmask, tmp,
97 &module->roi_in, &module->roi_out);
98 resmask = tmp;
99 if(inmask != src) dt_pixelpipe_cache_free_align(inmask);
100 inmask = tmp;
101 current_roi = module->roi_out;
102 }
103 else if(!module->module->distort_mask
104 && (module->roi_in.width != module->roi_out.width
105 || module->roi_in.height != module->roi_out.height
106 || module->roi_in.x != module->roi_out.x
107 || module->roi_in.y != module->roi_out.y))
108 fprintf(stderr, "FIXME: module `%s' changed the roi from %d x %d @ %d / %d to %d x %d | %d / %d but doesn't have "
109 "distort_mask() implemented!\n", module->module->op, module->roi_in.width,
110 module->roi_in.height, module->roi_in.x, module->roi_in.y,
111 module->roi_out.width, module->roi_out.height, module->roi_out.x,
112 module->roi_out.y);
113
114 if(module->module == target_module) break;
115 }
116 }
117 }
118
119 if(!IS_NULL_PTR(target_piece)
120 && (current_roi.scale != target_piece->roi_out.scale
121 || current_roi.width != target_piece->roi_out.width
122 || current_roi.height != target_piece->roi_out.height
123 || current_roi.x != target_piece->roi_out.x
124 || current_roi.y != target_piece->roi_out.y))
125 {
126 /* The cached raw-detail mask is kept at the full-resolution source ROI.
127 * When the downstream walk stops before matching the consumer output ROI,
128 * finish by resampling/cropping once into the consumer geometry, just like
129 * initialscale would do for the pixel buffer. */
131 (size_t)target_piece->roi_out.width * target_piece->roi_out.height, 0);
133 dt_interpolation_resample_roi_1c(itor, tmp, &target_piece->roi_out, inmask, &current_roi);
134 if(inmask != src) dt_pixelpipe_cache_free_align(inmask);
135 inmask = tmp;
136 resmask = tmp;
137 }
138
139 return resmask;
140}
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
void dt_vprint(dt_debug_thread_t thread, const char *msg,...)
Definition darktable.c:1473
darktable_t darktable
Definition darktable.c:173
@ DT_DEBUG_MASKS
Definition darktable.h:726
#define dt_pixelpipe_cache_alloc_align_float_cache(pixels, id)
Definition darktable.h:447
#define dt_pixelpipe_cache_free_align(mem)
Definition darktable.h:453
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition darktable.h:281
gboolean dt_dev_pixelpipe_activemodule_disables_currentmodule(struct dt_develop_t *dev, struct dt_iop_module_t *current_module)
Definition dev_pixelpipe.c:341
const struct dt_interpolation * dt_interpolation_new(enum dt_interpolation_type type)
Definition interpolation.c:648
void dt_interpolation_resample_roi_1c(const struct dt_interpolation *itor, float *out, const dt_iop_roi_t *const roi_out, const float *const in, const dt_iop_roi_t *const roi_in)
Definition interpolation.c:1470
@ DT_INTERPOLATION_USERPREF_WARP
Definition interpolation.h:48
uint64_t dt_dev_pixelpipe_rawdetail_mask_hash(const dt_dev_pixelpipe_iop_t *piece)
Definition pixelpipe.c:50
void dt_dev_clear_rawdetail_mask(dt_dev_pixelpipe_t *pipe)
Release the side-band detail mask cache reference currently owned by the pipeline.
Definition pixelpipe.c:63
void dt_dev_pixelpipe_cache_ref_count_entry(dt_dev_pixelpipe_cache_t *cache, gboolean lock, dt_pixel_cache_entry_t *cache_entry)
Increase/Decrease the reference count on the cache line as to prevent LRU item removal....
Definition pixelpipe_cache.c:2225
gboolean dt_dev_pixelpipe_cache_peek(dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, void **data, dt_pixel_cache_entry_t **entry, const int preferred_devid, void **cl_mem_output)
Non-owning lookup of an existing cache line.
Definition pixelpipe_cache.c:2052
dt_pixel_cache_entry_t * dt_dev_pixelpipe_cache_get_entry(dt_dev_pixelpipe_cache_t *cache, const uint64_t hash)
Get an internal reference to the cache entry matching hash. If you are going to access this entry mor...
Definition pixelpipe_cache.c:144
#define DT_PIXELPIPE_CACHE_HASH_INVALID
Definition pixelpipe_cache.h:42
float * dt_dev_distort_detail_mask(const dt_dev_pixelpipe_t *pipe, float *src, const dt_iop_module_t *target_module)
Definition pixelpipe_rawdetail.c:49
float * dt_dev_retrieve_rawdetail_mask(const dt_dev_pixelpipe_t *pipe, const dt_iop_module_t *target_module)
Definition pixelpipe_rawdetail.c:13
unsigned __int64 uint64_t
Definition strptime.c:75
struct dt_dev_pixelpipe_cache_t * pixelpipe_cache
Definition darktable.h:789
Definition pixelpipe_hb.h:96
gboolean enabled
Definition pixelpipe_hb.h:111
struct dt_iop_module_t *void * data
Definition pixelpipe_hb.h:97
dt_iop_roi_t roi_out
Definition pixelpipe_hb.h:132
Definition pixelpipe_hb.h:218
GList * nodes
Definition pixelpipe_hb.h:245
uint64_t rawdetail_mask_hash
Definition pixelpipe_hb.h:266
struct dt_iop_roi_t rawdetail_mask_roi
Definition pixelpipe_hb.h:267
int devid
Definition pixelpipe_hb.h:308
Definition interpolation.h:60
Definition imageop.h:246
GModule *dt_dev_operation_t op
Definition imageop.h:256
Region of interest passed through the pixelpipe.
Definition imageop.h:72
int x
Definition imageop.h:73
double scale
Definition imageop.h:74
int width
Definition imageop.h:73
int height
Definition imageop.h:73
int y
Definition imageop.h:73
Definition pixelpipe_cache.h:87