Leptonica 1.68
C Image Processing Library

pixacc.c File Reference

Simple interface for grayscale image arithmetic. More...

#include <stdio.h>
#include <stdlib.h>
#include "allheaders.h"

Go to the source code of this file.

Functions

PIXACCpixaccCreate (l_int32 w, l_int32 h, l_int32 negflag)
PIXACCpixaccCreateWithPix (PIX *pix, l_int32 negflag)
void pixaccDestroy (PIXACC **ppixacc)
PIXpixaccFinal (PIXACC *pixacc, l_int32 outdepth)
PIXpixaccGetPix (PIXACC *pixacc)
l_int32 pixaccGetOffset (PIXACC *pixacc)
l_int32 pixaccAdd (PIXACC *pixacc, PIX *pix)
l_int32 pixaccSubtract (PIXACC *pixacc, PIX *pix)
l_int32 pixaccMultConst (PIXACC *pixacc, l_float32 factor)
l_int32 pixaccMultConstAccumulate (PIXACC *pixacc, PIX *pix, l_float32 factor)

Detailed Description

Simple interface for grayscale image arithmetic.

    Pixacc creation, destruction
         PIXACC   *pixaccCreate()
         PIXACC   *pixaccCreateWithPix()
         void      pixaccDestroy()

    Pixacc finalization
         PIX      *pixaccFinal()

    Pixacc accessors
         PIX      *pixaccGetPix()
         l_int32   pixaccGetOffset()

    Pixacc accumulators
         l_int32   pixaccAdd()
         l_int32   pixaccSubtract()
         l_int32   pixaccMultConst()
         l_int32   pixaccMultConstAccumulate()

This is a simple interface for some of the pixel arithmetic operations 
in pixarith.c.  These are easy to code up, but not as fast as
hand-coded functions that do arithmetic on corresponding pixels.

Suppose you want to make a linear combination of pix1 and pix2:
   pixd = 0.4 * pix1 + 0.6 * pix2
where pix1 and pix2 are the same size and have depth 'd'.  Then:
   Pixacc *pacc = pixaccCreateWithPix(pix1, 0);  // first; addition only
   pixaccMultConst(pacc, 0.4);
   pixaccMultConstAccumulate(pacc, pix2, 0.6);  // Add in 0.6 of the second
   pixd = pixaccFinal(pacc, d);  // Get the result
   pixaccDestroy(&pacc);

Definition in file pixacc.c.


Function Documentation

PIXACC* pixaccCreate ( l_int32  w,
l_int32  h,
l_int32  negflag 
)

pixaccCreate()

Input: w, h (of 32 bpp internal Pix) negflag (0 if only positive numbers are involved; 1 if there will be negative numbers) Return: pixacc, or null on error

Notes: (1) Use = 1 for safety if any negative numbers are going to be used in the chain of operations. Negative numbers arise, e.g., by subtracting a pix, or by adding a pix that has been pre-multiplied by a negative number. (2) Initializes the internal 32 bpp pix, similarly to the initialization in pixInitAccumulate().

Definition at line 77 of file pixacc.c.

References CALLOC, ERROR_PTR, Pixacc::h, NULL, Pixacc::offset, Pixacc::pix, pixCreate(), pixSetAllArbitrary(), PROCNAME, and Pixacc::w.

Referenced by main(), pixaccCreateWithPix(), pixaccMultConstAccumulate(), pixCompareTiled(), and pixUnsharpMaskingGray().

PIXACC* pixaccCreateWithPix ( PIX pix,
l_int32  negflag 
)

pixaccCreateWithPix()

Input: pix negflag (0 if only positive numbers are involved; 1 if there will be negative numbers) Return: pixacc, or null on error

Notes: (1) See pixaccCreate()

Definition at line 114 of file pixacc.c.

References ERROR_PTR, NULL, pixaccAdd(), pixaccCreate(), pixGetDimensions(), and PROCNAME.

void pixaccDestroy ( PIXACC **  ppixacc)

pixaccDestroy()

Input: &pixacc (<can be="" null>="">) Return: void

Notes: (1) Always nulls the input ptr.

Definition at line 142 of file pixacc.c.

References FREE, L_WARNING, NULL, Pixacc::pix, pixDestroy(), and PROCNAME.

Referenced by main(), pixaccMultConstAccumulate(), pixCompareTiled(), and pixUnsharpMaskingGray().

PIX* pixaccFinal ( PIXACC pixacc,
l_int32  outdepth 
)

pixaccFinal()

Input: pixacc outdepth (8, 16 or 32 bpp) Return: pixd (8 , 16 or 32 bpp), or null on error

Definition at line 174 of file pixacc.c.

References ERROR_PTR, NULL, pixaccGetOffset(), pixaccGetPix(), pixFinalAccumulate(), and PROCNAME.

Referenced by main(), pixaccMultConstAccumulate(), pixCompareTiled(), and pixUnsharpMaskingGray().

PIX* pixaccGetPix ( PIXACC pixacc)

pixaccGetPix()

Input: pixacc Return: pix, or null on error

Definition at line 197 of file pixacc.c.

References ERROR_PTR, NULL, Pixacc::pix, and PROCNAME.

Referenced by pixaccAdd(), pixaccFinal(), pixaccMultConst(), and pixaccSubtract().

l_int32 pixaccGetOffset ( PIXACC pixacc)

pixaccGetOffset()

Input: pixacc Return: offset, or -1 on error

Definition at line 214 of file pixacc.c.

References ERROR_INT, Pixacc::offset, and PROCNAME.

Referenced by pixaccFinal(), and pixaccMultConst().

l_int32 pixaccAdd ( PIXACC pixacc,
PIX pix 
)

pixaccAdd()

Input: pixacc pix (to be added) Return: 0 if OK, 1 on error

Definition at line 235 of file pixacc.c.

References ERROR_INT, L_ARITH_ADD, pixaccGetPix(), pixAccumulate(), and PROCNAME.

Referenced by main(), pixaccCreateWithPix(), pixaccMultConstAccumulate(), pixCompareTiled(), and pixUnsharpMaskingGray().

l_int32 pixaccSubtract ( PIXACC pixacc,
PIX pix 
)

pixaccSubtract()

Input: pixacc pix (to be subtracted) Return: 0 if OK, 1 on error

Definition at line 257 of file pixacc.c.

References ERROR_INT, L_ARITH_SUBTRACT, pixaccGetPix(), pixAccumulate(), and PROCNAME.

Referenced by main(), and pixUnsharpMaskingGray().

l_int32 pixaccMultConst ( PIXACC pixacc,
l_float32  factor 
)

pixaccMultConst()

Input: pixacc factor Return: 0 if OK, 1 on error

Definition at line 279 of file pixacc.c.

References ERROR_INT, pixaccGetOffset(), pixaccGetPix(), pixMultConstAccumulate(), and PROCNAME.

Referenced by main(), pixaccMultConstAccumulate(), pixCompareTiled(), and pixUnsharpMaskingGray().

l_int32 pixaccMultConstAccumulate ( PIXACC pixacc,
PIX pix,
l_float32  factor 
)

pixaccMultConstAccumulate()

Input: pixacc pix factor Return: 0 if OK, 1 on error

Notes: (1) This creates a temp pix that is multiplied by the constant . It then adds that into .

Definition at line 305 of file pixacc.c.

References ERROR_INT, pixaccAdd(), pixaccCreate(), pixaccDestroy(), pixaccFinal(), pixaccMultConst(), pixDestroy(), pixGetDimensions(), and PROCNAME.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines