40#define S(V, params) ((params->mul) * ((float)V))
41#define P(V, params) (CLAMP((V), 0, (params->bins_count - 1)))
42#define PU(V, params) (MIN((V), (params->bins_count - 1)))
43#define PS(V, params) (P(S(V, params), params))
50 const uint32_t
i =
PS(*pixel, histogram_params);
55 const void *pixel, uint32_t *histogram,
int j,
59 const float *input = (
float *)pixel + roi->
width * j + roi->
crop_x;
72 const uint16_t
i =
PU(*pixel, histogram_params);
77 const void *pixel, uint32_t *histogram,
int j,
81 uint16_t *in = (uint16_t *)pixel + roi->
width * j + roi->
crop_x;
90inline static void __attribute__((__unused__)) histogram_helper_cs_rgb_helper_process_pixel_float(
93 const uint32_t
R =
PS(pixel[0], histogram_params);
94 const uint32_t G =
PS(pixel[1], histogram_params);
95 const uint32_t
B =
PS(pixel[2], histogram_params);
97 histogram[4 * G + 1]++;
98 histogram[4 *
B + 2]++;
101inline static void __attribute__((__unused__)) histogram_helper_cs_rgb_helper_process_pixel_float_compensated(
106 dt_ioppr_compensate_middle_grey(pixel[1], profile_info),
107 dt_ioppr_compensate_middle_grey(pixel[2], profile_info) };
108 const uint32_t
R =
PS(
rgb[0], histogram_params);
109 const uint32_t G =
PS(
rgb[1], histogram_params);
110 const uint32_t
B =
PS(
rgb[2], histogram_params);
112 histogram[4 * G + 1]++;
113 histogram[4 *
B + 2]++;
117 const void *pixel, uint32_t *histogram,
int j,
121 float *in = (
float *)pixel + 4 * (roi->
width * j + roi->
crop_x);
126 histogram_helper_cs_rgb_helper_process_pixel_float(histogram_params, in, histogram);
131 const void *pixel, uint32_t *histogram,
int j,
135 float *in = (
float *)pixel + 4 * (roi->
width * j + roi->
crop_x);
140 histogram_helper_cs_rgb_helper_process_pixel_float_compensated(histogram_params, in, histogram, profile_info);
146inline static void __attribute__((__unused__)) histogram_helper_cs_Lab_helper_process_pixel_float(
149 const float Lv = pixel[0];
150 const float av = pixel[1];
151 const float bv = pixel[2];
153 const uint32_t
L = CLAMP(histogram_params->
mul / 100.0f * (Lv), 0,
max);
154 const uint32_t
a = CLAMP(histogram_params->
mul / 256.0f * (av + 128.0f), 0,
max);
155 const uint32_t
b = CLAMP(histogram_params->
mul / 256.0f * (bv + 128.0f), 0,
max);
157 histogram[4 *
a + 1]++;
158 histogram[4 *
b + 2]++;
162 const void *pixel, uint32_t *histogram,
int j,
166 float *in = (
float *)pixel + 4 * (roi->
width * j + roi->
crop_x);
171 histogram_helper_cs_Lab_helper_process_pixel_float(histogram_params, in, histogram);
175inline static void __attribute__((__unused__)) histogram_helper_cs_Lab_LCh_helper_process_pixel_float(
179 dt_Lab_2_LCH(pixel, LCh);
180 const uint32_t
L =
PS((LCh[0] / 100.f), histogram_params);
181 const uint32_t
C =
PS((LCh[1] / (128.0f * sqrtf(2.0f))), histogram_params);
182 const uint32_t h =
PS(LCh[2], histogram_params);
184 histogram[4 *
C + 1]++;
185 histogram[4 * h + 2]++;
189 const void *pixel, uint32_t *histogram,
int j,
193 float *in = (
float *)pixel + 4 * (roi->
width * j + roi->
crop_x);
197 histogram_helper_cs_Lab_LCh_helper_process_pixel_float(histogram_params, in, histogram);
202 const void *pixel, uint32_t *histogram,
int j,
206 float *in = (
float *)pixel + 4 * (roi->
width * j + roi->
crop_x);
210 const uint32_t
L =
PS((in[0] / 100.f), histogram_params);
211 const uint32_t
C =
PS((in[1] / (128.0f * sqrtf(2.0f))), histogram_params);
212 const uint32_t h =
PS(in[2], histogram_params);
214 histogram[4 *
C + 1]++;
215 histogram[4 * h + 2]++;
223 uint32_t **histogram,
const dt_worker Worker,
228 const size_t bins_total = (size_t)4 * histogram_params->
bins_count;
229 const size_t buf_size = bins_total *
sizeof(uint32_t);
230 void *partial_hists = calloc(nthreads, buf_size);
238 uint32_t *thread_hist = (uint32_t *)partial_hists + bins_total *
omp_get_thread_num();
239 Worker(histogram_params, pixel, thread_hist, j, profile_info);
243 *histogram = realloc(*histogram, buf_size);
244 memset(*histogram, 0, buf_size);
245 uint32_t *hist = *histogram;
247#pragma omp parallel for default(firstprivate) \
248 shared(hist, partial_hists)
249 for(
size_t k = 0;
k < bins_total;
k++)
251 for(
size_t n = 0;
n < nthreads;
n++)
253 const uint32_t *thread_hist = (uint32_t *)partial_hists + bins_total *
n;
254 hist[
k] += thread_hist[
k];
258 *histogram = realloc(*histogram, buf_size);
259 memmove(*histogram, partial_hists, buf_size);
275 float *converted = NULL;
279 const size_t pixels = (size_t)roi->
width * roi->
height;
285 for(
size_t k = 0;
k < pixels;
k++)
287 const size_t offset = 4 *
k;
288 dt_Lab_2_LCH((
const float *)pixel + offset, converted + offset);
289 converted[offset + 3] = ((
const float *)pixel)[offset + 3];
298 histogram_stats->
ch = 1u;
303 if(compensate_middle_grey && profile_info)
307 histogram_stats->
ch = 3u;
318 histogram_stats->
ch = 3u;
327 uint32_t **histogram, uint32_t *histogram_max)
330 histogram_max[0] = histogram_max[1] = histogram_max[2] = histogram_max[3] = 0;
331 uint32_t *hist = *histogram;
336 histogram_max[0] = histogram_max[0] > hist[
k] ? histogram_max[0] : hist[
k];
343 histogram_max[0] = histogram_max[0] > hist[
k] ? histogram_max[0] : hist[
k];
345 histogram_max[1] = histogram_max[1] > hist[
k] ? histogram_max[1] : hist[
k];
347 histogram_max[2] = histogram_max[2] > hist[
k] ? histogram_max[2] : hist[
k];
349 histogram_max[3] = histogram_max[3] > hist[
k] ? histogram_max[3] : hist[
k];
358 histogram_max[0] = histogram_max[0] > hist[
k] ? histogram_max[0] : hist[
k];
360 histogram_max[1] = histogram_max[1] > hist[
k] ? histogram_max[1] : hist[
k];
362 histogram_max[2] = histogram_max[2] > hist[
k] ? histogram_max[2] : hist[
k];
364 histogram_max[3] = histogram_max[3] > hist[
k] ? histogram_max[3] : hist[
k];
370 histogram_max[0] = histogram_max[0] > hist[
k] ? histogram_max[0] : hist[
k];
373 for(
int k = 5;
k < 4 * (histogram_stats->
bins_count - 1);
k += 4)
374 histogram_max[1] = histogram_max[1] > hist[
k] ? histogram_max[1] : hist[
k];
375 for(
int k = 6;
k < 4 * (histogram_stats->
bins_count - 1);
k += 4)
376 histogram_max[2] = histogram_max[2] > hist[
k] ? histogram_max[2] : hist[
k];
static dt_aligned_pixel_t rgb
static const float const float C
static void histogram_helper_cs_Lab_LCh(const dt_dev_histogram_collection_params_t *const histogram_params, const void *pixel, uint32_t *histogram, int j, const dt_iop_order_iccprofile_info_t *const profile_info)
static void histogram_helper_cs_RAW_helper_process_pixel_float(const dt_dev_histogram_collection_params_t *const histogram_params, const float *pixel, uint32_t *histogram)
static void histogram_helper_cs_rgb(const dt_dev_histogram_collection_params_t *const histogram_params, const void *pixel, uint32_t *histogram, int j, const dt_iop_order_iccprofile_info_t *const profile_info)
static void histogram_helper_cs_RAW_helper_process_pixel_uint16(const dt_dev_histogram_collection_params_t *const histogram_params, const uint16_t *pixel, uint32_t *histogram)
static void histogram_helper_cs_RAW(const dt_dev_histogram_collection_params_t *const histogram_params, const void *pixel, uint32_t *histogram, int j, const dt_iop_order_iccprofile_info_t *const profile_info)
void dt_histogram_max_helper(const dt_dev_histogram_stats_t *const histogram_stats, const dt_iop_colorspace_type_t cst, const dt_iop_colorspace_type_t cst_to, uint32_t **histogram, uint32_t *histogram_max)
void dt_histogram_worker(dt_dev_histogram_collection_params_t *const histogram_params, dt_dev_histogram_stats_t *histogram_stats, const void *const pixel, uint32_t **histogram, const dt_worker Worker, const dt_iop_order_iccprofile_info_t *const profile_info)
void dt_histogram_helper(dt_dev_histogram_collection_params_t *histogram_params, dt_dev_histogram_stats_t *histogram_stats, const dt_iop_colorspace_type_t cst, const dt_iop_colorspace_type_t cst_to, const void *pixel, uint32_t **histogram, const int compensate_middle_grey, const dt_iop_order_iccprofile_info_t *const profile_info)
static void histogram_helper_cs_LCh(const dt_dev_histogram_collection_params_t *const histogram_params, const void *pixel, uint32_t *histogram, int j, const dt_iop_order_iccprofile_info_t *const profile_info)
static void histogram_helper_cs_rgb_compensated(const dt_dev_histogram_collection_params_t *const histogram_params, const void *pixel, uint32_t *histogram, int j, const dt_iop_order_iccprofile_info_t *const profile_info)
void dt_histogram_helper_cs_RAW_uint16(const dt_dev_histogram_collection_params_t *const histogram_params, const void *pixel, uint32_t *histogram, int j, const dt_iop_order_iccprofile_info_t *const profile_info)
static void histogram_helper_cs_Lab(const dt_dev_histogram_collection_params_t *const histogram_params, const void *pixel, uint32_t *histogram, int j, const dt_iop_order_iccprofile_info_t *const profile_info)
float *const restrict const size_t k
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
#define omp_get_max_threads()
#define omp_get_thread_num()
#define __OMP_PARALLEL_FOR__(...)
#define dt_pixelpipe_cache_alloc_align_float_cache(pixels, id)
#define dt_pixelpipe_cache_free_align(mem)
DT_ALIGNED_PIXEL float dt_aligned_pixel_t[4]
float dt_aligned_pixel_simd_t __attribute__((vector_size(16), aligned(16)))
Apply one channel's tone curve to each of the three colour channels, or pass the channel through unto...
const struct dt_histogram_roi_t * roi
A profile reduced to the arithmetic the pixel loop can run: two matrices and six tone-curve LUTs,...
typedef double((*spd)(unsigned long int wavelength, double TempK))