Leptonica  1.83.1
Image processing and image analysis suite
roplow.c File Reference
#include <string.h>
#include "allheaders.h"

Go to the source code of this file.

Macros

#define COMBINE_PARTIAL(d, s, m)   ( ((d) & ~(m)) | ((s) & (m)) )
 

Functions

static void rasteropUniWordAlignedLow (l_uint32 *datad, l_int32 dwpl, l_int32 dx, l_int32 dy, l_int32 dw, l_int32 dh, l_int32 op)
 
static void rasteropUniGeneralLow (l_uint32 *datad, l_int32 dwpl, l_int32 dx, l_int32 dy, l_int32 dw, l_int32 dh, l_int32 op)
 
static void rasteropWordAlignedLow (l_uint32 *datad, l_int32 dwpl, l_int32 dx, l_int32 dy, l_int32 dw, l_int32 dh, l_int32 op, l_uint32 *datas, l_int32 swpl, l_int32 sx, l_int32 sy)
 
static void rasteropVAlignedLow (l_uint32 *datad, l_int32 dwpl, l_int32 dx, l_int32 dy, l_int32 dw, l_int32 dh, l_int32 op, l_uint32 *datas, l_int32 swpl, l_int32 sx, l_int32 sy)
 
static void rasteropGeneralLow (l_uint32 *datad, l_int32 dwpl, l_int32 dx, l_int32 dy, l_int32 dw, l_int32 dh, l_int32 op, l_uint32 *datas, l_int32 swpl, l_int32 sx, l_int32 sy)
 
static void shiftDataHorizontalLow (l_uint32 *datad, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_int32 shift)
 
void rasteropUniLow (l_uint32 *datad, l_int32 dpixw, l_int32 dpixh, l_int32 depth, l_int32 dwpl, l_int32 dx, l_int32 dy, l_int32 dw, l_int32 dh, l_int32 op)
 
void rasteropLow (l_uint32 *datad, l_int32 dpixw, l_int32 dpixh, l_int32 depth, l_int32 dwpl, l_int32 dx, l_int32 dy, l_int32 dw, l_int32 dh, l_int32 op, l_uint32 *datas, l_int32 spixw, l_int32 spixh, l_int32 swpl, l_int32 sx, l_int32 sy)
 
void rasteropVipLow (l_uint32 *data, l_int32 pixw, l_int32 pixh, l_int32 depth, l_int32 wpl, l_int32 x, l_int32 w, l_int32 shift)
 
void rasteropHipLow (l_uint32 *data, l_int32 pixh, l_int32 depth, l_int32 wpl, l_int32 y, l_int32 h, l_int32 shift)
 

Variables

static const l_int32 SHIFT_LEFT = 0
 
static const l_int32 SHIFT_RIGHT = 1
 
static const l_uint32 lmask32 []
 
static const l_uint32 rmask32 []
 

Detailed Description

     Low level dest-only
          void            rasteropUniLow()
          static void     rasteropUniWordAlignedlLow()
          static void     rasteropUniGeneralLow()

     Low level src and dest
          void            rasteropLow()
          static void     rasteropWordAlignedLow()
          static void     rasteropVAlignedLow()
          static void     rasteropGeneralLow()

     Low level in-place full height vertical block transfer
          void            rasteropVipLow()

     Low level in-place full width horizontal block transfer
          void            rasteropHipLow()
          static void     shiftDataHorizontalLow()

Definition in file roplow.c.

Function Documentation

◆ rasteropGeneralLow()

static void rasteropGeneralLow ( l_uint32 *  datad,
l_int32  dwpl,
l_int32  dx,
l_int32  dy,
l_int32  dw,
l_int32  dh,
l_int32  op,
l_uint32 *  datas,
l_int32  swpl,
l_int32  sx,
l_int32  sy 
)
static

rasteropGeneralLow()

