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#include "develop/imageop_gui.h"
23
24#include "system/openmp.h"
26#include "system/mem_alloc.h"
28#include "caches/mipmap_cache.h"
29#include "develop/develop.h"
31#include "develop/imageop.h"
32#include "iop/iop_api.h"
33
34#include <string.h>
35
37
42
44
45const char *name()
46{
47 return _("base buffer");
48}
49
51{
53}
54
59
64
65// Full-size RAW in and out
67 const dt_iop_roi_t *const roi_out, dt_iop_roi_t *roi_in)
68{
69 *roi_in = (dt_iop_roi_t){ 0, 0, pipe->iwidth, pipe->iheight, 1.f };
70}
71
73 dt_iop_roi_t *roi_out, const dt_iop_roi_t *const roi_in)
74{
75 *roi_out = (dt_iop_roi_t){ 0, 0, pipe->iwidth, pipe->iheight, 1.f };
76}
77
78/* --- the geometry service's view of this module (develop/geometry/geometry.h) ---------
79 *
80 * basebuffer is the first module in the pipe and asserts the full sensor frame at scale 1,
81 * ignoring whatever roi_in it is handed. The geometry chain seeds its fold with exactly that
82 * -- the raw dimensions at scale 1 -- so re-asserting the input rect here reproduces the
83 * callback above for every position this module can occupy. It moves no points.
84 */
85
86static void _basebuffer_geometry_map_size(const void *data, const dt_iop_roi_t *const in, dt_iop_roi_t *out)
87{
88 *out = (dt_iop_roi_t){ 0, 0, in->width, in->height, 1.f };
89}
90
93 .transform = NULL,
94 .backtransform = NULL,
95};
96
97gboolean geometry_record(dt_iop_module_t *self, const void *params, dt_geometry_record_t *record)
98{
100 return TRUE;
101}
102
103
109
110
116
117
120 const void *const ivoid, void *const ovoid)
121{
122 const dt_iop_roi_t *const roi_out = &piece->roi_out;
124
126 if(IS_NULL_PTR(buf.buf))
127 {
129 return 1;
130 }
131
132 // Catch out-of-bounds here because roi_in -> roi_out conversions
133 // use float scaling that may not always respect initial size.
134
135 // Crop rectangle offset. roi_in is always the full sensor buffer here (modify_roi_in()
136 // always requests it whole, so basebuffer can crop any region from it) : the region
137 // actually requested downstream lives in roi_out.
138 const size_t x = MAX(roi_out->x, 0);
139 const size_t y = MAX(roi_out->y, 0);
140
141 // Crop rectangle size, and stride of the full source buffer we are cropping from
142 const size_t in_width = MIN((size_t)roi_out->width, pipe->iwidth - x);
143 const size_t in_height = MIN((size_t)roi_out->height, pipe->iheight - y);
144 const size_t in_stride = pipe->iwidth * piece->dsc_in.bpp;
145 const size_t out_stride = roi_out->width * piece->dsc_out.bpp;
146 const size_t row_bytes = in_width * piece->dsc_in.bpp;
147
148 // Crop offset translated in memory sizes
149 const size_t y_offset = y * in_stride;
150 const size_t x_offset = x * piece->dsc_in.bpp;
151
152 /* This stage copies the immutable mipmap-cache payload into the pixelpipe cacheline that will
153 * be consumed by the first real processing stage. Keeping the source copy local here makes the
154 * cache ownership and lifetime visible in the recursion instead of in a hidden bootstrap path. */
155 const void *const restrict input = buf.buf;
156
158 for(size_t j = 0; j < in_height; j++)
159 memcpy(ovoid + j * out_stride, input + x_offset + y_offset + j * in_stride, MIN(row_bytes, out_stride));
160
162
163 return 0;
164}
165
166#ifdef HAVE_OPENCL
167int 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)
168{
169 const dt_iop_roi_t *const roi_out = &piece->roi_out;
171
173 if(IS_NULL_PTR(buf.buf))
174 {
176 return FALSE;
177 }
178
179 // Catch out-of-bounds here because roi_in -> roi_out conversions
180 // use float scaling that may not always respect initial size.
181
182 // Crop rectangle offset. roi_in is always the full sensor buffer here (modify_roi_in()
183 // always requests it whole, so basebuffer can crop any region from it) : the region
184 // actually requested downstream lives in roi_out.
185 const size_t x = MAX(roi_out->x, 0);
186 const size_t y = MAX(roi_out->y, 0);
187
188 // Stride of the full source buffer we are cropping from
189 const size_t in_stride = pipe->iwidth * piece->dsc_in.bpp;
190
191 // Crop offset translated in memory sizes
192 const size_t y_offset = y * in_stride;
193 const size_t x_offset = x * piece->dsc_in.bpp;
194
195 /* This stage copies the immutable mipmap-cache payload into the pixelpipe cacheline that will
196 * be consumed by the first real processing stage. Keeping the source copy local here makes the
197 * cache ownership and lifetime visible in the recursion instead of in a hidden bootstrap path. */
198 const void *const restrict input = buf.buf;
199
200 // dev_out is a fresh, roi_out-sized device buffer: the write always starts at its own origin.
201 // The crop offset only applies to where we start reading from the host-side full buffer above.
202 size_t origin[] = { 0, 0, 0 };
203 size_t region[] = { MIN((size_t)roi_out->width, pipe->iwidth - x), MIN((size_t)roi_out->height, pipe->iheight - y), 1 };
204
205 int err = dt_opencl_write_host_to_device_raw(pipe->devid, input + x_offset + y_offset, dev_out, origin,
206 region, in_stride, CL_TRUE);
207
208
210
211 return err == CL_SUCCESS;
212}
213#endif
214
215
221
227
229{
230 self->params = calloc(1, sizeof(dt_iop_basebuffer_params_t));
231 self->default_params = calloc(1, sizeof(dt_iop_basebuffer_params_t));
232 self->default_enabled = 1;
233 self->hide_enable_button = 1;
235}
236
238{
239 dt_free(self->params);
240 dt_free(self->default_params);
241}
242
243// clang-format off
244// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
245// vim: shiftwidth=2 expandtab tabstop=2 cindent
246// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
247// clang-format on
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
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:72
int default_group()
Definition basebuffer.c:50
static void _basebuffer_geometry_map_size(const void *data, const dt_iop_roi_t *const in, dt_iop_roi_t *out)
Definition basebuffer.c:86
__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:119
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:66
static const dt_geometry_vtable_t _basebuffer_geometry_vtable
Definition basebuffer.c:91
const char * name()
Definition basebuffer.c:45
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:104
gboolean geometry_record(dt_iop_module_t *self, const void *params, dt_geometry_record_t *record)
Definition basebuffer.c:97
void cleanup_pipe(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
Definition basebuffer.c:222
int default_colorspace(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece)
Definition basebuffer.c:60
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:111
int flags()
Definition basebuffer.c:55
void init(dt_iop_module_t *self)
Definition basebuffer.c:228
void init_pipe(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
Definition basebuffer.c:216
dt_iop_basebuffer_params_t dt_iop_basebuffer_data_t
Definition basebuffer.c:43
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:167
void cleanup(dt_iop_module_t *self)
Definition basebuffer.c:237
static const float x
const dt_colormatrix_t dt_aligned_pixel_t out
Where things are on the image, answered without a pipeline.
@ IOP_FLAGS_HIDDEN
Definition imageop.h:189
@ IOP_FLAGS_TAKE_NO_INPUT
Definition imageop.h:195
@ IOP_FLAGS_UNSAFE_COPY
Definition imageop.h:196
@ IOP_FLAGS_ONE_INSTANCE
Definition imageop.h:191
@ IOP_FLAGS_CPU_WRITES_OPENCL
Definition imageop.h:199
@ IOP_FLAGS_NO_HISTORY_STACK
Definition imageop.h:193
@ IOP_GROUP_TECHNICAL
Definition imageop.h:162
void *const ovoid
static const dt_dev_pixelpipe_t * pipe
Definition layers.h:49
static const dt_dev_pixelpipe_t const dt_dev_pixelpipe_iop_t * piece
Definition layers.h:50
static const dt_iop_drawlayer_params_t * params
Definition layers.h:80
#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 macros.h:96
#define dt_free_align(ptr)
Release memory from dt_alloc_align() and set ptr to NULL.
Definition mem_alloc.h:214
static void * dt_calloc_align(size_t size)
dt_alloc_align() followed by a zero fill.
Definition mem_alloc.h:225
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
Definition mem_alloc.h:171
@ DT_MIPMAP_BLOCKING
#define dt_mipmap_cache_get(B, C, D, E, F)
#define dt_mipmap_cache_release(B)
#define DT_MODULE_INTROSPECTION(MODVER, PARAMSTYPE)
DT_MODULE() for a module whose params struct is introspected.
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:2725
#define __OMP_PARALLEL_FOR__(...)
Definition openmp.h:95
dt_mipmap_size_t size
struct dt_develop_t * dev
dt_image_t image_storage
Definition develop.h:225
One module instance's contribution, as data.
Definition geometry.h:99
const dt_geometry_vtable_t * vtable
Definition geometry.h:110
A module's geometry, evaluated. Pure functions of the record's own data.
Definition geometry.h:75
void(* map_size)(const void *data, const dt_iop_roi_t *const in, dt_iop_roi_t *out)
Full-resolution input rect -> output rect. Mirrors modify_roi_out() at scale 1.
Definition geometry.h:77
dt_iop_buffer_dsc_t dsc
Definition image.h:428
int32_t hide_enable_button
Definition imageop.h:270
dt_iop_params_t * default_params
Definition imageop.h:333
gboolean default_enabled
Definition imageop.h:318
int32_t params_size
Definition imageop.h:335
dt_iop_params_t * params
Definition imageop.h:333
Region of interest passed through the pixelpipe.
Definition format.h:49
int width
Definition format.h:50
int height
Definition format.h:50
#define __DT_CLONE_TARGETS__
#define MIN(a, b)
Definition thinplate.c:32
#define MAX(a, b)
Definition thinplate.c:29