Leptonica 1.85.0
Image processing and image analysis suite
Loading...
Searching...
No Matches
pixacc.c File Reference
#include "allheaders.h"
#include "pix_internal.h"

Go to the source code of this file.

Functions

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

Detailed Description


     Pixacc creation, destruction
          PIXACC   *pixaccCreate()
          PIXACC   *pixaccCreateFromPix()
          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 = pixaccCreateFromPix(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

◆ pixaccAdd()

l_ok pixaccAdd ( PIXACC * pixacc,
PIX * pix )

pixaccAdd()

Parameters
[in]pixacc
[in]pixto be added
Returns
0 if OK, 1 on error

Definition at line 243 of file pixacc.c.

References pixaccGetPix().

Referenced by pixaccCreateFromPix(), and pixaccMultConstAccumulate().

◆ pixaccCreate()

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

pixaccCreate()

Parameters
[in]w,hof 32 bpp internal Pix
[in]negflag0 if only positive numbers are involved; 1 if there will be negative numbers
Returns
pixacc, or NULL on error
Notes:
     (1) Use negflag = 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 93 of file pixacc.c.

References Pixacc::h, Pixacc::offset, Pixacc::pix, pixaccDestroy(), and Pixacc::w.

Referenced by pixaccCreateFromPix(), and pixaccMultConstAccumulate().

◆ pixaccCreateFromPix()

PIXACC * pixaccCreateFromPix ( PIX * pix,
l_int32 negflag )

pixaccCreateFromPix()

Parameters
[in]pix
[in]negflag0 if only positive numbers are involved; 1 if there will be negative numbers
Returns
pixacc, or NULL on error
Notes:
     (1) See pixaccCreate()

Definition at line 131 of file pixacc.c.

References pixaccAdd(), and pixaccCreate().

◆ pixaccDestroy()

void pixaccDestroy ( PIXACC ** ppixacc)

pixaccDestroy()

Parameters
[in,out]ppixaccwill be set to null before returning
Returns
void
Notes:
     (1) Always nulls the input ptr.

Definition at line 159 of file pixacc.c.

References Pixacc::pix.

Referenced by pixaccCreate(), and pixaccMultConstAccumulate().

◆ pixaccFinal()

PIX * pixaccFinal ( PIXACC * pixacc,
l_int32 outdepth )

pixaccFinal()

Parameters
[in]pixacc
[in]outdepth8, 16 or 32 bpp
Returns
pixd 8, 16 or 32 bpp, or NULL on error

Definition at line 188 of file pixacc.c.

References pixaccGetOffset(), and pixaccGetPix().

Referenced by pixaccMultConstAccumulate().

◆ pixaccGetOffset()

l_int32 pixaccGetOffset ( PIXACC * pixacc)

pixaccGetOffset()

Parameters
[in]pixacc
Returns
offset, or -1 on error

Definition at line 224 of file pixacc.c.

References Pixacc::offset.

Referenced by pixaccFinal(), and pixaccMultConst().

◆ pixaccGetPix()

PIX * pixaccGetPix ( PIXACC * pixacc)

pixaccGetPix()

Parameters
[in]pixacc
Returns
pix, or NULL on error

Definition at line 209 of file pixacc.c.

References Pixacc::pix.

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

◆ pixaccMultConst()

l_ok pixaccMultConst ( PIXACC * pixacc,
l_float32 factor )

pixaccMultConst()

Parameters
[in]pixacc
[in]factor
Returns
0 if OK, 1 on error

Definition at line 283 of file pixacc.c.

References pixaccGetOffset(), and pixaccGetPix().

Referenced by pixaccMultConstAccumulate().

◆ pixaccMultConstAccumulate()

l_ok pixaccMultConstAccumulate ( PIXACC * pixacc,
PIX * pix,
l_float32 factor )

pixaccMultConstAccumulate()

Parameters
[in]pixacc
[in]pix
[in]factor
Returns
0 if OK, 1 on error
Notes:
     (1) This creates a temp pix that is pix multiplied by the
         constant factor.  It then adds that into pixacc.

Definition at line 309 of file pixacc.c.

References pixaccAdd(), pixaccCreate(), pixaccDestroy(), pixaccFinal(), and pixaccMultConst().

◆ pixaccSubtract()

l_ok pixaccSubtract ( PIXACC * pixacc,
PIX * pix )

pixaccSubtract()

Parameters
[in]pixacc
[in]pixto be subtracted
Returns
0 if OK, 1 on error

Definition at line 263 of file pixacc.c.

References pixaccGetPix().