Parameters
[in]datadptr to dest image data
[in]dwplwpl of dest
[in]dxx val of UL corner of dest rectangle
[in]dyy val of UL corner of dest rectangle
[in]dwwidth of dest rectangle
[in]dhheight of dest rectangle
[in]opop code
[in]datasptr to src image data
[in]swplwpl of src
[in]sxx val of UL corner of src rectangle
[in]syy val of UL corner of src rectangle
Returns
void

This is called when the src and dest rects are do not have the same 32-bit word alignment.

The method is a generalization of rasteropVAlignLow. There, the src image pieces were directly merged with the dest. Here, we shift the source bits to fill words that are aligned with the dest, and then use those "source words" exactly in place of the source words that were used in rasteropVAlignLow.

The critical parameter is thus the shift required for the src. Consider the left edge of the rectangle. The overhang into the src and dest words are found, and the difference is exactly this shift. There are two separate cases, depending on whether the src pixels are shifted left or right. If the src overhang is larger than the dest overhang, the src is shifted to the right, and a number of pixels equal to the shift are left over for filling the next dest word, if necessary.

But if the dest overhang is larger than the src overhang, the src is shifted to the left, and depending on the width of transferred pixels, it may also be necessary to shift pixels in from the next src word, in order to fill the dest word. An interesting case is where the src overhang equals the width, dw, of the block. Then all the pixels necessary to fill the first dest word can be taken from the first src word, up to the last src pixel in the word, and no pixels from the next src word are required. Consider this simple example, where a single pixel from the src is transferred to the dest: pix1 = pixCreate(32, 1, 1); pix2 = pixCreate(32, 1, 1); pixRasterop(pix1, 30, 0, 1, 1, PIX_SRC, pix2, 31, 0); Here, the pixel at the right end of the src image (sx = 31) is shifted one bit to the left (to dx = 30). The width (1) equals the src overhang (1), and no pixels from the next word are required. (This must be true because there is only one src word.)

Definition at line 1359 of file roplow.c.

References lept_stderr().

Referenced by rasteropLow().

◆ rasteropHipLow()

void rasteropHipLow ( l_uint32 *  data,
l_int32  pixh,
l_int32  depth,
l_int32  wpl,
l_int32  y,
l_int32  h,
l_int32  shift 
)

rasteropHipLow()

Parameters
[in]dataptr to image data
[in]pixhheight
[in]depthdepth
[in]wplwpl
[in]yy val of UL corner of rectangle
[in]hheight of rectangle
[in]shift+ shifts data to the left in a horizontal column
Returns
0 if OK; 1 on error.
Notes:
     (1) This clears the pixels that are left exposed after the rasterop.
         Therefore, for Pix with depth > 1, these pixels become black,
         and must be subsequently SET if they are to be white.
         For example, see pixRasteropHip().
     (2) This function performs clipping and calls shiftDataHorizontalLow()
         to do the in-place rasterop on each line.

Definition at line 2386 of file roplow.c.

References shiftDataHorizontalLow().

Referenced by pixRasteropHip().

◆ rasteropLow()

void rasteropLow ( l_uint32 *  datad,
l_int32  dpixw,
l_int32  dpixh,
l_int32  depth,
l_int32  dwpl,
l_int32  dx,
l_int32  dy,
l_int32  dw,
l_int32  dh,
l_int32  op,
l_uint32 *  datas,
l_int32  spixw,
l_int32  spixh,
l_int32  swpl,
l_int32  sx,
l_int32  sy 
)

rasteropLow()

Parameters
[in]datadptr to dest image data
[in]dpixwwidth of dest
[in]dpixhheight of dest
[in]depthdepth of src and dest
[in]dwplwpl of dest
[in]dxx val of UL corner of dest rectangle
[in]dyy val of UL corner of dest rectangle
[in]dwwidth of dest rectangle
[in]dhheight of dest rectangle
[in]opop code
[in]datasptr to src image data
[in]spixwwidth of src
[in]spixhheight of src
[in]swplwpl of src
[in]sxx val of UL corner of src rectangle
[in]syy val of UL corner of src rectangle
Returns
void

Action: Scales width, performs clipping, checks alignment and dispatches for the rasterop.

Warning: the two images must have equal depth. This is not checked.

