Leptonica  1.82.0
Image processing and image analysis suite
shear.c File Reference
#include <string.h>
#include <math.h>
#include "allheaders.h"

Go to the source code of this file.

Macros

#define DEBUG   0
 

Functions

static l_float32 normalizeAngleForShear (l_float32 radang, l_float32 mindif)
 
PIXpixHShear (PIX *pixd, PIX *pixs, l_int32 yloc, l_float32 radang, l_int32 incolor)
 
PIXpixVShear (PIX *pixd, PIX *pixs, l_int32 xloc, l_float32 radang, l_int32 incolor)
 
PIXpixHShearCorner (PIX *pixd, PIX *pixs, l_float32 radang, l_int32 incolor)
 
PIXpixVShearCorner (PIX *pixd, PIX *pixs, l_float32 radang, l_int32 incolor)
 
PIXpixHShearCenter (PIX *pixd, PIX *pixs, l_float32 radang, l_int32 incolor)
 
PIXpixVShearCenter (PIX *pixd, PIX *pixs, l_float32 radang, l_int32 incolor)
 
l_ok pixHShearIP (PIX *pixs, l_int32 yloc, l_float32 radang, l_int32 incolor)
 
l_ok pixVShearIP (PIX *pixs, l_int32 xloc, l_float32 radang, l_int32 incolor)
 
PIXpixHShearLI (PIX *pixs, l_int32 yloc, l_float32 radang, l_int32 incolor)
 
PIXpixVShearLI (PIX *pixs, l_int32 xloc, l_float32 radang, l_int32 incolor)
 

Variables

static const l_float32 MinDiffFromHalfPi = 0.04
 

Detailed Description


   About arbitrary lines
          PIX      *pixHShear()
          PIX      *pixVShear()

   About special 'points': UL corner and center
          PIX      *pixHShearCorner()
          PIX      *pixVShearCorner()
          PIX      *pixHShearCenter()
          PIX      *pixVShearCenter()

   In place about arbitrary lines
          l_int32   pixHShearIP()
          l_int32   pixVShearIP()

   Linear interpolated shear about arbitrary lines
          PIX      *pixHShearLI()
          PIX      *pixVShearLI()

   Static helper
     static l_float32  normalizeAngleForShear()

Definition in file shear.c.

Function Documentation

◆ pixHShear()

PIX* pixHShear ( PIX pixd,
PIX pixs,
l_int32  yloc,
l_float32  radang,
l_int32  incolor 
)

pixHShear()

Parameters
[in]pixd[optional] this can be null, equal to pixs, or different from pixs
[in]pixsany depth; cmap ok
[in]yloclocation of horizontal line, measured from origin
[in]radangangle in radians
[in]incolorL_BRING_IN_WHITE, L_BRING_IN_BLACK;
Returns
pixd, always
Notes:
     (1) There are 3 cases:
           (a) pixd == null (make a new pixd)
           (b) pixd == pixs (in-place)
           (c) pixd != pixs
     (2) For these three cases, use these patterns, respectively:
             pixd = pixHShear(NULL, pixs, ...);
             pixHShear(pixs, pixs, ...);
             pixHShear(pixd, pixs, ...);
     (3) This shear leaves the horizontal line of pixels at y = yloc
         invariant.  For a positive shear angle, pixels above this
         line are shoved to the right, and pixels below this line
         move to the left.
     (4) With positive shear angle, this can be used, along with
         pixVShear(), to perform a cw rotation, either with 2 shears
         (for small angles) or in the general case with 3 shears.
     (5) Changing the value of yloc is equivalent to translating
         the result horizontally.
     (6) This brings in incolor pixels from outside the image.
     (7) In-place shears do not work on cmapped pix, because the
         in-place operation cannot initialize to the requested incolor,
         so we shear from a copy.
     (8) The angle is brought into the range [-pi, -pi].  It is
         not permitted to be within MinDiffFromHalfPi radians
         from either -pi/2 or pi/2.

Definition at line 117 of file shear.c.

References L_BRING_IN_BLACK, and L_BRING_IN_WHITE.

Referenced by pixHShearCenter(), and pixHShearCorner().

◆ pixHShearCenter()

PIX* pixHShearCenter ( PIX pixd,
PIX pixs,
l_float32  radang,
l_int32  incolor 
)

pixHShearCenter()

