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