VipsArithmetic

VipsArithmetic — operations which perform pixel arithmetic, trig, log, statistics

Stability Level

Stable, unless otherwise indicated

Synopsis

#include <vips/vips.h>

                    VipsArithmetic;
                    VipsArithmeticClass;
void                (*VipsArithmeticProcessFn)          (struct _VipsArithmetic *arithmetic,
                                                         VipsPel *out,
                                                         VipsPel **in,
                                                         int width);
void                vips_arithmetic_compile             (VipsArithmeticClass *klass);
VipsVector *        vips_arithmetic_get_program         (VipsArithmeticClass *klass,
                                                         VipsBandFormat fmt);
VipsVector *        vips_arithmetic_get_vector          (VipsArithmeticClass *klass,
                                                         VipsBandFormat fmt);
void                vips_arithmetic_set_format_table    (VipsArithmeticClass *klass,
                                                         const VipsBandFormat *format_table);

Object Hierarchy

  GObject
   +----VipsObject
         +----VipsOperation
               +----VipsArithmetic
                     +----VipsBinary
                     +----VipsUnary

Properties

  "out"                      VipsImage*            : Read / Write

Description

These operations perform pixel arithmetic, that is, they perform an arithmetic operation, such as addition, on every pixel in an image or a pair of images. All (except in a few cases noted below) will work with images of any type or any mixture of types, of any size and of any number of bands.

For binary operations, if the number of bands differs, one of the images must have one band. In this case, an n-band image is formed from the one-band image by joining n copies of the one-band image together, and then the two n-band images are operated upon.

In the same way, for operations that take an array constant, such as im_remainder_vec(), you can mix single-element arrays or single-band images freely.

Arithmetic operations try to preserve precision by increasing the number of bits in the output image when necessary. Generally, this follows the ANSI C conventions for type promotion, so multiplying two IM_BANDFMT_UCHAR images together, for example, produces a IM_BANDFMT_USHORT image, and taking the im_costra() of a IM_BANDFMT_USHORT image produces IM_BANDFMT_FLOAT image.

For binary arithmetic operations, type promotion occurs in two stages. First, the two input images are cast up to the smallest common format, that is, the type with the smallest range that can represent the full range of both inputs. This conversion can be represented as a table:

Table 1. Smallest common format

in2/in1 uchar char ushort short uint int float double complex double complex
uchar ushort short ushort short uint int float double complex double complex
char short short short short int int float double complex double complex
ushort ushort short ushort short uint int float double complex double complex
short short short short short int int float double complex double complex
uint uint int uint int uint int float double complex double complex
int int int int int int int float double complex double complex
float float float float float float float float double complex double complex
double double double double double double double double double double complex double complex
complex complex complex complex complex complex complex complex double complex complex double complex
double complex double complex double complex double complex double complex double complex double complex double complex double complex double complex double complex


In the second stage, the operation is performed between the two identical types to form the output. The details vary between operations, but generally the principle is that the output type should be large enough to represent the whole rage of possible values, except that int never becomes float.

Details

VipsArithmetic

typedef struct _VipsArithmetic VipsArithmetic;


VipsArithmeticClass

typedef struct {
	VipsOperationClass parent_class;

	/* For each input format, what output format. Used for arithmetic
	 * too, since we cast inputs to match.
	 */
	const VipsBandFormat *format_table;

	/* A vector program for each input type.
	 */
	VipsVector *vectors[VIPS_FORMAT_LAST];

	/* ... and if we've set a program for this format.
	 */
	gboolean vector_program[VIPS_FORMAT_LAST];

	/* The buffer processor.
	 */
	VipsArithmeticProcessFn process_line;
} VipsArithmeticClass;


VipsArithmeticProcessFn ()

void                (*VipsArithmeticProcessFn)          (struct _VipsArithmetic *arithmetic,
                                                         VipsPel *out,
                                                         VipsPel **in,
                                                         int width);


vips_arithmetic_compile ()

void                vips_arithmetic_compile             (VipsArithmeticClass *klass);


vips_arithmetic_get_program ()

VipsVector *        vips_arithmetic_get_program         (VipsArithmeticClass *klass,
                                                         VipsBandFormat fmt);


vips_arithmetic_get_vector ()

VipsVector *        vips_arithmetic_get_vector          (VipsArithmeticClass *klass,
                                                         VipsBandFormat fmt);


vips_arithmetic_set_format_table ()

void                vips_arithmetic_set_format_table    (VipsArithmeticClass *klass,
                                                         const VipsBandFormat *format_table);

Property Details

The "out" property

  "out"                      VipsImage*            : Read / Write

Output image.

See Also

boolean