Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
testimg.h
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2020 Martin Burri.
4 Copyright (C) 2020 Pascal Obry.
5 Copyright (C) 2022 Martin Baƙinka.
6
7 darktable is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 darktable is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with darktable. If not, see <http://www.gnu.org/licenses/>.
19*/
20/*
21 * Test image generation, access, printing etc. to be used for unit testing with
22 * cmocka.
23 *
24 * Please see ../README.md for more detailed documentation.
25 */
26
27typedef struct Testimg
28{
29 int width;
30 int height;
31 float *pixels; // [0]=red, [1]=green, [2]=blue, [3]=misc/mask
32 const char* name;
34
35
36/*
37 * Creation/deletion
38 */
39
40// standard dynamic range for test images in EV:
41#define TESTIMG_STD_DYN_RANGE_EV 15
42
43// standard width/height for test images:
44#define TESTIMG_STD_WIDTH (TESTIMG_STD_DYN_RANGE_EV + 1)
45#define TESTIMG_STD_HEIGHT (TESTIMG_STD_DYN_RANGE_EV + 1)
46
47// allocate an empty test image:
48Testimg *testimg_alloc(const int width, const int height);
49
50// free test image after usage:
51void testimg_free(Testimg *const ti);
52
53
54/*
55 * Access
56 */
57
58// access pixel (x -> width, y -> height):
59inline float* get_pixel(const Testimg *const ti, const int x, const int y)
60{
61 // y * width + x, so pixel at index 2 is top row, 2nd from left:
62 return ti->pixels + (y * ti->width + x) * 4;
63}
64
65// iterate over test images (x in outer loop):
66#define for_testimg_pixels_p_xy(ti) \
67 for (int x=0, y=0; x<ti->width; x+=1, y=0)\
68 for (float *p=get_pixel(ti, x, y); y<ti->height; y+=1, p=get_pixel(ti, x, y))
69
70// iterate over test images (y in outer loop):
71#define for_testimg_pixels_p_yx(ti) \
72 for (int y=0, x=0; y<ti->height; y+=1, x=0)\
73 for (float *p=get_pixel(ti, x, y); x<ti->width; x+=1, p=get_pixel(ti, x, y))
74
75
76/*
77 * Printing
78 */
79
80// print a color channel of a test image:
81void testimg_print_chan(const Testimg *const ti, const int chan_idx);
82
83// print a whole image, each color channel separately:
84void testimg_print_by_chan(const Testimg *const ti);
85
86// print a whole image, each pixel separately:
87void testimg_print_by_pixel(const Testimg *const ti);
88
89// default print:
90#define testimg_print testimg_print_by_pixel
91
92
93/*
94 * Conversion
95 */
96
97// convert a test image to log-RGB with fixed white point of 1.0f and dynamic
98// range of TESTIMG_STD_DYN_RANGE_EV:
100
101// convert a single value to log-RGB with fixed white point of 1.0f and dynamic
102// range of TESTIMG_STD_DYN_RANGE_EV:
103float testimg_val_to_log(const float val);
104
105// convert a test image to exp-RGB (i.e. a test image in log-RGB back to
106// linear-RGB) with fixed white point 1.0f and dynamic range
107// TESTIMG_STD_DYN_RANGE_EV:
109
110// convert a single value to exp-RGB (i.e. a value in log-RGB back to
111// linear-RGB) with fixed white point 1.0f and dynamic range
112// TESTIMG_STD_DYN_RANGE_EV:
113float testimg_val_to_exp(const float val);
114
115
116/*
117 * Constant color image generation
118 */
119
120// create an image of given size with constant grey color:
121Testimg *testimg_gen_all_grey(const int width, const int height,
122 const float value);
123
124// create a purely black image:
125Testimg *testimg_gen_all_black(const int width, const int height);
126
127// create a purely white image:
128Testimg *testimg_gen_all_white(const int width, const int height);
129
130
131/*
132 * Full color space image generation
133 */
134
135// create a grey gradient from black (left) to white (right) with given width
136// and fixed height=1:
138
139// create a gradient of 1 color from black (left) to white (right) with given
140// width and height=1 (0=red, 1=green, 2=blue):
141Testimg *testimg_gen_single_color_space(const int width, const int color_index);
142
143// create a gradient of 3 colors from black (left) to white (right) with given
144// width and height=3 (y=0 -> red, y=1 -> green, y=2 -> blue):
146
147// create a full rgb color space of given width and fixed height=width*width:
149
150
151/*
152 * Bad and nonsense value image generation
153 */
154
155// create greyscale pixels with max dynamic range values from FLT_MIN to FLT_MAX
156// with height=1 (note: values are in the range ]0.0; +inf[):
158
159// create greyscale pixels with max dynamic range values from -FLT_MAX to
160// -FLT_MIN and -0.0 with height=1 (note: values are in the range ]-inf; 0.0]):
162
163// create 3 "grey'ish" gradients where in each one a color dominates and clips:
164// height: 3, y=0 => red clips, y=1 => green clips, y=2 => blue clips
166// clang-format off
167// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
168// vim: shiftwidth=2 expandtab tabstop=2 cindent
169// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
170// clang-format on
171
int width
Definition bilateral.h:1
int height
Definition bilateral.h:1
static const dt_aligned_pixel_simd_t value
Definition darktable.h:501
static const float x
Definition iop_profile.h:239
Definition testimg.h:28
int width
Definition testimg.h:29
const char * name
Definition testimg.h:32
float * pixels
Definition testimg.h:31
int height
Definition testimg.h:30
Testimg * testimg_gen_all_black(const int width, const int height)
Definition testimg.c:144
void testimg_print_chan(const Testimg *const ti, const int chan_idx)
Definition testimg.c:51
void testimg_free(Testimg *const ti)
Definition testimg.c:45
Testimg * testimg_gen_grey_max_dr_neg()
Definition testimg.c:249
float testimg_val_to_log(const float val)
Definition testimg.c:109
Testimg * testimg_to_log(Testimg *ti)
Definition testimg.c:97
Testimg * testimg_gen_all_white(const int width, const int height)
Definition testimg.c:151
Testimg * testimg_gen_three_color_space(const int width)
Definition testimg.c:186
Testimg * testimg_gen_grey_space(const int width)
Definition testimg.c:158
void testimg_print_by_chan(const Testimg *const ti)
Definition testimg.c:67
Testimg * testimg_gen_grey_with_rgb_clipping(const int width)
Definition testimg.c:270
float * get_pixel(const Testimg *const ti, const int x, const int y)
Definition testimg.h:59
Testimg * testimg_alloc(const int width, const int height)
Definition testimg.c:35
void testimg_print_by_pixel(const Testimg *const ti)
Definition testimg.c:77
Testimg * testimg_gen_grey_max_dr()
Definition testimg.c:223
Testimg * testimg_gen_rgb_space(const int width)
Definition testimg.c:200
Testimg * testimg_to_exp(Testimg *ti)
Definition testimg.c:114
float testimg_val_to_exp(const float val)
Definition testimg.c:126
Testimg * testimg_gen_single_color_space(const int width, const int color_index)
Definition testimg.c:172
Testimg * testimg_gen_all_grey(const int width, const int height, const float value)
Definition testimg.c:131