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