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 πŸ™ˆ
πŸ’€ #/code without a starting #code is 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() becomes i_gpix() or i_gpixf() as appropriate. Cute, right? 🫢
  • IM_ADAPT_COLORS("dest_channels", "src_channels", "colors", "count")
    • Call i_adapt_colors() or i_adapt_fcolors().
  • IM_FILL_COMBINE("fill") β€” retrieve the combine function from a fill object.
  • IM_FILL_FILLER("fill") β€” retrieve the fill_with_* function from a fill object.
  • IM_ABS(sample) β€” calculate the absolute value of an IM_WORK_T value.
  • 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_t or i_fsample_t).
  • IM_COLOR β€” color type, either i_color or i_fcolor.
  • IM_WORK_T β€” working sample type, either int or double.
  • 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 _8 or _double onto 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