Parameters
[in]pixd[optional] if not null, must be equal to pixs
[in]pixsany depth
[in]radangangle in radians
[in]incolorL_BRING_IN_WHITE, L_BRING_IN_BLACK;
Returns
pixd, or NULL on error.
Notes:
     (1) See pixHShear() for usage.
     (2) This does a horizontal shear about the center, with (+) shear
         pushing increasingly leftward (-x) with increasing y.

Definition at line 402 of file shear.c.

References pixHShear().

◆ pixHShearCorner()

PIX* pixHShearCorner ( PIX pixd,
PIX pixs,
l_float32  radang,
l_int32  incolor 
)

pixHShearCorner()

Parameters
[in]pixd[optional], if not null, must be equal to pixs
[in]pixsany depth
[in]radangangle in radians
[in]incolorL_BRING_IN_WHITE, L_BRING_IN_BLACK;
Returns
pixd, or NULL on error.
Notes:
     (1) See pixHShear() for usage.
     (2) This does a horizontal shear about the UL corner, with (+) shear
         pushing increasingly leftward (-x) with increasing y.

Definition at line 340 of file shear.c.

References pixHShear().

◆ pixHShearIP()

l_ok pixHShearIP ( PIX pixs,
l_int32  yloc,
l_float32  radang,
l_int32  incolor 
)

pixHShearIP()

Parameters
[in]pixsany depth; no cmap
[in]yloclocation of horizontal line, measured from origin
[in]radangangle in radians
[in]incolorL_BRING_IN_WHITE, L_BRING_IN_BLACK;
Returns
0 if OK; 1 on error
Notes:
     (1) This is an in-place version of pixHShear(); see comments there.
     (2) This brings in 'incolor' pixels from outside the image.
     (3) pixs cannot be colormapped, because the in-place operation
         only blits in 0 or 1 bits, not an arbitrary colormap index.
     (4) Does a horizontal full-band shear about the line with (+) shear
         pushing increasingly leftward (-x) with increasing y.

Definition at line 471 of file shear.c.

References L_BRING_IN_BLACK, and L_BRING_IN_WHITE.

Referenced by pixAffineSequential().

◆ pixHShearLI()

PIX* pixHShearLI ( PIX pixs,
l_int32  yloc,
l_float32  radang,
l_int32  incolor 
)

pixHShearLI()

Parameters
[in]pixs8 bpp or 32 bpp, or colormapped
[in]yloclocation of horizontal line, measured from origin
[in]radangangle in radians, in range (-pi/2 ... pi/2)
[in]incolorL_BRING_IN_WHITE, L_BRING_IN_BLACK;
Returns
pixd sheared, or NULL on error
Notes:
     (1) This does horizontal shear with linear interpolation for
         accurate results on 8 bpp gray, 32 bpp rgb, or cmapped images.
         It is relatively slow compared to the sampled version
         implemented by rasterop, but the result is much smoother.
     (2) This shear leaves the horizontal line of pixels at y = yloc
         invariant.  For a positive shear angle, pixels above this
         line are shoved to the right, and pixels below this line
         move to the left.
     (3) Any colormap is removed.
     (4) The angle is brought into the range [-pi/2 + del, pi/2 - del],
         where del == MinDiffFromHalfPi.

Definition at line 629 of file shear.c.

References pixGetDimensions().

◆ pixVShear()

PIX* pixVShear ( PIX pixd,
PIX pixs,
l_int32  xloc,
l_float32  radang,
l_int32  incolor 
)

pixVShear()

Parameters
[in]pixd[optional], this can be null, equal to pixs, or different from pixs
[in]pixsany depth; cmap ok
[in]xloclocation of vertical line, measured from origin
[in]radangangle in radians; not too close to +-(pi / 2)
[in]incolorL_BRING_IN_WHITE, L_BRING_IN_BLACK;
Returns
pixd, or NULL on error
Notes:
     (1) There are 3 cases:
           (a) pixd == null (make a new pixd)
           (b) pixd == pixs (in-place)
           (c) pixd != pixs
     (2) For these three cases, use these patterns, respectively:
             pixd = pixVShear(NULL, pixs, ...);
             pixVShear(pixs, pixs, ...);
             pixVShear(pixd, pixs, ...);
     (3) This shear leaves the vertical line of pixels at x = xloc
         invariant.  For a positive shear angle, pixels to the right
         of this line are shoved downward, and pixels to the left
         of the line move upward.
     (4) With positive shear angle, this can be used, along with
         pixHShear(), to perform a cw rotation, either with 2 shears
         (for small angles) or in the general case with 3 shears.
     (5) Changing the value of xloc is equivalent to translating
         the result vertically.
     (6) This brings in incolor pixels from outside the image.
     (7) In-place shears do not work on cmapped pix, because the
         in-place operation cannot initialize to the requested incolor,
         so we shear from a copy.
     (8) The angle is brought into the range [-pi, -pi].  It is
         not permitted to be within MinDiffFromHalfPi radians
         from either -pi/2 or pi/2.

Definition at line 238 of file shear.c.

References L_BRING_IN_BLACK, and L_BRING_IN_WHITE.

Referenced by pixVShearCenter(), and pixVShearCorner().

◆ pixVShearCenter()

PIX* pixVShearCenter ( PIX pixd,
PIX pixs,
l_float32  radang,
l_int32  incolor 
)

pixVShearCenter()

Parameters
[in]pixd[optional] if not null, must be equal to pixs
[in]pixsany depth
[in]radangangle in radians
[in]incolorL_BRING_IN_WHITE, L_BRING_IN_BLACK;
Returns
pixd, or NULL on error.
Notes:
     (1) See pixVShear() for usage.
     (2) This does a vertical shear about the center, with (+) shear
         pushing increasingly downward (+y) with increasing x.

Definition at line 433 of file shear.c.

References pixVShear().

◆ pixVShearCorner()

PIX* pixVShearCorner ( PIX pixd,
PIX pixs,
l_float32  radang,
l_int32  incolor 
)

pixVShearCorner()

Parameters
[in]pixd[optional], if not null, must be equal to pixs
[in]pixsany depth
[in]radangangle in radians
[in]incolorL_BRING_IN_WHITE, L_BRING_IN_BLACK;
Returns
pixd, or NULL on error.
Notes:
     (1) See pixVShear() for usage.
     (2) This does a vertical shear about the UL corner, with (+) shear
         pushing increasingly downward (+y) with increasing x.

Definition at line 371 of file shear.c.

References pixVShear().

◆ pixVShearIP()

l_ok pixVShearIP ( PIX pixs,
l_int32  xloc,
l_float32  radang,
l_int32  incolor 
)

pixVShearIP()

Parameters
[in]pixsany depth; no cmap
[in]xloclocation of vertical line, measured from origin
[in]radangangle in radians
[in]incolorL_BRING_IN_WHITE, L_BRING_IN_BLACK;
Returns
0 if OK; 1 on error
Notes:
     (1) This is an in-place version of pixVShear(); see comments there.
     (2) This brings in 'incolor' pixels from outside the image.
     (3) pixs cannot be colormapped, because the in-place operation
         only blits in 0 or 1 bits, not an arbitrary colormap index.
     (4) Does a vertical full-band shear about the line with (+) shear
         pushing increasingly downward (+y) with increasing x.

Definition at line 546 of file shear.c.

References L_BRING_IN_BLACK, and L_BRING_IN_WHITE.

Referenced by pixAffineSequential().

◆ pixVShearLI()

PIX* pixVShearLI ( PIX pixs,
l_int32  xloc,
l_float32  radang,
l_int32  incolor 
)

pixVShearLI()

Parameters
[in]pixs8 bpp or 32 bpp, or colormapped
[in]xloclocation of vertical line, measured from origin
[in]radangangle in radians, in range (-pi/2 ... pi/2)
[in]incolorL_BRING_IN_WHITE, L_BRING_IN_BLACK;
Returns
pixd sheared, or NULL on error
Notes:
     (1) This does vertical shear with linear interpolation for
         accurate results on 8 bpp gray, 32 bpp rgb, or cmapped images.
         It is relatively slow compared to the sampled version
         implemented by rasterop, but the result is much smoother.
     (2) This shear leaves the vertical line of pixels at x = xloc
         invariant.  For a positive shear angle, pixels to the right
         of this line are shoved downward, and pixels to the left
         of the line move upward.
     (3) Any colormap is removed.
     (4) The angle is brought into the range [-pi/2 + del, pi/2 - del],
         where del == MinDiffFromHalfPi.

Definition at line 741 of file shear.c.

References pixGetDimensions().