Definition at line 485 of file roplow.c.

References lept_stderr(), rasteropGeneralLow(), rasteropVAlignedLow(), and rasteropWordAlignedLow().

◆ rasteropUniGeneralLow()

static void rasteropUniGeneralLow ( l_uint32 *  datad,
l_int32  dwpl,
l_int32  dx,
l_int32  dy,
l_int32  dw,
l_int32  dh,
l_int32  op 
)
static

rasteropUniGeneralLow()

Parameters
[in]datadptr to dest image data
[in]dwplwpl of dest
[in]dxx val of UL corner of dest rectangle
[in]dyy val of UL corner of dest rectangle
[in]dwwidth of dest rectangle
[in]dhheight of dest rectangle
[in]opop code
Returns
void

Definition at line 289 of file roplow.c.

Referenced by rasteropUniLow().

◆ rasteropUniLow()

void rasteropUniLow ( l_uint32 *  datad,
l_int32  dpixw,
l_int32  dpixh,
l_int32  depth,
l_int32  dwpl,
l_int32  dx,
l_int32  dy,
l_int32  dw,
l_int32  dh,
l_int32  op 
)

rasteropUniLow()

Parameters
[in]datadptr to dest image data
[in]dpixwwidth of dest
[in]dpixhheight of dest
[in]depthdepth of src and dest
[in]dwplwpl of dest
[in]dxx val of UL corner of dest rectangle
[in]dyy val of UL corner of dest rectangle
[in]dwwidth of dest rectangle
[in]dhheight of dest rectangle
[in]opop code
Returns
void

Action: scales width, performs clipping, checks alignment, and dispatches for the rasterop.

Definition at line 128 of file roplow.c.

References rasteropUniGeneralLow(), and rasteropUniWordAlignedLow().

Referenced by pixRasterop().

◆ rasteropUniWordAlignedLow()

static void rasteropUniWordAlignedLow ( l_uint32 *  datad,
l_int32  dwpl,
l_int32  dx,
l_int32  dy,
l_int32  dw,
l_int32  dh,
l_int32  op 
)
static

rasteropUniWordAlignedLow()

Parameters
[in]datadptr to dest image data
[in]dwplwpl of dest
[in]dxx val of UL corner of dest rectangle
[in]dyy val of UL corner of dest rectangle
[in]dwwidth of dest rectangle
[in]dhheight of dest rectangle
[in]opop code
Returns
void

This is called when the dest rect is left aligned on 32-bit word boundaries. That is: dx & 31 == 0.

We make an optimized implementation of this because it is a common case: e.g., operating on a full dest image.

Definition at line 208 of file roplow.c.

Referenced by rasteropUniLow().

◆ rasteropVAlignedLow()

static void rasteropVAlignedLow ( l_uint32 *  datad,
l_int32  dwpl,
l_int32  dx,
l_int32  dy,
l_int32  dw,
l_int32  dh,
l_int32  op,
l_uint32 *  datas,
l_int32  swpl,
l_int32  sx,
l_int32  sy 
)
static

rasteropVAlignedLow()

Parameters
[in]datadptr to dest image data
[in]dwplwpl of dest
[in]dxx val of UL corner of dest rectangle
[in]dyy val of UL corner of dest rectangle
[in]dwwidth of dest rectangle
[in]dhheight of dest rectangle
[in]opop code
[in]datasptr to src image data
[in]swplwpl of src
[in]sxx val of UL corner of src rectangle
[in]syy val of UL corner of src rectangle
Returns
void

