#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "allheaders.h"
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);
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);
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.
Input: pixs (all depths; colormap ok) npix (number of pixels to be added to each side) val (value of added border pixels) Return: pixd (with the input pixs centered), or null on error
Notes: (1) See pixAddBorderGeneral() for values of white & black pixels.
PIX* pixAddBorderGeneral | ( | PIX * | pixs, | |
l_int32 | left, | |||
l_int32 | right, | |||
l_int32 | top, | |||
l_int32 | bot, | |||
l_uint32 | val | |||
) |
Input: pixs (all depths; colormap ok) left, right, top, bot (number of pixels added) val (value of added border pixels) Return: pixd (with the input pixs inserted), or null on error
Notes: (1) For binary images: white: val = 0 black: val = 1 (2) For grayscale images: white: val = 2 ** d - 1 black: val = 0 (3) For rgb color images: white: val = 0xffffff00 black: val = 0
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.
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.
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.
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.
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!
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!
Input: pix (x,y) pixel coords Return: 0 if OK; 1 on error.
PIX* pixCopyBorder | ( | PIX * | pixd, | |
PIX * | pixs, | |||
l_int32 | left, | |||
l_int32 | right, | |||
l_int32 | top, | |||
l_int32 | bot | |||
) |
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.
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.
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.
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.
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.
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.
Input: pix (x,y) pixel coords Return: 0 if OK; 1 on error
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.
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.
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 not used 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.
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
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.
l_int32 pixGetRGBPixel | ( | PIX * | pix, | |
l_int32 | x, | |||
l_int32 | y, | |||
l_int32 * | prval, | |||
l_int32 * | pgval, | |||
l_int32 * | pbval | |||
) |
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
Input: pixs (all depths; colormap ok) npix (number to be removed from each of the 4 sides) Return: pixd (with pixels removed around border), or null on error
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
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.
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!
Input: pixs (all depths; cmap ok) incolor (L_BRING_IN_BLACK or L_BRING_IN_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.
l_int32 pixSetBorderVal | ( | PIX * | pixs, | |
l_int32 | left, | |||
l_int32 | right, | |||
l_int32 | top, | |||
l_int32 | bot, | |||
l_uint32 | val | |||
) |
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.
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.
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!
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.
l_int32 pixSetOrClearBorder | ( | PIX * | pixs, | |
l_int32 | left, | |||
l_int32 | right, | |||
l_int32 | top, | |||
l_int32 | bot, | |||
l_int32 | op | |||
) |
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.
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.
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.
Input: pix (x,y) pixel coords val (value to be inserted) Return: 0 if OK; 1 on error
Note: the input value is not checked for overflow, and the sign bit (if any) is ignored.
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 is not used in leptonica.
l_int32 pixSetRGBPixel | ( | PIX * | pix, | |
l_int32 | x, | |||
l_int32 | y, | |||
l_int32 | rval, | |||
l_int32 | gval, | |||
l_int32 | bval | |||
) |
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
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!
Инициализатор
{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}