API documentation (mostly)
[imager.git] / lib / Imager / APIRef.pod
CommitLineData
92bda632
TC
1Do not edit this file, it is generated automatically by apidocs.perl
2from Imager's source files.
3
5ca7e2ab
TC
4Each function description has a comment listing the source file where
5you can find the documentation.
92bda632
TC
6
7=head1 NAME
8
6cfee9d1 9Imager::APIRef - Imager's C API - reference.
92bda632
TC
10
11=head1 SYNOPSIS
12
13 i_color color;
6cfee9d1 14 color.rgba.r = 255; color.rgba.g = 0; color.rgba.b = 255;
92bda632
TC
15
16
bd8052a6
TC
17 # Data Types
18 i_img *img;
6cfee9d1
TC
19 i_color black;
20 black.rgba.r = black.rgba.g = black.rgba.b = black.rgba.a = 0;
21 i_fill_t *fill;
22 i_img_dim x;
bd8052a6 23
92bda632
TC
24 # Drawing
25 i_arc(im, 50, 50, 20, 45, 135, &color);
6cfee9d1 26 i_arc_cfill(im, 50, 50, 35, 90, 135, fill);
92bda632
TC
27 i_arc_aa(im, 50, 50, 35, 90, 135, &color);
28 i_arc_aa_cfill(im, 50, 50, 35, 90, 135, fill);
6cfee9d1 29 i_circle_aa(im, 50, 50, 45, &color);
92bda632 30 i_box(im, 0, 0, im->xsize-1, im->ysize-1, &color).
92bda632 31 i_box_filled(im, 0, 0, im->xsize-1, im->ysize-1, &color);
6cfee9d1 32 i_box_cfill(im, 0, 0, im->xsize-1, im->ysize-1, fill);
92bda632 33 i_flood_fill(im, 50, 50, &color);
6cfee9d1 34 i_flood_cfill(im, 50, 50, fill);
3efb0915 35 i_flood_fill_border(im, 50, 50, &color, &border);
6cfee9d1 36 i_flood_cfill_border(im, 50, 50, fill, border);
92bda632
TC
37
38 # Error handling
6cfee9d1
TC
39 i_clear_error();
40 i_push_error(0, "Yep, it's broken");
41 i_push_error(errno, "Error writing");
42 i_push_errorf(errno, "Cannot open file %s: %d", filename, errno);
92bda632 43
87deb14c 44 # Files
6cfee9d1 45 i_set_image_file_limits(500, 500, 1000000);
87deb14c
TC
46 i_get_image_file_limits(&width, &height, &bytes)
47 i_i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t))
87deb14c 48
92bda632 49 # Fills
6cfee9d1
TC
50 i_fill_t *fill = i_new_fill_solidf(&fcolor, combine);
51 i_fill_t *fill = i_new_fill_solid(&color, combine);
9167a5c6
TC
52 i_fill_t *fill = i_new_fill_hatch(&fg_color, &bg_color, combine, hatch, custom_hatch, dx, dy);
53 i_fill_t *fill = i_new_fill_hatchf(&fg_fcolor, &bg_fcolor, combine, hatch, custom_hatch, dx, dy);
54 i_fill_t *fill = i_new_fill_image(src_img, matrix, x_offset, y_offset, combine);
6cfee9d1
TC
55 fill = i_new_fill_fount(0, 0, 100, 100, i_ft_linear, i_ft_linear,
56 i_fr_triangle, 0, i_fts_grid, 9, 1, segs);
57 i_fill_destroy(fill);
92bda632
TC
58
59 # Image
60
bd8052a6 61 # Image creation/destruction
9167a5c6 62 i_img *img = i_img_8_new(width, height, channels);
9167a5c6
TC
63 i_img *img = i_sametype(src, width, height);
64 i_img *img = i_sametype_chans(src, width, height, channels);
6cfee9d1
TC
65 i_img *img = i_img_pal_new(width, height, channels, max_palette_size)
66 i_img *img = i_img_double_new(width, height, channels);
67 i_img *img = i_img_16_new(width, height, channels);
68 i_img_destroy(img)
92bda632 69
bd8052a6
TC
70 # Image Implementation
71
bea65b1f 72 # Image Information
6cfee9d1
TC
73 // only channel 0 writeable
74 i_img_setmask(img, 0x01);
75 int mask = i_img_getmask(img);
76 int channels = i_img_getchannels(img);
77 i_img_dim width = i_img_get_width(im);
78 i_img_dim height = i_img_get_height(im);
bea65b1f 79
92bda632
TC
80 # Image quantization
81
bd8052a6
TC
82 # Logging
83
92bda632
TC
84 # Paletted images
85
86 # Tags
6cfee9d1
TC
87 i_tags_set(&img->tags, "i_comment", -1);
88 i_tags_setn(&img->tags, "i_xres", 204);
89 i_tags_setn(&img->tags, "i_yres", 196);
92bda632 90
92bda632
TC
91=head1 DESCRIPTION
92
bd8052a6
TC
93=head2 Data Types
94
95=over
96
97=item i_img
98
99This is Imager's image type.
100
101It contains the following members:
102
103=over
104
105=item *
106
107channels - the number of channels in the image
108
109=item *
110
111xsize, ysize - the width and height of the image in pixels
112
113=item *
114
115bytes - the number of bytes used to store the image data. Undefined
116where virtual is non-zero.
117
118=item *
119
120ch_mask - a mask of writable channels. eg. if this is 6 then only
121channels 1 and 2 are writable. There may be bits set for which there
122are no channels in the image.
123
124=item *
125
126bits - the number of bits stored per sample. Should be one of
127i_8_bits, i_16_bits, i_double_bits.
128
129=item *
130
131type - either i_direct_type for direct color images, or i_palette_type
132for paletted images.
133
134=item *
135
136virtual - if zero then this image is-self contained. If non-zero then
137this image could be an interface to some other implementation.
138
139=item *
140
141idata - the image data. This should not be directly accessed. A new
142image implementation can use this to store its image data.
143i_img_destroy() will myfree() this pointer if it's non-null.
144
145=item *
146
147tags - a structure storing the image's tags. This should only be
148accessed via the i_tags_*() functions.
149
150=item *
151
152ext_data - a pointer for use internal to an image implementation.
153This should be freed by the image's destroy handler.
154
155=item *
156
157im_data - data internal to Imager. This is initialized by
158i_img_init().
159
160=item *
161
162i_f_ppix, i_f_ppixf, i_f_plin, i_f_plinf, i_f_gpix, i_f_gpixf,
163i_f_glin, i_f_glinf, i_f_gsamp, i_f_gampf - implementations for each
164of the required image functions. An image implementation should
165initialize these between calling i_img_alloc() and i_img_init().
166
167=item *
168
169i_f_gpal, i_f_ppal, i_f_addcolors, i_f_getcolors, i_f_colorcount,
170i_f_maxcolors, i_f_findcolor, i_f_setcolors - implementations for each
171paletted image function.
172
173=item *
174
175i_f_destroy - custom image destruction function. This should be used
176to release memory if necessary.
177
178=item *
179
180i_f_gsamp_bits - implements i_gsamp_bits() for this image.
181
182=item *
183
184i_f_psamp_bits - implements i_psamp_bits() for this image.
185
186=back
187
188
6cfee9d1
TC
189=for comment
190From: File imdatatypes.h
191
192=item i_color
193
194Type for 8-bit/sample color.
195
196Samples as per;
197
198 i_color c;
199
200i_color is a union of:
201
202=over
203
204=item *
205
206gray - contains a single element gray_color, eg. c.gray.gray_color
207
208=item *
209
210rgb - contains three elements r, g, b, eg. c.rgb.r
211
212=item *
213
214rgba - contains four elements r, g, b, a, eg. c.rgba.a
215
216=item *
217
218cmyk - contains four elements c, m, y, k, eg. C<c.cmyk.y>. Note that
219Imager never uses CMYK colors except when reading/writing files.
220
221=item *
222
223channels - an array of four channels, eg C<c.channels[2]>.
224
225=back
226
227
228=for comment
229From: File imdatatypes.h
230
231=item i_fcolor
232
233This is the double/sample color type.
234
235Its layout exactly corresponds to i_color.
236
237
238=for comment
239From: File imdatatypes.h
240
241=item i_fill_t
242
243This is the "abstract" base type for Imager's fill types.
244
245Unless you're implementing a new fill type you'll typically treat this
246as an opaque type.
247
248
249=for comment
250From: File imdatatypes.h
251
252=item i_img_dim
253
254A signed integer type that represents an image dimension or ordinate.
255
256May be larger than int on some platforms.
257
258
bd8052a6
TC
259=for comment
260From: File imdatatypes.h
261
262
263=back
264
92bda632
TC
265=head2 Drawing
266
267=over
268
269=item i_arc(im, x, y, rad, d1, d2, color)
270
271
272Fills an arc centered at (x,y) with radius I<rad> covering the range
273of angles in degrees from d1 to d2, with the color.
274
275
276=for comment
5ca7e2ab 277From: File draw.c
92bda632
TC
278
279=item i_arc_aa(im, x, y, rad, d1, d2, color)
280
281
282Antialias fills an arc centered at (x,y) with radius I<rad> covering
283the range of angles in degrees from d1 to d2, with the color.
284
285
286=for comment
5ca7e2ab 287From: File draw.c
92bda632
TC
288
289=item i_arc_aa_cfill(im, x, y, rad, d1, d2, fill)
290
291
292Antialias fills an arc centered at (x,y) with radius I<rad> covering
293the range of angles in degrees from d1 to d2, with the fill object.
294
295
296=for comment
5ca7e2ab 297From: File draw.c
92bda632
TC
298
299=item i_arc_cfill(im, x, y, rad, d1, d2, fill)
300
301
302Fills an arc centered at (x,y) with radius I<rad> covering the range
303of angles in degrees from d1 to d2, with the fill object.
304
305
306=for comment
5ca7e2ab 307From: File draw.c
92bda632
TC
308
309=item i_box(im, x1, y1, x2, y2, color)
310
311
312Outlines the box from (x1,y1) to (x2,y2) inclusive with I<color>.
313
314
315=for comment
5ca7e2ab 316From: File draw.c
92bda632
TC
317
318=item i_box_cfill(im, x1, y1, x2, y2, fill)
319
320
321Fills the box from (x1,y1) to (x2,y2) inclusive with fill.
322
323
324=for comment
5ca7e2ab 325From: File draw.c
92bda632
TC
326
327=item i_box_filled(im, x1, y1, x2, y2, color)
328
329
330Fills the box from (x1,y1) to (x2,y2) inclusive with color.
331
332
333=for comment
5ca7e2ab 334From: File draw.c
92bda632
TC
335
336=item i_circle_aa(im, x, y, rad, color)
337
338
339Antialias fills a circle centered at (x,y) for radius I<rad> with
340color.
341
342
343=for comment
5ca7e2ab 344From: File draw.c
92bda632
TC
345
346=item i_flood_cfill(im, seedx, seedy, fill)
347
348
349Flood fills the 4-connected region starting from the point (seedx,
350seedy) with I<fill>.
351
352Returns false if (seedx, seedy) are outside the image.
353
354
355=for comment
5ca7e2ab 356From: File draw.c
3efb0915
TC
357
358=item i_flood_cfill_border(im, seedx, seedy, fill, border)
359
360
361Flood fills the 4-connected region starting from the point (seedx,
362seedy) with I<fill>, the fill stops when it reaches pixels of color
363I<border>.
364
365Returns false if (seedx, seedy) are outside the image.
366
367
368=for comment
5ca7e2ab 369From: File draw.c
92bda632
TC
370
371=item i_flood_fill(im, seedx, seedy, color)
372
373
374Flood fills the 4-connected region starting from the point (seedx,
375seedy) with I<color>.
376
377Returns false if (seedx, seedy) are outside the image.
378
379
380=for comment
5ca7e2ab 381From: File draw.c
3efb0915
TC
382
383=item i_flood_fill_border(im, seedx, seedy, color, border)
384
385
386Flood fills the 4-connected region starting from the point (seedx,
387seedy) with I<color>, fill stops when the fill reaches a pixels with
388color I<border>.
389
390Returns false if (seedx, seedy) are outside the image.
391
392
393=for comment
5ca7e2ab 394From: File draw.c
92bda632
TC
395
396=item i_glin(im, l, r, y, colors)
397
398
399Retrieves (r-l) pixels starting from (l,y) into I<colors>.
400
401Returns the number of pixels retrieved.
402
403
404=for comment
5ca7e2ab 405From: File imext.c
92bda632
TC
406
407=item i_glinf(im, l, r, y, colors)
408
409
410Retrieves (r-l) pixels starting from (l,y) into I<colors> as floating
411point colors.
412
413Returns the number of pixels retrieved.
414
415
416=for comment
5ca7e2ab 417From: File imext.c
92bda632
TC
418
419=item i_gpal(im, x, r, y, indexes)
420
421
422Reads palette indexes for the horizontal line (x, y) to (r-1, y) into
423indexes.
424
425Returns the number of indexes read.
426
427Always returns 0 for direct color images.
428
429
430=for comment
5ca7e2ab 431From: File imext.c
92bda632
TC
432
433=item i_gpix(im, x, y, color)
434
435
436Retrieves the I<color> of the pixel (x,y).
437
438Returns 0 if the pixel was retrieved, or -1 if not.
439
440
441=for comment
5ca7e2ab 442From: File imext.c
92bda632
TC
443
444=item i_gpixf(im, x, y, fcolor)
445
446
447Retrieves the color of the pixel (x,y) as a floating point color into
448I<fcolor>.
449
450Returns 0 if the pixel was retrieved, or -1 if not.
451
452
453=for comment
5ca7e2ab 454From: File imext.c
92bda632
TC
455
456=item i_gsamp(im, l, r, y, samp, chans, chan_count)
457
458
459Reads sample values from im for the horizontal line (l, y) to (r-1,y)
460for the channels specified by chans, an array of int with chan_count
461elements.
462
463If chans is NULL then the first chan_count channels are retrieved for
464each pixel.
465
466Returns the number of samples read (which should be (r-l) *
467chan_count)
468
469
470=for comment
5ca7e2ab 471From: File imext.c
92bda632
TC
472
473=item i_gsampf(im, l, r, y, samp, chans, chan_count)
474
475
476Reads floating point sample values from im for the horizontal line (l,
477y) to (r-1,y) for the channels specified by chans, an array of int
478with chan_count elements.
479
480If chans is NULL then the first chan_count channels are retrieved for
481each pixel.
482
483Returns the number of samples read (which should be (r-l) *
484chan_count)
485
486
487=for comment
5ca7e2ab 488From: File imext.c
92bda632
TC
489
490=item i_line(im, x1, y1, x2, y2, val, endp)
491
492
493Draw a line to image using bresenhams linedrawing algorithm
494
495 im - image to draw to
496 x1 - starting x coordinate
497 y1 - starting x coordinate
498 x2 - starting x coordinate
499 y2 - starting x coordinate
500 val - color to write to image
501 endp - endpoint flag (boolean)
502
503
504=for comment
5ca7e2ab 505From: File draw.c
92bda632
TC
506
507=item i_line_aa(im, x1, x2, y1, y2, color, endp)
508
509
510Antialias draws a line from (x1,y1) to (x2, y2) in color.
511
512The point (x2, y2) is drawn only if endp is set.
513
514
515=for comment
5ca7e2ab 516From: File draw.c
92bda632
TC
517
518=item i_plin(im, l, r, y, colors)
519
520
521Sets (r-l) pixels starting from (l,y) using (r-l) values from
522I<colors>.
523
524Returns the number of pixels set.
525
526
527=for comment
5ca7e2ab 528From: File imext.c
92bda632
TC
529
530=item i_plinf(im, l, r, fcolors)
531
532
533Sets (r-l) pixels starting from (l,y) using (r-l) floating point
534colors from I<colors>.
535
536Returns the number of pixels set.
537
538
539=for comment
5ca7e2ab 540From: File imext.c
92bda632
TC
541
542=item i_ppal(im, x, r, y, indexes)
543
544
545Writes palette indexes for the horizontal line (x, y) to (r-1, y) from
546indexes.
547
548Returns the number of indexes written.
549
550Always returns 0 for direct color images.
551
552
553=for comment
5ca7e2ab 554From: File imext.c
92bda632
TC
555
556=item i_ppix(im, x, y, color)
557
558
559Sets the pixel at (x,y) to I<color>.
560
561Returns 0 if the pixel was drawn, or -1 if not.
562
563Does no alpha blending, just copies the channels from the supplied
564color to the image.
565
566
567=for comment
5ca7e2ab 568From: File imext.c
92bda632
TC
569
570=item i_ppixf(im, x, y, fcolor)
571
572
573Sets the pixel at (x,y) to the floating point color I<fcolor>.
574
575Returns 0 if the pixel was drawn, or -1 if not.
576
577Does no alpha blending, just copies the channels from the supplied
578color to the image.
579
580
581=for comment
5ca7e2ab 582From: File imext.c
92bda632
TC
583
584
585=back
586
587=head2 Error handling
588
589=over
590
591=item i_clear_error()
592
92bda632
TC
593Clears the error stack.
594
595Called by any imager function before doing any other processing.
596
597
598=for comment
5ca7e2ab 599From: File error.c
92bda632
TC
600
601=item i_push_error(int code, char const *msg)
602
6cfee9d1 603Called by an Imager function to push an error message onto the stack.
92bda632
TC
604
605No message is pushed if the stack is full (since this means someone
606forgot to call i_clear_error(), or that a function that doesn't do
607error handling is calling function that does.).
608
609
610=for comment
5ca7e2ab 611From: File error.c
92bda632
TC
612
613=item i_push_errorf(int code, char const *fmt, ...)
614
92bda632
TC
615A version of i_push_error() that does printf() like formating.
616
6cfee9d1
TC
617Does not support perl specific format codes.
618
92bda632
TC
619
620=for comment
5ca7e2ab 621From: File error.c
92bda632
TC
622
623=item i_push_errorvf(int code, char const *fmt, va_list ap)
624
625
626Intended for use by higher level functions, takes a varargs pointer
627and a format to produce the finally pushed error message.
628
6cfee9d1
TC
629Does not support perl specific format codes.
630
92bda632
TC
631
632=for comment
5ca7e2ab 633From: File error.c
92bda632
TC
634
635
87deb14c
TC
636=back
637
638=head2 Files
639
640=over
641
642=item i_get_image_file_limits(&width, &height, &bytes)
643
644
645Retrieves the file limits set by i_set_image_file_limits().
646
647
648=for comment
5ca7e2ab 649From: File limits.c
87deb14c
TC
650
651=item i_int_check_image_file_limits(width, height, channels, sample_size)
652
653
654Checks the size of a file in memory against the configured image file
655limits.
656
657This also range checks the values to those permitted by Imager and
658checks for overflows in calculating the size.
659
660Returns non-zero if the file is within limits.
661
662This function is intended to be called by image file read functions.
663
664
665=for comment
5ca7e2ab 666From: File limits.c
87deb14c
TC
667
668=item i_set_image_file_limits(width, height, bytes)
669
670
671Set limits on the sizes of images read by Imager.
672
673Setting a limit to 0 means that limit is ignored.
674
675Negative limits result in failure.
676
677Returns non-zero on success.
678
679
680=for comment
5ca7e2ab 681From: File limits.c
87deb14c
TC
682
683
92bda632
TC
684=back
685
686=head2 Fills
687
688=over
689
92bda632
TC
690=item i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, count, segs)
691
692
693
694Creates a new general fill which fills with a fountain fill.
695
696
697=for comment
bea65b1f 698From: File filters.im
92bda632
TC
699
700=item i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy)
701
702
703Creates a new hatched fill with the fg color used for the 1 bits in
704the hatch and bg for the 0 bits. If combine is non-zero alpha values
705will be combined.
706
707If cust_hatch is non-NULL it should be a pointer to 8 bytes of the
708hash definition, with the high-bits to the left.
709
710If cust_hatch is NULL then one of the standard hatches is used.
711
712(dx, dy) are an offset into the hatch which can be used to unalign adjoining areas, or to align the origin of a hatch with the the side of a filled area.
713
714
715=for comment
5ca7e2ab 716From: File fills.c
92bda632
TC
717
718=item i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy)
719
720
721Creates a new hatched fill with the fg color used for the 1 bits in
722the hatch and bg for the 0 bits. If combine is non-zero alpha values
723will be combined.
724
725If cust_hatch is non-NULL it should be a pointer to 8 bytes of the
726hash definition, with the high-bits to the left.
727
728If cust_hatch is NULL then one of the standard hatches is used.
729
730(dx, dy) are an offset into the hatch which can be used to unalign adjoining areas, or to align the origin of a hatch with the the side of a filled area.
731
732
733=for comment
5ca7e2ab 734From: File fills.c
92bda632
TC
735
736=item i_new_fill_image(im, matrix, xoff, yoff, combine)
737
738
739Create an image based fill.
740
741matrix is an array of 9 doubles representing a transformation matrix.
742
743xoff and yoff are the offset into the image to start filling from.
744
745
746=for comment
5ca7e2ab 747From: File fills.c
92bda632
TC
748
749=item i_new_fill_solid(color, combine)
750
751
752Create a solid fill based on an 8-bit color.
753
754If combine is non-zero then alpha values will be combined.
755
756
757=for comment
5ca7e2ab 758From: File fills.c
92bda632
TC
759
760=item i_new_fill_solidf(color, combine)
761
762
763Create a solid fill based on a float color.
764
765If combine is non-zero then alpha values will be combined.
766
767
6cfee9d1
TC
768=for comment
769From: File fills.c
770
771=item i_fill_destroy(fill)
772
773Call to destroy any fill object.
774
775
92bda632 776=for comment
5ca7e2ab 777From: File fills.c
92bda632
TC
778
779
780=back
781
782=head2 Image
783
784=over
785
786=item i_copy(src)
787
788
789Creates a new image that is a copy of src.
790
791Tags are not copied, only the image data.
792
793Returns: i_img *
794
795
796=for comment
5ca7e2ab 797From: File image.c
92bda632
TC
798
799=item i_copyto(dest, src, x1, y1, x2, y2, tx, ty)
800
801
802Copies image data from the area (x1,y1)-[x2,y2] in the source image to
803a rectangle the same size with it's top-left corner at (tx,ty) in the
804destination image.
805
806If x1 > x2 or y1 > y2 then the corresponding co-ordinates are swapped.
807
808
809=for comment
9b1ec2b8 810From: File paste.im
92bda632
TC
811
812=item i_copyto_trans(im, src, x1, y1, x2, y2, tx, ty, trans)
813
814
815(x1,y1) (x2,y2) specifies the region to copy (in the source coordinates)
816(tx,ty) specifies the upper left corner for the target image.
817pass NULL in trans for non transparent i_colors.
818
819
92bda632 820=for comment
5ca7e2ab 821From: File image.c
92bda632
TC
822
823=item i_img_info(im, info)
824
825
826Return image information
827
828 im - Image pointer
829 info - pointer to array to return data
830
831info is an array of 4 integers with the following values:
832
833 info[0] - width
834 info[1] - height
835 info[2] - channels
836 info[3] - channel mask
837
838
839=for comment
5ca7e2ab 840From: File image.c
92bda632
TC
841
842=item i_rubthru(im, src, tx, ty, src_minx, src_miny, src_maxx, src_maxy )
843
844
845Takes the sub image I<src[src_minx, src_maxx)[src_miny, src_maxy)> and
846overlays it at (I<tx>,I<ty>) on the image object.
847
848The alpha channel of each pixel in I<src> is used to control how much
849the existing colour in I<im> is replaced, if it is 255 then the colour
850is completely replaced, if it is 0 then the original colour is left
851unmodified.
852
853
854=for comment
fe415ad2 855From: File rubthru.im
92bda632
TC
856
857
858=back
859
6cfee9d1 860=head2 Image creation/destruction
92bda632
TC
861
862=over
863
864=item i_img_16_new(x, y, ch)
865
866
867Create a new 16-bit/sample image.
868
869Returns the image on success, or NULL on failure.
870
871
872=for comment
5ca7e2ab 873From: File img16.c
92bda632
TC
874
875=item i_img_8_new(x, y, ch)
876
877
9167a5c6 878
92bda632
TC
879Creates a new image object I<x> pixels wide, and I<y> pixels high with
880I<ch> channels.
881
882
883=for comment
5ca7e2ab 884From: File image.c
92bda632
TC
885
886=item i_img_double_new(int x, int y, int ch)
887
92bda632
TC
888Creates a new double per sample image.
889
890
891=for comment
5ca7e2ab 892From: File imgdouble.c
92bda632
TC
893
894=item i_img_pal_new(x, y, channels, maxpal)
895
896
897Creates a new paletted image of the supplied dimensions.
898
9167a5c6
TC
899I<maxpal> is the maximum palette size and should normally be 256.
900
92bda632
TC
901Returns a new image or NULL on failure.
902
903
904=for comment
5ca7e2ab 905From: File palimg.c
92bda632
TC
906
907=item i_sametype(i_img *im, int xsize, int ysize)
908
909
910Returns an image of the same type (sample size, channels, paletted/direct).
911
912For paletted images the palette is copied from the source.
913
914
915=for comment
5ca7e2ab 916From: File image.c
92bda632
TC
917
918=item i_sametype_chans(i_img *im, int xsize, int ysize, int channels)
919
920
921Returns an image of the same type (sample size).
922
923For paletted images the equivalent direct type is returned.
924
925
6cfee9d1
TC
926=for comment
927From: File image.c
928
929=item i_img_destroy(img)
930
931Destroy an image object
932
933
92bda632 934=for comment
5ca7e2ab 935From: File image.c
92bda632
TC
936
937
bd8052a6
TC
938=back
939
940=head2 Image Implementation
941
942=over
943
944=item i_img_alloc()
945
946Allocates a new i_img structure.
947
948When implementing a new image type perform the following steps in your
949image object creation function:
950
951=over
952
953=item 1.
954
955allocate the image with i_img_alloc().
956
957=item 2.
958
959initialize any function pointers or other data as needed, you can
960overwrite the whole block if you need to.
961
962=item 3.
963
964initialize Imager's internal data by calling i_img_init() on the image
965object.
966
967=back
968
969
970=for comment
971From: File image.c
972
973=item i_img_init(img)
974
975Imager interal initialization of images.
976
977Currently this does very little, in the future it may be used to
978support threads, or color profiles.
979
980
981=for comment
982From: File image.c
983
984
bea65b1f
TC
985=back
986
987=head2 Image Information
988
989=over
990
991=item i_img_color_channels(im)
992
993
994The number of channels holding color information.
995
996
997=for comment
998From: File immacros.h
999
6cfee9d1
TC
1000=item i_img_get_height(im)
1001
1002Returns the height in pixels of the image.
1003
1004
1005=for comment
1006From: File image.c
1007
1008=item i_img_get_width(im)
1009
1010Returns the width in pixels of the image.
1011
1012
1013=for comment
1014From: File image.c
1015
1016=item i_img_getchannels(im)
1017
1018Get the number of channels in I<im>.
1019
1020
1021=for comment
1022From: File image.c
1023
1024=item i_img_getmask(im)
1025
1026Get the image channel mask for I<im>.
1027
1028
1029=for comment
1030From: File image.c
1031
bea65b1f
TC
1032=item i_img_has_alpha(im)
1033
1034
1035Return true if the image has an alpha channel.
1036
1037
1038=for comment
1039From: File immacros.h
1040
6cfee9d1
TC
1041=item i_img_setmask(im, ch_mask)
1042
1043Set the image channel mask for I<im> to I<ch_mask>.
1044
1045The image channel mask gives some control over which channels can be
1046written to in the image.
1047
1048
1049=for comment
1050From: File image.c
1051
bea65b1f 1052
92bda632
TC
1053=back
1054
1055=head2 Image quantization
1056
1057=over
1058
1059=item i_quant_makemap(quant, imgs, count)
1060
1061
1062Analyzes the I<count> images in I<imgs> according to the rules in
1063I<quant> to build a color map (optimal or not depending on
1064quant->make_colors).
1065
1066
1067=for comment
5ca7e2ab 1068From: File quant.c
92bda632
TC
1069
1070=item i_quant_translate(quant, img)
1071
1072
1073Quantize the image given the palette in quant.
1074
1075On success returns a pointer to a memory block of img->xsize *
1076img->ysize i_palidx entries.
1077
1078On failure returns NULL.
1079
1080You should call myfree() on the returned block when you're done with
1081it.
1082
1083This function will fail if the supplied palette contains no colors.
1084
1085
1086=for comment
5ca7e2ab 1087From: File quant.c
92bda632
TC
1088
1089=item i_quant_transparent(quant, data, img, trans_index)
1090
1091
1092Dither the alpha channel on I<img> into the palette indexes in
1093I<data>. Pixels to be transparent are replaced with I<trans_pixel>.
1094
1095The method used depends on the tr_* members of quant.
1096
1097
1098=for comment
5ca7e2ab 1099From: File quant.c
92bda632
TC
1100
1101
bd8052a6
TC
1102=back
1103
1104=head2 Logging
1105
1106=over
1107
6cfee9d1
TC
1108=item i_lhead(file, line)
1109
1110This is an internal function called by the mm_log() macro.
1111
1112
1113=for comment
1114From: File log.c
1115
bd8052a6
TC
1116=item i_loog(level, format, ...)
1117
1118This is an internal function called by the mm_log() macro.
1119
1120
1121=for comment
1122From: File log.c
1123
1124=item mm_log((level, format, ...))
1125
1126This is the main entry point to logging. Note that the extra set of
1127parentheses are required due to limitations in C89 macros.
1128
1129This will format a string with the current file and line number to the
1130log file if logging is enabled.
1131
1132
1133=for comment
1134From: File log.h
1135
1136
92bda632
TC
1137=back
1138
1139=head2 Paletted images
1140
1141=over
1142
1143=item i_addcolors(im, colors, count)
1144
1145
1146Adds colors to the image's palette.
1147
1148On success returns the index of the lowest color added.
1149
1150On failure returns -1.
1151
1152Always fails for direct color images.
1153
1154
1155=for comment
5ca7e2ab 1156From: File imext.c
92bda632
TC
1157
1158=item i_colorcount(im)
1159
1160
1161Returns the number of colors in the image's palette.
1162
1163Returns -1 for direct images.
1164
1165
1166=for comment
5ca7e2ab 1167From: File imext.c
92bda632
TC
1168
1169=item i_findcolor(im, color, &entry)
1170
1171
1172Searches the images palette for the given color.
1173
1174On success sets *I<entry> to the index of the color, and returns true.
1175
1176On failure returns false.
1177
1178Always fails on direct color images.
1179
1180
1181=for comment
5ca7e2ab 1182From: File imext.c
92bda632
TC
1183
1184=item i_getcolors(im, index, colors, count)
1185
1186
1187Retrieves I<count> colors starting from I<index> in the image's
1188palette.
1189
1190On success stores the colors into I<colors> and returns true.
1191
1192On failure returns false.
1193
1194Always fails for direct color images.
1195
1196Fails if there are less than I<index>+I<count> colors in the image's
1197palette.
1198
1199
1200=for comment
5ca7e2ab 1201From: File imext.c
92bda632
TC
1202
1203=item i_maxcolors(im)
1204
1205
1206Returns the maximum number of colors the palette can hold for the
1207image.
1208
1209Returns -1 for direct color images.
1210
1211
1212=for comment
5ca7e2ab 1213From: File imext.c
92bda632
TC
1214
1215=item i_setcolors(im, index, colors, count)
1216
1217
1218Sets I<count> colors starting from I<index> in the image's palette.
1219
1220On sucess returns true.
1221
1222On failure returns false.
1223
1224The image must have at least I<index>+I<count> colors in it's palette
1225for this to succeed.
1226
1227Always fails on direct color images.
1228
1229
1230=for comment
5ca7e2ab 1231From: File imext.c
92bda632
TC
1232
1233
1234=back
1235
1236=head2 Tags
1237
1238=over
1239
1240=item i_tags_delbycode(tags, code)
1241
1242
1243Delete any tags with the given code.
1244
1245Returns the number of tags deleted.
1246
1247
1248=for comment
5ca7e2ab 1249From: File tags.c
92bda632
TC
1250
1251=item i_tags_delbyname(tags, name)
1252
1253
1254Delete any tags with the given name.
1255
1256Returns the number of tags deleted.
1257
1258
1259=for comment
5ca7e2ab 1260From: File tags.c
92bda632
TC
1261
1262=item i_tags_delete(tags, index)
1263
1264
1265Delete a tag by index.
1266
1267Returns true on success.
1268
1269
1270=for comment
5ca7e2ab 1271From: File tags.c
92bda632
TC
1272
1273=item i_tags_destroy(tags)
1274
1275
1276Destroys the given tags structure. Called by i_img_destroy().
1277
1278
1279=for comment
5ca7e2ab 1280From: File tags.c
92bda632
TC
1281
1282=item i_tags_find(tags, name, start, &entry)
1283
1284
1285Searchs for a tag of the given I<name> starting from index I<start>.
1286
1287On success returns true and sets *I<entry>.
1288
1289On failure returns false.
1290
1291
1292=for comment
5ca7e2ab 1293From: File tags.c
92bda632
TC
1294
1295=item i_tags_findn(tags, code, start, &entry)
1296
1297
1298Searchs for a tag of the given I<code> starting from index I<start>.
1299
1300On success returns true and sets *I<entry>.
1301
1302On failure returns false.
1303
1304
1305=for comment
5ca7e2ab 1306From: File tags.c
92bda632
TC
1307
1308=item i_tags_get_color(tags, name, code, &value)
1309
1310
1311Retrieve a tag specified by name or code as color.
1312
1313On success sets the i_color *I<value> to the color and returns true.
1314
1315On failure returns false.
1316
1317
1318=for comment
5ca7e2ab 1319From: File tags.c
92bda632
TC
1320
1321=item i_tags_get_float(tags, name, code, value)
1322
1323
1324Retrieves a tag as a floating point value.
1325
1326If the tag has a string value then that is parsed as a floating point
1327number, otherwise the integer value of the tag is used.
1328
1329On success sets *I<value> and returns true.
1330
1331On failure returns false.
1332
1333
1334=for comment
5ca7e2ab 1335From: File tags.c
92bda632
TC
1336
1337=item i_tags_get_int(tags, name, code, &value)
1338
1339
1340Retrieve a tag specified by name or code as an integer.
1341
3efb0915 1342On success sets the int *I<value> to the integer and returns true.
92bda632
TC
1343
1344On failure returns false.
1345
1346
1347=for comment
5ca7e2ab 1348From: File tags.c
92bda632
TC
1349
1350=item i_tags_get_string(tags, name, code, value, value_size)
1351
1352
1353Retrieves a tag by name or code as a string.
1354
1355On success copies the string to value for a max of value_size and
1356returns true.
1357
1358On failure returns false.
1359
1360value_size must be at least large enough for a string representation
1361of an integer.
1362
1363The copied value is always NUL terminated.
1364
1365
1366=for comment
5ca7e2ab 1367From: File tags.c
92bda632
TC
1368
1369=item i_tags_new(i_img_tags *tags)
1370
1371
1372Initialize a tags structure. Should not be used if the tags structure
1373has been previously used.
1374
1375This should be called tags member of an i_img object on creation (in
1376i_img_*_new() functions).
1377
1378To destroy the contents use i_tags_destroy()
1379
1380
1381=for comment
5ca7e2ab 1382From: File tags.c
92bda632
TC
1383
1384=item i_tags_set(tags, name, data, size)
1385
92bda632
TC
1386Sets the given tag to the string I<data>
1387
6cfee9d1
TC
1388If size is -1 then the strlen(I<data>) bytes are stored.
1389
1390Even on failure, if an existing tag I<name> exists, it will be
1391removed.
1392
92bda632
TC
1393
1394=for comment
5ca7e2ab 1395From: File tags.c
92bda632
TC
1396
1397=item i_tags_set_color(tags, name, code, &value)
1398
1399
1400Stores the given color as a tag with the given name and code.
1401
1402
1403=for comment
5ca7e2ab 1404From: File tags.c
92bda632
TC
1405
1406=item i_tags_set_float(tags, name, code, value)
1407
1408
1409Equivalent to i_tags_set_float2(tags, name, code, value, 30).
1410
1411
1412=for comment
5ca7e2ab 1413From: File tags.c
92bda632
TC
1414
1415=item i_tags_set_float2(tags, name, code, value, places)
1416
1417
1418Sets the tag with the given name and code to the given floating point
1419value.
1420
1421Since tags are strings or ints, we convert the value to a string before
1422storage at the precision specified by C<places>.
1423
1424
1425=for comment
5ca7e2ab 1426From: File tags.c
92bda632
TC
1427
1428=item i_tags_setn(tags, name, idata)
1429
92bda632
TC
1430Sets the given tag to the integer I<idata>
1431
6cfee9d1
TC
1432Even on failure, if an existing tag I<name> exists, it will be
1433removed.
d5477d3d
TC
1434
1435
1436=for comment
6cfee9d1 1437From: File tags.c
d5477d3d
TC
1438
1439
92bda632
TC
1440=back
1441
1442
1443=head1 AUTHOR
1444
1445Tony Cook <tony@imager.perl.org>
1446
1447=head1 SEE ALSO
1448
1449Imager, Imager::ExtUtils, Imager::Inline
1450
1451=cut