This is called when the left side of the src and dest rects have the same alignment relative to 32-bit word boundaries; i.e., dx & 31) == (sx & 31

Definition at line 830 of file roplow.c.

Referenced by rasteropLow().

◆ rasteropVipLow()

void rasteropVipLow ( l_uint32 *  data,
l_int32  pixw,
l_int32  pixh,
l_int32  depth,
l_int32  wpl,
l_int32  x,
l_int32  w,
l_int32  shift 
)

rasteropVipLow()

Parameters
[in]dataptr to image data
[in]pixwwidth
[in]pixhheight
[in]depthdepth
[in]wplwpl
[in]xx val of UL corner of rectangle
[in]wwidth of rectangle
[in]shift+ shifts data downward in vertical column
Returns
0 if OK; 1 on error.
Notes:
     (1) This clears the pixels that are left exposed after the
         translation.  You can consider them as pixels that are
         shifted in from outside the image.  This can be later
         overridden by the incolor parameter in higher-level functions
         that call this.  For example, for images with depth > 1,
         these pixels are cleared to black; to be white they
         must later be SET to white.  See, e.g., pixRasteropVip().
     (2) This function scales the width to accommodate any depth,
         performs clipping, and then does the in-place rasterop.

Definition at line 2173 of file roplow.c.

Referenced by pixRasteropVip().

◆ rasteropWordAlignedLow()

static void rasteropWordAlignedLow ( l_uint32 *  datad,
l_int32  dwpl,
l_int32  dx,
l_int32  dy,
l_int32  dw,
l_int32  dh,
l_int32  op,
l_uint32 *  datas,
l_int32  swpl,
l_int32  sx,
l_int32  sy 
)
static

rasteropWordAlignedLow()

Parameters
[in]datadptr to dest image data
[in]dwplwpl of dest
[in]dxx val of UL corner of dest rectangle
[in]dyy val of UL corner of dest rectangle
[in]dwwidth of dest rectangle
[in]dhheight of dest rectangle
[in]opop code
[in]datasptr to src image data
[in]swplwpl of src
[in]sxx val of UL corner of src rectangle
[in]syy val of UL corner of src rectangle
Returns
void

This is called when both the src and dest rects are left aligned on 32-bit word boundaries. That is: dx & 31 == 0 and sx & 31 == 0

We make an optimized implementation of this because it is a common case: e.g., two images are rasterop'd starting from their UL corners 0,0.

Definition at line 606 of file roplow.c.

Referenced by rasteropLow().

◆ shiftDataHorizontalLow()

static void shiftDataHorizontalLow ( l_uint32 *  datad,
l_int32  wpld,
l_uint32 *  datas,
l_int32  wpls,
l_int32  shift 
)
static

shiftDataHorizontalLow()

Parameters
[in]datadptr to beginning of dest line
[in]wpldwpl of dest
[in]datasptr to beginning of src line
[in]wplswpl of src
[in]shifthorizontal shift of block; >0 is to right
Returns
void
Notes:
     (1) This can also be used for in-place operation; see, e.g.,
         rasteropHipLow().
     (2) We are clearing the pixels that are shifted in from
         outside the image.  This can be overridden by the
         incolor parameter in higher-level functions that call this.

Definition at line 2435 of file roplow.c.

Referenced by rasteropHipLow().

Variable Documentation

◆ lmask32

const l_uint32 lmask32[]
static
Initial value:
= {0x0,
0x80000000, 0xc0000000, 0xe0000000, 0xf0000000,
0xf8000000, 0xfc000000, 0xfe000000, 0xff000000,
0xff800000, 0xffc00000, 0xffe00000, 0xfff00000,
0xfff80000, 0xfffc0000, 0xfffe0000, 0xffff0000,
0xffff8000, 0xffffc000, 0xffffe000, 0xfffff000,
0xfffff800, 0xfffffc00, 0xfffffe00, 0xffffff00,
0xffffff80, 0xffffffc0, 0xffffffe0, 0xfffffff0,
0xfffffff8, 0xfffffffc, 0xfffffffe, 0xffffffff}

Definition at line 85 of file roplow.c.

◆ rmask32

const l_uint32 rmask32[]
static
Initial value:
= {0x0,
0x00000001, 0x00000003, 0x00000007, 0x0000000f,
0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff,
0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff,
0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff,
0x0001ffff, 0x0003ffff, 0x0007ffff, 0x000fffff,
0x001fffff, 0x003fffff, 0x007fffff, 0x00ffffff,
0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff,
0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff}

Definition at line 95 of file roplow.c.