Imager...terface(3pm)
π Imager...terface(3pm) π
User Contributed Perl Documentation bestie!! This is the page for Imager...terface(3pm) β yes, it's giving C-level virtual image interface tea, and we are sipping. π΅
β¨ NAME β¨
Imager::interface.pod β describes the C level virtual image interface. Periodt. π
π¦ SYNOPSIS π¦
(blank β no synopsis here, just vibes and then the actual lore below)
πΈ DESCRIPTION πΈ
The Imager virtual interface is here to let image types get created for special purposes β both so images with different sample sizes and organizations can be accessed consistently, and so synthesized or virtual images can be created. Slay. β¨
This is a C level interface, not a Perl one. Ngl, important.
πΌοΈ Existing Images πΌοΈ
As of this writing, these concrete image types exist:
- 8-bit/sample direct images
- 16-bit/sample direct images
- double/sample direct images
- 8-bit/sample 8-bit/index paletted images
Currently there is only one virtual image type:
- masked images, where a mask image can control write access to an underlying image π
Other possible concrete images include:
"bitmaps", 1 bit/sample images (perhaps limited to a single channel)- 16-bit/index paletted images
Some other possible virtual images:
- image alpha combining, where the combining function can be specified (see the layer modes in graphical editors like the GIMP or Photoshop)
π§ THE INTERFACE π§
Each image type needs to define a bunch of functions that implement the image operations. The image structure includes information that describes the image, and you can use that info to figure out the image's structure:
channelsβ the number of samples kept for each pixel in the image. For paletted images, the samples are kept for each entry in the palette.xsize,ysizeβ the dimensions of the image in pixels.bytesβ the number of bytes of data kept for the image. Zero for virtual images. Does not include the space required for the palette for paletted images.ch_maskβ controls which samples will be written to for direct images.bitsβ the number of bits kept for each sample. There are enum valuesi_8_bits,i_16_bitsandi_double_bits(64).typeβ the type of image, eitheri_direct_typeori_palette_type. Direct images keep the samples for every pixel image, whilei_palette_typeimages keep an index into a color table for each pixel.virtualβ whether the image keeps any pixel data. If this is non-zero thenidatapoints to image data, otherwise it points to implementation defined data, thoughext_datais more likely to be used for that.idataβ image data. If the image is 8-bit direct, non-virtual, then this consists of each sample of the image stored one after another, otherwise it is implementation defined.tagsβ will be used to store meta-data for an image, eg. tags from a TIFF file, or animation information from a GIF file. This should be initialized with a call toi_tags_new()in your image constructor if creating a new image type.ext_dataβ for internal use of image types. This is not released by the standardi_img_exorcise()function. If you create a new image type and want to store a pointer to allocated memory here you should pointi_f_destroyat a function that will release the data.
If a caller has no knowledge of the internal format of an image, the caller must call the appropriate image function pointer. Imager provides macros that wrap these functions, so it isn't necessary to call them directly. π«Ά
Many functions have a similar function with an 'f' suffix, these take or return samples specified with floating point values rather than 8-bit integers (unsigned char). Floating point samples are returned in the range 0 to 1 inclusive. π
i_f_ppix(im,x,y,color)/i_f_ppixf(im,x,y,fcolor)β stores the specified color at pixel(x,y)in the image. If the pixel can be stored return0, otherwise-1. An image type may choose to return0under some circumstances, eg. writing to a masked area of an image. Thecolororfcoloralways contains the actual samples to be written, rather than a palette index.i_f_plin(im,l,r,y,colors)/i_f_plinf(im,l,r,y,fcolors)β stores(r-l)pixels at positions(l,y)...(r-1, y)from the array specified bycolors(orfcolors). Returns the number of pixels written to. Iflis negative it will return0. Ifr > im->xsizethen only(im->xsize - l)will be written.i_f_gpix(im,x,y,color)/i_f_gpixf(im,x,y,fcolor)β retrieves a single pixel from position(x,y). This returns the samples rather than the index for paletted images.i_f_glin(im,l,r,y,colors)/i_f_glinf(im,l,r,y,fcolors)β retrieves(r-l)pixels from positions(l, y)through(r-1, y)into the array specified by colors. Returns the number of pixels retrieved. Ifl < 0no pixels are retrieved. Ifr > im->xsizethen pixels(l, y)...(im->xsize-1, y)are retrieved. Retrieves the samples rather than the color indexes for paletted images.i_f_gsamp(im,l,r,y,samples,chans,chan_count)/i_f_gsampf(im,l,r,y,fsamples,chans,chan_count)β retrieves samples from channels specified bychans(for lengthchan_count) from pixels at positions(l,y)...(r-1, y). IfchansisNULLthen samples from channels0...chan_count-1will be retrieved. Returns the number of sample retrieved (not the number of channels). If a channel inchansis not present in the image orl < 0, returns0. Ifr > im->xsize, then the samples from(l,y)...(im->xsize-1, y)are returned.
The following are for images where type == i_palette_type only. π
i_f_gpal(im,l,r,y,vals)β retrieves color indexes from the image for pixels(l, y)...(r-1, y)intovals. Returns the number of indexes retrieved.i_f_ppal(im,l,r,y,vals)β stores color indexes into the image for pixels(l, y)...(r-1, y)fromvals. Returns the number of indexes retrieved. If indexes are outside the range of the images palette, then you may have problems reading those pixels withi_gpix()ori_glin(). πi_f_addcolors(im,colors,count)β adds thecountcolors to the image's palette. Returns the index of the first color added, or-1if there is not enough space forcountcolors.i_f_getcolors(im,index,colors,count)β retrievescountcolors from the image's palette starting from entryindexin the palette. Returns non-zero on success.i_f_colorcount(im)β returns the number of colors in the image's palette. Returns-1if this is not a paletted image.i_f_maxcolors(im)β returns the maximum number of colors that can fit in the image's palette. Returns-1if this is not a paletted image.i_f_findcolor(im,color,entry)β searches the image's palette for the specified color, setting*entryto the index and returning non-zero. Returns zero if the color is not found.i_f_setcolors_t(im,index,colors,count)β setscountcolors starting fromindexin the image from the array colors. The colors to be set must already have entries in the image's palette. Returns non-zero on success.
Finally, the i_f_destroy function pointer can be set which is called when the image is destroyed. This can be used to release memory pointed to by ext_data or release any other resources. πβ¨
When writing to a paletted image with i_ppix() or i_plin() and the color you are writing doesn't exist in the image, then it's possible that the image will be internally converted to a direct image with the same number of channels. Big mood, but also a warning.
π οΈ TOOLS π οΈ
Several functions have been written to simplify creating new image types. These tools are available by including imagei.h. π§°
π§ Floating point wrappers π§
These functions implement the floating point sample versions of each interface function in terms of the integer sample version. These are:
i_ppixf_fpi_gpixf_fpi_plinf_fpi_glinf_fpi_gsampf_fp
π Forwarding functions π
These functions are used in virtual images where the call should simply be forwarded to the underlying image. The underlying image is assumed to be the first pointer in a structure pointed at by ext_data.
If this is not the case then these functions will just crash :) π
i_addcolors_forwardi_getcolors_forwardi_colorcount_forwardi_maxcolors_forwardi_findcolor_forwardi_setcolors_forward
𧬠Sample macros π§¬
imagei.h defines several macros for converting samples between different sizes.
Each macro is of the form "Sample"size"To"size where size is one of 8, 16, or F (for floating-point samples).
SampleFTo16(sample)Sample16ToF(sample)SampleFTo8(sample)Sample8ToF(sample)Sample16To8(num)Sample8To16(num)
π AUTHOR π
Tony Cook <tonyc@cpan.org>, Arnar M. Hrafnkelsson
That's the whole page, bestie!! Signing off from Imager...terface(3pm) β perl v5.42.3, 2026-08-19. Byeee πβ¨
π¦ where this page comes from
- ubuntu stonking: libimager-perl 1.035+dfsg-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms