---
name: "Imager::Preprocess"
section: "3pm"
platform: "linux"
package: "libimager-perl"
version: "1.027+dfsg-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Imager::Preprocess"
---

# Imager::Preprocess(3pm)

simple preprocessor for handling multiple sample sizes

## NAME

Imager::Preprocess - simple preprocessor for handling multiple sample sizes

## 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
```

## DESCRIPTION

This is a simple preprocessor that aims to reduce duplication of source code when implementing an algorithm both for 8-bit samples and double samples in Imager.

Imager's `"Makefile.PL"` currently scans the *MANIFEST* for *.im* files and adds Makefile files to convert these to *.c* files.

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.

\#/code without a starting #code is an error.

You can also define extra sample-size dependent macros with `"#!define"`:

`"#define"` *common-name* *eight-bit-name* *floating-point-name*

The following types and values are defined in a #code section:

- •

  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.

- •

  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.

## AUTHOR

Tony Cook \<tonyc@cpan.org\>
