]> git.imager.perl.org - imager.git/blob - lib/Imager/APIRef.pod
89554be1af696139227d7445cba1815ed46a8894
[imager.git] / lib / Imager / APIRef.pod
1 Do not edit this file, it is generated automatically by apidocs.perl
2 from Imager's source files.
3
4 Each function description has a comment listing the source file where
5 you can find the documentation.
6
7 =head1 NAME
8
9 Imager::APIRef - Imager's C API - reference.
10
11 =head1 SYNOPSIS
12
13   i_color color;
14   color.rgba.r = 255; color.rgba.g = 0; color.rgba.b = 255;
15   double x[] = { ... };
16   double y[] = { ... };
17   i_polygon_t poly;
18   poly.count = sizeof(x) / sizeof(*x);
19   poly.x = x;
20   poly.y = y;
21
22
23   # Blit tools
24
25   # Data Types
26   i_img *img;
27   i_color black;
28   black.rgba.r = black.rgba.g = black.rgba.b = black.rgba.a = 0;
29   i_fill_t *fill;
30   i_img_dim x, y;
31   printf("left %" i_DF "\n", i_DFc(x));
32   printf("point (" i_DFp ")\n", i_DFcp(x, y));
33
34   # Drawing
35   i_arc(im, 50, 50, 20, 45, 135, &color);
36   i_arc_cfill(im, 50, 50, 35, 90, 135, fill);
37   i_arc_aa(im, 50, 50, 35, 90, 135, &color);
38   i_arc_aa_cfill(im, 50, 50, 35, 90, 135, fill);
39   i_circle_aa(im, 50, 50, 45, &color);
40   i_box(im, 0, 0, im->xsize-1, im->ysize-1, &color).
41   i_box_filled(im, 0, 0, im->xsize-1, im->ysize-1, &color);
42   i_box_cfill(im, 0, 0, im->xsize-1, im->ysize-1, fill);
43   i_flood_fill(im, 50, 50, &color);
44   i_flood_cfill(im, 50, 50, fill);
45   i_flood_fill_border(im, 50, 50, &color, &border);
46   i_flood_cfill_border(im, 50, 50, fill, border);
47   i_poly_poly_aa(im, 1, &poly, mode, color);
48   i_poly_aa_m(im, count, x, y, mode, color);
49   i_poly_poly_aa_cfill(im, 1, &poly, mode, fill);
50   i_poly_aa_cfill(im, count, x, y, mode, fill);
51
52   # Error handling
53   im_clear_error(aIMCTX);
54   i_clear_error();
55   i_push_error(0, "Yep, it's broken");
56   i_push_error(errno, "Error writing");
57   im_push_error(aIMCTX, 0, "Something is wrong");
58   va_args args;
59   va_start(args, lastarg);
60   im_push_errorvf(ctx, code, format, args);
61   i_push_errorf(errno, "Cannot open file %s: %d", filename, errno);
62   im_push_errorf(aIMCTX, errno, "Cannot open file %s: %d", filename, errno);
63
64   # Files
65   im_set_image_file_limits(aIMCTX, 500, 500, 1000000);
66   i_set_image_file_limits(500, 500, 1000000);
67   im_get_image_file_limits(aIMCTX, &width, &height, &bytes)
68   i_get_image_file_limits(&width, &height, &bytes)
69   im_int_check_image_file_limits(aIMCTX, width, height, channels, sizeof(i_sample_t))
70   i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t))
71
72   # Fills
73   i_fill_t *fill = i_new_fill_solidf(&fcolor, combine);
74   i_fill_t *fill = i_new_fill_solid(&color, combine);
75   i_fill_t *fill = i_new_fill_hatch(&fg_color, &bg_color, combine, hatch, custom_hatch, dx, dy);
76   i_fill_t *fill = i_new_fill_hatchf(&fg_fcolor, &bg_fcolor, combine, hatch, custom_hatch, dx, dy);
77   i_fill_t *fill = i_new_fill_image(src_img, matrix, x_offset, y_offset, combine);
78   fill = i_new_fill_fount(0, 0, 100, 100, i_ft_linear, i_ft_linear, 
79                           i_fr_triangle, 0, i_fts_grid, 9, 1, segs);
80   i_fill_destroy(fill);
81
82   # I/O Layers
83   ssize_t count = i_io_peekn(ig, buffer, sizeof(buffer));
84   ssize_t result = i_io_write(io, buffer, size)
85   char buffer[BUFSIZ]
86   ssize_t len = i_io_gets(buffer, sizeof(buffer), '\n');
87   io_glue_destroy(ig);
88
89   # Image
90
91   # Image creation/destruction
92   i_img *img = i_sametype(src, width, height);
93   i_img *img = i_sametype_chans(src, width, height, channels);
94   i_img *img = im_img_16_new(aIMCTX, width, height, channels);
95   i_img *img = i_img_16_new(width, height, channels);
96   i_img *img = im_img_8_new(aIMCTX, width, height, channels);
97   i_img *img = i_img_8_new(width, height, channels);
98   i_img *img = im_img_double_new(aIMCTX, width, height, channels);
99   i_img *img = i_img_double_new(width, height, channels);
100   i_img *img = im_img_pal_new(aIMCTX, width, height, channels, max_palette_size)
101   i_img *img = i_img_pal_new(width, height, channels, max_palette_size)
102   i_img_destroy(img)
103
104   # Image Implementation
105   i_img *im = im_img_alloc(aIMCTX);
106   i_img *im = i_img_alloc();
107   im_img_init(aIMCTX, im);
108   i_img_init(im);
109
110   # Image Information
111   // only channel 0 writable 
112   i_img_setmask(img, 0x01);
113   int mask = i_img_getmask(img);
114   int channels = i_img_getchannels(img);
115   i_img_dim width = i_img_get_width(im);
116   i_img_dim height = i_img_get_height(im);
117
118   # Image quantization
119
120   # Logging
121
122   # Mutex functions
123   i_mutex_t m = i_mutex_new();
124   i_mutex_destroy(m);
125   i_mutex_lock(m);
126   i_mutex_unlock(m);
127
128   # Paletted images
129
130   # Tags
131   i_tags_set(&img->tags, "i_comment", -1);
132   i_tags_setn(&img->tags, "i_xres", 204);
133   i_tags_setn(&img->tags, "i_yres", 196);
134
135 =head1 DESCRIPTION
136
137 =head2 Blit tools
138
139 =over
140
141 =item i_render_color(r, x, y, width, source, color)
142
143 Render the given color with the coverage specified by C<source[0]> to
144 C<source[width-1]>.
145
146 Renders in normal combine mode.
147
148
149 =for comment
150 From: File render.im
151
152 =item i_render_delete(r)
153
154 Release an C<i_render> object.
155
156
157 =for comment
158 From: File render.im
159
160 =item i_render_fill(r, x, y, width, source, fill)
161
162 Render the given fill with the coverage in C<source[0]> through
163 C<source[width-1]>.
164
165
166 =for comment
167 From: File render.im
168
169 =item i_render_line(r, x, y, width, source, fill)
170
171 Render the given fill with the coverage in C<source[0]> through
172 C<source[width-1]>.
173
174
175 =for comment
176 From: File render.im
177
178 =item i_render_linef(r, x, y, width, source, fill)
179
180 Render the given fill with the coverage in C<source[0]> through
181 C<source[width-1]>.
182
183
184 =for comment
185 From: File render.im
186
187 =item i_render_new(im, width)
188
189 Allocate a new C<i_render> object and initialize it.
190
191
192 =for comment
193 From: File render.im
194
195
196 =back
197
198 =head2 Data Types
199
200 =over
201
202 =item i_img
203
204   i_img *img;
205
206 This is Imager's image type.
207
208 It contains the following members:
209
210 =over
211
212 =item *
213
214 C<channels> - the number of channels in the image
215
216 =item *
217
218 C<xsize>, C<ysize> - the width and height of the image in pixels
219
220 =item *
221
222 C<bytes> - the number of bytes used to store the image data.  Undefined
223 where virtual is non-zero.
224
225 =item *
226
227 C<ch_mask> - a mask of writable channels.  eg. if this is 6 then only
228 channels 1 and 2 are writable.  There may be bits set for which there
229 are no channels in the image.
230
231 =item *
232
233 C<bits> - the number of bits stored per sample.  Should be one of
234 i_8_bits, i_16_bits, i_double_bits.
235
236 =item *
237
238 C<type> - either i_direct_type for direct color images, or i_palette_type
239 for paletted images.
240
241 =item *
242
243 C<virtual> - if zero then this image is-self contained.  If non-zero
244 then this image could be an interface to some other implementation.
245
246 =item *
247
248 C<idata> - the image data.  This should not be directly accessed.  A new
249 image implementation can use this to store its image data.
250 i_img_destroy() will myfree() this pointer if it's non-null.
251
252 =item *
253
254 C<tags> - a structure storing the image's tags.  This should only be
255 accessed via the i_tags_*() functions.
256
257 =item *
258
259 C<ext_data> - a pointer for use internal to an image implementation.
260 This should be freed by the image's destroy handler.
261
262 =item *
263
264 C<im_data> - data internal to Imager.  This is initialized by
265 i_img_init().
266
267 =item *
268
269 i_f_ppix, i_f_ppixf, i_f_plin, i_f_plinf, i_f_gpix, i_f_gpixf,
270 i_f_glin, i_f_glinf, i_f_gsamp, i_f_gampf - implementations for each
271 of the required image functions.  An image implementation should
272 initialize these between calling i_img_alloc() and i_img_init().
273
274 =item *
275
276 i_f_gpal, i_f_ppal, i_f_addcolors, i_f_getcolors, i_f_colorcount,
277 i_f_maxcolors, i_f_findcolor, i_f_setcolors - implementations for each
278 paletted image function.
279
280 =item *
281
282 i_f_destroy - custom image destruction function.  This should be used
283 to release memory if necessary.
284
285 =item *
286
287 i_f_gsamp_bits - implements i_gsamp_bits() for this image.
288
289 =item *
290
291 i_f_psamp_bits - implements i_psamp_bits() for this image.
292
293 =item *
294
295 i_f_psamp - implements psamp() for this image.
296
297 =item *
298
299 i_f_psampf - implements psamp() for this image.
300
301 =item *
302
303 C<im_data> - image specific data internal to Imager.
304
305 =item *
306
307 C<context> - the Imager API context this image belongs to.
308
309 =back
310
311
312 =for comment
313 From: File imdatatypes.h
314
315 =item i_color
316
317   i_color black;
318   black.rgba.r = black.rgba.g = black.rgba.b = black.rgba.a = 0;
319
320 Type for 8-bit/sample color.
321
322 Samples as per;
323
324   i_color c;
325
326 i_color is a union of:
327
328 =over
329
330 =item *
331
332 gray - contains a single element gray_color, eg. C<c.gray.gray_color>
333
334 =item *
335
336 C<rgb> - contains three elements C<r>, C<g>, C<b>, eg. C<c.rgb.r>
337
338 =item *
339
340 C<rgba> - contains four elements C<r>, C<g>, C<b>, C<a>, eg. C<c.rgba.a>
341
342 =item *
343
344 C<cmyk> - contains four elements C<c>, C<m>, C<y>, C<k>,
345 eg. C<c.cmyk.y>.  Note that Imager never uses CMYK colors except when
346 reading/writing files.
347
348 =item *
349
350 channels - an array of four channels, eg C<c.channels[2]>.
351
352 =back
353
354
355 =for comment
356 From: File imdatatypes.h
357
358 =item i_fcolor
359
360 This is the double/sample color type.
361
362 Its layout exactly corresponds to i_color.
363
364
365 =for comment
366 From: File imdatatypes.h
367
368 =item i_fill_t
369
370   i_fill_t *fill;
371
372 This is the "abstract" base type for Imager's fill types.
373
374 Unless you're implementing a new fill type you'll typically treat this
375 as an opaque type.
376
377
378 =for comment
379 From: File imdatatypes.h
380
381 =item i_img_dim
382
383   i_img_dim x, y;
384
385 A signed integer type that represents an image dimension or ordinate.
386
387 May be larger than int on some platforms.
388
389
390 =for comment
391 From: File imdatatypes.h
392
393 =item i_DF
394
395   printf("left %" i_DF "\n", i_DFc(x));
396
397 This is a constant string that can be used with functions like
398 printf() to format i_img_dim values after they're been cast with i_DFc().
399
400 Does not include the leading C<%>.
401
402
403 =for comment
404 From: File imdatatypes.h
405
406 =item i_DFc
407
408 Cast an C<i_img_dim> value to a type for use with the i_DF format
409 string.
410
411
412 =for comment
413 From: File imdatatypes.h
414
415 =item i_DFcp
416
417 Casts two C<i_img_dim> values for use with the i_DF (or i_DFp) format.
418
419
420 =for comment
421 From: File imdatatypes.h
422
423 =item i_DFp
424
425   printf("point (" i_DFp ")\n", i_DFcp(x, y));
426
427 Format a pair of C<i_img_dim> values.  This format string I<does>
428 include the leading C<%>.
429
430
431 =for comment
432 From: File imdatatypes.h
433
434
435 =back
436
437 =head2 Drawing
438
439 =over
440
441 =item i_arc(im, x, y, rad, d1, d2, color)
442
443
444   i_arc(im, 50, 50, 20, 45, 135, &color);
445
446 Fills an arc centered at (x,y) with radius I<rad> covering the range
447 of angles in degrees from d1 to d2, with the color.
448
449
450 =for comment
451 From: File draw.c
452
453 =item i_arc_aa(im, x, y, rad, d1, d2, color)
454
455
456   i_arc_aa(im, 50, 50, 35, 90, 135, &color);
457
458 Anti-alias fills an arc centered at (x,y) with radius I<rad> covering
459 the range of angles in degrees from d1 to d2, with the color.
460
461
462 =for comment
463 From: File draw.c
464
465 =item i_arc_aa_cfill(im, x, y, rad, d1, d2, fill)
466
467
468   i_arc_aa_cfill(im, 50, 50, 35, 90, 135, fill);
469
470 Anti-alias fills an arc centered at (x,y) with radius I<rad> covering
471 the range of angles in degrees from d1 to d2, with the fill object.
472
473
474 =for comment
475 From: File draw.c
476
477 =item i_arc_cfill(im, x, y, rad, d1, d2, fill)
478
479
480   i_arc_cfill(im, 50, 50, 35, 90, 135, fill);
481
482 Fills an arc centered at (x,y) with radius I<rad> covering the range
483 of angles in degrees from d1 to d2, with the fill object.
484
485
486 =for comment
487 From: File draw.c
488
489 =item i_box(im, x1, y1, x2, y2, color)
490
491
492   i_box(im, 0, 0, im->xsize-1, im->ysize-1, &color).
493
494 Outlines the box from (x1,y1) to (x2,y2) inclusive with I<color>.
495
496
497 =for comment
498 From: File draw.c
499
500 =item i_box_cfill(im, x1, y1, x2, y2, fill)
501
502
503   i_box_cfill(im, 0, 0, im->xsize-1, im->ysize-1, fill);
504
505 Fills the box from (x1,y1) to (x2,y2) inclusive with fill.
506
507
508 =for comment
509 From: File draw.c
510
511 =item i_box_filled(im, x1, y1, x2, y2, color)
512
513
514   i_box_filled(im, 0, 0, im->xsize-1, im->ysize-1, &color);
515
516 Fills the box from (x1,y1) to (x2,y2) inclusive with color.
517
518
519 =for comment
520 From: File draw.c
521
522 =item i_circle_aa(im, x, y, rad, color)
523
524
525   i_circle_aa(im, 50, 50, 45, &color);
526
527 Anti-alias fills a circle centered at (x,y) for radius I<rad> with
528 color.
529
530
531 =for comment
532 From: File draw.c
533
534 =item i_flood_cfill(C<im>, C<seedx>, C<seedy>, C<fill>)
535
536
537   i_flood_cfill(im, 50, 50, fill);
538
539 Flood fills the 4-connected region starting from the point (C<seedx>,
540 C<seedy>) with C<fill>.
541
542 Returns false if (C<seedx>, C<seedy>) are outside the image.
543
544
545 =for comment
546 From: File draw.c
547
548 =item i_flood_cfill_border(C<im>, C<seedx>, C<seedy>, C<fill>, C<border>)
549
550
551   i_flood_cfill_border(im, 50, 50, fill, border);
552
553 Flood fills the 4-connected region starting from the point (C<seedx>,
554 C<seedy>) with C<fill>, the fill stops when it reaches pixels of color
555 C<border>.
556
557 Returns false if (C<seedx>, C<seedy>) are outside the image.
558
559
560 =for comment
561 From: File draw.c
562
563 =item i_flood_fill(C<im>, C<seedx>, C<seedy>, C<color>)
564
565
566   i_flood_fill(im, 50, 50, &color);
567
568 Flood fills the 4-connected region starting from the point (C<seedx>,
569 C<seedy>) with I<color>.
570
571 Returns false if (C<seedx>, C<seedy>) are outside the image.
572
573
574 =for comment
575 From: File draw.c
576
577 =item i_flood_fill_border(C<im>, C<seedx>, C<seedy>, C<color>, C<border>)
578
579
580   i_flood_fill_border(im, 50, 50, &color, &border);
581
582 Flood fills the 4-connected region starting from the point (C<seedx>,
583 C<seedy>) with C<color>, fill stops when the fill reaches a pixels
584 with color C<border>.
585
586 Returns false if (C<seedx>, C<seedy>) are outside the image.
587
588
589 =for comment
590 From: File draw.c
591
592 =item i_glin(im, l, r, y, colors)
593
594
595 Retrieves (r-l) pixels starting from (l,y) into I<colors>.
596
597 Returns the number of pixels retrieved.
598
599
600 =for comment
601 From: File imext.c
602
603 =item i_glinf(im, l, r, y, colors)
604
605
606 Retrieves (r-l) pixels starting from (l,y) into I<colors> as floating
607 point colors.
608
609 Returns the number of pixels retrieved.
610
611
612 =for comment
613 From: File imext.c
614
615 =item i_gpal(im, left, right, y, indexes)
616
617
618 Reads palette indexes for the horizontal line (left, y) to (right-1,
619 y) into C<indexes>.
620
621 Returns the number of indexes read.
622
623 Always returns 0 for direct color images.
624
625
626 =for comment
627 From: File imext.c
628
629 =item i_gpix(im, C<x>, C<y>, C<color>)
630
631
632 Retrieves the C<color> of the pixel (x,y).
633
634 Returns 0 if the pixel was retrieved, or -1 if not.
635
636
637 =for comment
638 From: File imext.c
639
640 =item i_gpixf(im, C<x>, C<y>, C<fcolor>)
641
642
643 Retrieves the color of the pixel (x,y) as a floating point color into
644 C<fcolor>.
645
646 Returns 0 if the pixel was retrieved, or -1 if not.
647
648
649 =for comment
650 From: File imext.c
651
652 =item i_gsamp(im, left, right, y, samples, channels, channel_count)
653
654
655 Reads sample values from C<im> for the horizontal line (left, y) to
656 (right-1,y) for the channels specified by C<channels>, an array of int
657 with C<channel_count> elements.
658
659 If channels is NULL then the first channels_count channels are retrieved for
660 each pixel.
661
662 Returns the number of samples read (which should be (right-left) *
663 channel_count)
664
665
666 =for comment
667 From: File imext.c
668
669 =item i_gsamp_bg(im, l, r, y, samples, out_channels, background)
670
671
672 Like C<i_gsampf()> but applies the source image color over a supplied
673 background color.
674
675 This is intended for output to image formats that don't support alpha
676 channels.
677
678
679 =for comment
680 From: File paste.im
681
682 =item i_gsamp_bits(im, left, right, y, samples, channels, channel_count, bits)
683
684 Reads integer samples scaled to C<bits> bits of precision into the
685 C<unsigned int> array C<samples>.
686
687 Expect this to be slow unless C<< bits == im->bits >>.
688
689 Returns the number of samples copied, or -1 on error.
690
691 Not all image types implement this method.
692
693 Pushes errors, but does not call C<i_clear_error()>.
694
695
696 =for comment
697 From: File imext.c
698
699 =item i_gsampf(im, left, right, y, samples, channels, channel_count)
700
701
702 Reads floating point sample values from C<im> for the horizontal line
703 (left, y) to (right-1,y) for the channels specified by C<channels>, an
704 array of int with channel_count elements.
705
706 If C<channels> is NULL then the first C<channel_count> channels are
707 retrieved for each pixel.
708
709 Returns the number of samples read (which should be (C<right>-C<left>)
710 * C<channel_count>)
711
712
713 =for comment
714 From: File imext.c
715
716 =item i_gsampf_bg(im, l, r, y, samples, out_channels, background)
717
718
719 Like C<i_gsampf()> but applies the source image color over a supplied
720 background color.
721
722 This is intended for output to image formats that don't support alpha
723 channels.
724
725
726 =for comment
727 From: File paste.im
728
729 =item i_line(C<im>, C<x1>, C<y1>, C<x2>, C<y2>, C<color>, C<endp>)
730
731
732 =for stopwords Bresenham's
733
734 Draw a line to image using Bresenham's line drawing algorithm
735
736    im    - image to draw to
737    x1    - starting x coordinate
738    y1    - starting x coordinate
739    x2    - starting x coordinate
740    y2    - starting x coordinate
741    color - color to write to image
742    endp  - endpoint flag (boolean)
743
744
745 =for comment
746 From: File draw.c
747
748 =item i_line_aa(C<im>, C<x1>, C<x2>, C<y1>, C<y2>, C<color>, C<endp>)
749
750
751 Anti-alias draws a line from (x1,y1) to (x2, y2) in color.
752
753 The point (x2, y2) is drawn only if C<endp> is set.
754
755
756 =for comment
757 From: File draw.c
758
759 =item i_plin(im, l, r, y, colors)
760
761
762 Sets (r-l) pixels starting from (l,y) using (r-l) values from
763 I<colors>.
764
765 Returns the number of pixels set.
766
767
768 =for comment
769 From: File imext.c
770
771 =item i_plinf(im, C<left>, C<right>, C<fcolors>)
772
773
774 Sets (right-left) pixels starting from (left,y) using (right-left)
775 floating point colors from C<fcolors>.
776
777 Returns the number of pixels set.
778
779
780 =for comment
781 From: File imext.c
782
783 =item i_poly_aa_cfill_m(im, count, x, y, mode, fill)
784
785   i_poly_aa_cfill(im, count, x, y, mode, fill);
786
787 Fill a polygon defined by the points specified by the x and y arrays with
788 the fill specified by C<fill>.
789
790
791 =for comment
792 From: File polygon.c
793
794 =item i_poly_aa_m(im, count, x, y, mode, color)
795
796   i_poly_aa_m(im, count, x, y, mode, color);
797
798 Fill a polygon defined by the points specified by the x and y arrays with
799 the color specified by C<color>.
800
801
802 =for comment
803 From: File polygon.c
804
805 =item i_poly_poly_aa(im, count, polys, mode, color)
806
807   i_poly_poly_aa(im, 1, &poly, mode, color);
808
809 Fill the C<count> polygons defined by C<polys> the color specified by
810 C<color>.
811
812 At least one polygon must be supplied.
813
814 All polygons must have at least 3 points.
815
816
817 =for comment
818 From: File polygon.c
819
820 =item i_poly_poly_aa_cfill(im, count, polys, mode, fill)
821
822   i_poly_poly_aa_cfill(im, 1, &poly, mode, fill);
823
824 Fill the C<count> polygons defined by C<polys> the fill specified by
825 C<fill>.
826
827 At least one polygon must be supplied.
828
829 All polygons must have at least 3 points.
830
831
832 =for comment
833 From: File polygon.c
834
835 =item i_ppal(im, left, right, y, indexes)
836
837
838 Writes palette indexes for the horizontal line (left, y) to (right-1,
839 y) from C<indexes>.
840
841 Returns the number of indexes written.
842
843 Always returns 0 for direct color images.
844
845
846 =for comment
847 From: File imext.c
848
849 =item i_ppix(im, x, y, color)
850
851
852 Sets the pixel at (x,y) to I<color>.
853
854 Returns 0 if the pixel was drawn, or -1 if not.
855
856 Does no alpha blending, just copies the channels from the supplied
857 color to the image.
858
859
860 =for comment
861 From: File imext.c
862
863 =item i_ppixf(im, C<x>, C<y>, C<fcolor>)
864
865
866 Sets the pixel at (C<x>,C<y>) to the floating point color C<fcolor>.
867
868 Returns 0 if the pixel was drawn, or -1 if not.
869
870 Does no alpha blending, just copies the channels from the supplied
871 color to the image.
872
873
874 =for comment
875 From: File imext.c
876
877 =item i_psamp(im, left, right, y, samples, channels, channel_count)
878
879 Writes sample values from C<samples> to C<im> for the horizontal line
880 (left, y) to (right-1, y) inclusive for the channels specified by
881 C<channels>, an array of C<int> with C<channel_count> elements.
882
883 If C<channels> is C<NULL> then the first C<channels_count> channels
884 are written to for each pixel.
885
886 Returns the number of samples written, which should be (right - left)
887 * channel_count.  If a channel not in the image is in channels, left
888 is negative, left is outside the image or y is outside the image,
889 returns -1 and pushes an error.
890
891
892 =for comment
893 From: File immacros.h
894
895 =item i_psamp_bits(im, left, right, y, samples, channels, channel_count, bits)
896
897 Writes integer samples scaled to C<bits> bits of precision from the
898 C<unsigned int> array C<samples>.
899
900 Expect this to be slow unless C<< bits == im->bits >>.
901
902 Returns the number of samples copied, or -1 on error.
903
904 Not all image types implement this method.
905
906 Pushes errors, but does not call C<i_clear_error()>.
907
908
909 =for comment
910 From: File imext.c
911
912 =item i_psampf(im, left, right, y, samples, channels, channel_count)
913
914 Writes floating point sample values from C<samples> to C<im> for the
915 horizontal line (left, y) to (right-1, y) inclusive for the channels
916 specified by C<channels>, an array of C<int> with C<channel_count>
917 elements.
918
919 If C<channels> is C<NULL> then the first C<channels_count> channels
920 are written to for each pixel.
921
922 Returns the number of samples written, which should be (right - left)
923 * channel_count.  If a channel not in the image is in channels, left
924 is negative, left is outside the image or y is outside the image,
925 returns -1 and pushes an error.
926
927
928 =for comment
929 From: File immacros.h
930
931
932 =back
933
934 =head2 Error handling
935
936 =over
937
938 =item i_push_errorf(int code, char const *fmt, ...)
939
940   i_push_errorf(errno, "Cannot open file %s: %d", filename, errno);
941
942 A version of i_push_error() that does printf() like formatting.
943
944 Does not support perl specific format codes.
945
946
947 =for comment
948 From: File error.c
949
950 =item im_clear_error(ctx)
951 X<im_clear_error API>X<i_clear_error API>
952
953   im_clear_error(aIMCTX);
954   i_clear_error();
955
956 Clears the error stack.
957
958 Called by any Imager function before doing any other processing.
959
960 Also callable as C<i_clear_error()>.
961
962
963 =for comment
964 From: File error.c
965
966 =item im_push_error(ctx, code, message)
967 X<im_push_error API>X<i_push_error API>
968
969   i_push_error(0, "Yep, it's broken");
970   i_push_error(errno, "Error writing");
971   im_push_error(aIMCTX, 0, "Something is wrong");
972
973 Called by an Imager function to push an error message onto the stack.
974
975 No message is pushed if the stack is full (since this means someone
976 forgot to call i_clear_error(), or that a function that doesn't do
977 error handling is calling function that does.).
978
979
980 =for comment
981 From: File error.c
982
983 =item im_push_errorf(ctx, code, char const *fmt, ...)
984
985   im_push_errorf(aIMCTX, errno, "Cannot open file %s: %d", filename, errno);
986
987 A version of im_push_error() that does printf() like formatting.
988
989 Does not support perl specific format codes.
990
991
992 =for comment
993 From: File error.c
994
995 =item im_push_errorvf(ctx, code, format, args)
996 X<im_push_error_vf API>X<i_push_errorvf API>
997
998   va_args args;
999   va_start(args, lastarg);
1000   im_push_errorvf(ctx, code, format, args);
1001
1002 Intended for use by higher level functions, takes a varargs pointer
1003 and a format to produce the finally pushed error message.
1004
1005 Does not support perl specific format codes.
1006
1007 Also callable as C<i_push_errorvf(code, format, args)>
1008
1009
1010 =for comment
1011 From: File error.c
1012
1013
1014 =back
1015
1016 =head2 Files
1017
1018 =over
1019
1020 =item i_get_file_background(im, &bg)
1021
1022
1023 Retrieve the file write background color tag from the image.
1024
1025 If not present, C<bg> is set to black.
1026
1027 Returns 1 if the C<i_background> tag was found and valid.
1028
1029
1030 =for comment
1031 From: File image.c
1032
1033 =item i_get_file_backgroundf(im, &bg)
1034
1035
1036 Retrieve the file write background color tag from the image as a
1037 floating point color.
1038
1039 Implemented in terms of i_get_file_background().
1040
1041 If not present, C<bg> is set to black.
1042
1043 Returns 1 if the C<i_background> tag was found and valid.
1044
1045
1046 =for comment
1047 From: File image.c
1048
1049 =item im_get_image_file_limits(ctx, &width, &height, &bytes)
1050 X<im_get_image_file_limits API>X<i_get_image_file_limits>
1051
1052   im_get_image_file_limits(aIMCTX, &width, &height, &bytes)
1053   i_get_image_file_limits(&width, &height, &bytes)
1054
1055 Retrieves the file limits set by i_set_image_file_limits().
1056
1057 =over
1058
1059 =item *
1060
1061 i_img_dim *width, *height - the maximum width and height of the image.
1062
1063 =item *
1064
1065 size_t *bytes - size in memory of the image in bytes.
1066
1067 =back
1068
1069 Also callable as C<i_get_image_file_limits(&width, &height, &bytes)>.
1070
1071
1072 =for comment
1073 From: File limits.c
1074
1075 =item im_int_check_image_file_limits(width, height, channels, sample_size)
1076 X<im_int_check_image_file_limits API>X<i_int_check_image_file_limits>
1077
1078   im_int_check_image_file_limits(aIMCTX, width, height, channels, sizeof(i_sample_t))
1079   i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t))
1080
1081 Checks the size of a file in memory against the configured image file
1082 limits.
1083
1084 This also range checks the values to those permitted by Imager and
1085 checks for overflows in calculating the size.
1086
1087 Returns non-zero if the file is within limits.
1088
1089 This function is intended to be called by image file read functions.
1090
1091 Also callable as C<i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t)>.
1092
1093
1094 =for comment
1095 From: File limits.c
1096
1097 =item im_set_image_file_limits(ctx, width, height, bytes)
1098 X<im_set_image_file_limits API>X<i_set_image_file_limits API>
1099
1100   im_set_image_file_limits(aIMCTX, 500, 500, 1000000);
1101   i_set_image_file_limits(500, 500, 1000000);
1102
1103 Set limits on the sizes of images read by Imager.
1104
1105 Setting a limit to 0 means that limit is ignored.
1106
1107 Negative limits result in failure.
1108
1109 Parameters:
1110
1111 =over
1112
1113 =item *
1114
1115 i_img_dim width, height - maximum width and height.
1116
1117 =item *
1118
1119 size_t bytes - maximum size in memory in bytes.  A value of zero sets
1120 this limit to one gigabyte.
1121
1122 =back
1123
1124 Returns non-zero on success.
1125
1126 Also callable as C<i_set_image_file_limits(width, height, bytes)>.
1127
1128
1129 =for comment
1130 From: File limits.c
1131
1132
1133 =back
1134
1135 =head2 Fills
1136
1137 =over
1138
1139 =item i_new_fill_fount(C<xa>, C<ya>, C<xb>, C<yb>, C<type>, C<repeat>, C<combine>, C<super_sample>, C<ssample_param>, C<count>, C<segs>)
1140
1141
1142   fill = i_new_fill_fount(0, 0, 100, 100, i_ft_linear, i_ft_linear, 
1143                           i_fr_triangle, 0, i_fts_grid, 9, 1, segs);
1144
1145
1146 Creates a new general fill which fills with a fountain fill.
1147
1148
1149 =for comment
1150 From: File filters.im
1151
1152 =item i_new_fill_hatch(C<fg>, C<bg>, C<combine>, C<hatch>, C<cust_hatch>, C<dx>, C<dy>)
1153
1154
1155   i_fill_t *fill = i_new_fill_hatch(&fg_color, &bg_color, combine, hatch, custom_hatch, dx, dy);
1156
1157 Creates a new hatched fill with the C<fg> color used for the 1 bits in
1158 the hatch and C<bg> for the 0 bits.  If C<combine> is non-zero alpha
1159 values will be combined.
1160
1161 If C<cust_hatch> is non-NULL it should be a pointer to 8 bytes of the
1162 hash definition, with the high-bits to the left.
1163
1164 If C<cust_hatch> is NULL then one of the standard hatches is used.
1165
1166 (C<dx>, C<dy>) are an offset into the hatch which can be used to hatch
1167 adjoining areas out of alignment, or to align the origin of a hatch
1168 with the side of a filled area.
1169
1170
1171 =for comment
1172 From: File fills.c
1173
1174 =item i_new_fill_hatchf(C<fg>, C<bg>, C<combine>, C<hatch>, C<cust_hatch>, C<dx>, C<dy>)
1175
1176
1177   i_fill_t *fill = i_new_fill_hatchf(&fg_fcolor, &bg_fcolor, combine, hatch, custom_hatch, dx, dy);
1178
1179 Creates a new hatched fill with the C<fg> color used for the 1 bits in
1180 the hatch and C<bg> for the 0 bits.  If C<combine> is non-zero alpha
1181 values will be combined.
1182
1183 If C<cust_hatch> is non-NULL it should be a pointer to 8 bytes of the
1184 hash definition, with the high-bits to the left.
1185
1186 If C<cust_hatch> is NULL then one of the standard hatches is used.
1187
1188 (C<dx>, C<dy>) are an offset into the hatch which can be used to hatch
1189 adjoining areas out of alignment, or to align the origin of a hatch
1190 with the side of a filled area.
1191
1192
1193 =for comment
1194 From: File fills.c
1195
1196 =item i_new_fill_image(C<im>, C<matrix>, C<xoff>, C<yoff>, C<combine>)
1197
1198
1199   i_fill_t *fill = i_new_fill_image(src_img, matrix, x_offset, y_offset, combine);
1200
1201 Create an image based fill.
1202
1203 matrix is an array of 9 doubles representing a transformation matrix.
1204
1205 C<xoff> and C<yoff> are the offset into the image to start filling from.
1206
1207
1208 =for comment
1209 From: File fills.c
1210
1211 =item i_new_fill_solid(color, combine)
1212
1213
1214   i_fill_t *fill = i_new_fill_solid(&color, combine);
1215
1216 Create a solid fill based on an 8-bit color.
1217
1218 If combine is non-zero then alpha values will be combined.
1219
1220
1221 =for comment
1222 From: File fills.c
1223
1224 =item i_new_fill_solidf(color, combine)
1225
1226
1227   i_fill_t *fill = i_new_fill_solidf(&fcolor, combine);
1228
1229 Create a solid fill based on a float color.
1230
1231 If combine is non-zero then alpha values will be combined.
1232
1233
1234 =for comment
1235 From: File fills.c
1236
1237 =item i_fill_destroy(fill)
1238
1239   i_fill_destroy(fill);
1240
1241 Call to destroy any fill object.
1242
1243
1244 =for comment
1245 From: File fills.c
1246
1247
1248 =back
1249
1250 =head2 I/O Layers
1251
1252 =over
1253
1254 =item im_io_new_bufchain(ctx)
1255 X<im_io_new_bufchain API>X<i_io_new_bufchain API>
1256
1257 Returns a new io_glue object that has the 'empty' source and but can
1258 be written to and read from later (like a pseudo file).
1259
1260 Also callable as C<io_new_bufchain()>.
1261
1262
1263 =for comment
1264 From: File iolayer.c
1265
1266 =item im_io_new_buffer(ctx, data, length)
1267 X<im_io_new_buffer API>X<io_new_buffer API>
1268
1269 Returns a new io_glue object that has the source defined as reading
1270 from specified buffer.  Note that the buffer is not copied.
1271
1272    ctx - an Imager context object
1273    data - buffer to read from
1274    length - length of buffer
1275
1276 Also callable as C<io_new_buffer(data, length>.
1277
1278
1279 =for comment
1280 From: File iolayer.c
1281
1282 =item im_io_new_cb(ctx, p, read_cb, write_cb, seek_cb, close_cb, destroy_cb)
1283 X<im_io_new_cb API>X<io_new_cb API>
1284
1285 Create a new I/O layer object that calls your supplied callbacks.
1286
1287 In general the callbacks should behave like the corresponding POSIX
1288 primitives.
1289
1290 =over
1291
1292 =item *
1293
1294 C<read_cb>(p, buffer, length) should read up to C<length> bytes into
1295 C<buffer> and return the number of bytes read.  At end of file, return
1296 0.  On error, return -1.
1297
1298 =item *
1299
1300 C<write_cb>(p, buffer, length) should write up to C<length> bytes from
1301 C<buffer> and return the number of bytes written.  A return value <= 0
1302 will be treated as an error.
1303
1304 =item *
1305
1306 C<seekcb>(p, offset, whence) should seek and return the new offset.
1307
1308 =item *
1309
1310 C<close_cb>(p) should return 0 on success, -1 on failure.
1311
1312 =item *
1313
1314 C<destroy_cb>(p) should release any memory specific to your callback
1315 handlers.
1316
1317 =back
1318
1319 Also callable as C<io_new_cb(p, readcb, writecb, seekcb, closecb,
1320 destroycb)>.
1321
1322
1323 =for comment
1324 From: File iolayer.c
1325
1326 =item im_io_new_fd(ctx, file)
1327 X<io_new_fd API>X<im_io_new_fd API>
1328
1329 Returns a new io_glue object that has the source defined as reading
1330 from specified file descriptor.  Note that the interface to receiving
1331 data from the io_glue callbacks hasn't been done yet.
1332
1333   ctx - and Imager context object
1334   file - file descriptor to read/write from
1335
1336 Also callable as C<io_new_fd(file)>.
1337
1338
1339 =for comment
1340 From: File iolayer.c
1341
1342 =item i_io_close(io)
1343
1344 Flush any pending output and perform the close action for the stream.
1345
1346 Returns 0 on success.
1347
1348
1349 =for comment
1350 From: File iolayer.c
1351
1352 =item i_io_flush(io)
1353
1354 Flush any buffered output.
1355
1356 Returns true on success,
1357
1358
1359 =for comment
1360 From: File iolayer.c
1361
1362 =item i_io_getc(ig)
1363
1364 A macro to read a single byte from a buffered I/O glue object.
1365
1366 Returns EOF on failure, or a byte.
1367
1368
1369 =for comment
1370 From: File iolayer.c
1371
1372 =item i_io_gets(ig, buffer, size, end_of_line)
1373
1374   char buffer[BUFSIZ]
1375   ssize_t len = i_io_gets(buffer, sizeof(buffer), '\n');
1376
1377 Read up to C<size>-1 bytes from the stream C<ig> into C<buffer>.
1378
1379 If the byte C<end_of_line> is seen then no further bytes will be read.
1380
1381 Returns the number of bytes read.
1382
1383 Always C<NUL> terminates the buffer.
1384
1385
1386 =for comment
1387 From: File iolayer.c
1388
1389 =item i_io_peekc(ig)
1390
1391 Read the next character from the stream without advancing the stream.
1392
1393 On error or end of file, return EOF.
1394
1395 For unbuffered streams a single character buffer will be setup.
1396
1397
1398 =for comment
1399 From: File iolayer.c
1400
1401 =item i_io_peekn(ig, buffer, size)
1402
1403   ssize_t count = i_io_peekn(ig, buffer, sizeof(buffer));
1404
1405 Buffer at least C<size> (at most C<< ig->buf_size >> bytes of data
1406 from the stream and return C<size> bytes of it to the caller in
1407 C<buffer>.
1408
1409 This ignores the buffered state of the stream, and will always setup
1410 buffering if needed.
1411
1412 If no C<type> parameter is provided to Imager::read() or
1413 Imager::read_multi(), Imager will call C<i_io_peekn()> when probing
1414 for the file format.
1415
1416 Returns -1 on error, 0 if there is no data before EOF, or the number
1417 of bytes read into C<buffer>.
1418
1419
1420 =for comment
1421 From: File iolayer.c
1422
1423 =item i_io_putc(ig, c)
1424
1425 Write a single character to the stream.
1426
1427 On success return c, on error returns EOF
1428
1429
1430 =for comment
1431 From: File iolayer.c
1432
1433 =item i_io_read(io, buffer, size)
1434
1435 Read up to C<size> bytes from the stream C<io> into C<buffer>.
1436
1437 Returns the number of bytes read.  Returns 0 on end of file.  Returns
1438 -1 on error.
1439
1440
1441 =for comment
1442 From: File iolayer.c
1443
1444 =item i_io_seek(io, offset, whence)
1445
1446 Seek within the stream.
1447
1448 Acts like perl's seek.
1449
1450
1451 =for comment
1452 From: File iolayer.c
1453
1454 =item i_io_set_buffered(io, buffered)
1455
1456 Set the buffering mode of the stream.
1457
1458 If you switch buffering off on a stream with buffering on:
1459
1460 =over
1461
1462 =item *
1463
1464 any buffered output will be flushed.
1465
1466 =item *
1467
1468 any existing buffered input will be consumed before reads become
1469 unbuffered.
1470
1471 =back
1472
1473 Returns true on success.  This may fail if any buffered output cannot
1474 be flushed.
1475
1476
1477 =for comment
1478 From: File iolayer.c
1479
1480 =item i_io_write(io, buffer, size)
1481
1482   ssize_t result = i_io_write(io, buffer, size)
1483
1484 Write to the given I/O stream.
1485
1486 Returns the number of bytes written.
1487
1488
1489 =for comment
1490 From: File iolayer.c
1491
1492 =item io_slurp(ig, c)
1493 X<io_slurp API>
1494
1495 Takes the source that the io_glue is bound to and allocates space for
1496 a return buffer and returns the entire content in a single buffer.
1497 Note: This only works for io_glue objects created by
1498 io_new_bufchain().  It is useful for saving to scalars and such.
1499
1500    ig - io_glue object
1501    c  - pointer to a pointer to where data should be copied to
1502
1503   char *data;
1504   size_t size = io_slurp(ig, &data);
1505   ... do something with the data ...
1506   myfree(data);
1507
1508 io_slurp() will abort the program if the supplied I/O layer is not
1509 from io_new_bufchain().
1510
1511
1512 =for comment
1513 From: File iolayer.c
1514
1515 =item io_glue_destroy(ig)
1516 X<io_glue_destroy API>
1517
1518   io_glue_destroy(ig);
1519
1520 Destroy an io_glue objects.  Should clean up all related buffers.
1521
1522    ig - io_glue object to destroy.
1523
1524
1525 =for comment
1526 From: File iolayer.c
1527
1528
1529 =back
1530
1531 =head2 Image
1532
1533 =over
1534
1535 =item i_copy(source)
1536
1537
1538 Creates a new image that is a copy of the image C<source>.
1539
1540 Tags are not copied, only the image data.
1541
1542 Returns: i_img *
1543
1544
1545 =for comment
1546 From: File image.c
1547
1548 =item i_copyto(C<dest>, C<src>, C<x1>, C<y1>, C<x2>, C<y2>, C<tx>, C<ty>)
1549
1550
1551 Copies image data from the area (C<x1>,C<y1>)-[C<x2>,C<y2>] in the
1552 source image to a rectangle the same size with it's top-left corner at
1553 (C<tx>,C<ty>) in the destination image.
1554
1555 If C<x1> > C<x2> or C<y1> > C<y2> then the corresponding co-ordinates
1556 are swapped.
1557
1558
1559 =for comment
1560 From: File paste.im
1561
1562 =item i_copyto_trans(C<im>, C<src>, C<x1>, C<y1>, C<x2>, C<y2>, C<tx>, C<ty>, C<trans>)
1563
1564
1565 (C<x1>,C<y1>) (C<x2>,C<y2>) specifies the region to copy (in the
1566 source coordinates) (C<tx>,C<ty>) specifies the upper left corner for
1567 the target image.  pass NULL in C<trans> for non transparent i_colors.
1568
1569
1570 =for comment
1571 From: File image.c
1572
1573 =item i_img_info(im, info)
1574
1575
1576 Return image information
1577
1578    im - Image pointer
1579    info - pointer to array to return data
1580
1581 info is an array of 4 integers with the following values:
1582
1583  info[0] - width
1584  info[1] - height
1585  info[2] - channels
1586  info[3] - channel mask
1587
1588
1589 =for comment
1590 From: File image.c
1591
1592 =item i_rubthru(C<im>, C<src>, C<tx>, C<ty>, C<src_minx>, C<src_miny>, C<src_maxx>, C<src_maxy>)
1593
1594
1595 Takes the sub image C<src>[C<src_minx>, C<src_maxx>)[C<src_miny>, C<src_maxy>)> and
1596 overlays it at (C<tx>,C<ty>) on the image object.
1597
1598 The alpha channel of each pixel in C<src> is used to control how much
1599 the existing color in C<im> is replaced, if it is 255 then the color
1600 is completely replaced, if it is 0 then the original color is left
1601 unmodified.
1602
1603
1604 =for comment
1605 From: File rubthru.im
1606
1607
1608 =back
1609
1610 =head2 Image creation/destruction
1611
1612 =over
1613
1614 =item i_sametype(C<im>, C<xsize>, C<ysize>)
1615
1616
1617   i_img *img = i_sametype(src, width, height);
1618
1619 Returns an image of the same type (sample size, channels, paletted/direct).
1620
1621 For paletted images the palette is copied from the source.
1622
1623
1624 =for comment
1625 From: File image.c
1626
1627 =item i_sametype_chans(C<im>, C<xsize>, C<ysize>, C<channels>)
1628
1629
1630   i_img *img = i_sametype_chans(src, width, height, channels);
1631
1632 Returns an image of the same type (sample size).
1633
1634 For paletted images the equivalent direct type is returned.
1635
1636
1637 =for comment
1638 From: File image.c
1639
1640 =item im_img_16_new(ctx, x, y, ch)
1641 X<im_img_16_new API>X<i_img_16_new API>
1642
1643   i_img *img = im_img_16_new(aIMCTX, width, height, channels);
1644   i_img *img = i_img_16_new(width, height, channels);
1645
1646 Create a new 16-bit/sample image.
1647
1648 Returns the image on success, or NULL on failure.
1649
1650 Also callable as C<i_img_16_new(x, y, ch)>
1651
1652
1653 =for comment
1654 From: File img16.c
1655
1656 =item im_img_8_new(ctx, x, y, ch)
1657 X<im_img_8_new API>X<i_img_8_new API>
1658
1659   i_img *img = im_img_8_new(aIMCTX, width, height, channels);
1660   i_img *img = i_img_8_new(width, height, channels);
1661
1662 Creates a new image object I<x> pixels wide, and I<y> pixels high with
1663 I<ch> channels.
1664
1665
1666 =for comment
1667 From: File img8.c
1668
1669 =item im_img_double_new(ctx, x, y, ch)
1670 X<im_img_double_new API>X<i_img_double_new API>
1671
1672   i_img *img = im_img_double_new(aIMCTX, width, height, channels);
1673   i_img *img = i_img_double_new(width, height, channels);
1674
1675 Creates a new double per sample image.
1676
1677 Also callable as C<i_img_double_new(width, height, channels)>.
1678
1679
1680 =for comment
1681 From: File imgdouble.c
1682
1683 =item im_img_pal_new(ctx, C<x>, C<y>, C<channels>, C<maxpal>)
1684 X<im_img_pal_new API>X<i_img_pal_new API>
1685
1686   i_img *img = im_img_pal_new(aIMCTX, width, height, channels, max_palette_size)
1687   i_img *img = i_img_pal_new(width, height, channels, max_palette_size)
1688
1689 Creates a new paletted image of the supplied dimensions.
1690
1691 C<maxpal> is the maximum palette size and should normally be 256.
1692
1693 Returns a new image or NULL on failure.
1694
1695 Also callable as C<i_img_pal_new(width, height, channels, max_palette_size)>.
1696
1697
1698 =for comment
1699 From: File palimg.c
1700
1701 =item i_img_destroy(C<img>)
1702
1703   i_img_destroy(img)
1704
1705 Destroy an image object
1706
1707
1708 =for comment
1709 From: File image.c
1710
1711
1712 =back
1713
1714 =head2 Image Implementation
1715
1716 =over
1717
1718 =item im_img_alloc(aIMCTX)
1719 X<im_img_alloc API>X<i_img_alloc API>
1720
1721   i_img *im = im_img_alloc(aIMCTX);
1722   i_img *im = i_img_alloc();
1723
1724 Allocates a new i_img structure.
1725
1726 When implementing a new image type perform the following steps in your
1727 image object creation function:
1728
1729 =over
1730
1731 =item 1.
1732
1733 allocate the image with i_img_alloc().
1734
1735 =item 2.
1736
1737 initialize any function pointers or other data as needed, you can
1738 overwrite the whole block if you need to.
1739
1740 =item 3.
1741
1742 initialize Imager's internal data by calling i_img_init() on the image
1743 object.
1744
1745 =back
1746
1747
1748 =for comment
1749 From: File image.c
1750
1751 =item im_img_init(aIMCTX, image)
1752 X<im_img_init API>X<i_img_init API>
1753
1754   im_img_init(aIMCTX, im);
1755   i_img_init(im);
1756
1757 Imager internal initialization of images.
1758
1759 See L</im_img_alloc(aIMCTX)> for more information.
1760
1761
1762 =for comment
1763 From: File image.c
1764
1765
1766 =back
1767
1768 =head2 Image Information
1769
1770 =over
1771
1772 =item i_img_color_channels(C<im>)
1773
1774
1775 The number of channels holding color information.
1776
1777
1778 =for comment
1779 From: File immacros.h
1780
1781 =item i_img_get_height(C<im>)
1782
1783   i_img_dim height = i_img_get_height(im);
1784
1785 Returns the height in pixels of the image.
1786
1787
1788 =for comment
1789 From: File image.c
1790
1791 =item i_img_get_width(C<im>)
1792
1793   i_img_dim width = i_img_get_width(im);
1794
1795 Returns the width in pixels of the image.
1796
1797
1798 =for comment
1799 From: File image.c
1800
1801 =item i_img_getchannels(C<im>)
1802
1803   int channels = i_img_getchannels(img);
1804
1805 Get the number of channels in C<im>.
1806
1807
1808 =for comment
1809 From: File image.c
1810
1811 =item i_img_getmask(C<im>)
1812
1813   int mask = i_img_getmask(img);
1814
1815 Get the image channel mask for C<im>.
1816
1817
1818 =for comment
1819 From: File image.c
1820
1821 =item i_img_has_alpha(C<im>)
1822
1823
1824 Return true if the image has an alpha channel.
1825
1826
1827 =for comment
1828 From: File immacros.h
1829
1830 =item i_img_is_monochrome(img, &zero_is_white)
1831
1832
1833 Tests an image to check it meets our monochrome tests.
1834
1835 The idea is that a file writer can use this to test where it should
1836 write the image in whatever bi-level format it uses, eg. C<pbm> for
1837 C<pnm>.
1838
1839 For performance of encoders we require monochrome images:
1840
1841 =over
1842
1843 =item *
1844
1845 be paletted
1846
1847 =item *
1848
1849 have a palette of two colors, containing only C<(0,0,0)> and
1850 C<(255,255,255)> in either order.
1851
1852 =back
1853
1854 C<zero_is_white> is set to non-zero if the first palette entry is white.
1855
1856
1857 =for comment
1858 From: File image.c
1859
1860 =item i_img_setmask(C<im>, C<ch_mask>)
1861
1862   // only channel 0 writable 
1863   i_img_setmask(img, 0x01);
1864
1865 Set the image channel mask for C<im> to C<ch_mask>.
1866
1867 The image channel mask gives some control over which channels can be
1868 written to in the image.
1869
1870
1871 =for comment
1872 From: File image.c
1873
1874
1875 =back
1876
1877 =head2 Image quantization
1878
1879 =over
1880
1881 =item i_quant_makemap(C<quant>, C<imgs>, C<count>)
1882
1883
1884 Analyzes the C<count> images in C<imgs> according to the rules in
1885 C<quant> to build a color map (optimal or not depending on
1886 C<< quant->make_colors >>).
1887
1888
1889 =for comment
1890 From: File quant.c
1891
1892 =item i_quant_translate(C<quant>, C<img>)
1893
1894
1895 Quantize the image given the palette in C<quant>.
1896
1897 On success returns a pointer to a memory block of C<< img->xsize *
1898 img->ysize >> C<i_palidx> entries.
1899
1900 On failure returns NULL.
1901
1902 You should call myfree() on the returned block when you're done with
1903 it.
1904
1905 This function will fail if the supplied palette contains no colors.
1906
1907
1908 =for comment
1909 From: File quant.c
1910
1911 =item i_quant_transparent(C<quant>, C<data>, C<img>, C<trans_index>)
1912
1913
1914 Dither the alpha channel on C<img> into the palette indexes in
1915 C<data>.  Pixels to be transparent are replaced with C<trans_pixel>.
1916
1917 The method used depends on the tr_* members of C<quant>.
1918
1919
1920 =for comment
1921 From: File quant.c
1922
1923
1924 =back
1925
1926 =head2 Logging
1927
1928 =over
1929
1930 =item i_lhead(file, line)
1931
1932 This is an internal function called by the mm_log() macro.
1933
1934
1935 =for comment
1936 From: File log.c
1937
1938 =item i_loog(level, format, ...)
1939
1940 This is an internal function called by the mm_log() macro.
1941
1942
1943 =for comment
1944 From: File log.c
1945
1946
1947 =back
1948
1949 =head2 Mutex functions
1950
1951 =over
1952
1953 =item i_mutex_new()
1954
1955   i_mutex_t m = i_mutex_new();
1956
1957 Create a mutex.
1958
1959 If a critical section cannot be created for whatever reason, Imager
1960 will abort.
1961
1962
1963 =for comment
1964 From: File mutexwin.c
1965
1966 =item i_mutex_destroy(m)
1967
1968   i_mutex_destroy(m);
1969
1970 Destroy a mutex.
1971
1972
1973 =for comment
1974 From: File mutexwin.c
1975
1976 =item i_mutex_lock(m)
1977
1978   i_mutex_lock(m);
1979
1980 Lock the mutex, waiting if another thread has the mutex locked.
1981
1982
1983 =for comment
1984 From: File mutexwin.c
1985
1986 =item i_mutex_unlock(m)
1987
1988   i_mutex_unlock(m);
1989
1990 Release the mutex.
1991
1992 The behavior of releasing a mutex you don't hold is unspecified.
1993
1994
1995 =for comment
1996 From: File mutexwin.c
1997
1998
1999 =back
2000
2001 =head2 Paletted images
2002
2003 =over
2004
2005 =item i_addcolors(im, colors, count)
2006
2007
2008 Adds colors to the image's palette.
2009
2010 On success returns the index of the lowest color added.
2011
2012 On failure returns -1.
2013
2014 Always fails for direct color images.
2015
2016
2017 =for comment
2018 From: File imext.c
2019
2020 =item i_colorcount(im)
2021
2022
2023 Returns the number of colors in the image's palette.
2024
2025 Returns -1 for direct images.
2026
2027
2028 =for comment
2029 From: File imext.c
2030
2031 =item i_findcolor(im, color, &entry)
2032
2033
2034 Searches the images palette for the given color.
2035
2036 On success sets *I<entry> to the index of the color, and returns true.
2037
2038 On failure returns false.
2039
2040 Always fails on direct color images.
2041
2042
2043 =for comment
2044 From: File imext.c
2045
2046 =item i_getcolors(im, index, colors, count)
2047
2048
2049 Retrieves I<count> colors starting from I<index> in the image's
2050 palette.
2051
2052 On success stores the colors into I<colors> and returns true.
2053
2054 On failure returns false.
2055
2056 Always fails for direct color images.
2057
2058 Fails if there are less than I<index>+I<count> colors in the image's
2059 palette.
2060
2061
2062 =for comment
2063 From: File imext.c
2064
2065 =item i_maxcolors(im)
2066
2067
2068 Returns the maximum number of colors the palette can hold for the
2069 image.
2070
2071 Returns -1 for direct color images.
2072
2073
2074 =for comment
2075 From: File imext.c
2076
2077 =item i_setcolors(im, index, colors, count)
2078
2079
2080 Sets I<count> colors starting from I<index> in the image's palette.
2081
2082 On success returns true.
2083
2084 On failure returns false.
2085
2086 The image must have at least I<index>+I<count> colors in it's palette
2087 for this to succeed.
2088
2089 Always fails on direct color images.
2090
2091
2092 =for comment
2093 From: File imext.c
2094
2095
2096 =back
2097
2098 =head2 Tags
2099
2100 =over
2101
2102 =item i_tags_delbycode(tags, code)
2103
2104
2105 Delete any tags with the given code.
2106
2107 Returns the number of tags deleted.
2108
2109
2110 =for comment
2111 From: File tags.c
2112
2113 =item i_tags_delbyname(tags, name)
2114
2115
2116 Delete any tags with the given name.
2117
2118 Returns the number of tags deleted.
2119
2120
2121 =for comment
2122 From: File tags.c
2123
2124 =item i_tags_delete(tags, index)
2125
2126
2127 Delete a tag by index.
2128
2129 Returns true on success.
2130
2131
2132 =for comment
2133 From: File tags.c
2134
2135 =item i_tags_destroy(tags)
2136
2137
2138 Destroys the given tags structure.  Called by i_img_destroy().
2139
2140
2141 =for comment
2142 From: File tags.c
2143
2144 =item i_tags_find(tags, name, start, &entry)
2145
2146
2147 Searches for a tag of the given I<name> starting from index I<start>.
2148
2149 On success returns true and sets *I<entry>.
2150
2151 On failure returns false.
2152
2153
2154 =for comment
2155 From: File tags.c
2156
2157 =item i_tags_findn(tags, code, start, &entry)
2158
2159
2160 Searches for a tag of the given I<code> starting from index I<start>.
2161
2162 On success returns true and sets *I<entry>.
2163
2164 On failure returns false.
2165
2166
2167 =for comment
2168 From: File tags.c
2169
2170 =item i_tags_get_color(tags, name, code, &value)
2171
2172
2173 Retrieve a tag specified by name or code as color.
2174
2175 On success sets the i_color *I<value> to the color and returns true.
2176
2177 On failure returns false.
2178
2179
2180 =for comment
2181 From: File tags.c
2182
2183 =item i_tags_get_float(tags, name, code, value)
2184
2185
2186 Retrieves a tag as a floating point value.  
2187
2188 If the tag has a string value then that is parsed as a floating point
2189 number, otherwise the integer value of the tag is used.
2190
2191 On success sets *I<value> and returns true.
2192
2193 On failure returns false.
2194
2195
2196 =for comment
2197 From: File tags.c
2198
2199 =item i_tags_get_int(tags, name, code, &value)
2200
2201
2202 Retrieve a tag specified by name or code as an integer.
2203
2204 On success sets the int *I<value> to the integer and returns true.
2205
2206 On failure returns false.
2207
2208
2209 =for comment
2210 From: File tags.c
2211
2212 =item i_tags_get_string(tags, name, code, value, value_size)
2213
2214
2215 Retrieves a tag by name or code as a string.
2216
2217 On success copies the string to value for a max of value_size and
2218 returns true.
2219
2220 On failure returns false.
2221
2222 value_size must be at least large enough for a string representation
2223 of an integer.
2224
2225 The copied value is always C<NUL> terminated.
2226
2227
2228 =for comment
2229 From: File tags.c
2230
2231 =item i_tags_new(i_img_tags *tags)
2232
2233
2234 Initialize a tags structure.  Should not be used if the tags structure
2235 has been previously used.
2236
2237 This should be called tags member of an i_img object on creation (in
2238 i_img_*_new() functions).
2239
2240 To destroy the contents use i_tags_destroy()
2241
2242
2243 =for comment
2244 From: File tags.c
2245
2246 =item i_tags_set(tags, name, data, size)
2247
2248   i_tags_set(&img->tags, "i_comment", -1);
2249
2250 Sets the given tag to the string I<data>
2251
2252 If size is -1 then the strlen(I<data>) bytes are stored.
2253
2254 Even on failure, if an existing tag I<name> exists, it will be
2255 removed.
2256
2257
2258 =for comment
2259 From: File tags.c
2260
2261 =item i_tags_set_color(tags, name, code, &value)
2262
2263
2264 Stores the given color as a tag with the given name and code.
2265
2266
2267 =for comment
2268 From: File tags.c
2269
2270 =item i_tags_set_float(tags, name, code, value)
2271
2272
2273 Equivalent to i_tags_set_float2(tags, name, code, value, 30).
2274
2275
2276 =for comment
2277 From: File tags.c
2278
2279 =item i_tags_set_float2(tags, name, code, value, places)
2280
2281
2282 Sets the tag with the given name and code to the given floating point
2283 value.
2284
2285 Since tags are strings or ints, we convert the value to a string before
2286 storage at the precision specified by C<places>.
2287
2288
2289 =for comment
2290 From: File tags.c
2291
2292 =item i_tags_setn(C<tags>, C<name>, C<idata>)
2293
2294   i_tags_setn(&img->tags, "i_xres", 204);
2295   i_tags_setn(&img->tags, "i_yres", 196);
2296
2297 Sets the given tag to the integer C<idata>
2298
2299 Even on failure, if an existing tag C<name> exists, it will be
2300 removed.
2301
2302
2303 =for comment
2304 From: File tags.c
2305
2306
2307 =back
2308
2309 =head2 Uncategorized functions
2310
2311 =over
2312
2313 =item i_utf8_advance(char **p, size_t *len)
2314
2315 Retrieve a C<UTF-8> character from the stream.
2316
2317 Modifies *p and *len to indicate the consumed characters.
2318
2319 This doesn't support the extended C<UTF-8> encoding used by later
2320 versions of Perl.  Since this is typically used to implement text
2321 output by font drivers, the strings supplied shouldn't have such out
2322 of range characters.
2323
2324 This doesn't check that the C<UTF-8> character is using the shortest
2325 possible representation.
2326
2327 Returns ~0UL on failure.
2328
2329
2330 =for comment
2331 From: File io.c
2332
2333 =item im_context_refdec(ctx, where)
2334 X<im_context_refdec API>
2335 =section Context objects
2336
2337   im_context_refdec(aIMCTX, "a description");
2338
2339 Remove a reference to the context, releasing it if all references have
2340 been removed.
2341
2342
2343 =for comment
2344 From: File context.c
2345
2346 =item im_context_refinc(ctx, where)
2347 X<im_context_refinc API>
2348 =section Context objects
2349
2350   im_context_refinc(aIMCTX, "a description");
2351
2352 Add a new reference to the context.
2353
2354
2355 =for comment
2356 From: File context.c
2357
2358 =item im_context_slot_get(ctx, slot)
2359
2360 Retrieve the value previously stored in the given slot of the context
2361 object.
2362
2363
2364 =for comment
2365 From: File context.c
2366
2367 =item im_context_slot_new(destructor)
2368
2369 Allocate a new context-local-storage slot.
2370
2371 C<desctructor> will be called when the context is destroyed if the
2372 corresponding slot is non-NULL.
2373
2374
2375 =for comment
2376 From: File context.c
2377
2378 =item im_context_slot_set(slot, value)
2379
2380 Set the value of a slot.
2381
2382 Returns true on success.
2383
2384 Aborts if the slot supplied is invalid.
2385
2386 If reallocation of slot storage fails, returns false.
2387
2388
2389 =for comment
2390 From: File context.c
2391
2392 =item im_errors(ctx)
2393
2394   i_errmsg *errors = im_errors(aIMCTX);
2395   i_errmsg *errors = i_errors();
2396
2397 Returns a pointer to the first element of an array of error messages,
2398 terminated by a NULL pointer.  The highest level message is first.
2399
2400 Also callable as C<i_errors()>.
2401
2402
2403 =for comment
2404 From: File error.c
2405
2406 =item im_get_context()
2407
2408 Retrieve the context object for the current thread.
2409
2410 Inside Imager itself this is just a function pointer, which the
2411 F<Imager.xs> BOOT handler initializes for use within perl.  If you're
2412 taking the Imager code and embedding it elsewhere you need to
2413 initialize the C<im_get_context> pointer at some point.
2414
2415
2416 =for comment
2417 From: File imext.c
2418
2419
2420
2421 =back
2422
2423
2424 =head1 UNDOCUMENTED
2425
2426 The following API functions are undocumented so far, hopefully this
2427 will change:
2428
2429 =over
2430
2431 =item *
2432
2433 B<im_lhead>
2434
2435 =item *
2436
2437 B<im_loog>
2438
2439 =item *
2440
2441 B<mm_log>
2442
2443
2444
2445 =back
2446
2447
2448 =head1 AUTHOR
2449
2450 Tony Cook <tonyc@cpan.org>
2451
2452 =head1 SEE ALSO
2453
2454 Imager, Imager::API, Imager::ExtUtils, Imager::Inline
2455
2456 =cut