Leptonica 1.68
C Image Processing Library

pix2.c File Reference

Pixel poking of image, pad and border pixels. More...

#include <string.h>
#include "allheaders.h"

Go to the source code of this file.

Defines

#define DEBUG_SERIALIZE   0

Functions

l_int32 pixGetPixel (PIX *pix, l_int32 x, l_int32 y, l_uint32 *pval)
l_int32 pixSetPixel (PIX *pix, l_int32 x, l_int32 y, l_uint32 val)
l_int32 pixGetRGBPixel (PIX *pix, l_int32 x, l_int32 y, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
l_int32 pixSetRGBPixel (PIX *pix, l_int32 x, l_int32 y, l_int32 rval, l_int32 gval, l_int32 bval)
l_int32 pixGetRandomPixel (PIX *pix, l_uint32 *pval, l_int32 *px, l_int32 *py)
l_int32 pixClearPixel (PIX *pix, l_int32 x, l_int32 y)
l_int32 pixFlipPixel (PIX *pix, l_int32 x, l_int32 y)
void setPixelLow (l_uint32 *line, l_int32 x, l_int32 depth, l_uint32 val)
l_int32 pixClearAll (PIX *pix)
l_int32 pixSetAll (PIX *pix)
l_int32 pixSetAllArbitrary (PIX *pix, l_uint32 val)
l_int32 pixSetBlackOrWhite (PIX *pixs, l_int32 op)
l_int32 pixClearInRect (PIX *pix, BOX *box)
l_int32 pixSetInRect (PIX *pix, BOX *box)
l_int32 pixSetInRectArbitrary (PIX *pix, BOX *box, l_uint32 val)
l_int32 pixBlendInRect (PIX *pixs, BOX *box, l_uint32 val, l_float32 fract)
l_int32 pixSetPadBits (PIX *pix, l_int32 val)
l_int32 pixSetPadBitsBand (PIX *pix, l_int32 by, l_int32 bh, l_int32 val)
l_int32 pixSetOrClearBorder (PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot, l_int32 op)
l_int32 pixSetBorderVal (PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot, l_uint32 val)
l_int32 pixSetBorderRingVal (PIX *pixs, l_int32 dist, l_uint32 val)
l_int32 pixSetMirroredBorder (PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
PIXpixCopyBorder (PIX *pixd, PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
PIXpixAddBorder (PIX *pixs, l_int32 npix, l_uint32 val)
PIXpixAddBlackBorder (PIX *pixs, l_int32 npix)
PIXpixAddBorderGeneral (PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot, l_uint32 val)
PIXpixRemoveBorder (PIX *pixs, l_int32 npix)
PIXpixRemoveBorderGeneral (PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
PIXpixAddMirroredBorder (PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
PIXpixAddRepeatedBorder (PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
PIXpixAddMixedBorder (PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
PIXpixCreateRGBImage (PIX *pixr, PIX *pixg, PIX *pixb)
PIXpixGetRGBComponent (PIX *pixs, l_int32 color)
l_int32 pixSetRGBComponent (PIX *pixd, PIX *pixs, l_int32 color)
PIXpixGetRGBComponentCmap (PIX *pixs, l_int32 color)
l_int32 composeRGBPixel (l_int32 rval, l_int32 gval, l_int32 bval, l_uint32 *ppixel)
void extractRGBValues (l_uint32 pixel, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
l_int32 extractMinMaxComponent (l_uint32 pixel, l_int32 type)
l_int32 pixGetRGBLine (PIX *pixs, l_int32 row, l_uint8 *bufr, l_uint8 *bufg, l_uint8 *bufb)
PIXpixEndianByteSwapNew (PIX *pixs)
l_int32 pixEndianByteSwap (PIX *pixs)
l_int32 lineEndianByteSwap (l_uint32 *datad, l_uint32 *datas, l_int32 wpl)
PIXpixEndianTwoByteSwapNew (PIX *pixs)
l_int32 pixEndianTwoByteSwap (PIX *pixs)
l_int32 pixGetRasterData (PIX *pixs, l_uint8 **pdata, size_t *pnbytes)
l_uint8 ** pixSetupByteProcessing (PIX *pix, l_int32 *pw, l_int32 *ph)
l_int32 pixCleanupByteProcessing (PIX *pix, l_uint8 **lineptrs)
void l_setAlphaMaskBorder (l_float32 val1, l_float32 val2)

Variables

static const l_uint32 rmask32 []
LEPT_DLL l_float32 AlphaMaskBorderVals [2] = {0.0, 0.5}

Detailed Description

Pixel poking of image, pad and border pixels.

  This file has these basic operations:

    (1) Get and set: individual pixels, full image, rectangular region,
        pad pixels, border pixels, and color components for RGB
    (2) Add and remove border pixels
    (3) Endian byte swaps
    (4) Simple method for byte-processing images (instead of words)

    Pixel poking
         l_int32     pixGetPixel()
         l_int32     pixSetPixel()
         l_int32     pixGetRGBPixel()
         l_int32     pixSetRGBPixel()
         l_int32     pixGetRandomPixel()
         l_int32     pixClearPixel()
         l_int32     pixFlipPixel()
         void        setPixelLow()

    Full image clear/set/set-to-arbitrary-value
         l_int32     pixClearAll()
         l_int32     pixSetAll()
         l_int32     pixSetAllArbitrary()
         l_int32     pixSetBlackOrWhite()

    Rectangular region clear/set/set-to-arbitrary-value/blend
         l_int32     pixClearInRect()
         l_int32     pixSetInRect()
         l_int32     pixSetInRectArbitrary()
         l_int32     pixBlendInRect()

    Set pad bits
         l_int32     pixSetPadBits()
         l_int32     pixSetPadBitsBand()

    Assign border pixels
         l_int32     pixSetOrClearBorder()
         l_int32     pixSetBorderVal()
         l_int32     pixSetBorderRingVal()
         l_int32     pixSetMirroredBorder()
         PIX        *pixCopyBorder()

    Add and remove border
         PIX        *pixAddBorder()
         PIX        *pixAddBlackBorder()
         PIX        *pixAddBorderGeneral()
         PIX        *pixRemoveBorder()
         PIX        *pixRemoveBorderGeneral()
         PIX        *pixAddMirroredBorder()
         PIX        *pixAddRepeatedBorder()
         PIX        *pixAddMixedBorder()

    Color sample setting and extraction
         PIX        *pixCreateRGBImage()
         PIX        *pixGetRGBComponent()
         l_int32     pixSetRGBComponent()
         PIX        *pixGetRGBComponentCmap()
         l_int32     composeRGBPixel()
         void        extractRGBValues()
         l_int32     extractMinMaxComponent()
         l_int32     pixGetRGBLine()

    Conversion between big and little endians
         PIX        *pixEndianByteSwapNew()
         l_int32     pixEndianByteSwap()
         l_int32     lineEndianByteSwap()
         PIX        *pixEndianTwoByteSwapNew()
         l_int32     pixEndianTwoByteSwap()

    Extract raster data as binary string
         l_int32     pixGetRasterData()

    Setup helpers for 8 bpp byte processing
         l_uint8   **pixSetupByteProcessing()
         l_int32     pixCleanupByteProcessing()

    Setting parameters for antialias masking with alpha transforms
         void        l_setAlphaMaskBorder()

 indicates implicit assumption about RGB component ordering

Definition in file pix2.c.


Define Documentation

#define DEBUG_SERIALIZE   0

Definition at line 121 of file pix2.c.


Function Documentation

l_int32 pixGetPixel ( PIX pix,
l_int32  x,
l_int32  y,
l_uint32 pval 
)

pixGetPixel()

Input: pix (x,y) pixel coords &val (<return> pixel value) Return: 0 if OK; 1 on error

Notes: (1) This returns the value in the data array. If the pix is colormapped, it returns the colormap index, not the rgb value. (2) Because of the function overhead and the parameter checking, this is much slower than using the GET_DATA_*() macros directly. Speed on a 1 Mpixel RGB image, using a 3 GHz machine: * pixGet/pixSet: ~25 Mpix/sec * GET_DATA/SET_DATA: ~350 MPix/sec If speed is important and you're doing random access into the pix, use pixGetLinePtrs() and the array access macros.

Definition at line 148 of file pix2.c.

References ERROR_INT, GET_DATA_BIT, GET_DATA_BYTE, GET_DATA_DIBIT, GET_DATA_QBIT, GET_DATA_TWO_BYTES, pixGetData(), pixGetDimensions(), pixGetWpl(), and PROCNAME.

Referenced by adjacentOnPixelInRaster(), findTilePatchCenter(), generateBinaryMaze(), getCutPathForHole(), kernelCreateFromPix(), localSearchForBackground(), main(), pixApplyInvBackgroundGrayMap(), pixApplyInvBackgroundRGBMap(), pixBlendCmap(), pixBlendMask(), pixEqualWithCmap(), pixExtendByReplication(), pixExtractOnLine(), pixFillMapHoles(), pixGenerateSelRandom(), pixGetCCBorders(), pixGetEdgeProfile(), pixGetLastOffPixelInRun(), pixGetLastOnPixelInRun(), pixGetRandomPixel(), pixGetRunsOnLine(), pixMaskedThreshOnBackgroundNorm(), pixMeanInRectangle(), pixOtsuAdaptiveThreshold(), pixOtsuThreshOnBackgroundNorm(), pixPlotAlongPta(), pixQualifyLocalMinima(), pixRenderPtaBlend(), pixSearchBinaryMaze(), pixSearchGrayMaze(), pixVarianceInRectangle(), pixWriteStreamAsciiPnm(), selCreateFromColorPix(), selCreateFromPix(), and wshedApply().

l_int32 pixSetPixel ( PIX pix,
l_int32  x,
l_int32  y,
l_uint32  val 
)

pixSetPixel()

Input: pix (x,y) pixel coords val (value to be inserted) Return: 0 if OK; 1 on error

Notes: (1) Warning: the input value is not checked for overflow with respect the the depth of , and the sign bit (if any) is ignored. * For d == 1, > 0 sets the bit on. * For d == 2, 4, 8 and 16, is masked to the maximum allowable pixel value, and any (invalid) higher order bits are discarded. (2) See pixGetPixel() for information on performance.

Definition at line 219 of file pix2.c.

References CLEAR_DATA_BIT, ERROR_INT, pixGetData(), pixGetDimensions(), pixGetWpl(), PROCNAME, SET_DATA_BIT, SET_DATA_BYTE, SET_DATA_DIBIT, SET_DATA_QBIT, and SET_DATA_TWO_BYTES.

Referenced by ccbaDisplayBorder(), ccbaDisplayImage1(), ccbaDisplayImage2(), ccbaDisplaySPBorder(), generateBinaryMaze(), identifyWatershedBasin(), main(), pixBlendMask(), pixDisplayHitMissSel(), pixDisplayPta(), pixDisplayPtaa(), pixExtendByReplication(), pixFillMapHoles(), pixGenerateFromPta(), pixGetBackgroundGrayMap(), pixGetBackgroundRGBMap(), pixGetEdgeProfile(), pixOtsuAdaptiveThreshold(), pixReadStreamPnm(), pixRenderPta(), pixRenderPtaArb(), pixRenderPtaBlend(), pixSearchBinaryMaze(), pixSearchGrayMaze(), pixSetBorderRingVal(), pixSubsampleBoundaryPixels(), selaAddCrossJunctions(), and selaAddTJunctions().

l_int32 pixGetRGBPixel ( PIX pix,
l_int32  x,
l_int32  y,
l_int32 prval,
l_int32 pgval,
l_int32 pbval 
)

pixGetRGBPixel()

Input: pix (32 bpp rgb, not colormapped) (x,y) pixel coords &rval (<optional return>=""> red component) &gval (<optional return>=""> green component) &bval (<optional return>=""> blue component) Return: 0 if OK; 1 on error

Definition at line 283 of file pix2.c.

References COLOR_BLUE, COLOR_GREEN, COLOR_RED, ERROR_INT, GET_DATA_BYTE, pixGetData(), pixGetDimensions(), pixGetWpl(), and PROCNAME.

l_int32 pixSetRGBPixel ( PIX pix,
l_int32  x,
l_int32  y,
l_int32  rval,
l_int32  gval,
l_int32  bval 
)

pixSetRGBPixel()

Input: pix (32 bpp rgb) (x,y) pixel coords rval (red component) gval (green component) bval (blue component) Return: 0 if OK; 1 on error

Definition at line 326 of file pix2.c.

References composeRGBPixel(), ERROR_INT, pixGetData(), pixGetDimensions(), pixGetWpl(), and PROCNAME.

Referenced by displayHSVColorRange().

l_int32 pixGetRandomPixel ( PIX pix,
l_uint32 pval,
l_int32 px,
l_int32 py 
)

pixGetRandomPixel()

Input: pix (any depth; can be colormapped) &val (<return> pixel value) &x (<optional return>=""> x coordinate chosen; can be null) &y (<optional return>=""> y coordinate chosen; can be null) Return: 0 if OK; 1 on error

Notes: (1) If the pix is colormapped, it returns the rgb value.

Definition at line 371 of file pix2.c.

References composeRGBPixel(), ERROR_INT, NULL, pixcmapGetColor(), pixGetColormap(), pixGetDimensions(), pixGetPixel(), and PROCNAME.

l_int32 pixClearPixel ( PIX pix,
l_int32  x,
l_int32  y 
)

pixClearPixel()

Input: pix (x,y) pixel coords Return: 0 if OK; 1 on error.

Definition at line 413 of file pix2.c.

References CLEAR_DATA_BIT, CLEAR_DATA_DIBIT, CLEAR_DATA_QBIT, ERROR_INT, pixGetData(), pixGetDimensions(), pixGetWpl(), PROCNAME, SET_DATA_BYTE, and SET_DATA_TWO_BYTES.

Referenced by pixRenderPta().

l_int32 pixFlipPixel ( PIX pix,
l_int32  x,
l_int32  y 
)
void setPixelLow ( l_uint32 line,
l_int32  x,
l_int32  depth,
l_uint32  val 
)

setPixelLow()

Input: line (ptr to beginning of line), x (pixel location in line) depth (bpp) val (to be inserted) Return: void

Notes: (1) Caution: input variables are not checked!

Definition at line 546 of file pix2.c.

References CLEAR_DATA_BIT, SET_DATA_BIT, SET_DATA_BYTE, SET_DATA_DIBIT, SET_DATA_QBIT, and SET_DATA_TWO_BYTES.

Referenced by pixFewColorsOctcubeQuant2().

l_int32 pixClearAll ( PIX pix)

pixClearAll()

Input: pix (all depths; use cmapped with caution) Return: 0 if OK, 1 on error

Notes: (1) Clears all data to 0. For 1 bpp, this is white; for grayscale or color, this is black. (2) Caution: for colormapped pix, this sets the color to the first one in the colormap. Be sure that this is the intended color!

Definition at line 598 of file pix2.c.

References ERROR_INT, NULL, PIX_CLR, pixGetHeight(), pixGetWidth(), pixRasterop(), and PROCNAME.

Referenced by compareResults(), jbAccumulateComposites(), main(), pixAffineSampled(), pixaSplitPix(), pixBilinearSampled(), pixDilate(), pixHMT(), pixMakeRangeMaskHS(), pixMakeRangeMaskHV(), pixMakeRangeMaskSV(), pixProjectiveSampled(), pixSetBlackOrWhite(), pixSetLowContrast(), and TestTiling().

l_int32 pixSetAll ( PIX pix)

pixSetAll()

Input: pix (all depths; use cmapped with caution) Return: 0 if OK, 1 on error

Notes: (1) Sets all data to 1. For 1 bpp, this is black; for grayscale or color, this is white. (2) Caution: for colormapped pix, this sets the pixel value to the maximum value supported by the colormap: 2^d - 1. However, this color may not be defined, because the colormap may not be full.

Definition at line 625 of file pix2.c.

References ERROR_INT, NULL, PIX_SET, pixcmapGetCount(), pixGetColormap(), pixGetHeight(), pixGetWidth(), pixRasterop(), and PROCNAME.

Referenced by kernelDisplayInPix(), main(), pixacompDisplayTiledAndScaled(), pixaDisplay(), pixaDisplayOnColor(), pixaDisplayTiled(), pixaDisplayTiledAndScaled(), pixaDisplayTiledInRows(), pixAffinePtaWithAlpha(), pixAffineSampled(), pixaSplitPix(), pixBilinearPtaWithAlpha(), pixBilinearSampled(), pixBlockrank(), pixErode(), pixFillHolesToBoundingRect(), pixHMT(), pixIntersectionOfMorphOps(), pixMakeRangeMaskHS(), pixMakeRangeMaskHV(), pixMakeRangeMaskSV(), pixProjectivePtaWithAlpha(), pixProjectiveSampled(), pixRotateWithAlpha(), pixScaleWithAlpha(), pixSearchGrayMaze(), pixSetBlackOrWhite(), selaAddCrossJunctions(), and selaAddTJunctions().

l_int32 pixSetAllArbitrary ( PIX pix,
l_uint32  val 
)

pixSetAllArbitrary()

Input: pix (all depths; use cmapped with caution) val (value to set all pixels) Return: 0 if OK; 1 on error

Notes: (1) For colormapped pix, be sure the value is the intended one in the colormap. (2) Caution: for colormapped pix, this sets each pixel to the color at the index equal to val. Be sure that this index exists in the colormap and that it is the intended one!

Definition at line 661 of file pix2.c.

References ERROR_INT, L_WARNING, L_WARNING_INT, NULL, pixcmapGetCount(), pixGetColormap(), pixGetData(), pixGetDimensions(), pixGetWpl(), and PROCNAME.

Referenced by main(), pixaccCreate(), pixAddBorderGeneral(), pixaDisplayOnColor(), pixaDisplayUnsplit(), pixAffineColor(), pixAffineGray(), pixAffinePtaWithAlpha(), pixAffineSampled(), pixaSplitPix(), pixBilinearColor(), pixBilinearGray(), pixBilinearPtaWithAlpha(), pixBilinearSampled(), pixDisplayColorArray(), pixInitAccumulate(), pixProjectiveColor(), pixProjectiveGray(), pixProjectivePtaWithAlpha(), pixProjectiveSampled(), pixRasteropHip(), pixRasteropVip(), pixRotateWithAlpha(), pixScaleWithAlpha(), pixSetBlackOrWhite(), pixSetMaskedGeneral(), and wshedCreate().

l_int32 pixSetBlackOrWhite ( PIX pixs,
l_int32  op 
)

pixSetBlackOrWhite()

Input: pixs (all depths; cmap ok) op (L_SET_BLACK, L_SET_WHITE) Return: 0 if OK; 1 on error

Notes: (1) Function for setting all pixels in an image to either black or white. (2) If pixs is colormapped, it adds black or white to the colormap if it's not there and there is room. If the colormap is full, it finds the closest color in intensity. This index is written to all pixels.

Definition at line 735 of file pix2.c.

References ERROR_INT, L_SET_BLACK, L_SET_WHITE, pixClearAll(), pixcmapAddBlackOrWhite(), pixGetColormap(), pixGetDepth(), pixSetAll(), pixSetAllArbitrary(), and PROCNAME.

Referenced by pixAddSingleTextblock(), pixConvertToPdfDataSegmented(), pixEmbedForRotation(), pixHShear(), pixHShearLI(), pixQuadraticVShearLI(), pixQuadraticVShearSampled(), pixRotateBySampling(), pixStretchHorizontalLI(), pixStretchHorizontalSampled(), pixVShear(), and pixVShearLI().

l_int32 pixClearInRect ( PIX pix,
BOX box 
)

pixClearInRect()

Input: pix (all depths; can be cmapped) box (in which all pixels will be cleared) Return: 0 if OK, 1 on error

Notes: (1) Clears all data in rect to 0. For 1 bpp, this is white; for grayscale or color, this is black. (2) Caution: for colormapped pix, this sets the color to the first one in the colormap. Be sure that this is the intended color!

Definition at line 786 of file pix2.c.

References boxGetGeometry(), ERROR_INT, NULL, PIX_CLR, pixRasterop(), and PROCNAME.

Referenced by main(), pixFindHistoPeaksHSV(), pixSetBlackOrWhiteBoxa(), pixSetInRectArbitrary(), and pixSplitComponentIntoBoxa().

l_int32 pixSetInRect ( PIX pix,
BOX box 
)

pixSetInRect()

Input: pix (all depths, can be cmapped) box (in which all pixels will be set) Return: 0 if OK, 1 on error

Notes: (1) Sets all data in rect to 1. For 1 bpp, this is black; for grayscale or color, this is white. (2) Caution: for colormapped pix, this sets the pixel value to the maximum value supported by the colormap: 2^d - 1. However, this color may not be defined, because the colormap may not be full.

Definition at line 819 of file pix2.c.

References boxGetGeometry(), ERROR_INT, NULL, PIX_SET, pixcmapGetCount(), pixGetColormap(), pixRasterop(), and PROCNAME.

Referenced by main(), pixSetBlackOrWhiteBoxa(), and pixSetInRectArbitrary().

l_int32 pixSetInRectArbitrary ( PIX pix,
BOX box,
l_uint32  val 
)

pixSetInRectArbitrary()

Input: pix (all depths; can be cmapped) box (in which all pixels will be set to val) val (value to set all pixels) Return: 0 if OK; 1 on error

Notes: (1) For colormapped pix, be sure the value is the intended one in the colormap. (2) Caution: for colormapped pix, this sets each pixel in the rect to the color at the index equal to val. Be sure that this index exists in the colormap and that it is the intended one!

Definition at line 859 of file pix2.c.

References boxClipToRectangle(), boxDestroy(), boxGetGeometry(), ERROR_INT, L_WARNING, L_WARNING_INT, NULL, pixClearInRect(), pixcmapGetCount(), pixGetColormap(), pixGetData(), pixGetDimensions(), pixGetWpl(), pixSetInRect(), PROCNAME, SET_DATA_BYTE, SET_DATA_DIBIT, SET_DATA_QBIT, and SET_DATA_TWO_BYTES.

Referenced by pixPaintBoxa(), pixPaintBoxaRandom(), and pixSetBlackOrWhiteBoxa().

l_int32 pixBlendInRect ( PIX pixs,
BOX box,
l_uint32  val,
l_float32  fract 
)

pixBlendInRect()

Input: pixs (32 bpp rgb) box (in which all pixels will be blended) val (blend value; 0xrrggbb00) fract (fraction of color to be blended with each pixel in pixs) Return: 0 if OK; 1 on error

Notes: (1) This is an in-place function. It blends the input color with the pixels in pixs in the specified rectangle.

Definition at line 972 of file pix2.c.

References boxGetGeometry(), composeRGBPixel(), ERROR_INT, extractRGBValues(), NULL, pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), and PROCNAME.

Referenced by pixBlendBoxaRandom().

l_int32 pixSetPadBits ( PIX pix,
l_int32  val 
)

pixSetPadBits()

Input: pix (1, 2, 4, 8, 16, 32 bpp) val (0 or 1) Return: 0 if OK; 1 on error

Notes: (1) The pad bits are the bits that expand each scanline to a multiple of 32 bits. They are usually not used in image processing operations. When boundary conditions are important, as in seedfill, they must be set properly. (2) This sets the value of the pad bits (if any) in the last 32-bit word in each scanline. (3) For 32 bpp pix, there are no pad bits, so this is a no-op.

Definition at line 1033 of file pix2.c.

References ERROR_INT, pixGetData(), pixGetDimensions(), pixGetWpl(), PROCNAME, and rmask32.

Referenced by main(), pixCreateNoInit(), and pixSeedfillBinary().

l_int32 pixSetPadBitsBand ( PIX pix,
l_int32  by,
l_int32  bh,
l_int32  val 
)

pixSetPadBitsBand()

Input: pix (1, 2, 4, 8, 16, 32 bpp) by (starting y value of band) bh (height of band) val (0 or 1) Return: 0 if OK; 1 on error

Notes: (1) The pad bits are the bits that expand each scanline to a multiple of 32 bits. They are usually not used in image processing operations. When boundary conditions are important, as in seedfill, they must be set properly. (2) This sets the value of the pad bits (if any) in the last 32-bit word in each scanline, within the specified band of raster lines. (3) For 32 bpp pix, there are no pad bits, so this is a no-op.

Definition at line 1092 of file pix2.c.

References ERROR_INT, pixGetData(), pixGetDimensions(), pixGetWpl(), PROCNAME, and rmask32.

l_int32 pixSetOrClearBorder ( PIX pixs,
l_int32  left,
l_int32  right,
l_int32  top,
l_int32  bot,
l_int32  op 
)

pixSetOrClearBorder()

Input: pixs (all depths) left, right, top, bot (amount to set or clear) operation (PIX_SET or PIX_CLR) Return: 0 if OK; 1 on error

Notes: (1) The border region is defined to be the region in the image within a specific distance of each edge. Here, we allow the pixels within a specified distance of each edge to be set independently. This either sets or clears all pixels in the border region. (2) For binary images, use PIX_SET for black and PIX_CLR for white. (3) For grayscale or color images, use PIX_SET for white and PIX_CLR for black.

Definition at line 1162 of file pix2.c.

References ERROR_INT, NULL, PIX_CLR, PIX_SET, pixGetDimensions(), pixRasterop(), and PROCNAME.

Referenced by main(), pixCloseCompBrickDwa(), pixCloseGray(), pixConformsToRectangle(), pixDilateGray(), pixErodeGray(), pixExtractBorderConnComps(), pixFillClosedBorders(), pixFMorphopGen_1(), pixFMorphopGen_2(), pixFMorphopGen_3(), pixHolesByFilling(), pixOpenCompBrickDwa(), pixOpenGray(), and pixRemoveSeededComponents().

l_int32 pixSetBorderVal ( PIX pixs,
l_int32  left,
l_int32  right,
l_int32  top,
l_int32  bot,
l_uint32  val 
)

pixSetBorderVal()

Input: pixs (8, 16 or 32 bpp) left, right, top, bot (amount to set) val (value to set at each border pixel) Return: 0 if OK; 1 on error

Notes: (1) The border region is defined to be the region in the image within a specific distance of each edge. Here, we allow the pixels within a specified distance of each edge to be set independently. This sets the pixels in the border region to the given input value. (2) For efficiency, use pixSetOrClearBorder() if you're setting the border to either black or white. (3) If d != 32, the input value should be masked off to the appropriate number of least significant bits. (4) The code is easily generalized for 2 or 4 bpp.

Definition at line 1209 of file pix2.c.

References ERROR_INT, pixGetData(), pixGetDimensions(), pixGetWpl(), PROCNAME, SET_DATA_BYTE, and SET_DATA_TWO_BYTES.

Referenced by pixCloseGray3(), pixDilateGray3h(), pixErodeGray3h(), and pixOpenGray3().

l_int32 pixSetBorderRingVal ( PIX pixs,
l_int32  dist,
l_uint32  val 
)

pixSetBorderRingVal()

Input: pixs (any depth; cmap OK) dist (distance from outside; must be > 0; first ring is 1) val (value to set at each border pixel) Return: 0 if OK; 1 on error

Notes: (1) The rings are single-pixel-wide rectangular sets of pixels at a given distance from the edge of the pix. This sets all pixels in a given ring to a value.

Definition at line 1313 of file pix2.c.

References ERROR_INT, pixGetDimensions(), pixSetPixel(), and PROCNAME.

Referenced by pixAffinePtaWithAlpha(), pixBilinearPtaWithAlpha(), pixProjectivePtaWithAlpha(), pixRotateWithAlpha(), and pixScaleWithAlpha().

l_int32 pixSetMirroredBorder ( PIX pixs,
l_int32  left,
l_int32  right,
l_int32  top,
l_int32  bot 
)

pixSetMirroredBorder()

Input: pixs (all depths; colormap ok) left, right, top, bot (number of pixels to set) Return: 0 if OK, 1 on error

Notes: (1) This applies what is effectively mirror boundary conditions to a border region in the image. It is in-place. (2) This is useful for setting pixels near the border to a value representative of the near pixels to the interior. (3) The general pixRasterop() is used for an in-place operation here because there is no overlap between the src and dest rectangles.

Definition at line 1362 of file pix2.c.

References ERROR_INT, NULL, PIX_SRC, pixGetDimensions(), pixRasterop(), and PROCNAME.

Referenced by pixDistanceFunction().

PIX* pixCopyBorder ( PIX pixd,
PIX pixs,
l_int32  left,
l_int32  right,
l_int32  top,
l_int32  bot 
)

pixCopyBorder()

Input: pixd (all depths; colormap ok; can be NULL) pixs (same depth and size as pixd) left, right, top, bot (number of pixels to copy) Return: pixd, or null on error if pixd is not defined

Notes: (1) pixd can be null, but otherwise it must be the same size and depth as pixs. Always returns pixd. (1) This is useful in situations where by setting a few border pixels we can avoid having to copy all pixels in pixs into pixd as an initialization step for some operation.

Definition at line 1409 of file pix2.c.

References ERROR_PTR, L_WARNING, NULL, PIX_SRC, pixCreateTemplateNoInit(), pixGetDimensions(), pixRasterop(), pixSizesEqual(), and PROCNAME.

Referenced by pixUnsharpMaskingGray1D(), and pixUnsharpMaskingGray2D().

PIX* pixAddBlackBorder ( PIX pixs,
l_int32  npix 
)

pixAddBlackBorder()

Input: pixs (all depths; colormap ok) npix (number of pixels to be added to each side) Return: pixd (with the added exterior pixels), or null on error

Definition at line 1485 of file pix2.c.

References ERROR_PTR, NULL, pixAddBorderGeneral(), pixClone(), pixcmapGetRankIntensity(), pixGetColormap(), pixGetDepth(), and PROCNAME.

Referenced by main().

PIX* pixAddBorderGeneral ( PIX pixs,
l_int32  left,
l_int32  right,
l_int32  top,
l_int32  bot,
l_uint32  val 
)

pixAddBorderGeneral()

Input: pixs (all depths; colormap ok) left, right, top, bot (number of pixels added) val (value of added border pixels) Return: pixd (with the added exterior pixels), or null on error

Notes: (1) For binary images: white: val = 0 black: val = 1 For grayscale images: white: val = 2 ** d - 1 black: val = 0 For rgb color images: white: val = 0xffffff00 black: val = 0 For colormapped images, use 'index' found this way: white: pixcmapGetRankIntensity(cmap, 1.0, &index); black: pixcmapGetRankIntensity(cmap, 0.0, &index);

Definition at line 1531 of file pix2.c.

References ERROR_PTR, NULL, PIX_CLR, PIX_SET, PIX_SRC, pixCopyColormap(), pixCopyResolution(), pixCreateNoInit(), pixGetDimensions(), pixRasterop(), pixSetAllArbitrary(), PROCNAME, and UNDEF.

Referenced by jbClassifyCorrelation(), jbClassifyRankHaus(), main(), pixaAddBorderGeneral(), pixAddBlackBorder(), pixAddBorder(), pixAddMirroredBorder(), pixAddMixedBorder(), pixAddRepeatedBorder(), pixAffineSequential(), pixCloseCompBrickExtendDwa(), pixCloseGray(), pixCloseGray3(), pixCloseSafe(), pixDilateGray(), pixDilateGray3(), pixErodeGray(), pixErodeGray3(), pixMirrorDetectDwa(), pixOpenGray(), pixOpenGray3(), pixUpDownDetectGeneralDwa(), pixWindowedMean(), pixWindowedMeanSquare(), pixWindowedStats(), and ptaaGetBoundaryPixels().

PIX* pixRemoveBorderGeneral ( PIX pixs,
l_int32  left,
l_int32  right,
l_int32  top,
l_int32  bot 
)

pixRemoveBorderGeneral()

Input: pixs (all depths; colormap ok) left, right, top, bot (number of pixels added) Return: pixd (with pixels removed around border), or null on error

Definition at line 1608 of file pix2.c.

References ERROR_PTR, NULL, PIX_SRC, pixCopyColormap(), pixCopyResolution(), pixCreateNoInit(), pixGetDimensions(), pixRasterop(), and PROCNAME.

Referenced by pixAffineSequential(), pixCloseCompBrickExtendDwa(), pixCloseGray(), pixCloseGray3(), pixCloseSafe(), pixDilateGray(), pixDilateGray3(), pixErodeGray(), pixErodeGray3(), pixOpenGray(), pixOpenGray3(), and pixRemoveBorder().

PIX* pixAddMirroredBorder ( PIX pixs,
l_int32  left,
l_int32  right,
l_int32  top,
l_int32  bot 
)

pixAddMirroredBorder()

Input: pixs (all depths; colormap ok) left, right, top, bot (number of pixels added) Return: pixd, or null on error

Notes: (1) This applies what is effectively mirror boundary conditions. For the added border pixels in pixd, the pixels in pixs near the border are mirror-copied into the border region. (2) This is useful for avoiding special operations near boundaries when doing image processing operations such as rank filters and convolution. In use, one first adds mirrored pixels to each side of the image. The number of pixels added on each side is half the filter dimension. Then the image processing operations proceed over a region equal to the size of the original image, and write directly into a dest pix of the same size as pixs. (3) The general pixRasterop() is used for an in-place operation here because there is no overlap between the src and dest rectangles.

Definition at line 1664 of file pix2.c.

References ERROR_PTR, NULL, PIX_SRC, pixAddBorderGeneral(), pixGetDimensions(), pixRasterop(), and PROCNAME.

Referenced by main(), pixBlockconvGrayUnnormalized(), pixConvolve(), pixFindHistoPeaksHSV(), pixRankFilterGray(), pixSauvolaBinarize(), pixSobelEdgeFilter(), and pixTilingGetTile().

PIX* pixAddRepeatedBorder ( PIX pixs,
l_int32  left,
l_int32  right,
l_int32  top,
l_int32  bot 
)

pixAddRepeatedBorder()

Input: pixs (all depths; colormap ok) left, right, top, bot (number of pixels added) Return: pixd, or null on error

Notes: (1) This applies a repeated border, as if the central part of the image is tiled over the plane. So, for example, the pixels in the left border come from the right side of the image. (2) The general pixRasterop() is used for an in-place operation here because there is no overlap between the src and dest rectangles.

Definition at line 1714 of file pix2.c.

References ERROR_PTR, NULL, PIX_SRC, pixAddBorderGeneral(), pixGetDimensions(), pixRasterop(), and PROCNAME.

PIX* pixAddMixedBorder ( PIX pixs,
l_int32  left,
l_int32  right,
l_int32  top,
l_int32  bot 
)

pixAddMixedBorder()

Input: pixs (all depths; colormap ok) left, right, top, bot (number of pixels added) Return: pixd, or null on error

Notes: (1) This applies mirrored boundary conditions horizontally and repeated b.c. vertically. (2) It is specifically used for avoiding special operations near boundaries when convolving a hue-saturation histogram with a given window size. The repeated b.c. are used vertically for hue, and the mirrored b.c. are used horizontally for saturation. The number of pixels added on each side is approximately (but not quite) half the filter dimension. The image processing operations can then proceed over a region equal to the size of the original image, and write directly into a dest pix of the same size as pixs. (3) The general pixRasterop() can be used for an in-place operation here because there is no overlap between the src and dest rectangles.

Definition at line 1768 of file pix2.c.

References ERROR_PTR, NULL, PIX_SRC, pixAddBorderGeneral(), pixGetDimensions(), pixRasterop(), and PROCNAME.

Referenced by pixFindHistoPeaksHSV().

PIX* pixCreateRGBImage ( PIX pixr,
PIX pixg,
PIX pixb 
)

pixCreateRGBImage()

Input: 8 bpp red pix 8 bpp green pix 8 bpp blue pix Return: 32 bpp pix, interleaved with 4 samples/pixel, or null on error

Notes: (1) the 4th byte, sometimes called the "alpha channel", and which is often used for blending between different images, is left with 0 value. (2) see Note (4) in pix.h for details on storage of 8-bit samples within each 32-bit word. (3) This implementation, setting the r, g and b components sequentially, is much faster than setting them in parallel by constructing an RGB dest pixel and writing it to dest. The reason is there are many more cache misses when reading from 3 input images simultaneously.

Definition at line 1827 of file pix2.c.

References COLOR_BLUE, COLOR_GREEN, COLOR_RED, ERROR_PTR, NULL, pixCopyResolution(), pixCreate(), pixGetDimensions(), pixSetRGBComponent(), and PROCNAME.

Referenced by pixBlockconv(), pixBlockconvTiled(), pixColorMorph(), pixCompareRGB(), pixConvolveRGB(), pixConvolveRGBSep(), pixRankFilterRGB(), pixScaleColor4xLI(), pixSetUnderTransparency(), pixUnsharpMasking(), pixUnsharpMaskingFast(), and pixWarpStereoscopic().

PIX* pixGetRGBComponent ( PIX pixs,
l_int32  color 
)

pixGetRGBComponent()

Input: pixs (32 bpp) color (one of {COLOR_RED, COLOR_GREEN, COLOR_BLUE, L_ALPHA_CHANNEL}) Return: pixd, the selected 8 bpp component image of the input 32 bpp image, or null on error

Notes: (1) The alpha channel (in the 4th byte of each RGB pixel) is mostly ignored in leptonica. (2) Three calls to this function generate the three 8 bpp component images. This is much faster than generating the three images in parallel, by extracting a src pixel and setting the pixels of each component image from it. The reason is there are many more cache misses when writing to three output images simultaneously.

Definition at line 1883 of file pix2.c.

References COLOR_BLUE, COLOR_GREEN, COLOR_RED, ERROR_PTR, GET_DATA_BYTE, L_ALPHA_CHANNEL, NULL, pixCopyResolution(), pixCreate(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), PROCNAME, and SET_DATA_BYTE.

Referenced by main(), pixBlendWithGrayMask(), pixBlockconv(), pixBlockconvTiled(), pixColorMorph(), pixColorsForQuantization(), pixCompareRGB(), pixCompareTiled(), pixConvolveRGB(), pixConvolveRGBSep(), pixEqualizeTRC(), pixGammaTRCWithAlpha(), pixGetAverageMaskedRGB(), pixGetAverageTiledRGB(), pixGetRankColorArray(), pixRankFilterRGB(), pixScaleColor4xLI(), pixSetUnderTransparency(), pixUnsharpMasking(), pixUnsharpMaskingFast(), and pixWarpStereoscopic().

l_int32 pixSetRGBComponent ( PIX pixd,
PIX pixs,
l_int32  color 
)

pixSetRGBComponent()

Input: pixd (32 bpp) pixs (8 bpp) color (one of {COLOR_RED, COLOR_GREEN, COLOR_BLUE, L_ALPHA_CHANNEL}) Return: 0 if OK; 1 on error

Notes: (1) This places the 8 bpp pixel in pixs into the specified color component (properly interleaved) in pixd. (2) The alpha channel component mostly ignored in leptonica.

Definition at line 1940 of file pix2.c.

References COLOR_BLUE, COLOR_GREEN, COLOR_RED, ERROR_INT, GET_DATA_BYTE, L_ALPHA_CHANNEL, NULL, pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetHeight(), pixGetWidth(), pixGetWpl(), PROCNAME, and SET_DATA_BYTE.

Referenced by main(), pixAffinePtaWithAlpha(), pixBilinearPtaWithAlpha(), pixCreateRGBImage(), pixEqualizeTRC(), pixGammaTRCWithAlpha(), pixProjectivePtaWithAlpha(), pixRotateWithAlpha(), pixScaleWithAlpha(), and pixSetUnderTransparency().

PIX* pixGetRGBComponentCmap ( PIX pixs,
l_int32  color 
)

pixGetRGBComponentCmap()

Input: pixs (colormapped) color (one of {COLOR_RED, COLOR_GREEN, COLOR_BLUE}) Return: pixd (the selected 8 bpp component image of the input cmapped image), or null on error

Definition at line 1994 of file pix2.c.

References PixColormap::array, COLOR_BLUE, COLOR_GREEN, COLOR_RED, ERROR_PTR, GET_DATA_BYTE, RGBA_Quad::green, NULL, pixClone(), pixConvertTo8(), pixCopyResolution(), pixCreateNoInit(), pixDestroy(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), PROCNAME, RGBA_Quad::red, SET_DATA_BYTE, and TRUE.

Referenced by pixGetAverageMaskedRGB(), and pixGetAverageTiledRGB().

l_int32 composeRGBPixel ( l_int32  rval,
l_int32  gval,
l_int32  bval,
l_uint32 ppixel 
)

composeRGBPixel()

Input: rval, gval, bval &rgbpixel (<return> 32-bit pixel) Return: 0 if OK; 1 on error

Notes: (1) A slower implementation uses macros: SET_DATA_BYTE(ppixel, COLOR_RED, rval); SET_DATA_BYTE(ppixel, COLOR_GREEN, gval); SET_DATA_BYTE(ppixel, COLOR_BLUE, bval);

Definition at line 2076 of file pix2.c.

References ERROR_INT, L_BLUE_SHIFT, L_GREEN_SHIFT, L_RED_SHIFT, and PROCNAME.

Referenced by AddTransformsRGB(), AddTransformsYUV(), main(), pixAddSingleTextblock(), pixApplyInvBackgroundRGBMap(), pixBlendBoxaRandom(), pixBlendColor(), pixBlendColorByChannel(), pixBlendGray(), pixBlendGrayAdapt(), pixBlendHardLight(), pixBlendInRect(), pixBlendMask(), pixBlendWithGrayMask(), pixClipMasked(), pixcmapGetColor32(), pixcmapToRGBTable(), pixColorGray(), pixConvert24To32(), pixConvertColorToSubpixelRGB(), pixConvertGrayToSubpixelRGB(), pixConvertHSVToRGB(), pixConvertYUVToRGB(), pixDisplayPta(), pixDisplayPtaa(), pixelFractionalShift(), pixelLinearMapToTargetColor(), pixFadeWithGray(), pixFixedOctcubeQuantGenRGB(), pixGetBinnedColor(), pixGetRandomPixel(), pixGlobalNormRGB(), pixHShearLI(), pixLinearMapToTargetColor(), pixModifyHue(), pixModifySaturation(), pixMultConstantColor(), pixMultMatrixColor(), pixPaintBoxaRandom(), pixQuadraticVShearLI(), pixReadFromTiffStream(), pixReadStreamJpeg(), pixReadStreamPnm(), pixRemoveColormap(), pixRenderPtaArb(), pixRenderPtaBlend(), pixSearchBinaryMaze(), pixSearchGrayMaze(), pixSetRGBPixel(), pixSetTextline(), pixStereoFromPair(), pixStretchHorizontalLI(), pixVShearLI(), rotateAMColorCornerLow(), rotateAMColorLow(), scaleAreaMapLow2(), and scaleColorAreaMapLow().

void extractRGBValues ( l_uint32  pixel,
l_int32 prval,
l_int32 pgval,
l_int32 pbval 
)

extractRGBValues()

Input: pixel (32 bit) &rval (<optional return>=""> red component) &gval (<optional return>=""> green component) &bval (<optional return>=""> blue component) Return: void

Notes: (1) A slower implementation uses macros: *prval = GET_DATA_BYTE(&pixel, COLOR_RED); *pgval = GET_DATA_BYTE(&pixel, COLOR_GREEN); *pbval = GET_DATA_BYTE(&pixel, COLOR_BLUE);

Definition at line 2108 of file pix2.c.

References L_BLUE_SHIFT, L_GREEN_SHIFT, and L_RED_SHIFT.

Referenced by boxaaDisplay(), extractMinMaxComponent(), make_24_bpp_pix(), octreeGenerateAndPrune(), pixAddSingleTextblock(), pixBlendColor(), pixBlendColorByChannel(), pixBlendGray(), pixBlendGrayAdapt(), pixBlendHardLight(), pixBlendInRect(), pixBlendMask(), pixBlendWithGrayMask(), pixClipMasked(), pixcmapGrayToColor(), pixColorContent(), pixColorFraction(), pixColorMagnitude(), pixConvert32To24(), pixConvertColorToSubpixelRGB(), pixConvertRGBToGrayMinMax(), pixConvertRGBToHSV(), pixConvertRGBToHue(), pixConvertRGBToSaturation(), pixConvertRGBToValue(), pixConvertRGBToYUV(), pixDisplayColorArray(), pixDrawBoxa(), pixelLinearMapToTargetColor(), pixFadeWithGray(), pixFewColorsOctcubeQuant1(), pixFewColorsOctcubeQuant2(), pixFixedOctcubeQuant256(), pixFixedOctcubeQuantGenRGB(), pixGenerateMaskByBand32(), pixGenerateMaskByDiscr32(), pixGetBinnedColor(), pixGetBinnedComponentRange(), pixGetColorHistogram(), pixGetColorHistogramMasked(), pixGetDifferenceHistogram(), pixGetPSNR(), pixGetRasterData(), pixGlobalNormRGB(), pixLinearMapToTargetColor(), pixMaskOverColorPixels(), pixMeasureSaturation(), pixMedianCutQuantMixed(), pixModifyHue(), pixModifySaturation(), pixMultConstantColor(), pixMultMatrixColor(), pixNumberOccupiedOctcubes(), pixNumColors(), pixOctcubeHistogram(), pixOctcubeQuantFromCmapLUT(), pixOctcubeQuantMixedWithGray(), pixOctreeQuantByPopulation(), pixOctreeQuantizePixels(), pixOctreeQuantNumColors(), pixPaintBoxa(), pixPaintThroughMask(), pixSetMasked(), pixSetTextline(), pixSetUnderTransparency(), pixSnapColor(), and pixSnapColorCmap().

l_int32 extractMinMaxComponent ( l_uint32  pixel,
l_int32  type 
)

extractMinMaxComponent()

Input: pixel (32 bpp RGB) type (L_CHOOSE_MIN or L_CHOOSE_MAX) Return: componet (in range [0 ... 255], or null on error

Definition at line 2128 of file pix2.c.

References extractRGBValues(), L_CHOOSE_MIN, L_MAX, and L_MIN.

l_int32 pixGetRGBLine ( PIX pixs,
l_int32  row,
l_uint8 bufr,
l_uint8 bufg,
l_uint8 bufb 
)

pixGetRGBLine()

Input: pixs (32 bpp) row bufr (array of red samples; size w bytes) bufg (array of green samples; size w bytes) bufb (array of blue samples; size w bytes) Return: 0 if OK; 1 on error

Notes: (1) This puts rgb components from the input line in pixs into the given buffers.

Definition at line 2161 of file pix2.c.

References COLOR_BLUE, COLOR_GREEN, COLOR_RED, ERROR_INT, GET_DATA_BYTE, NULL, pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), and PROCNAME.

Referenced by pixDitherOctindexWithCmap(), pixOctreeQuantizePixels(), and pixQuantizeWithColormap().

PIX* pixEndianByteSwapNew ( PIX pixs)

pixEndianByteSwapNew()

Input: pixs Return: pixd, or null on error

Notes: (1) This is used to convert the data in a pix to a serialized byte buffer in raster order, and, for RGB, in order RGBA. This requires flipping bytes within each 32-bit word for little-endian platforms, because the words have a MSB-to-the-left rule, whereas byte raster-order requires the left-most byte in each word to be byte 0. For big-endians, no swap is necessary, so this returns a clone. (2) Unlike pixEndianByteSwap(), which swaps the bytes in-place, this returns a new pix (or a clone). We provide this because often when serialization is done, the source pix needs to be restored to canonical little-endian order, and this requires a second byte swap. In such a situation, it is twice as fast to make a new pix in big-endian order, use it, and destroy it.

Definition at line 2222 of file pix2.c.

References ERROR_PTR, NULL, pixClone(), pixCreateTemplate(), pixGetData(), pixGetHeight(), pixGetWpl(), and PROCNAME.

Referenced by pixWriteStreamPng(), pixWriteStreamWebP(), and pixWriteToTiffStream().

l_int32 pixEndianByteSwap ( PIX pixs)

pixEndianByteSwap()

Input: pixs Return: 0 if OK, 1 on error

Notes: (1) This is used on little-endian platforms to swap the bytes within a word; bytes 0 and 3 are swapped, and bytes 1 and 2 are swapped. (2) This is required for little-endians in situations where we convert from a serialized byte order that is in raster order, as one typically has in file formats, to one with MSB-to-the-left in each 32-bit word, or v.v. See pix.h for a description of the canonical format (MSB-to-the left) that is used for both little-endian and big-endian platforms. For big-endians, the MSB-to-the-left word order has the bytes in raster order when serialized, so no byte flipping is required.

Definition at line 2283 of file pix2.c.

References ERROR_INT, pixGetData(), pixGetHeight(), pixGetWpl(), and PROCNAME.

Referenced by pixCleanupByteProcessing(), pixReadFromTiffStream(), pixReadStreamBmp(), pixReadStreamWebP(), pixSetupByteProcessing(), pixWriteStreamBmp(), and pixWriteStreamPng().

l_int32 lineEndianByteSwap ( l_uint32 datad,
l_uint32 datas,
l_int32  wpl 
)

lineEndianByteSwap()

Input datad (dest byte array data, reordered on little-endians) datas (a src line of pix data) wpl (number of 32 bit words in the line) Return: 0 if OK, 1 on error

Notes: (1) This is used on little-endian platforms to swap the bytes within each word in the line of image data. Bytes 0 <==> 3 and 1 <==> 2 are swapped in the dest byte array data8d, relative to the pix data in datas. (2) The bytes represent 8 bit pixel values. They are swapped for little endians so that when the dest array (char *)datad is addressed by bytes, the pixels are chosen sequentially from left to right in the image.

Definition at line 2339 of file pix2.c.

References ERROR_INT, and PROCNAME.

PIX* pixEndianTwoByteSwapNew ( PIX pixs)

pixEndianTwoByteSwapNew()

Input: pixs Return: 0 if OK, 1 on error

Notes: (1) This is used on little-endian platforms to swap the 2-byte entities within a 32-bit word. (2) This is equivalent to a full byte swap, as performed by pixEndianByteSwap(), followed by byte swaps in each of the 16-bit entities separately. (3) Unlike pixEndianTwoByteSwap(), which swaps the shorts in-place, this returns a new pix (or a clone). We provide this to avoid having to swap twice in situations where the input pix must be restored to canonical little-endian order.

Definition at line 2390 of file pix2.c.

References ERROR_PTR, NULL, pixClone(), pixCreateTemplate(), pixGetData(), pixGetHeight(), pixGetWpl(), and PROCNAME.

Referenced by pixWriteToTiffStream().

l_int32 pixEndianTwoByteSwap ( PIX pixs)

pixEndianTwoByteSwap()

Input: pixs Return: 0 if OK, 1 on error

Notes: (1) This is used on little-endian platforms to swap the 2-byte entities within a 32-bit word. (2) This is equivalent to a full byte swap, as performed by pixEndianByteSwap(), followed by byte swaps in each of the 16-bit entities separately.

Definition at line 2441 of file pix2.c.

References ERROR_INT, pixGetData(), pixGetHeight(), pixGetWpl(), and PROCNAME.

Referenced by pixReadFromTiffStream().

l_int32 pixGetRasterData ( PIX pixs,
l_uint8 **  pdata,
size_t *  pnbytes 
)

pixGetRasterData()

Input: pixs (1, 8, 32 bpp) &data (<return> raster data in memory) &nbytes (<return> number of bytes in data string) Return: 0 if OK, 1 on error

Notes: (1) This returns the raster data as a byte string, padded to the byte. For 1 bpp, the first pixel is the MSbit in the first byte. For rgb, the bytes are in (rgb) order. This is the format required for flate encoding of pixels in a PostScript file.

Definition at line 2493 of file pix2.c.

References CALLOC, ERROR_INT, extractRGBValues(), GET_DATA_BYTE, GET_DATA_TWO_BYTES, NULL, pixGetData(), pixGetDimensions(), pixGetWpl(), and PROCNAME.

Referenced by pixGenerateFlateData().

l_uint8** pixSetupByteProcessing ( PIX pix,
l_int32 pw,
l_int32 ph 
)

pixSetupByteProcessing()

Input: pix (8 bpp, no colormap) &w (<optional return>=""> width) &h (<optional return>=""> height) Return: line ptr array, or null on error

Notes: (1) This is a simple helper for processing 8 bpp images with direct byte access. It can swap byte order within each word. (2) After processing, you must call pixCleanupByteProcessing(), which frees the lineptr array and restores byte order. (3) Usage: l_uint8 **lineptrs = pixSetupByteProcessing(pix, &w, &h); for (i = 0; i < h; i++) { l_uint8 *line = lineptrs[i]; for (j = 0; j < w; j++) { val = line[j]; ... } } pixCleanupByteProcessing(pix, lineptrs);

Definition at line 2583 of file pix2.c.

References ERROR_PTR, NULL, pixEndianByteSwap(), pixGetColormap(), pixGetDepth(), pixGetDimensions(), pixGetLinePtrs(), and PROCNAME.

l_int32 pixCleanupByteProcessing ( PIX pix,
l_uint8 **  lineptrs 
)

pixCleanupByteProcessing()

Input: pix (8 bpp, no colormap) lineptrs (ptrs to the beginning of each raster line of data) Return: 0 if OK, 1 on error

Notes: (1) This must be called after processing that was initiated by pixSetupByteProcessing() has finished.

Definition at line 2619 of file pix2.c.

References ERROR_INT, FREE, pixEndianByteSwap(), and PROCNAME.

void l_setAlphaMaskBorder ( l_float32  val1,
l_float32  val2 
)

l_setAlphaMaskBorder()

Input: val1, val2 (in [0.0 ... 1.0]) Return: void

Notes: (1) This sets the opacity values used to generate the two outer boundary rings in the alpha mask associated with geometric transforms such as pixRotateWithAlpha(). (2) The default values are val1 = 0.0 (completely transparent in the outermost ring) and val2 = 0.5 (half transparent in the second ring). When the image is blended, this completely removes the outer ring (shrinking the image by 2 in each direction), and alpha-blends with 0.5 the second ring. (3) The actual mask values are found by multiplying these normalized opacity values by 255.

Definition at line 2657 of file pix2.c.

References AlphaMaskBorderVals, L_MAX, and L_MIN.


Variable Documentation

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 104 of file pix2.c.

Referenced by pixSetPadBits(), and pixSetPadBitsBand().

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines