Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
imagebuf.h
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2020-2021 Ralf Brown.
4 Copyright (C) 2021 Pascal Obry.
5 Copyright (C) 2022, 2025-2026 Aurélien PIERRE.
6 Copyright (C) 2022 Martin Bařinka.
7 Copyright (C) 2025 Alynx Zhou.
8
9 darktable is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 darktable is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with darktable. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#pragma once
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#include "develop/imageop.h" // for dt_iop_roi_t
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34// Allocate a 64-byte aligned buffer for an image of the given dimensions and channels.
35// The return value must be freed with dt_pixelpipe_cache_free_align().
36static inline float *__restrict__ dt_iop_image_alloc(const size_t width, const size_t height, const size_t ch)
37{
39}
40
41// Allocate one or more buffers as detailed in the given parameters. If any allocation fails, free all of them,
42// set the module's trouble flag, and return FALSE.
43// The variable arguments take the form SIZE, PTR-to-floatPTR, SIZE, PTR-to-floatPTR, etc. except that if the SIZE
44// indicates a per-thread allocation, a second pointer is passed: SIZE, PTR-to-floatPTR, PTR-to-size_t, SIZE, etc.
45// SIZE is the number of floats per pixel, ORed with appropriate flags from the list following below
46int dt_iop_alloc_image_buffers(struct dt_iop_module_t *const module,
47 const struct dt_iop_roi_t *const roi_in,
48 const struct dt_iop_roi_t *const roi_out, ...);
49// Optional flags to add to size request. Default is to allocate N channels per pixel according to
50// the dimensions of roi_out
51#define DT_IMGSZ_CH_MASK 0x000FFFF // isolate just the number of floats per pixel
52
53#define DT_IMGSZ_ROI_MASK 0x0100000 // isolate just input/output selection
54#define DT_IMGSZ_OUTPUT 0x0000000 // read image dimensions from roi_out
55#define DT_IMGSZ_INPUT 0x0100000 // read image dimensions from roi_in
56
57#define DT_IMGSZ_PERTHREAD 0x0200000 // allocate a separate buffer for each thread
58#define DT_IMGSZ_CLEARBUF 0x0400000 // zero the allocated buffer
59
60#define DT_IMGSZ_DIM_MASK 0x00F0000 // isolate the requested image dimension(s)
61#define DT_IMGSZ_FULL 0x0000000 // full height times width
62#define DT_IMGSZ_HEIGHT 0x0010000 // buffer equal to one column of the image
63#define DT_IMGSZ_WIDTH 0x0020000 // buffer equal to one row of the image
64#define DT_IMGSZ_LONGEST 0x0030000 // buffer equal to larger of one row/one column
65
66
68static inline void dt_simd_memcpy(const float *const __restrict__ in,
69 float *const __restrict__ out,
70 const size_t num_elem)
71{
72 // Perform a parallel vectorized memcpy on 64-bits aligned
73 // contiguous buffers. This is several times faster than the original memcpy
74 __OMP_PARALLEL_FOR_SIMD__(aligned(in, out:64))
75 for(size_t k = 0; k < num_elem; k++)
76 out[k] = in[k];
77}
78
79// Copy an image buffer, specifying the number of floats it contains. Use of this function is to be preferred
80// over a bare memcpy both because it helps document the purpose of the code and because it gives us a single
81// point where we can optimize performance on different architectures.
82void dt_iop_image_copy(float *const __restrict__ out, const float *const __restrict__ in, const size_t nfloats);
83
84// Copy an image buffer, specifying its dimensions and number of channels. Use of this function is to be
85// preferred over a bare memcpy both because it helps document the purpose of the code and because it gives us
86// a single point where we can optimize performance on different architectures.
87static inline void dt_iop_image_copy_by_size(float *const __restrict__ out, const float *const __restrict__ in,
88 const size_t width, const size_t height, const size_t ch)
89{
91}
92
93// Copy an image buffer, specifying the region of interest. The output RoI may be larger than the input RoI,
94// in which case the result is optionally padded with zeros. If the output RoI is smaller than the input RoI,
95// only a portion of the input buffer will be copied.
96void dt_iop_copy_image_roi(float *const __restrict__ out, const float *const __restrict__ in, const size_t ch,
97 const dt_iop_roi_t *const __restrict__ roi_in,
98 const dt_iop_roi_t *const __restrict__ roi_out, const int zero_pad);
99
100// Copy one image buffer to another, multiplying each element by the specified scale factor
101void dt_iop_image_scaled_copy(float *const __restrict__ buf, const float *const __restrict__ src, const float scale,
102 const size_t width, const size_t height, const size_t ch);
103
104// Fill an image buffer with a specified value.
105void dt_iop_image_fill(float *const buf, const float fill_value, const size_t width, const size_t height,
106 const size_t ch);
107
108// Add a specified constant value to every element of the image buffer
109void dt_iop_image_add_const(float *const buf, const float add_value, const size_t width, const size_t height,
110 const size_t ch);
111
112// Add the contents of another image buffer to the given buffer, element-wise
113void dt_iop_image_add_image(float *const buf, const float *const other_buf, const size_t width, const size_t height,
114 const size_t ch);
115
116// Subtract the contents of another image buffer from the given buffer, element-wise
117void dt_iop_image_sub_image(float *const buf, const float *const other_buf, const size_t width, const size_t height,
118 const size_t ch);
119
120// Subtract each element of the image buffer from the given constant value
121void dt_iop_image_invert(float *const buf, const float max_value, const size_t width, const size_t height,
122 const size_t ch);
123
124// Multiply every element of the image buffer by a specified constant value
125void dt_iop_image_mul_const(float *const buf, const float mul_value, const size_t width, const size_t height,
126 const size_t ch);
127
128// Divide every element of the image buffer by a specified constant value
129void dt_iop_image_div_const(float *const buf, const float div_value, const size_t width, const size_t height,
130 const size_t ch);
131
132// elementwise: buf = lammda*buf + (1-lambda)*other
133void dt_iop_image_linear_blend(float *const __restrict__ buf, const float lambda, const float *const __restrict__ other_buf,
134 const size_t width, const size_t height, const size_t ch);
135
136#ifdef __cplusplus
137}
138#endif
139
140// clang-format off
141// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
142// vim: shiftwidth=2 expandtab tabstop=2 cindent
143// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
144// clang-format on
int width
Definition bilateral.h:1
int height
Definition bilateral.h:1
const dt_colormatrix_t dt_aligned_pixel_t out
Definition colorspaces_inline_conversions.h:42
#define dt_pixelpipe_cache_alloc_align_float_cache(pixels, id)
Definition darktable.h:447
#define __DT_CLONE_TARGETS__
Definition darktable.h:367
#define __OMP_PARALLEL_FOR_SIMD__(...)
Definition darktable.h:259
void dt_iop_image_div_const(float *const buf, const float div_value, const size_t width, const size_t height, const size_t ch)
Definition imagebuf.c:376
int dt_iop_alloc_image_buffers(struct dt_iop_module_t *const module, const struct dt_iop_roi_t *const roi_in, const struct dt_iop_roi_t *const roi_out,...)
Definition imagebuf.c:31
static __DT_CLONE_TARGETS__ void dt_simd_memcpy(const float *const __restrict__ in, float *const __restrict__ out, const size_t num_elem)
Definition imagebuf.h:68
void dt_iop_image_scaled_copy(float *const __restrict__ buf, const float *const __restrict__ src, const float scale, const size_t width, const size_t height, const size_t ch)
void dt_iop_image_fill(float *const buf, const float fill_value, const size_t width, const size_t height, const size_t ch)
Definition imagebuf.c:214
void dt_iop_image_mul_const(float *const buf, const float mul_value, const size_t width, const size_t height, const size_t ch)
Definition imagebuf.c:351
static void dt_iop_image_copy_by_size(float *const __restrict__ out, const float *const __restrict__ in, const size_t width, const size_t height, const size_t ch)
Definition imagebuf.h:87
void dt_iop_copy_image_roi(float *const __restrict__ out, const float *const __restrict__ in, const size_t ch, const dt_iop_roi_t *const __restrict__ roi_in, const dt_iop_roi_t *const __restrict__ roi_out, const int zero_pad)
Definition imagebuf.c:159
void dt_iop_image_add_image(float *const buf, const float *const other_buf, const size_t width, const size_t height, const size_t ch)
Definition imagebuf.c:276
void dt_iop_image_invert(float *const buf, const float max_value, const size_t width, const size_t height, const size_t ch)
Definition imagebuf.c:326
void dt_iop_image_sub_image(float *const buf, const float *const other_buf, const size_t width, const size_t height, const size_t ch)
Definition imagebuf.c:301
static float *__restrict__ dt_iop_image_alloc(const size_t width, const size_t height, const size_t ch)
Definition imagebuf.h:36
void dt_iop_image_add_const(float *const buf, const float add_value, const size_t width, const size_t height, const size_t ch)
Definition imagebuf.c:251
void dt_iop_image_copy(float *const __restrict__ out, const float *const __restrict__ in, const size_t nfloats)
Definition imagebuf.c:138
void dt_iop_image_linear_blend(float *const __restrict__ buf, const float lambda, const float *const __restrict__ other_buf, const size_t width, const size_t height, const size_t ch)
float *const restrict const size_t k
Definition luminance_mask.h:78
float *const restrict const size_t const size_t ch
Definition luminance_mask.h:78
Definition imageop.h:246
Region of interest passed through the pixelpipe.
Definition imageop.h:72