36#define S(V, params) ((params->mul) * ((float)V))
37#define P(V, params) (CLAMP((V), 0, (params->bins_count - 1)))
38#define PU(V, params) (MIN((V), (params->bins_count - 1)))
39#define PS(V, params) (P(S(V, params), params))
46 const uint32_t
i =
PS(*pixel, histogram_params);
51 const void *pixel, uint32_t *histogram,
int j,
55 const float *input = (
float *)pixel + roi->
width * j + roi->
crop_x;
68 const uint16_t
i =
PU(*pixel, histogram_params);
73 const void *pixel, uint32_t *histogram,
int j,
77 uint16_t *in = (uint16_t *)pixel + roi->
width * j + roi->
crop_x;
86inline static void __attribute__((__unused__)) histogram_helper_cs_rgb_helper_process_pixel_float(
89 const uint32_t
R =
PS(pixel[0], histogram_params);
90 const uint32_t G =
PS(pixel[1], histogram_params);
91 const uint32_t
B =
PS(pixel[2], histogram_params);
93 histogram[4 * G + 1]++;
94 histogram[4 *
B + 2]++;
97inline static void __attribute__((__unused__)) histogram_helper_cs_rgb_helper_process_pixel_float_compensated(
102 dt_ioppr_compensate_middle_grey(pixel[1], profile_info),
103 dt_ioppr_compensate_middle_grey(pixel[2], profile_info) };
104 const uint32_t
R =
PS(
rgb[0], histogram_params);
105 const uint32_t G =
PS(
rgb[1], histogram_params);
106 const uint32_t
B =
PS(
rgb[2], histogram_params);
108 histogram[4 * G + 1]++;
109 histogram[4 *
B + 2]++;
113 const void *pixel, uint32_t *histogram,
int j,
117 float *in = (
float *)pixel + 4 * (roi->
width * j + roi->
crop_x);
122 histogram_helper_cs_rgb_helper_process_pixel_float(histogram_params, in, histogram);
127 const void *pixel, uint32_t *histogram,
int j,
131 float *in = (
float *)pixel + 4 * (roi->
width * j + roi->
crop_x);
136 histogram_helper_cs_rgb_helper_process_pixel_float_compensated(histogram_params, in, histogram, profile_info);
142inline static void __attribute__((__unused__)) histogram_helper_cs_Lab_helper_process_pixel_float(
145 const float Lv = pixel[0];
146 const float av = pixel[1];
147 const float bv = pixel[2];
149 const uint32_t
L = CLAMP(histogram_params->
mul / 100.0f * (Lv), 0,
max);
150 const uint32_t a = CLAMP(histogram_params->
mul / 256.0f * (av + 128.0f), 0,
max);
151 const uint32_t
b = CLAMP(histogram_params->
mul / 256.0f * (bv + 128.0f), 0,
max);
153 histogram[4 * a + 1]++;
154 histogram[4 *
b + 2]++;
158 const void *pixel, uint32_t *histogram,
int j,
162 float *in = (
float *)pixel + 4 * (roi->
width * j + roi->
crop_x);
167 histogram_helper_cs_Lab_helper_process_pixel_float(histogram_params, in, histogram);
171inline static void __attribute__((__unused__)) histogram_helper_cs_Lab_LCh_helper_process_pixel_float(
175 dt_Lab_2_LCH(pixel, LCh);
176 const uint32_t
L =
PS((LCh[0] / 100.f), histogram_params);
177 const uint32_t
C =
PS((LCh[1] / (128.0f * sqrtf(2.0f))), histogram_params);
178 const uint32_t h =
PS(LCh[2], histogram_params);
180 histogram[4 *
C + 1]++;
181 histogram[4 * h + 2]++;
185 const void *pixel, uint32_t *histogram,
int j,
189 float *in = (
float *)pixel + 4 * (roi->
width * j + roi->
crop_x);
193 histogram_helper_cs_Lab_LCh_helper_process_pixel_float(histogram_params, in, histogram);
198 const void *pixel, uint32_t *histogram,
int j,
202 float *in = (
float *)pixel + 4 * (roi->
width * j + roi->
crop_x);
206 const uint32_t
L =
PS((in[0] / 100.f), histogram_params);
207 const uint32_t
C =
PS((in[1] / (128.0f * sqrtf(2.0f))), histogram_params);
208 const uint32_t h =
PS(in[2], histogram_params);
210 histogram[4 *
C + 1]++;
211 histogram[4 * h + 2]++;
219 uint32_t **histogram,
const dt_worker Worker,
224 const size_t bins_total = (size_t)4 * histogram_params->
bins_count;
225 const size_t buf_size = bins_total *
sizeof(uint32_t);
226 void *partial_hists = calloc(nthreads, buf_size);
234 uint32_t *thread_hist = (uint32_t *)partial_hists + bins_total *
omp_get_thread_num();
235 Worker(histogram_params, pixel, thread_hist, j, profile_info);
239 *histogram = realloc(*histogram, buf_size);
240 memset(*histogram, 0, buf_size);
241 uint32_t *hist = *histogram;
243#pragma omp parallel for default(firstprivate) \
244 shared(hist, partial_hists)
245 for(
size_t k = 0;
k < bins_total;
k++)
247 for(
size_t n = 0;
n < nthreads;
n++)
249 const uint32_t *thread_hist = (uint32_t *)partial_hists + bins_total *
n;
250 hist[
k] += thread_hist[
k];
254 *histogram = realloc(*histogram, buf_size);
255 memmove(*histogram, partial_hists, buf_size);
271 float *converted = NULL;
275 const size_t pixels = (size_t)roi->
width * roi->
height;
281 for(
size_t k = 0;
k < pixels;
k++)
283 const size_t offset = 4 *
k;
284 dt_Lab_2_LCH((
const float *)pixel + offset, converted + offset);
285 converted[offset + 3] = ((
const float *)pixel)[offset + 3];
294 histogram_stats->
ch = 1u;
299 if(compensate_middle_grey && profile_info)
303 histogram_stats->
ch = 3u;
314 histogram_stats->
ch = 3u;
323 uint32_t **histogram, uint32_t *histogram_max)
326 histogram_max[0] = histogram_max[1] = histogram_max[2] = histogram_max[3] = 0;
327 uint32_t *hist = *histogram;
332 histogram_max[0] = histogram_max[0] > hist[
k] ? histogram_max[0] : hist[
k];
339 histogram_max[0] = histogram_max[0] > hist[
k] ? histogram_max[0] : hist[
k];
341 histogram_max[1] = histogram_max[1] > hist[
k] ? histogram_max[1] : hist[
k];
343 histogram_max[2] = histogram_max[2] > hist[
k] ? histogram_max[2] : hist[
k];
345 histogram_max[3] = histogram_max[3] > hist[
k] ? histogram_max[3] : hist[
k];
354 histogram_max[0] = histogram_max[0] > hist[
k] ? histogram_max[0] : hist[
k];
356 histogram_max[1] = histogram_max[1] > hist[
k] ? histogram_max[1] : hist[
k];
358 histogram_max[2] = histogram_max[2] > hist[
k] ? histogram_max[2] : hist[
k];
360 histogram_max[3] = histogram_max[3] > hist[
k] ? histogram_max[3] : hist[
k];
366 histogram_max[0] = histogram_max[0] > hist[
k] ? histogram_max[0] : hist[
k];
369 for(
int k = 5;
k < 4 * (histogram_stats->
bins_count - 1);
k += 4)
370 histogram_max[1] = histogram_max[1] > hist[
k] ? histogram_max[1] : hist[
k];
371 for(
int k = 6;
k < 4 * (histogram_stats->
bins_count - 1);
k += 4)
372 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)
#define dt_pixelpipe_cache_alloc_align_float_cache(pixels, id)
#define omp_get_max_threads()
float dt_aligned_pixel_simd_t __attribute__((vector_size(16), aligned(16)))
Enable aggressive floating-point arithmetic optimizations, in denormals handling. Set through user pr...
#define omp_get_thread_num()
#define dt_pixelpipe_cache_free_align(mem)
#define __OMP_PARALLEL_FOR__(...)
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
float *const restrict const size_t k
float dt_aligned_pixel_t[4]
const struct dt_histogram_roi_t * roi
typedef double((*spd)(unsigned long int wavelength, double TempK))