1 #include "test-common.h"
6 /* gegl_buffer_sample() should not be used in performance-critical code. the
7 * corresponding tests take a long time to finish, and are disabled by default.
8 * uncomment this line to enable them.
10 /* #define TEST_BUFFER_SAMPLE */
17 GeglRectangle bound
= {0, 0, 4024, 4024};
18 const Babl
*format
, *format2
;
22 gegl_init (NULL
, NULL
);
23 format
= babl_format ("RGBA float");
24 format2
= babl_format ("R'G'B'A float");
25 buffer
= gegl_buffer_new (&bound
, format
);
26 buf
= g_malloc0 (bound
.width
* bound
.height
* BPP
);
29 gegl_buffer_set (buffer
, &bound
, 0, NULL
, buf
, GEGL_AUTO_ROWSTRIDE
);
31 format
= babl_format ("RGBA float");
34 gint rands
[SAMPLES
*2];
36 for (i
= 0; i
< SAMPLES
; i
++)
38 rands
[i
*2] = rand()%1000;
39 rands
[i
*2+1] = rand()%1000;
40 rands
[i
*2] = i
/ 1000;
41 rands
[i
*2+1] = i
% 1000;
45 for (i
=0;i
<ITERATIONS
&& converged
< BAIL_COUNT
;i
++)
48 float px
[4] = {0.2, 0.4, 0.1, 0.5};
50 for (j
= 0; j
< SAMPLES
; j
++)
54 GeglRectangle rect
= {x
, y
, 1, 1};
55 gegl_buffer_get (buffer
, &rect
, 1.0, format2
, (void*)&px
[0],
56 GEGL_AUTO_ROWSTRIDE
, GEGL_ABYSS_NONE
);
60 test_end ("gegl_buffer_get 1x1 + babl", 1.0 * SAMPLES
* ITERATIONS
* BPP
);
63 for (i
=0;i
<ITERATIONS
&& converged
< BAIL_COUNT
;i
++)
66 float px
[4] = {0.2, 0.4, 0.1, 0.5};
68 for (j
= 0; j
< SAMPLES
; j
++)
72 gegl_buffer_sample (buffer
, x
, y
, NULL
, (void*)&px
[0], format
,
73 GEGL_SAMPLER_NEAREST
, GEGL_ABYSS_NONE
);
77 test_end ("gegl_buffer_sample nearest", 1.0 * SAMPLES
* ITERATIONS
* BPP
);
80 for (i
=0;i
<ITERATIONS
&& converged
< BAIL_COUNT
;i
++)
83 float px
[4] = {0.2, 0.4, 0.1, 0.5};
85 for (j
= 0; j
< SAMPLES
; j
++)
89 gegl_buffer_sample (buffer
, x
, y
, NULL
, (void*)&px
[0], format
,
90 GEGL_SAMPLER_NEAREST
, GEGL_ABYSS_NONE
);
94 test_end ("gegl_buffer_sample near+ba", 1.0 * SAMPLES
* ITERATIONS
* BPP
);
97 for (i
=0;i
<ITERATIONS
&& converged
< BAIL_COUNT
;i
++)
100 float px
[4] = {0.2, 0.4, 0.1, 0.5};
101 GeglSampler
*sampler
= gegl_buffer_sampler_new (buffer
, format
,
102 GEGL_SAMPLER_NEAREST
);
105 for (j
= 0; j
< SAMPLES
; j
++)
108 int y
= rands
[j
*2+1];
109 gegl_sampler_get (sampler
, x
, y
, NULL
, (void*)&px
[0], GEGL_ABYSS_NONE
);
113 g_object_unref (sampler
);
115 test_end ("gegl_sampler_get nearest", 1.0 * SAMPLES
* ITERATIONS
* BPP
);
118 for (i
=0;i
<ITERATIONS
&& converged
< BAIL_COUNT
;i
++)
121 float px
[4] = {0.2, 0.4, 0.1, 0.5};
122 GeglSampler
*sampler
= gegl_buffer_sampler_new (buffer
, format
,
123 GEGL_SAMPLER_NEAREST
);
124 GeglSamplerGetFun sampler_get_fun
= gegl_sampler_get_fun (sampler
);
127 for (j
= 0; j
< SAMPLES
; j
++)
130 int y
= rands
[j
*2+1];
131 sampler_get_fun (sampler
, x
, y
, NULL
, (void*)&px
[0], GEGL_ABYSS_NONE
);
135 g_object_unref (sampler
);
137 test_end ("sampler_get_fun nearest", 1.0 * SAMPLES
* ITERATIONS
* BPP
);
141 for (i
=0;i
<ITERATIONS
&& converged
< BAIL_COUNT
;i
++)
144 float px
[4] = {0.2, 0.4, 0.1, 0.5};
145 GeglSampler
*sampler
= gegl_buffer_sampler_new (buffer
, format2
,
146 GEGL_SAMPLER_NEAREST
);
147 GeglSamplerGetFun sampler_get_fun
= gegl_sampler_get_fun (sampler
);
150 for (j
= 0; j
< SAMPLES
; j
++)
153 int y
= rands
[j
*2+1];
154 sampler_get_fun (sampler
, x
, y
, NULL
, (void*)&px
[0], GEGL_ABYSS_NONE
);
158 g_object_unref (sampler
);
160 test_end ("sampler_get_fun nearest+babl", 1.0 * SAMPLES
* ITERATIONS
* BPP
);
163 #ifdef TEST_BUFFER_SAMPLE
165 for (i
=0;i
<ITERATIONS
&& converged
< BAIL_COUNT
;i
++)
168 float px
[4] = {0.2, 0.4, 0.1, 0.5};
170 for (j
= 0; j
< SAMPLES
; j
++)
173 int y
= rands
[j
*2+1];
174 gegl_buffer_sample (buffer
, x
, y
, NULL
, (void*)&px
[0], format
,
175 GEGL_SAMPLER_LINEAR
, GEGL_ABYSS_NONE
);
179 test_end ("gegl_buffer_sample linear", 1.0 * SAMPLES
* ITERATIONS
* BPP
);
183 for (i
=0;i
<ITERATIONS
&& converged
< BAIL_COUNT
;i
++)
186 float px
[4] = {0.2, 0.4, 0.1, 0.5};
187 GeglSampler
*sampler
= gegl_buffer_sampler_new (buffer
, format
,
188 GEGL_SAMPLER_LINEAR
);
191 for (j
= 0; j
< SAMPLES
; j
++)
194 int y
= rands
[j
*2+1];
195 gegl_sampler_get (sampler
, x
, y
, NULL
, (void*)&px
[0], GEGL_ABYSS_NONE
);
199 g_object_unref (sampler
);
201 test_end ("gegl_sampler_get linear", 1.0 * SAMPLES
* ITERATIONS
* BPP
);
204 for (i
=0;i
<ITERATIONS
&& converged
< BAIL_COUNT
;i
++)
207 float px
[4] = {0.2, 0.4, 0.1, 0.5};
208 GeglSampler
*sampler
= gegl_buffer_sampler_new (buffer
, format
,
209 GEGL_SAMPLER_LINEAR
);
210 GeglSamplerGetFun sampler_get_fun
= gegl_sampler_get_fun (sampler
);
213 for (j
= 0; j
< SAMPLES
; j
++)
216 int y
= rands
[j
*2+1];
217 sampler_get_fun (sampler
, x
, y
, NULL
, (void*)&px
[0], GEGL_ABYSS_NONE
);
221 g_object_unref (sampler
);
223 test_end ("sampler_get_fun linear", 1.0 * SAMPLES
* ITERATIONS
* BPP
);
225 #ifdef TEST_BUFFER_SAMPLE
227 for (i
=0;i
<ITERATIONS
&& converged
< BAIL_COUNT
;i
++)
230 float px
[4] = {0.2, 0.4, 0.1, 0.5};
232 for (j
= 0; j
< SAMPLES
; j
++)
235 int y
= rands
[j
*2+1];
236 gegl_buffer_sample (buffer
, x
, y
, NULL
, (void*)&px
[0], format
,
237 GEGL_SAMPLER_CUBIC
, GEGL_ABYSS_NONE
);
241 test_end ("gegl_buffer_sample cubic", 1.0 * SAMPLES
* ITERATIONS
* BPP
);
245 for (i
=0;i
<ITERATIONS
&& converged
< BAIL_COUNT
;i
++)
248 float px
[4] = {0.2, 0.4, 0.1, 0.5};
249 GeglSampler
*sampler
= gegl_buffer_sampler_new (buffer
, format
,
253 for (j
= 0; j
< SAMPLES
; j
++)
256 int y
= rands
[j
*2+1];
257 gegl_sampler_get (sampler
, x
, y
, NULL
, (void*)&px
[0], GEGL_ABYSS_NONE
);
261 g_object_unref (sampler
);
263 test_end ("gegl_sampler_get cubic", 1.0 * SAMPLES
* ITERATIONS
* BPP
);
266 for (i
=0;i
<ITERATIONS
&& converged
< BAIL_COUNT
;i
++)
269 float px
[4] = {0.2, 0.4, 0.1, 0.5};
270 GeglSampler
*sampler
= gegl_buffer_sampler_new (buffer
, format
,
272 GeglSamplerGetFun sampler_get_fun
= gegl_sampler_get_fun (sampler
);
275 for (j
= 0; j
< SAMPLES
; j
++)
278 int y
= rands
[j
*2+1];
279 sampler_get_fun (sampler
, x
, y
, NULL
, (void*)&px
[0], GEGL_ABYSS_NONE
);
283 g_object_unref (sampler
);
285 test_end ("sampler_get_fun cubic", 1.0 * SAMPLES
* ITERATIONS
* BPP
);
288 for (i
=0;i
<ITERATIONS
&& converged
< BAIL_COUNT
;i
++)
291 float px
[4] = {0.2, 0.4, 0.1, 0.5};
292 GeglSampler
*sampler
= gegl_buffer_sampler_new (buffer
, format
,
293 GEGL_SAMPLER_NOHALO
);
296 for (j
= 0; j
< SAMPLES
; j
++)
299 int y
= rands
[j
*2+1];
300 gegl_sampler_get (sampler
, x
, y
, NULL
, (void*)&px
[0], GEGL_ABYSS_NONE
);
304 g_object_unref (sampler
);
306 test_end ("gegl_sampler_get nohalo", 1.0 * SAMPLES
* ITERATIONS
* BPP
);
309 for (i
=0;i
<ITERATIONS
&& converged
< BAIL_COUNT
;i
++)
312 float px
[4] = {0.2, 0.4, 0.1, 0.5};
313 GeglSampler
*sampler
= gegl_buffer_sampler_new (buffer
, format
,
314 GEGL_SAMPLER_LOHALO
);
317 for (j
= 0; j
< SAMPLES
; j
++)
320 int y
= rands
[j
*2+1];
321 gegl_sampler_get (sampler
, x
, y
, NULL
, (void*)&px
[0], GEGL_ABYSS_NONE
);
325 g_object_unref (sampler
);
327 test_end ("gegl_sampler_get lohalo", 1.0 * SAMPLES
* ITERATIONS
* BPP
);
334 g_object_unref (buffer
);