]>
Commit | Line | Data |
---|---|---|
92bda632 TC |
1 | #!perl -w |
2 | # | |
3 | # this tests both the Inline interface and the API | |
4 | use strict; | |
92bda632 | 5 | use Test::More; |
d8d215e3 | 6 | use Imager::Test qw(is_color3 is_color4); |
92bda632 | 7 | eval "require Inline::C;"; |
85071ac0 | 8 | plan skip_all => "Inline required for testing API" if $@; |
92bda632 | 9 | |
c045de59 TC |
10 | eval "require Parse::RecDescent;"; |
11 | plan skip_all => "Could not load Parse::RecDescent" if $@; | |
12 | ||
89e3c0aa TC |
13 | use Cwd 'getcwd'; |
14 | plan skip_all => "Inline won't work in directories with spaces" | |
15 | if getcwd() =~ / /; | |
16 | ||
3d3fc93b TC |
17 | plan skip_all => "perl 5.005_04, 5.005_05 too buggy" |
18 | if $] =~ /^5\.005_0[45]$/; | |
19 | ||
40e78f96 TC |
20 | -d "testout" or mkdir "testout"; |
21 | ||
d03fd5a4 | 22 | plan tests => 115; |
92bda632 TC |
23 | require Inline; |
24 | Inline->import(with => 'Imager'); | |
22f9ca48 | 25 | Inline->import("FORCE"); # force rebuild |
6d5c85a2 | 26 | #Inline->import(C => Config => OPTIMIZE => "-g"); |
92bda632 TC |
27 | |
28 | Inline->bind(C => <<'EOS'); | |
29 | #include <math.h> | |
30 | ||
31 | int pixel_count(Imager::ImgRaw im) { | |
32 | return im->xsize * im->ysize; | |
33 | } | |
34 | ||
35 | int count_color(Imager::ImgRaw im, Imager::Color c) { | |
36 | int count = 0, x, y, chan; | |
37 | i_color read_c; | |
38 | ||
39 | for (x = 0; x < im->xsize; ++x) { | |
40 | for (y = 0; y < im->ysize; ++y) { | |
41 | int match = 1; | |
42 | i_gpix(im, x, y, &read_c); | |
43 | for (chan = 0; chan < im->channels; ++chan) { | |
44 | if (read_c.channel[chan] != c->channel[chan]) { | |
45 | match = 0; | |
46 | break; | |
47 | } | |
48 | } | |
49 | if (match) | |
50 | ++count; | |
51 | } | |
52 | } | |
53 | ||
54 | return count; | |
55 | } | |
56 | ||
57 | Imager make_10x10() { | |
58 | i_img *im = i_img_8_new(10, 10, 3); | |
59 | i_color c; | |
60 | c.channel[0] = c.channel[1] = c.channel[2] = 255; | |
61 | i_box_filled(im, 0, 0, im->xsize-1, im->ysize-1, &c); | |
62 | ||
63 | return im; | |
64 | } | |
65 | ||
66 | /* tests that all of the APIs are visible - most of them anyway */ | |
67 | Imager do_lots(Imager src) { | |
68 | i_img *im = i_img_8_new(100, 100, 3); | |
69 | i_img *fill_im = i_img_8_new(5, 5, 3); | |
70 | i_img *testim; | |
3efb0915 | 71 | i_color red, blue, green, black, temp_color; |
92bda632 TC |
72 | i_fcolor redf, bluef; |
73 | i_fill_t *hatch, *fhatch_fill; | |
74 | i_fill_t *im_fill; | |
75 | i_fill_t *solid_fill, *fsolid_fill; | |
76 | i_fill_t *fount_fill; | |
77 | void *block; | |
78 | double matrix[9] = /* 30 degree rotation */ | |
79 | { | |
80 | 0.866025, -0.5, 0, | |
81 | 0.5, 0.866025, 0, | |
82 | 0, 0, 1, | |
83 | }; | |
84 | i_fountain_seg fseg; | |
85 | i_img_tags tags; | |
86 | int entry; | |
87 | double temp_double; | |
88 | ||
89 | red.channel[0] = 255; red.channel[1] = 0; red.channel[2] = 0; | |
90 | red.channel[3] = 255; | |
91 | blue.channel[0] = 0; blue.channel[1] = 0; blue.channel[2] = 255; | |
92 | blue.channel[3] = 255; | |
3efb0915 TC |
93 | green.channel[0] = 0; green.channel[1] = 255; green.channel[2] = 0; |
94 | green.channel[3] = 255; | |
95 | black.channel[0] = black.channel[1] = black.channel[2] = 0; | |
96 | black.channel[3] = 255; | |
92bda632 TC |
97 | hatch = i_new_fill_hatch(&red, &blue, 0, 1, NULL, 0, 0); |
98 | ||
99 | i_box(im, 0, 0, 9, 9, &red); | |
100 | i_box_filled(im, 10, 0, 19, 9, &blue); | |
101 | i_box_cfill(im, 20, 0, 29, 9, hatch); | |
102 | ||
103 | /* make an image fill, and try it */ | |
104 | i_box_cfill(fill_im, 0, 0, 4, 4, hatch); | |
105 | im_fill = i_new_fill_image(fill_im, matrix, 2, 2, 0); | |
106 | ||
107 | i_box_cfill(im, 30, 0, 39, 9, im_fill); | |
108 | ||
109 | /* make a solid fill and try it */ | |
110 | solid_fill = i_new_fill_solid(&red, 0); | |
111 | i_box_cfill(im, 40, 0, 49, 9, solid_fill); | |
112 | ||
113 | /* floating fills */ | |
114 | redf.channel[0] = 1.0; redf.channel[1] = 0; redf.channel[2] = 0; | |
115 | redf.channel[3] = 1.0; | |
116 | bluef.channel[0] = 0; bluef.channel[1] = 0; bluef.channel[2] = 1.0; | |
117 | bluef.channel[3] = 1.0; | |
118 | ||
119 | fsolid_fill = i_new_fill_solidf(&redf, 0); | |
120 | i_box_cfill(im, 50, 0, 59, 9, fsolid_fill); | |
121 | ||
122 | fhatch_fill = i_new_fill_hatchf(&redf, &bluef, 0, 2, NULL, 0, 0); | |
123 | i_box_cfill(im, 60, 0, 69, 9, fhatch_fill); | |
124 | ||
125 | /* fountain fill */ | |
126 | fseg.start = 0; | |
127 | fseg.middle = 0.5; | |
128 | fseg.end = 1.0; | |
129 | fseg.c[0] = redf; | |
130 | fseg.c[1] = bluef; | |
131 | fseg.type = i_fst_linear; | |
132 | fseg.color = i_fc_hue_down; | |
133 | fount_fill = i_new_fill_fount(70, 0, 80, 0, i_ft_linear, i_fr_triangle, 0, i_fts_none, 1, 1, &fseg); | |
134 | ||
135 | i_box_cfill(im, 70, 0, 79, 9, fount_fill); | |
136 | ||
137 | i_line(im, 0, 10, 10, 15, &blue, 1); | |
138 | i_line_aa(im, 0, 19, 10, 15, &red, 1); | |
139 | ||
140 | i_arc(im, 15, 15, 4, 45, 160, &blue); | |
141 | i_arc_aa(im, 25, 15, 4, 75, 280, &red); | |
142 | i_arc_cfill(im, 35, 15, 4, 0, 215, hatch); | |
143 | i_arc_aa_cfill(im, 45, 15, 4, 30, 210, hatch); | |
144 | i_circle_aa(im, 55, 15, 4, &red); | |
145 | ||
146 | i_box(im, 61, 11, 68, 18, &red); | |
147 | i_flood_fill(im, 65, 15, &blue); | |
148 | i_box(im, 71, 11, 78, 18, &red); | |
149 | i_flood_cfill(im, 75, 15, hatch); | |
150 | ||
3efb0915 TC |
151 | i_box_filled(im, 1, 21, 9, 24, &red); |
152 | i_box_filled(im, 1, 25, 9, 29, &blue); | |
153 | i_flood_fill_border(im, 5, 25, &green, &black); | |
154 | ||
155 | i_box_filled(im, 11, 21, 19, 24, &red); | |
156 | i_box_filled(im, 11, 25, 19, 29, &blue); | |
157 | i_flood_cfill_border(im, 15, 25, hatch, &black); | |
158 | ||
92bda632 TC |
159 | i_fill_destroy(fount_fill); |
160 | i_fill_destroy(fhatch_fill); | |
161 | i_fill_destroy(solid_fill); | |
162 | i_fill_destroy(fsolid_fill); | |
163 | i_fill_destroy(hatch); | |
164 | i_fill_destroy(im_fill); | |
165 | i_img_destroy(fill_im); | |
166 | ||
167 | /* make sure we can make each image type */ | |
168 | testim = i_img_16_new(100, 100, 3); | |
169 | i_img_destroy(testim); | |
170 | testim = i_img_double_new(100, 100, 3); | |
171 | i_img_destroy(testim); | |
172 | testim = i_img_pal_new(100, 100, 3, 256); | |
173 | i_img_destroy(testim); | |
174 | testim = i_sametype(im, 50, 50); | |
175 | i_img_destroy(testim); | |
176 | testim = i_sametype_chans(im, 50, 50, 4); | |
177 | i_img_destroy(testim); | |
178 | ||
179 | i_clear_error(); | |
180 | i_push_error(0, "Hello"); | |
181 | i_push_errorf(0, "%s", "World"); | |
182 | ||
183 | /* make sure tags create/destroy work */ | |
184 | i_tags_new(&tags); | |
185 | i_tags_destroy(&tags); | |
186 | ||
187 | block = mymalloc(20); | |
188 | block = myrealloc(block, 50); | |
189 | myfree(block); | |
190 | ||
191 | i_tags_set(&im->tags, "lots_string", "foo", -1); | |
192 | i_tags_setn(&im->tags, "lots_number", 101); | |
193 | ||
194 | if (!i_tags_find(&im->tags, "lots_number", 0, &entry)) { | |
195 | i_push_error(0, "lots_number tag not found"); | |
196 | i_img_destroy(im); | |
197 | return NULL; | |
198 | } | |
199 | i_tags_delete(&im->tags, entry); | |
200 | ||
201 | /* these won't delete anything, but it makes sure the macros and function | |
202 | pointers are correct */ | |
203 | i_tags_delbyname(&im->tags, "unknown"); | |
204 | i_tags_delbycode(&im->tags, 501); | |
205 | i_tags_set_float(&im->tags, "lots_float", 0, 3.14); | |
206 | if (!i_tags_get_float(&im->tags, "lots_float", 0, &temp_double)) { | |
207 | i_push_error(0, "lots_float not found"); | |
208 | i_img_destroy(im); | |
209 | return NULL; | |
210 | } | |
211 | if (fabs(temp_double - 3.14) > 0.001) { | |
212 | i_push_errorf(0, "lots_float incorrect %g", temp_double); | |
213 | i_img_destroy(im); | |
214 | return NULL; | |
215 | } | |
216 | i_tags_set_float2(&im->tags, "lots_float2", 0, 100 * sqrt(2.0), 5); | |
217 | if (!i_tags_get_int(&im->tags, "lots_float2", 0, &entry)) { | |
218 | i_push_error(0, "lots_float2 not found as int"); | |
219 | i_img_destroy(im); | |
220 | return NULL; | |
221 | } | |
222 | if (entry != 141) { | |
223 | i_push_errorf(0, "lots_float2 unexpected value %d", entry); | |
224 | i_img_destroy(im); | |
225 | return NULL; | |
226 | } | |
227 | ||
228 | i_tags_set_color(&im->tags, "lots_color", 0, &red); | |
229 | if (!i_tags_get_color(&im->tags, "lots_color", 0, &temp_color)) { | |
230 | i_push_error(0, "lots_color not found as color"); | |
231 | i_img_destroy(im); | |
232 | return NULL; | |
233 | } | |
234 | ||
235 | return im; | |
236 | } | |
237 | ||
6d5c85a2 TC |
238 | void |
239 | io_fd(int fd) { | |
240 | Imager::IO io = io_new_fd(fd); | |
241 | i_io_write(io, "test", 4); | |
242 | i_io_close(io); | |
243 | io_glue_destroy(io); | |
244 | } | |
245 | ||
246 | int | |
247 | io_bufchain_test() { | |
248 | Imager::IO io = io_new_bufchain(); | |
249 | unsigned char *result; | |
250 | size_t size; | |
251 | if (i_io_write(io, "test2", 5) != 5) { | |
252 | fprintf(stderr, "write failed\n"); | |
253 | return 0; | |
254 | } | |
255 | if (!i_io_flush(io)) { | |
256 | fprintf(stderr, "flush failed\n"); | |
257 | return 0; | |
258 | } | |
259 | if (i_io_close(io) != 0) { | |
260 | fprintf(stderr, "close failed\n"); | |
261 | return 0; | |
262 | } | |
263 | size = io_slurp(io, &result); | |
264 | if (size != 5) { | |
265 | fprintf(stderr, "wrong size\n"); | |
266 | return 0; | |
267 | } | |
268 | if (memcmp(result, "test2", 5)) { | |
269 | fprintf(stderr, "data mismatch\n"); | |
270 | return 0; | |
271 | } | |
272 | if (i_io_seek(io, 0, 0) != 0) { | |
273 | fprintf(stderr, "seek failure\n"); | |
274 | return 0; | |
275 | } | |
276 | myfree(result); | |
277 | io_glue_destroy(io); | |
278 | ||
279 | return 1; | |
280 | } | |
281 | ||
282 | const char * | |
283 | io_buffer_test(SV *in) { | |
284 | STRLEN len; | |
285 | const char *in_str = SvPV(in, len); | |
286 | static char buf[100]; | |
287 | Imager::IO io = io_new_buffer(in_str, len, NULL, NULL); | |
288 | ssize_t read_size; | |
289 | ||
290 | read_size = i_io_read(io, buf, sizeof(buf)-1); | |
291 | io_glue_destroy(io); | |
292 | if (read_size < 0 || read_size >= sizeof(buf)) { | |
293 | return ""; | |
294 | } | |
295 | ||
296 | buf[read_size] = '\0'; | |
297 | ||
298 | return buf; | |
299 | } | |
300 | ||
301 | const char * | |
302 | io_peekn_test(SV *in) { | |
303 | STRLEN len; | |
304 | const char *in_str = SvPV(in, len); | |
305 | static char buf[100]; | |
306 | Imager::IO io = io_new_buffer(in_str, len, NULL, NULL); | |
307 | ssize_t read_size; | |
308 | ||
309 | read_size = i_io_peekn(io, buf, sizeof(buf)-1); | |
310 | io_glue_destroy(io); | |
311 | if (read_size < 0 || read_size >= sizeof(buf)) { | |
312 | return ""; | |
313 | } | |
314 | ||
315 | buf[read_size] = '\0'; | |
316 | ||
317 | return buf; | |
318 | } | |
319 | ||
320 | const char * | |
321 | io_gets_test(SV *in) { | |
322 | STRLEN len; | |
323 | const char *in_str = SvPV(in, len); | |
324 | static char buf[100]; | |
325 | Imager::IO io = io_new_buffer(in_str, len, NULL, NULL); | |
326 | ssize_t read_size; | |
327 | ||
328 | read_size = i_io_gets(io, buf, sizeof(buf), 's'); | |
329 | io_glue_destroy(io); | |
330 | if (read_size < 0 || read_size >= sizeof(buf)) { | |
331 | return ""; | |
332 | } | |
333 | ||
334 | return buf; | |
335 | } | |
336 | ||
337 | int | |
338 | io_getc_test(SV *in) { | |
339 | STRLEN len; | |
340 | const char *in_str = SvPV(in, len); | |
341 | static char buf[100]; | |
342 | Imager::IO io = io_new_buffer(in_str, len, NULL, NULL); | |
343 | int result; | |
344 | ||
345 | result = i_io_getc(io); | |
346 | io_glue_destroy(io); | |
347 | ||
348 | return result; | |
349 | } | |
350 | ||
351 | int | |
352 | io_peekc_test(SV *in) { | |
353 | STRLEN len; | |
354 | const char *in_str = SvPV(in, len); | |
355 | static char buf[100]; | |
356 | Imager::IO io = io_new_buffer(in_str, len, NULL, NULL); | |
357 | int result; | |
358 | ||
359 | i_io_set_buffered(io, 0); | |
360 | ||
361 | result = i_io_peekc(io); | |
362 | io_glue_destroy(io); | |
363 | ||
364 | return result; | |
365 | } | |
366 | ||
d8d215e3 TC |
367 | |
368 | ||
369 | int | |
370 | test_render_color(Imager work_8) { | |
371 | i_render *r8; | |
372 | i_color c; | |
373 | unsigned char render_coverage[3]; | |
374 | ||
375 | render_coverage[0] = 0; | |
376 | render_coverage[1] = 128; | |
377 | render_coverage[2] = 255; | |
378 | ||
379 | r8 = i_render_new(work_8, 10); | |
380 | c.channel[0] = 128; | |
381 | c.channel[1] = 255; | |
382 | c.channel[2] = 0; | |
383 | c.channel[3] = 255; | |
384 | i_render_color(r8, 0, 0, sizeof(render_coverage), render_coverage, &c); | |
385 | ||
386 | c.channel[3] = 128; | |
387 | i_render_color(r8, 0, 1, sizeof(render_coverage), render_coverage, &c); | |
388 | ||
389 | c.channel[3] = 0; | |
390 | i_render_color(r8, 0, 2, sizeof(render_coverage), render_coverage, &c); | |
391 | ||
392 | i_render_delete(r8); | |
393 | ||
394 | return 1; | |
395 | } | |
396 | ||
23c6bf56 TC |
397 | int |
398 | raw_psamp(Imager im, int chan_count) { | |
399 | static i_sample_t samps[] = { 0, 127, 255 }; | |
400 | ||
401 | i_clear_error(); | |
402 | return i_psamp(im, 0, 1, 0, samps, NULL, chan_count); | |
403 | } | |
404 | ||
405 | int | |
406 | raw_psampf(Imager im, int chan_count) { | |
407 | static i_fsample_t samps[] = { 0, 0.5, 1.0 }; | |
408 | ||
409 | i_clear_error(); | |
410 | return i_psampf(im, 0, 1, 0, samps, NULL, chan_count); | |
411 | } | |
412 | ||
92bda632 TC |
413 | EOS |
414 | ||
415 | my $im = Imager->new(xsize=>50, ysize=>50); | |
416 | is(pixel_count($im), 2500, "pixel_count"); | |
417 | ||
418 | my $black = Imager::Color->new(0,0,0); | |
419 | is(count_color($im, $black), 2500, "count_color black on black image"); | |
420 | ||
421 | my $im2 = make_10x10(); | |
422 | my $white = Imager::Color->new(255, 255, 255); | |
423 | is(count_color($im2, $white), 100, "check new image white count"); | |
424 | ok($im2->box(filled=>1, xmin=>1, ymin=>1, xmax => 8, ymax=>8, color=>$black), | |
425 | "try new image"); | |
426 | is(count_color($im2, $black), 64, "check modified black count"); | |
427 | is(count_color($im2, $white), 36, "check modified white count"); | |
428 | ||
429 | my $im3 = do_lots($im2); | |
430 | ok($im3, "do_lots()") | |
431 | or print "# ", Imager->_error_as_msg, "\n"; | |
432 | ok($im3->write(file=>'testout/t82lots.ppm'), "write t82lots.ppm"); | |
b340c629 TC |
433 | |
434 | { # RT #24992 | |
435 | # the T_IMAGER_FULL_IMAGE typemap entry was returning a blessed | |
436 | # hash with an extra ref, causing memory leaks | |
437 | ||
438 | my $im = make_10x10(); | |
439 | my $im2 = Imager->new(xsize => 10, ysize => 10); | |
3d3fc93b | 440 | require B; |
b340c629 TC |
441 | my $imb = B::svref_2object($im); |
442 | my $im2b = B::svref_2object($im2); | |
443 | is ($imb->REFCNT, $im2b->REFCNT, | |
444 | "check refcnt of imager object hash between normal and typemap generated"); | |
445 | } | |
6d5c85a2 TC |
446 | |
447 | SKIP: | |
448 | { | |
449 | use IO::File; | |
450 | my $fd_filename = "testout/t82fd.txt"; | |
451 | { | |
452 | my $fh = IO::File->new($fd_filename, "w") | |
453 | or skip("Can't create file: $!", 1); | |
454 | io_fd(fileno($fh)); | |
455 | $fh->close; | |
456 | } | |
457 | { | |
458 | my $fh = IO::File->new($fd_filename, "r") | |
459 | or skip("Can't open file: $!", 1); | |
460 | my $data = <$fh>; | |
461 | is($data, "test", "make sure data written to fd"); | |
462 | } | |
463 | unlink $fd_filename; | |
464 | } | |
465 | ||
466 | ok(io_bufchain_test(), "check bufchain functions"); | |
467 | ||
468 | is(io_buffer_test("test3"), "test3", "check io_new_buffer() and i_io_read"); | |
469 | ||
470 | is(io_peekn_test("test5"), "test5", "check i_io_peekn"); | |
471 | ||
472 | is(io_gets_test("test"), "tes", "check i_io_gets()"); | |
473 | ||
474 | is(io_getc_test("ABC"), ord "A", "check i_io_getc(_imp)?"); | |
475 | ||
476 | is(io_getc_test("XYZ"), ord "X", "check i_io_peekc(_imp)?"); | |
d8d215e3 TC |
477 | |
478 | for my $bits (8, 16) { | |
479 | print "# bits: $bits\n"; | |
480 | ||
481 | # the floating point processing is a little more accurate | |
482 | my $bump = $bits == 16 ? 1 : 0; | |
483 | { | |
484 | my $im = Imager->new(xsize => 10, ysize => 10, channels => 3, bits => $bits); | |
485 | ok($im->box(filled => 1, color => '#808080'), "fill work image with gray"); | |
486 | ok(test_render_color($im), | |
487 | "call render_color on 3 channel image"); | |
488 | is_color3($im->getpixel(x => 0, y => 0), 128, 128, 128, | |
489 | "check zero coverage, alpha 255 color, bits $bits"); | |
490 | is_color3($im->getpixel(x => 1, y => 0), 128, 191+$bump, 63+$bump, | |
491 | "check 128 coverage, alpha 255 color, bits $bits"); | |
492 | is_color3($im->getpixel(x => 2, y => 0), 128, 255, 0, | |
493 | "check 255 coverage, alpha 255 color, bits $bits"); | |
494 | ||
495 | is_color3($im->getpixel(x => 0, y => 1), 128, 128, 128, | |
496 | "check zero coverage, alpha 128 color, bits $bits"); | |
497 | is_color3($im->getpixel(x => 1, y => 1), 128, 159+$bump, 95+$bump, | |
498 | "check 128 coverage, alpha 128 color, bits $bits"); | |
499 | is_color3($im->getpixel(x => 2, y => 1), 128, 191+$bump, 63+$bump, | |
500 | "check 255 coverage, alpha 128 color, bits $bits"); | |
501 | ||
502 | is_color3($im->getpixel(x => 0, y => 2), 128, 128, 128, | |
503 | "check zero coverage, alpha 0 color, bits $bits"); | |
504 | is_color3($im->getpixel(x => 1, y => 2), 128, 128, 128, | |
505 | "check 128 coverage, alpha 0 color, bits $bits"); | |
506 | is_color3($im->getpixel(x => 2, y => 2), 128, 128, 128, | |
507 | "check 255 coverage, alpha 0 color, bits $bits"); | |
508 | } | |
509 | { | |
510 | my $im = Imager->new(xsize => 10, ysize => 10, channels => 4, bits => $bits); | |
511 | ok($im->box(filled => 1, color => '#808080'), "fill work image with opaque gray"); | |
512 | ok(test_render_color($im), | |
513 | "call render_color on 4 channel image"); | |
514 | is_color4($im->getpixel(x => 0, y => 0), 128, 128, 128, 255, | |
515 | "check zero coverage, alpha 255 color, bits $bits"); | |
516 | is_color4($im->getpixel(x => 1, y => 0), 128, 191+$bump, 63+$bump, 255, | |
517 | "check 128 coverage, alpha 255 color, bits $bits"); | |
518 | is_color4($im->getpixel(x => 2, y => 0), 128, 255, 0, 255, | |
519 | "check 255 coverage, alpha 255 color, bits $bits"); | |
520 | ||
521 | is_color4($im->getpixel(x => 0, y => 1), 128, 128, 128, 255, | |
522 | "check zero coverage, alpha 128 color, bits $bits"); | |
523 | is_color4($im->getpixel(x => 1, y => 1), 128, 159+$bump, 95+$bump, 255, | |
524 | "check 128 coverage, alpha 128 color, bits $bits"); | |
525 | is_color4($im->getpixel(x => 2, y => 1), 128, 191+$bump, 63+$bump, 255, | |
526 | "check 255 coverage, alpha 128 color, bits $bits"); | |
527 | ||
528 | is_color4($im->getpixel(x => 0, y => 2), 128, 128, 128, 255, | |
529 | "check zero coverage, alpha 0 color, bits $bits"); | |
530 | is_color4($im->getpixel(x => 1, y => 2), 128, 128, 128, 255, | |
531 | "check 128 coverage, alpha 0 color, bits $bits"); | |
532 | is_color4($im->getpixel(x => 2, y => 2), 128, 128, 128, 255, | |
533 | "check 255 coverage, alpha 0 color, bits $bits"); | |
534 | } | |
535 | ||
536 | { | |
537 | my $im = Imager->new(xsize => 10, ysize => 10, channels => 4, bits => $bits); | |
538 | ok($im->box(filled => 1, color => Imager::Color->new(128, 128, 128, 64)), "fill work image with translucent gray"); | |
539 | ok(test_render_color($im), | |
540 | "call render_color on 4 channel image"); | |
541 | is_color4($im->getpixel(x => 0, y => 0), 128, 128, 128, 64, | |
542 | "check zero coverage, alpha 255 color, bits $bits"); | |
543 | is_color4($im->getpixel(x => 1, y => 0), 128, 230, 25+$bump, 159+$bump, | |
544 | "check 128 coverage, alpha 255 color, bits $bits"); | |
545 | is_color4($im->getpixel(x => 2, y => 0), 128, 255, 0, 255, | |
546 | "check 255 coverage, alpha 255 color, bits $bits"); | |
547 | ||
548 | is_color4($im->getpixel(x => 0, y => 1), 128, 128, 128, 64, | |
549 | "check zero coverage, alpha 128 color, bits $bits"); | |
550 | is_color4($im->getpixel(x => 1, y => 1), 129-$bump, 202-$bump, 55, 111+$bump, | |
551 | "check 128 coverage, alpha 128 color, bits $bits"); | |
552 | is_color4($im->getpixel(x => 2, y => 1), 128, 230, 25+$bump, 159+$bump, | |
553 | "check 255 coverage, alpha 128 color, bits $bits"); | |
554 | ||
555 | is_color4($im->getpixel(x => 0, y => 2), 128, 128, 128, 64, | |
556 | "check zero coverage, alpha 0 color, bits $bits"); | |
557 | is_color4($im->getpixel(x => 1, y => 2), 128, 128, 128, 64, | |
558 | "check 128 coverage, alpha 0 color, bits $bits"); | |
559 | is_color4($im->getpixel(x => 2, y => 2), 128, 128, 128, 64, | |
560 | "check 255 coverage, alpha 0 color, bits $bits"); | |
561 | } | |
562 | } | |
23c6bf56 TC |
563 | |
564 | { | |
565 | my $im = Imager->new(xsize => 10, ysize => 10); | |
566 | is(raw_psamp($im, 4), -1, "bad channel list (4) for psamp should fail"); | |
567 | is(_get_error(), "chan_count 4 out of range, must be >0, <= channels", | |
568 | "check message"); | |
569 | is(raw_psamp($im, 0), -1, "bad channel list (0) for psamp should fail"); | |
570 | is(_get_error(), "chan_count 0 out of range, must be >0, <= channels", | |
571 | "check message"); | |
572 | is(raw_psampf($im, 4), -1, "bad channel list (4) for psampf should fail"); | |
573 | is(_get_error(), "chan_count 4 out of range, must be >0, <= channels", | |
574 | "check message"); | |
575 | is(raw_psampf($im, 0), -1, "bad channel list (0) for psampf should fail"); | |
576 | is(_get_error(), "chan_count 0 out of range, must be >0, <= channels", | |
577 | "check message"); | |
578 | } | |
579 | ||
580 | { | |
581 | my $im = Imager->new(xsize => 10, ysize => 10, bits => 16); | |
582 | is(raw_psamp($im, 4), -1, "bad channel list (4) for psamp should fail (16-bit)"); | |
583 | is(_get_error(), "chan_count 4 out of range, must be >0, <= channels", | |
584 | "check message"); | |
585 | is(raw_psamp($im, 0), -1, "bad channel list (0) for psamp should fail (16-bit)"); | |
586 | is(_get_error(), "chan_count 0 out of range, must be >0, <= channels", | |
587 | "check message"); | |
588 | is(raw_psampf($im, 4), -1, "bad channel list (4) for psampf should fail (16-bit)"); | |
589 | is(_get_error(), "chan_count 4 out of range, must be >0, <= channels", | |
590 | "check message"); | |
591 | is(raw_psampf($im, 0), -1, "bad channel list (0) for psampf should fail (16-bit)"); | |
592 | is(_get_error(), "chan_count 0 out of range, must be >0, <= channels", | |
593 | "check message"); | |
594 | } | |
595 | ||
596 | { | |
597 | my $im = Imager->new(xsize => 10, ysize => 10, bits => 'double'); | |
598 | is(raw_psamp($im, 4), -1, "bad channel list (4) for psamp should fail (double)"); | |
599 | is(_get_error(), "chan_count 4 out of range, must be >0, <= channels", | |
600 | "check message"); | |
601 | is(raw_psamp($im, 0), -1,, "bad channel list (0) for psamp should fail (double)"); | |
602 | is(_get_error(), "chan_count 0 out of range, must be >0, <= channels", | |
603 | "check message"); | |
604 | is(raw_psampf($im, 4), -1, "bad channel list (4) for psampf should fail (double)"); | |
605 | is(_get_error(), "chan_count 4 out of range, must be >0, <= channels", | |
606 | "check message"); | |
607 | is(raw_psampf($im, 0), -1, "bad channel list (0) for psampf should fail (double)"); | |
608 | is(_get_error(), "chan_count 0 out of range, must be >0, <= channels", | |
609 | "check message"); | |
610 | } | |
611 | ||
612 | { | |
613 | my $im = Imager->new(xsize => 10, ysize => 10, type => "paletted"); | |
614 | is(raw_psamp($im, 4), -1, "bad channel list (4) for psamp should fail (paletted)"); | |
615 | is(_get_error(), "chan_count 4 out of range, must be >0, <= channels", | |
616 | "check message"); | |
617 | is(raw_psamp($im, 0), -1, "bad channel list (0) for psamp should fail (paletted)"); | |
618 | is(_get_error(), "chan_count 0 out of range, must be >0, <= channels", | |
619 | "check message"); | |
620 | is(raw_psampf($im, 4), -1, "bad channel list (4) for psampf should fail (paletted)"); | |
621 | is(_get_error(), "chan_count 4 out of range, must be >0, <= channels", | |
622 | "check message"); | |
623 | is(raw_psampf($im, 0), -1, "bad channel list (0) for psampf should fail (paletted)"); | |
624 | is(_get_error(), "chan_count 0 out of range, must be >0, <= channels", | |
625 | "check message"); | |
626 | is($im->type, "paletted", "make sure we kept the image type"); | |
627 | } | |
628 | ||
629 | sub _get_error { | |
630 | my @errors = Imager::i_errors(); | |
631 | return join(": ", map $_->[0], @errors); | |
632 | } |