Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
basebuffer.c
Go to the documentation of this file.
1/*
2 This file is part of Ansel.
3 Copyright (C) 2026 Guillaume Stutin.
4
5 Ansel 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 Ansel 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 Ansel. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#ifdef HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include "common/darktable.h"
24#include "common/imagebuf.h"
25#include "develop/develop.h"
26#include "develop/imageop.h"
28#include "iop/iop_api.h"
29
30#include <string.h>
31
33
38
40
41const char *name()
42{
43 return _("base buffer");
44}
45
47{
49}
50
55
57{
58 return pipe->dev->image_storage.dsc.cst;
59}
60
61// Full-size RAW in and out
63 const dt_iop_roi_t *const roi_out, dt_iop_roi_t *roi_in)
64{
65 *roi_in = (dt_iop_roi_t){ 0, 0, pipe->iwidth, pipe->iheight, 1.f };
66}
67
69 dt_iop_roi_t *roi_out, const dt_iop_roi_t *const roi_in)
70{
71 *roi_out = (dt_iop_roi_t){ 0, 0, pipe->iwidth, pipe->iheight, 1.f };
72}
73
74
77{
78 memcpy(dsc, &pipe->dev->image_storage.dsc, sizeof(dt_iop_buffer_dsc_t));
79}
80
81
84{
85 memcpy(dsc, &pipe->dev->image_storage.dsc, sizeof(dt_iop_buffer_dsc_t));
86}
87
88
91 const void *const ivoid, void *const ovoid)
92{
93 const dt_iop_roi_t *const roi_out = &piece->roi_out;
94 const dt_iop_roi_t *const roi_in = &piece->roi_in;
96
98
99 // Catch out-of-bounds here because roi_in -> roi_out conversions
100 // use float scaling that may not always respect initial size.
101
102 // Crop rectangle offset
103 const size_t x = MAX(roi_in->x, 0);
104 const size_t y = MAX(roi_in->y, 0);
105
106 // Crop rectangle size
107 const size_t in_width = MIN(roi_in->width, pipe->iwidth - x);
108 const size_t in_height = MIN(roi_in->height, pipe->iheight - y);
109 const size_t in_stride = in_width * piece->dsc_in.bpp;
110 const size_t out_stride = roi_out->width * piece->dsc_out.bpp;
111
112 // Crop offset translated in memory sizes
113 const size_t y_offset = y * in_stride;
114 const size_t x_offset = x * piece->dsc_in.bpp;
115
116 /* This stage copies the immutable mipmap-cache payload into the pixelpipe cacheline that will
117 * be consumed by the first real processing stage. Keeping the source copy local here makes the
118 * cache ownership and lifetime visible in the recursion instead of in a hidden bootstrap path. */
119 const void *const restrict input = buf.buf;
120
122 for(size_t j = 0; j < MIN(roi_out->height, in_height); j++)
123 memcpy(ovoid + j * out_stride, input + x_offset + y_offset + j * in_stride, MIN(in_stride, out_stride));
124
126
127 return 0;
128}
129
130#ifdef HAVE_OPENCL
131int process_cl(struct dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, cl_mem dev_out)
132{
133 const dt_iop_roi_t *const roi_out = &piece->roi_out;
134 const dt_iop_roi_t *const roi_in = &piece->roi_in;
136
138
139 // Catch out-of-bounds here because roi_in -> roi_out conversions
140 // use float scaling that may not always respect initial size.
141
142 // Crop rectangle offset
143 const size_t x = MAX(roi_in->x, 0);
144 const size_t y = MAX(roi_in->y, 0);
145
146 // Crop rectangle size
147 const size_t in_width = MIN(roi_in->width, pipe->iwidth - x);
148 const size_t in_stride = in_width * piece->dsc_in.bpp;
149
150 // Crop offset translated in memory sizes
151 const size_t y_offset = y * in_stride;
152 const size_t x_offset = x * piece->dsc_in.bpp;
153
154 /* This stage copies the immutable mipmap-cache payload into the pixelpipe cacheline that will
155 * be consumed by the first real processing stage. Keeping the source copy local here makes the
156 * cache ownership and lifetime visible in the recursion instead of in a hidden bootstrap path. */
157 const void *const restrict input = buf.buf;
158
159 size_t origin[] = { x, y, 0 };
160 size_t region[] = { MIN(roi_out->width, roi_in->width), MIN(roi_out->height, roi_in->height), 1 };
161
162 int err = dt_opencl_write_host_to_device_raw(pipe->devid, input + x_offset + y_offset, dev_out, origin,
163 region, in_stride, CL_TRUE);
164
165
167
168 return err == CL_SUCCESS;
169}
170#endif
171
172
178
180{
181 dt_free_align(piece->data);
182 piece->data = NULL;
183}
184
186{
187 self->params = calloc(1, sizeof(dt_iop_basebuffer_params_t));
188 self->default_params = calloc(1, sizeof(dt_iop_basebuffer_params_t));
189 self->default_enabled = 1;
190 self->hide_enable_button = 1;
192 self->gui_data = NULL;
193}
194
196{
197 dt_free(self->params);
198 dt_free(self->default_params);
199}
200
201// clang-format off
202// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
203// vim: shiftwidth=2 expandtab tabstop=2 cindent
204// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
205// clang-format on
void modify_roi_out(dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece, dt_iop_roi_t *roi_out, const dt_iop_roi_t *const roi_in)
Definition basebuffer.c:68
int default_group()
Definition basebuffer.c:46
__DT_CLONE_TARGETS__ int process(dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid)
Definition basebuffer.c:90
void modify_roi_in(dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece, const dt_iop_roi_t *const roi_out, dt_iop_roi_t *roi_in)
Definition basebuffer.c:62
const char * name()
Definition basebuffer.c:41
void output_format(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece, dt_iop_buffer_dsc_t *dsc)
Definition basebuffer.c:75
void cleanup_pipe(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
Definition basebuffer.c:179
int default_colorspace(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece)
Definition basebuffer.c:56
void input_format(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece, dt_iop_buffer_dsc_t *dsc)
Definition basebuffer.c:82
int flags()
Definition basebuffer.c:51
void init(dt_iop_module_t *self)
Definition basebuffer.c:185
void init_pipe(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
Definition basebuffer.c:173
dt_iop_basebuffer_params_t dt_iop_basebuffer_data_t
Definition basebuffer.c:39
int process_cl(struct dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, cl_mem dev_out)
Definition basebuffer.c:131
void cleanup(dt_iop_module_t *self)
Definition basebuffer.c:195
darktable_t darktable
Definition darktable.c:181
#define dt_free_align(ptr)
Definition darktable.h:481
static void * dt_calloc_align(size_t size)
Definition darktable.h:488
#define dt_free(ptr)
Definition darktable.h:456
#define DT_MODULE_INTROSPECTION(MODVER, PARAMSTYPE)
Definition darktable.h:151
#define __DT_CLONE_TARGETS__
Definition darktable.h:367
#define __OMP_PARALLEL_FOR__(...)
Definition darktable.h:258
@ IOP_FLAGS_HIDDEN
Definition imageop.h:170
@ IOP_FLAGS_TAKE_NO_INPUT
Definition imageop.h:176
@ IOP_FLAGS_UNSAFE_COPY
Definition imageop.h:177
@ IOP_FLAGS_ONE_INSTANCE
Definition imageop.h:172
@ IOP_FLAGS_CPU_WRITES_OPENCL
Definition imageop.h:180
@ IOP_FLAGS_NO_HISTORY_STACK
Definition imageop.h:174
@ IOP_GROUP_TECHNICAL
Definition imageop.h:143
void *const ovoid
static const float x
#define dt_mipmap_cache_get(A, B, C, D, E, F)
@ DT_MIPMAP_BLOCKING
#define dt_mipmap_cache_release(A, B)
int dt_opencl_write_host_to_device_raw(const int devid, const void *host, void *device, const size_t *origin, const size_t *region, const int rowpitch, const int blocking)
Definition opencl.c:2249
struct dt_mipmap_cache_t * mipmap_cache
Definition darktable.h:776
dt_iop_buffer_dsc_t dsc_out
dt_iop_buffer_dsc_t dsc_in
struct dt_iop_module_t *void * data
dt_mipmap_size_t size
struct dt_develop_t * dev
dt_image_t image_storage
Definition develop.h:259
dt_iop_buffer_dsc_t dsc
Definition image.h:337
int32_t hide_enable_button
Definition imageop.h:262
dt_iop_params_t * default_params
Definition imageop.h:307
dt_iop_gui_data_t * gui_data
Definition imageop.h:311
gboolean default_enabled
Definition imageop.h:303
int32_t params_size
Definition imageop.h:309
dt_iop_params_t * params
Definition imageop.h:307
Region of interest passed through the pixelpipe.
Definition imageop.h:72
#define MIN(a, b)
Definition thinplate.c:32
#define MAX(a, b)
Definition thinplate.c:29