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 darktable developers.
4
5 darktable 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 darktable 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 darktable. If not, see <http://www.gnu.org/licenses/>.
17*/
18/*
19 * Test image generation, access, printing etc. to be used for unit testing with
20 * cmocka.
21 *
22 * Please see ../README.md for more detailed documentation.
23 */
24
25typedef struct Testimg
26{
27 int width;
28 int height;
29 float *pixels; // [0]=red, [1]=green, [2]=blue, [3]=misc/mask
30 const char* name;
32
33
34/*
35 * Creation/deletion
36 */
37
38// standard dynamic range for test images in EV:
39#define TESTIMG_STD_DYN_RANGE_EV 15
40
41// standard width/height for test images:
42#define TESTIMG_STD_WIDTH (TESTIMG_STD_DYN_RANGE_EV + 1)
43#define TESTIMG_STD_HEIGHT (TESTIMG_STD_DYN_RANGE_EV + 1)
44
45// allocate an empty test image:
46Testimg *testimg_alloc(const int width, const int height);
47
48// free test image after usage:
49void testimg_free(Testimg *const ti);
50
51
52/*
53 * Access
54 */
55
56// access pixel (x -> width, y -> height):
57inline float* get_pixel(const Testimg *const ti, const int x, const int y)
58{
59 // y * width + x, so pixel at index 2 is top row, 2nd from left:
60 return ti->pixels + (y * ti->width + x) * 4;
61}
62
63// iterate over test images (x in outer loop):
64#define for_testimg_pixels_p_xy(ti) \
65 for (int x=0, y=0; x<ti->width; x+=1, y=0)\
66 for (float *p=get_pixel(ti, x, y); y<ti->height; y+=1, p=get_pixel(ti, x, y))
67
68// iterate over test images (y in outer loop):
69#define for_testimg_pixels_p_yx(ti) \
70 for (int y=0, x=0; y<ti->height; y+=1, x=0)\
71 for (float *p=get_pixel(ti, x, y); x<ti->width; x+=1, p=get_pixel(ti, x, y))
72
73
74/*
75 * Printing
76 */
77
78// print a color channel of a test image:
79void testimg_print_chan(const Testimg *const ti, const int chan_idx);
80
81// print a whole image, each color channel separately:
82void testimg_print_by_chan(const Testimg *const ti);
83
84// print a whole image, each pixel separately:
85void testimg_print_by_pixel(const Testimg *const ti);
86
87// default print:
88#define testimg_print testimg_print_by_pixel
89
90
91/*
92 * Conversion
93 */
94
95// convert a test image to log-RGB with fixed white point of 1.0f and dynamic
96// range of TESTIMG_STD_DYN_RANGE_EV:
98
99// convert a single value to log-RGB with fixed white point of 1.0f and dynamic
100// range of TESTIMG_STD_DYN_RANGE_EV:
101float testimg_val_to_log(const float val);
102
103// convert a test image to exp-RGB (i.e. a test image in log-RGB back to
104// linear-RGB) with fixed white point 1.0f and dynamic range
105// TESTIMG_STD_DYN_RANGE_EV:
107
108// convert a single value to exp-RGB (i.e. a value in log-RGB back to
109// linear-RGB) with fixed white point 1.0f and dynamic range
110// TESTIMG_STD_DYN_RANGE_EV:
111float testimg_val_to_exp(const float val);
112
113
114/*
115 * Constant color image generation
116 */
117
118// create an image of given size with constant grey color:
119Testimg *testimg_gen_all_grey(const int width, const int height,
120 const float value);
121
122// create a purely black image:
123Testimg *testimg_gen_all_black(const int width, const int height);
124
125// create a purely white image:
126Testimg *testimg_gen_all_white(const int width, const int height);
127
128
129/*
130 * Full color space image generation
131 */
132
133// create a grey gradient from black (left) to white (right) with given width
134// and fixed height=1:
136
137// create a gradient of 1 color from black (left) to white (right) with given
138// width and height=1 (0=red, 1=green, 2=blue):
139Testimg *testimg_gen_single_color_space(const int width, const int color_index);
140
141// create a gradient of 3 colors from black (left) to white (right) with given
142// width and height=3 (y=0 -> red, y=1 -> green, y=2 -> blue):
144
145// create a full rgb color space of given width and fixed height=width*width:
147
148
149/*
150 * Bad and nonsense value image generation
151 */
152
153// create greyscale pixels with max dynamic range values from FLT_MIN to FLT_MAX
154// with height=1 (note: values are in the range ]0.0; +inf[):
156
157// create greyscale pixels with max dynamic range values from -FLT_MAX to
158// -FLT_MIN and -0.0 with height=1 (note: values are in the range ]-inf; 0.0]):
160
161// create 3 "grey'ish" gradients where in each one a color dominates and clips:
162// height: 3, y=0 => red clips, y=1 => green clips, y=2 => blue clips
164// clang-format off
165// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
166// vim: shiftwidth=2 expandtab tabstop=2 cindent
167// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
168// clang-format on
169
int width
Definition bilateral.h:1
int height
Definition bilateral.h:1
Definition testimg.h:26
int width
Definition testimg.h:27
const char * name
Definition testimg.h:30
float * pixels
Definition testimg.h:29
int height
Definition testimg.h:28
Testimg * testimg_gen_all_black(const int width, const int height)
Definition testimg.c:140
void testimg_print_chan(const Testimg *const ti, const int chan_idx)
Definition testimg.c:47
void testimg_free(Testimg *const ti)
Definition testimg.c:41
Testimg * testimg_gen_grey_max_dr_neg()
Definition testimg.c:245
float testimg_val_to_log(const float val)
Definition testimg.c:105
Testimg * testimg_to_log(Testimg *ti)
Definition testimg.c:93
Testimg * testimg_gen_all_white(const int width, const int height)
Definition testimg.c:147
Testimg * testimg_gen_three_color_space(const int width)
Definition testimg.c:182
Testimg * testimg_gen_grey_space(const int width)
Definition testimg.c:154
void testimg_print_by_chan(const Testimg *const ti)
Definition testimg.c:63
Testimg * testimg_gen_grey_with_rgb_clipping(const int width)
Definition testimg.c:266
float * get_pixel(const Testimg *const ti, const int x, const int y)
Definition testimg.h:57
Testimg * testimg_alloc(const int width, const int height)
Definition testimg.c:31
void testimg_print_by_pixel(const Testimg *const ti)
Definition testimg.c:73
Testimg * testimg_gen_grey_max_dr()
Definition testimg.c:219
Testimg * testimg_gen_rgb_space(const int width)
Definition testimg.c:196
Testimg * testimg_to_exp(Testimg *ti)
Definition testimg.c:110
float testimg_val_to_exp(const float val)
Definition testimg.c:122
Testimg * testimg_gen_single_color_space(const int width, const int color_index)
Definition testimg.c:168
Testimg * testimg_gen_all_grey(const int width, const int height, const float value)
Definition testimg.c:127