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