Imager...rocess(3pm)
π NAME π
Imager::Preprocess β it's a lil preprocessor bestie, and its whole job is handling multiple sample sizes so you don't have to write the same algorithm twice πβ¨
(This is from the User Contributed Perl Documentation, page vibes courtesy of Imager...rocess(3pm).)
πΈ SYNOPSIS πΈ
/* in the source: */
#code condition true to work with 8-bit samples
... code using preprocessor types/values ...
#/code
# process and make #line directives
perl -MImager::Preprocess -epreprocess foo.im foo.c
# process and no #line directives
perl -MImager::Preprocess -epreprocess -l foo.im foo.c
That's the whole ritual, no cap π«
π¦ DESCRIPTION π¦
Okay so listen π β this is a simple preprocessor, and its entire main character purpose is reducing duplication of source code when you're implementing an algorithm both for 8-bit samples and double samples in Imager. Like, one source, two flavors. Slay π
Imager's Makefile.PL currently scans the MANIFEST for .im files and adds Makefile files to convert these to .c files. So that's happening automatically, iykyk π
The beginning of a sample-independent section of code is preceded by:
#code expression
where expression should return true if processing should be done at 8-bits/sample.
You can also use a #code block around a function definition to produce 8-bit and double sample versions of a function π₯ In this case #code has no expression and you will need to use IM_SUFFIX() to produce different function names.
The end of a sample-independent section of code is terminated by:
#/code
β οΈ #code sections cannot be nested. Like, don't even try it π
π#/codewithout a starting#codeis an error. Periodt.
π§ Defining extra macros
You can also define extra sample-size dependent macros with #!define:
"#define" common-name eight-bit-name floating-point-name
β¨ The types and values β¨
The following types and values are defined in a #code section β memorize these, they're iconic π
IM_GPIX("im", "x", "y", &col)IM_GLIN("im", "l", "r", "y", "colors")IM_PPIX("im", "x", "y", &col)IM_PLIN("im", "x", "y", "colors")IM_GSAMP("im", "l", "r", "y", "samples", "chans", "chan_count")- These correspond to the appropriate image function, eg.
IM_GPIX()becomesi_gpix()ori_gpixf()as appropriate. Cute, right? π«Ά
- These correspond to the appropriate image function, eg.
IM_ADAPT_COLORS("dest_channels", "src_channels", "colors", "count")- Call
i_adapt_colors()ori_adapt_fcolors().
- Call
IM_FILL_COMBINE("fill")β retrieve the combine function from a fill object.IM_FILL_FILLER("fill")β retrieve thefill_with_*function from a fill object.IM_ABS(sample)β calculate the absolute value of anIM_WORK_Tvalue.IM_SAMPLE_MAXβ maximum value for a sample.IM_SAMPLE_MAX2β maximum value for a sample, squared.IM_SAMPLE_Tβ type of a sample (i_sample_tori_fsample_t).IM_COLORβ color type, eitheri_colorori_fcolor.IM_WORK_Tβ working sample type, eitherintordouble.IM_Sfβ format string for the sample type,"%d"or"%f".IM_Wfβ format string for the work type,"%d"or"%f".IM_SUFFIX(identifier)β adds_8or_doubleonto the end of identifier.IM_EIGHT_BITβ this is a macro defined only in 8-bit/sample code.
Other types, functions and values may be added in the future. So stay tuned bestie π
π AUTHOR π
Tony Cook <tonyc@cpan.org> β thank you for your service, king π«‘π
Okay that's the whole page!! Brought to you by perl v5.42.3 dated 2026-08-19, and yes that's the vibe, that's the version, mwah πβ¨
π¦ 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