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