Leptonica 1.68
C Image Processing Library
|
Convert between images of different types without scaling. More...
Go to the source code of this file.
Convert between images of different types without scaling.
These functions convert between images of different types without scaling. Conversion from 8 bpp grayscale to 1, 2, 4 and 8 bpp PIX *pixThreshold8() Conversion from colormap to full color or grayscale PIX *pixRemoveColormap() Add colormap losslessly (8 to 8) l_int32 pixAddGrayColormap8() PIX *pixAddMinimalGrayColormap8() Conversion from RGB color to grayscale PIX *pixConvertRGBToLuminance() PIX *pixConvertRGBToGray() PIX *pixConvertRGBToGrayFast() PIX *pixConvertRGBToGrayMinMax() Conversion from grayscale to colormap PIX *pixConvertGrayToColormap() -- 2, 4, 8 bpp PIX *pixConvertGrayToColormap8() -- 8 bpp only Colorizing conversion from grayscale to color PIX *pixColorizeGray() -- 8 bpp or cmapped Conversion from RGB color to colormap PIX *pixConvertRGBToColormap() Quantization for relatively small number of colors in source l_int32 pixQuantizeIfFewColors() Conversion from 16 bpp to 8 bpp PIX *pixConvert16To8() Conversion from grayscale to false color PIX *pixConvertGrayToFalseColor() Unpacking conversion from 1 bpp to 2, 4, 8, 16 and 32 bpp PIX *pixUnpackBinary() PIX *pixConvert1To16() PIX *pixConvert1To32() Unpacking conversion from 1 bpp to 2 bpp PIX *pixConvert1To2Cmap() PIX *pixConvert1To2() Unpacking conversion from 1 bpp to 4 bpp PIX *pixConvert1To4Cmap() PIX *pixConvert1To4() Unpacking conversion from 1, 2 and 4 bpp to 8 bpp PIX *pixConvert1To8() PIX *pixConvert2To8() PIX *pixConvert4To8() Unpacking conversion from 8 bpp to 16 bpp PIX *pixConvert8To16() Top-level conversion to 1 bpp PIX *pixConvertTo1() PIX *pixConvertTo1BySampling() Top-level conversion to 8 bpp PIX *pixConvertTo8() PIX *pixConvertTo8BySampling() Top-level conversion to 16 bpp PIX *pixConvertTo16() Top-level conversion to 32 bpp (RGB) PIX *pixConvertTo32() *** PIX *pixConvertTo32BySampling() *** PIX *pixConvert8To32() *** Top-level conversion to 8 or 32 bpp, without colormap PIX *pixConvertTo8Or32 Conversion between 24 bpp and 32 bpp rgb PIX *pixConvert24To32() PIX *pixConvert32To24() Lossless depth conversion (unpacking) PIX *pixConvertLossless() Conversion for printing in PostScript PIX *pixConvertForPSWrap() Scaling conversion to subpixel RGB PIX *pixConvertToSubpixelRGB() PIX *pixConvertGrayToSubpixelRGB() PIX *pixConvertColorToSubpixelRGB() indicates implicit assumption about RGB component ordering
Definition in file pixconv.c.
Input: pix (8 bpp grayscale) d (destination depth: 1, 2, 4 or 8) nlevels (number of levels to be used for colormap) cmapflag (1 if makes colormap; 0 otherwise) Return: pixd (thresholded with standard dest thresholds), or null on error
Notes: (1) This uses, by default, equally spaced "target" values that depend on the number of levels, with thresholds halfway between. For N levels, with separation (N-1)/255, there are N-1 fixed thresholds. (2) For 1 bpp destination, the number of levels can only be 2 and if a cmap is made, black is (0,0,0) and white is (255,255,255), which is opposite to the convention without a colormap. (3) For 1, 2 and 4 bpp, the nlevels arg is used if a colormap is made; otherwise, we take the most significant bits from the src that will fit in the dest. (4) For 8 bpp, the input pixs is quantized to nlevels. The dest quantized with that mapping, either through a colormap table or directly with 8 bit values. (5) Typically you should not use make a colormap for 1 bpp dest. (6) This is not dithering. Each pixel is treated independently.
Definition at line 157 of file pixconv.c.
References ERROR_PTR, NULL, pixcmapCreateLinear(), pixGetDepth(), pixSetColormap(), pixThresholdOn8bpp(), pixThresholdTo2bpp(), pixThresholdTo4bpp(), pixThresholdToBinary(), and PROCNAME.
Referenced by main().
Input: pixs (see restrictions below) type (REMOVE_CMAP_TO_BINARY, REMOVE_CMAP_TO_GRAYSCALE, REMOVE_CMAP_TO_FULL_COLOR, REMOVE_CMAP_BASED_ON_SRC) Return: new pix, or null on error
Notes: (1) If there is no colormap, a clone is returned. (2) Otherwise, the input pixs is restricted to 1, 2, 4 or 8 bpp. (3) Use REMOVE_CMAP_TO_BINARY only on 1 bpp pix. (4) For grayscale conversion from RGB, use a weighted average of RGB values, and always return an 8 bpp pix, regardless of whether the input pixs depth is 2, 4 or 8 bpp.
Definition at line 223 of file pixconv.c.
References CALLOC, composeRGBPixel(), ERROR_PTR, FREE, GET_DATA_BIT, GET_DATA_BYTE, GET_DATA_DIBIT, GET_DATA_QBIT, L_WARNING, NULL, pixClone(), pixcmapGetColor(), pixcmapGetCount(), pixcmapHasColor(), pixcmapToArrays(), pixCopy(), pixCopyResolution(), pixCreate(), pixDestroyColormap(), pixGetColormap(), pixGetData(), pixGetDimensions(), pixGetWpl(), pixInvert(), PROCNAME, REMOVE_CMAP_BASED_ON_SRC, REMOVE_CMAP_TO_BINARY, REMOVE_CMAP_TO_FULL_COLOR, REMOVE_CMAP_TO_GRAYSCALE, SET_DATA_BYTE, x1, and x3.
Referenced by convertFilesTo1bpp(), convertToPSEmbed(), ioFormatTest(), main(), pixAddMinimalGrayColormap8(), pixAffine(), pixAffinePta(), pixAverageIntensityProfile(), pixBilinear(), pixBilinearPta(), pixBlend(), pixBlendColor(), pixBlendColorByChannel(), pixBlendGray(), pixBlendGrayAdapt(), pixBlendHardLight(), pixBlendMask(), pixBlendWithGrayMask(), pixBlockconv(), pixBlockconvTiled(), pixColorContent(), pixColorizeGray(), pixColorMagnitude(), pixCompareGrayOrRGB(), pixConvert2To8(), pixConvert4To8(), pixConvert8To16(), pixConvert8To32(), pixConvertColorToSubpixelRGB(), pixConvertForPSWrap(), pixConvertGrayToFalseColor(), pixConvertGrayToSubpixelRGB(), pixConvertRGBToHue(), pixConvertRGBToSaturation(), pixConvertRGBToValue(), pixConvertTo8(), pixConvertTo8Or32(), pixConvertToFPix(), pixConvertToPdfDataSegmented(), pixConvertToSubpixelRGB(), pixDitherTo2bppSpec(), pixDitherToBinaryLUT(), pixDitherToBinarySpec(), pixEqual(), pixEqualizeTRC(), pixFadeWithGray(), pixGenerateMaskByBand(), pixGenerateMaskByValue(), pixGetAverageMasked(), pixGetAverageTiled(), pixGetDifferenceHistogram(), pixGetGrayHistogram(), pixGetGrayHistogramMasked(), pixGetRankColorArray(), pixHShearLI(), pixMaskOverColorPixels(), pixPlotAlongPta(), pixProjective(), pixProjectivePta(), pixQuadraticVShearLI(), pixReadStreamBmp(), pixReversalProfile(), pixRotate(), pixRotateAM(), pixRotateAMCorner(), pixScaleAreaMap(), pixScaleAreaMap2(), pixScaleSmooth(), pixThresholdGrayArb(), pixThresholdOn8bpp(), pixThresholdTo2bpp(), pixThresholdTo4bpp(), pixThresholdToBinary(), pixVShearLI(), pixWriteStreamAsciiPnm(), pixWriteStreamPnm(), pixWriteStreamWebP(), pixWriteWebPwithTargetPSNR(), TestImage(), and writeMultipageTiffSA().
Input: pixs (8 bpp) Return: 0 if OK, 1 on error
Notes: (1) If pixs has a colormap, this is a no-op.
Definition at line 492 of file pixconv.c.
References ERROR_INT, pixcmapCreateLinear(), pixGetColormap(), pixGetDepth(), pixSetColormap(), and PROCNAME.
Referenced by pixAddMinimalGrayColormap8(), and pixConvertTo8().
Input: pixs (8 bpp) Return: 0 if OK, 1 on error
Notes: (1) This generates a colormapped version of the input image that has the same number of colormap entries as the input image has unique gray levels.
Definition at line 521 of file pixconv.c.
References CALLOC, ERROR_PTR, FREE, GET_DATA_BYTE, NULL, pixAddGrayColormap8(), pixClone(), pixcmapAddColor(), pixcmapCreate(), pixcmapGetCount(), pixCopy(), pixCopyResolution(), pixCreateTemplate(), pixDestroy(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixNumColors(), pixRemoveColormap(), pixSetColormap(), PROCNAME, REMOVE_CMAP_TO_GRAYSCALE, and SET_DATA_BYTE.
Input: pix (32 bpp RGB) Return: 8 bpp pix, or null on error
Notes: (1) Use a standard luminance conversion.
Definition at line 608 of file pixconv.c.
References pixConvertRGBToGray().
Referenced by convertFilesTo1bpp(), main(), pixColorsForQuantization(), pixConvertTo8(), pixConvertToFPix(), pixHalfEdgeByBandpass(), pixQuantizeIfFewColors(), and pixWriteSegmentedPageToPS().
Input: pix (32 bpp RGB) rwt, gwt, bwt (non-negative; these should add to 1.0, or use 0.0 for default) Return: 8 bpp pix, or null on error
Notes: (1) Use a weighted average of the RGB values.
Definition at line 626 of file pixconv.c.
References ERROR_PTR, L_ABS, L_BLUE_SHIFT, L_BLUE_WEIGHT, L_GREEN_SHIFT, L_GREEN_WEIGHT, L_RED_SHIFT, L_RED_WEIGHT, L_WARNING, NULL, pixCopyResolution(), pixCreate(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), PROCNAME, and SET_DATA_BYTE.
Referenced by main(), and pixConvertRGBToLuminance().
Input: pix (32 bpp RGB) Return: 8 bpp pix, or null on error
Notes: (1) This function should be used if speed of conversion is paramount, and the green channel can be used as a fair representative of the RGB intensity. It is several times faster than pixConvertRGBToGray(). (2) To combine RGB to gray conversion with subsampling, use pixScaleRGBToGrayFast() instead.
Definition at line 701 of file pixconv.c.
References ERROR_PTR, L_GREEN_SHIFT, NULL, pixCopyResolution(), pixCreate(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), PROCNAME, and SET_DATA_BYTE.
Referenced by main(), and pixGetBackgroundRGBMap().
Input: pix (32 bpp RGB) type (L_CHOOSE_MIN or L_CHOOSE_MAX) Return: 8 bpp pix, or null on error
Notes: (1) chooses among the 3 color components for each pixel (2) This is useful when looking for the maximum deviation of a component from either 0 or 255. For finding the deviation of a single component, it is more sensitive than using a weighted average.
Definition at line 751 of file pixconv.c.
References ERROR_PTR, extractRGBValues(), L_CHOOSE_MAX, L_CHOOSE_MIN, L_MAX, L_MIN, NULL, pixCopyResolution(), pixCreate(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), PROCNAME, and SET_DATA_BYTE.
Referenced by pixGetRankColorArray().
Input: pixs (2, 4 or 8 bpp grayscale) Return: pixd (2, 4 or 8 bpp with colormap), or null on error
Notes: (1) This is a simple interface for adding a colormap to a 2, 4 or 8 bpp grayscale image without causing any quantization. There is some similarity to operations in grayquant.c, such as pixThresholdOn8bpp(), where the emphasis is on quantization with an arbitrary number of levels, and a colormap is an option. (2) Returns a copy if pixs already has a colormap. (3) For 8 bpp src, this is a lossless transformation. (4) For 2 and 4 bpp src, this generates a colormap that assumes full coverage of the gray space, with equally spaced levels: 4 levels for d = 2 and 16 levels for d = 4. (5) In all cases, the depth of the dest is the same as the src.
Definition at line 822 of file pixconv.c.
References ERROR_PTR, L_WARNING, NULL, pixcmapCreateLinear(), pixConvertGrayToColormap8(), pixCopy(), pixGetColormap(), pixGetDepth(), pixSetColormap(), and PROCNAME.
Referenced by main().
Input: pixs (8 bpp grayscale) mindepth (of pixd; valid values are 2, 4 and 8) Return: pixd (2, 4 or 8 bpp with colormap), or null on error
Notes: (1) Returns a copy if pixs already has a colormap. (2) This is a lossless transformation; there is no quantization. We compute the number of different gray values in pixs, and construct a colormap that has exactly these values. (3) 'mindepth' is the minimum depth of pixd. If mindepth == 8, pixd will always be 8 bpp. Let the number of different gray values in pixs be ngray. If mindepth == 4, we attempt to save pixd as a 4 bpp image, but if ngray > 16, pixd must be 8 bpp. Likewise, if mindepth == 2, the depth of pixd will be 2 if ngray <= 4 and 4 if ngray > 4 but <= 16.
Definition at line 874 of file pixconv.c.
References ERROR_PTR, GET_DATA_BYTE, L_GREATER_THAN_ZERO, L_WARNING, NULL, numaDestroy(), numaGetCountRelativeToZero(), numaGetIValue(), pixcmapAddColor(), pixcmapCreate(), pixCopy(), pixCopyResolution(), pixCreate(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetGrayHistogram(), pixGetWpl(), pixSetColormap(), PROCNAME, SET_DATA_BYTE, SET_DATA_DIBIT, and SET_DATA_QBIT.
Referenced by pixConvertGrayToColormap(), and TestHardlight().
Input: pixs (8 bpp gray; 2, 4 or 8 bpp colormapped) color (32 bit rgba pixel) cmapflag (1 for result to have colormap; 0 for RGB) Return: pixd (8 bpp colormapped or 32 bpp rgb), or null on error
Notes: (1) This applies the specific color to the grayscale image. (2) If pixs already has a colormap, it is removed to gray before colorizing.
Definition at line 967 of file pixconv.c.
References ERROR_PTR, FREE, GET_DATA_BYTE, NULL, pixClone(), pixcmapDestroy(), pixcmapGrayToColor(), pixcmapToRGBTable(), pixCopy(), pixCopyResolution(), pixCreate(), pixDestroy(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixRemoveColormap(), pixSetColormap(), PROCNAME, and REMOVE_CMAP_TO_GRAYSCALE.
Referenced by DisplayResult(), and pixSimpleCaptcha().
Input: pixs (32 bpp rgb) ditherflag (1 to dither, 0 otherwise) Return: pixd (2, 4 or 8 bpp with colormap), or null on error
Notes: (1) This function has two relatively simple modes of color quantization: (a) If the image is made orthographically and has not more than 256 'colors' at the level 4 octcube leaves, it is quantized nearly exactly. The ditherflag is ignored. (b) Most natural images have more than 256 different colors; in that case we use adaptive octree quantization, with dithering if requested. (2) If there are not more than 256 occupied level 4 octcubes, the color in the colormap that represents all pixels in one of those octcubes is given by the first pixel that falls into that octcube. (3) If there are more than 256 colors, we use adaptive octree color quantization. (4) Dithering gives better visual results on images where there is a color wash (a slow variation of color), but it is about twice as slow and results in significantly larger files when losslessly compressed (e.g., into png).
Definition at line 1053 of file pixconv.c.
References ERROR_PTR, L_INFO, NULL, numaDestroy(), pixFewColorsOctcubeQuant2(), pixGetDepth(), pixOctcubeHistogram(), pixOctreeColorQuant(), and PROCNAME.
Referenced by main(), pixWriteStreamGif(), and TestImage().
l_int32 pixQuantizeIfFewColors | ( | PIX * | pixs, |
l_int32 | maxcolors, | ||
l_int32 | mingraycolors, | ||
l_int32 | octlevel, | ||
PIX ** | ppixd | ||
) |
Input: pixs (8 bpp gray or 32 bpp rgb) maxcolors (max number of colors allowed to be returned from pixColorsForQuantization(); use 0 for default) mingraycolors (min number of gray levels that a grayscale image is quantized to; use 0 for default) octlevel (for octcube quantization: 3 or 4) &pixd (2, 4 or 8 bpp quantized; null if too many colors) Return: 0 if OK, 1 on error or if pixs can't be quantized into a small number of colors.
Notes: (1) This is a wrapper that tests if the pix can be quantized with good quality using a small number of colors. If so, it does the quantization, defining a colormap and using pixels whose value is an index into the colormap. (2) If the image has color, it is quantized with 8 bpp pixels. If the image is essentially grayscale, the pixels are either 4 or 8 bpp, depending on the size of the required colormap. (3) = 3 works well for most images. However, for best quality, at a cost of more colors in the colormap, use = 4. (4) If the image already has a colormap, it returns a clone.
Definition at line 1127 of file pixconv.c.
References ERROR_INT, L_MAX, L_MIN, L_WARNING, NULL, pixClone(), pixColorsForQuantization(), pixConvertRGBToLuminance(), pixDestroy(), pixFewColorsOctcubeQuant1(), pixGetColormap(), pixGetDepth(), pixThresholdOn8bpp(), pixThresholdTo4bpp(), and PROCNAME.
Input: pixs (16 bpp) whichbyte (1 for MSB, 0 for LSB) Return: pixd (8 bpp), or null on error
Notes: (1) For each dest pixel, use either the MSB or LSB of each src pixel.
Definition at line 1224 of file pixconv.c.
References ERROR_PTR, NULL, pixCopyResolution(), pixCreate(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), PROCNAME, and SET_DATA_TWO_BYTES.
Referenced by convertToPSEmbed(), main(), pixConvertForPSWrap(), pixConvertGrayToFalseColor(), pixConvertTo32(), pixConvertTo8(), and pixDisplayWithTitle().
Input: pixs (8 or 16 bpp grayscale) gamma factor (0.0 or 1.0 for default; > 1.0 for brighter; 2.0 is quite nice) Return: pixd (8 bpp with colormap), or null on error
Notes: (1) For 8 bpp input, this simply adds a colormap to the input image. (2) For 16 bpp input, it first converts to 8 bpp and then adds the colormap. (3) The colormap is modeled after the Matlab "jet" configuration.
Definition at line 1292 of file pixconv.c.
References CALLOC, ERROR_PTR, FREE, NULL, pixcmapAddColor(), pixcmapCreate(), pixConvert16To8(), pixCopy(), pixCopyResolution(), pixGetColormap(), pixGetDepth(), pixRemoveColormap(), pixSetColormap(), PROCNAME, and REMOVE_CMAP_TO_GRAYSCALE.
Referenced by main(), and pixFindHistoPeaksHSV().
Input: pixs (1 bpp) depth (of destination: 2, 4, 8, 16 or 32 bpp) invert (0: binary 0 --> grayscale 0 binary 1 --> grayscale 0xff... 1: binary 0 --> grayscale 0xff... binary 1 --> grayscale 0) Return: pixd (2, 4, 8, 16 or 32 bpp), or null on error
Notes: (1) This function calls special cases of pixConvert1To*(), for 2, 4, 8, 16 and 32 bpp destinations.
Definition at line 1387 of file pixconv.c.
References ERROR_PTR, NULL, pixConvert1To16(), pixConvert1To2(), pixConvert1To32(), pixConvert1To4(), pixConvert1To8(), pixGetDepth(), and PROCNAME.
Referenced by main(), pixPaintThroughMask(), pixSearchBinaryMaze(), pixSetMasked(), and pixSetMaskedGeneral().
Input: pixd (<optional> 16 bpp, can be null) pixs (1 bpp) val0 (16 bit value to be used for 0s in pixs) val1 (16 bit value to be used for 1s in pixs) Return: pixd (16 bpp)
Notes: (1) If pixd is null, a new pix is made. (2) If pixd is not null, it must be of equal width and height as pixs. It is always returned.
Definition at line 1453 of file pixconv.c.
References CALLOC, ERROR_PTR, FREE, GET_DATA_DIBIT, NULL, pixCopyResolution(), pixCreate(), pixGetData(), pixGetDepth(), pixGetHeight(), pixGetWidth(), pixGetWpl(), and PROCNAME.
Referenced by pixConvertTo16(), and pixUnpackBinary().
Input: pixd (<optional> 32 bpp, can be null) pixs (1 bpp) val0 (32 bit value to be used for 0s in pixs) val1 (32 bit value to be used for 1s in pixs) Return: pixd (32 bpp)
Notes: (1) If pixd is null, a new pix is made. (2) If pixd is not null, it must be of equal width and height as pixs. It is always returned.
Definition at line 1527 of file pixconv.c.
References ERROR_PTR, GET_DATA_BIT, NULL, pixCopyResolution(), pixCreate(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetHeight(), pixGetWidth(), pixGetWpl(), and PROCNAME.
Referenced by pixConvertTo32(), and pixUnpackBinary().
Input: pixs (1 bpp) Return: pixd (2 bpp, cmapped)
Notes: (1) Input 0 is mapped to (255, 255, 255); 1 is mapped to (0, 0, 0)
Definition at line 1588 of file pixconv.c.
References ERROR_PTR, NULL, pixcmapAddColor(), pixcmapCreate(), pixConvert1To2(), pixGetDepth(), pixSetColormap(), and PROCNAME.
Referenced by jbDataRender().
Input: pixd (<optional> 2 bpp, can be null) pixs (1 bpp) val0 (2 bit value to be used for 0s in pixs) val1 (2 bit value to be used for 1s in pixs) Return: pixd (2 bpp)
Notes: (1) If pixd is null, a new pix is made. (2) If pixd is not null, it must be of equal width and height as pixs. It is always returned. (3) A simple unpacking might use val0 = 0 and val1 = 3. (4) If you want a colormapped pixd, use pixConvert1To2Cmap().
Definition at line 1628 of file pixconv.c.
References CALLOC, ERROR_PTR, FREE, GET_DATA_BYTE, PixMemoryStore::nbytes, NULL, pixCopyResolution(), pixCreate(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetHeight(), pixGetWidth(), pixGetWpl(), PROCNAME, and SET_DATA_TWO_BYTES.
Referenced by main(), pixConvert1To2Cmap(), and pixUnpackBinary().
Input: pixs (1 bpp) Return: pixd (4 bpp, cmapped)
Notes: (1) Input 0 is mapped to (255, 255, 255); 1 is mapped to (0, 0, 0)
Definition at line 1706 of file pixconv.c.
References ERROR_PTR, NULL, pixcmapAddColor(), pixcmapCreate(), pixConvert1To4(), pixGetDepth(), pixSetColormap(), and PROCNAME.
Referenced by pixDebugFlipDetect().
Input: pixd (<optional> 4 bpp, can be null) pixs (1 bpp) val0 (4 bit value to be used for 0s in pixs) val1 (4 bit value to be used for 1s in pixs) Return: pixd (4 bpp)
Notes: (1) If pixd is null, a new pix is made. (2) If pixd is not null, it must be of equal width and height as pixs. It is always returned. (3) A simple unpacking might use val0 = 0 and val1 = 15, or v.v. (4) If you want a colormapped pixd, use pixConvert1To4Cmap().
Definition at line 1746 of file pixconv.c.
References CALLOC, ERROR_PTR, FREE, GET_DATA_BYTE, PixMemoryStore::nbytes, NULL, pixCopyResolution(), pixCreate(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetHeight(), pixGetWidth(), pixGetWpl(), and PROCNAME.
Referenced by main(), pixConvert1To4Cmap(), pixDisplayMatchedPattern(), and pixUnpackBinary().
Input: pixd (<optional> 8 bpp, can be null) pixs (1 bpp) val0 (8 bit value to be used for 0s in pixs) val1 (8 bit value to be used for 1s in pixs) Return: pixd (8 bpp)
Notes: (1) If pixd is null, a new pix is made. (2) If pixd is not null, it must be of equal width and height as pixs. It is always returned. (3) A simple unpacking might use val0 = 0 and val1 = 255, or v.v. (4) In a typical application where one wants to use a colormap with the dest, you can use val0 = 0, val1 = 1 to make a non-cmapped 8 bpp pix, and then make a colormap and set 0 and 1 to the desired colors. Here is an example: pixd = pixConvert1To8(NULL, pixs, 0, 1); cmap = pixCreate(8); pixcmapAddColor(cmap, 255, 255, 255); pixcmapAddColor(cmap, 0, 0, 0); pixSetColormap(pixd, cmap);
Definition at line 1838 of file pixconv.c.
References CALLOC, ERROR_PTR, FREE, GET_DATA_QBIT, NULL, pixCopyResolution(), pixCreate(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetHeight(), pixGetWidth(), pixGetWpl(), and PROCNAME.
Referenced by main(), pixaDisplayRandomCmap(), pixConvertTo8(), pixDisplayHitMissSel(), pixPaintBoxaRandom(), pixScaleToGrayMipmap(), and pixUnpackBinary().
PIX* pixConvert2To8 | ( | PIX * | pixs, |
l_uint8 | val0, | ||
l_uint8 | val1, | ||
l_uint8 | val2, | ||
l_uint8 | val3, | ||
l_int32 | cmapflag | ||
) |
Input: pixs (2 bpp) val0 (8 bit value to be used for 00 in pixs) val1 (8 bit value to be used for 01 in pixs) val2 (8 bit value to be used for 10 in pixs) val3 (8 bit value to be used for 11 in pixs) cmapflag (TRUE if pixd is to have a colormap; FALSE otherwise) Return: pixd (8 bpp), or null on error
Notes:
Definition at line 1927 of file pixconv.c.
References CALLOC, ERROR_PTR, FALSE, FREE, GET_DATA_BYTE, GET_DATA_DIBIT, PixMemoryStore::nbytes, NULL, pixcmapAddColor(), pixcmapCreate(), pixcmapGetColor(), pixcmapGetCount(), pixCopyResolution(), pixCreate(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixRemoveColormap(), pixSetColormap(), PROCNAME, REMOVE_CMAP_TO_GRAYSCALE, SET_DATA_BYTE, and TRUE.
Referenced by main(), pixConvertForPSWrap(), pixConvertTo32(), and pixConvertTo8().
Input: pixs (4 bpp) cmapflag (TRUE if pixd is to have a colormap; FALSE otherwise) Return: pixd (8 bpp), or null on error
Notes:
Definition at line 2042 of file pixconv.c.
References ERROR_PTR, FALSE, GET_DATA_QBIT, NULL, pixcmapAddColor(), pixcmapCreate(), pixcmapGetColor(), pixcmapGetCount(), pixCopyResolution(), pixCreate(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixRemoveColormap(), pixSetColormap(), PROCNAME, REMOVE_CMAP_TO_GRAYSCALE, SET_DATA_BYTE, and TRUE.
Referenced by main(), pixConvertForPSWrap(), pixConvertTo32(), and pixConvertTo8().
Input: pixs (8 bpp; colormap removed to gray) leftshift (number of bits: 0 is no shift; 8 replicates in MSB and LSB of dest) Return: pixd (16 bpp), or null on error
Notes: (1) For left shift of 8, the 8 bit value is replicated in both the MSB and the LSB of the pixels in pixd. That way, we get proportional mapping, with a correct map from 8 bpp white (0xff) to 16 bpp white (0xffff).
Definition at line 2130 of file pixconv.c.
References ERROR_PTR, GET_DATA_BYTE, NULL, pixClone(), pixCreate(), pixDestroy(), pixGetColormap(), pixGetData(), pixGetDimensions(), pixGetWpl(), pixRemoveColormap(), PROCNAME, REMOVE_CMAP_TO_GRAYSCALE, and SET_DATA_TWO_BYTES.
Referenced by main(), and pixConvertTo16().
Input: pixs (1, 2, 4, 8, 16 or 32 bpp) threshold (for final binarization, relative to 8 bpp) Return: pixd (1 bpp), or null on error
Notes: (1) This is a top-level function, with simple default values used in pixConvertTo8() if unpacking is necessary. (2) Any existing colormap is removed. (3) If the input image has 1 bpp and no colormap, the operation is lossless and a copy is returned.
Definition at line 2194 of file pixconv.c.
References ERROR_PTR, FALSE, NULL, pixcmapGetColor(), pixConvertTo8(), pixCopy(), pixDestroy(), pixDestroyColormap(), pixGetColormap(), pixGetDepth(), pixInvert(), pixThresholdToBinary(), and PROCNAME.
Referenced by GetImageMask(), main(), pixacompDisplayTiledAndScaled(), pixaDisplayTiledAndScaled(), pixaDisplayTiledInRows(), pixConvertTo1BySampling(), and pixDeskewGeneral().
Input: pixs (1, 2, 4, 8, 16 or 32 bpp) factor (submsampling factor; integer >= 1) threshold (for final binarization, relative to 8 bpp) Return: pixd (1 bpp), or null on error
Notes: (1) This is a fast, quick/dirty, top-level converter. (2) See pixConvertTo1() for default values.
Definition at line 2248 of file pixconv.c.
References ERROR_PTR, NULL, pixConvertTo1(), pixDestroy(), pixScaleBySampling(), and PROCNAME.
Input: pixs (1, 2, 4, 8, 16 or 32 bpp) cmapflag (TRUE if pixd is to have a colormap; FALSE otherwise) Return: pixd (8 bpp), or null on error
Notes: (1) This is a top-level function, with simple default values for unpacking. (2) The result, pixd, is made with a colormap if specified. (3) If d == 8, and cmapflag matches the existence of a cmap in pixs, the operation is lossless and it returns a copy. (4) The default values used are:
Definition at line 2297 of file pixconv.c.
References ERROR_PTR, NULL, pixAddGrayColormap8(), pixcmapAddColor(), pixcmapCreate(), pixConvert16To8(), pixConvert1To8(), pixConvert2To8(), pixConvert4To8(), pixConvertRGBToLuminance(), pixCopy(), pixGetColormap(), pixGetDepth(), pixRemoveColormap(), pixSetColormap(), PROCNAME, and REMOVE_CMAP_TO_GRAYSCALE.
Referenced by convertToPSEmbed(), main(), pixacompDisplayTiledAndScaled(), pixaDisplayTiledAndScaled(), pixaDisplayTiledInRows(), pixAffine(), pixAffinePta(), pixAverageIntensityProfile(), pixaWriteCompressedToPS(), pixBilinear(), pixBilinearPta(), pixBlendGray(), pixBlendGrayAdapt(), pixBlendMask(), pixBlendWithGrayMask(), pixColorGrayCmap(), pixConvertTo1(), pixConvertTo8BySampling(), pixConvertTo8Or32(), pixConvertToPdfDataSegmented(), pixDrawBoxa(), pixEqual(), pixFewColorsMedianCutQuantMixed(), pixFewColorsOctcubeQuantMixed(), pixFindLargestRectangle(), pixGenerateFlateData(), pixGetBackgroundGrayMapMorph(), pixGetBackgroundRGBMapMorph(), pixGetEdgeProfile(), pixGetRGBComponentCmap(), pixLocateBarcodes(), pixMedianCutQuantGeneral(), pixMedianCutQuantMixed(), pixOctreeColorQuantGeneral(), pixPaintBoxa(), pixProcessBarcodes(), pixProjective(), pixProjectivePta(), pixRenderRandomCmapPtaa(), pixReversalProfile(), pixRotate(), pixRotateAM(), pixRotateAMCorner(), pixRotateBinaryNice(), pixSaveTiledOutline(), pixScaleAreaMap(), pixScaleAreaMap2(), pixScaleSmooth(), pixSimpleCaptcha(), pixWriteStreamGif(), and QuantizeNonImageRegion().
Input: pixs (1, 2, 4, 8, 16 or 32 bpp) factor (submsampling factor; integer >= 1) cmapflag (TRUE if pixd is to have a colormap; FALSE otherwise) Return: pixd (8 bpp), or null on error
Notes: (1) This is a fast, quick/dirty, top-level converter. (2) See pixConvertTo8() for default values.
Definition at line 2368 of file pixconv.c.
References ERROR_PTR, NULL, pixConvertTo8(), pixDestroy(), pixScaleBySampling(), and PROCNAME.
Referenced by pixSplitDistributionFgBg(), and pixThresholdForFgBg().
Input: pixs (1, 8 bpp) Return: pixd (16 bpp), or null on error
Usage: Top-level function, with simple default values for unpacking. 1 bpp: val0 = 0xffff, val1 = 0 8 bpp: replicates the 8 bit value in both the MSB and LSB of the 16 bit pixel.
Definition at line 2406 of file pixconv.c.
References ERROR_PTR, NULL, pixConvert1To16(), pixConvert8To16(), pixGetDepth(), and PROCNAME.
Referenced by main().
Input: pixs (1, 2, 4, 8, 16 or 32 bpp) Return: pixd (32 bpp), or null on error
Usage: Top-level function, with simple default values for unpacking. 1 bpp: val0 = 255, val1 = 0 and then replication into R, G and B components 2 bpp: if colormapped, use the colormap values; otherwise, use val0 = 0, val1 = 0x55, val2 = 0xaa, val3 = 255 and replicate gray into R, G and B components 4 bpp: if colormapped, use the colormap values; otherwise, replicate 2 nybs into a byte, and then into R,G,B components 8 bpp: if colormapped, use the colormap values; otherwise, replicate gray values into R, G and B components 16 bpp: replicate MSB into R, G and B components 24 bpp: unpack the pixels, maintaining word alignment on each scanline 32 bpp: makes a copy
Notes: (1) Implicit assumption about RGB component ordering.
Definition at line 2453 of file pixconv.c.
References ERROR_PTR, NULL, pixConvert16To8(), pixConvert1To32(), pixConvert24To32(), pixConvert2To8(), pixConvert4To8(), pixConvert8To32(), pixCopy(), pixDestroy(), pixGetDepth(), PROCNAME, and TRUE.
Referenced by AddScaledImages(), dewarpBuildModel(), fpixaDisplayQuadtree(), main(), pixacompDisplayTiledAndScaled(), pixaDisplayOnColor(), pixaDisplayOnLattice(), pixaDisplayTiled(), pixaDisplayTiledAndScaled(), pixaDisplayTiledInRows(), pixBlendBoxaRandom(), pixBlendColor(), pixBlendColorByChannel(), pixBlendHardLight(), pixBlendWithGrayMask(), pixColorGray(), pixConvertTo32BySampling(), pixDisplayPta(), pixDisplayPtaa(), pixDrawBoxa(), pixDrawBoxaRandom(), pixFindBaselines(), pixFindHistoPeaksHSV(), pixItalicWords(), pixPaintBoxa(), pixPaintBoxaRandom(), PixSave32(), pixSaveTiledOutline(), pixSaveTiledWithText(), pixWarpStereoscopic(), pixWriteStreamWebP(), pixWriteTTFText(), pixWriteWebPwithTargetPSNR(), QuantizeNonImageRegion(), TestHardlight(), and wshedRenderColors().
Input: pixs (1, 2, 4, 8, 16 or 32 bpp) factor (submsampling factor; integer >= 1) Return: pixd (32 bpp), or null on error
Notes: (1) This is a fast, quick/dirty, top-level converter. (2) See pixConvertTo32() for default values.
Definition at line 2508 of file pixconv.c.
References ERROR_PTR, NULL, pixConvertTo32(), pixDestroy(), pixScaleBySampling(), and PROCNAME.
Input: pix (8 bpp) Return: 32 bpp rgb pix, or null on error
Notes: (1) If there is no colormap, replicates the gray value into the 3 MSB of the dest pixel. (2) Implicit assumption about RGB component ordering.
Definition at line 2542 of file pixconv.c.
References CALLOC, ERROR_PTR, FREE, GET_DATA_BYTE, NULL, pixCopyResolution(), pixCreate(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixRemoveColormap(), PROCNAME, and REMOVE_CMAP_TO_FULL_COLOR.
Referenced by main(), pixConvertTo32(), and pixSearchGrayMaze().
Input: pixs (1, 2, 4, 8, 16, with or without colormap; or 32 bpp rgb) copyflag (use 0 to return clone if pixs does not need to be changed; 1 to return a copy in those situations) warnflag (1 to issue warning if colormap is removed; else 0) Return: pixd (8 bpp grayscale or 32 bpp rgb), or null on error
Notes: (1) If there is a colormap, the colormap is removed to 8 or 32 bpp, depending on whether the colors in the colormap are all gray. (2) If the input is either rgb or 8 bpp without a colormap, this returns either a clone or a copy, depending on . (3) Otherwise, the pix is converted to 8 bpp grayscale. In all cases, pixd does not have a colormap.
Definition at line 2609 of file pixconv.c.
References ERROR_PTR, L_WARNING, NULL, pixClone(), pixConvertTo8(), pixCopy(), pixDestroy(), pixGetColormap(), pixGetDepth(), pixRemoveColormap(), PROCNAME, and REMOVE_CMAP_BASED_ON_SRC.
Referenced by pixScaleGeneral(), pixScaleLI(), pixUnsharpMasking(), pixUnsharpMaskingFast(), and pixWriteSegmentedPageToPS().
Input: pixs (24 bpp rgb) Return: pixd (32 bpp rgb), or null on error
Notes: (1) 24 bpp rgb pix are not supported in leptonica. The data is a byte array, with pixels in order r,g,b, and padded to 32 bit boundaries in each line. (2) Because they are conveniently generated by programs such as xpdf, we need to provide the ability to write them in png, jpeg and tiff, as well as to convert between 24 and 32 bpp in memory.
Definition at line 2665 of file pixconv.c.
References composeRGBPixel(), ERROR_PTR, NULL, pixCopyInputFormat(), pixCopyResolution(), pixCreateNoInit(), pixGetData(), pixGetDimensions(), pixGetWpl(), and PROCNAME.
Referenced by pixConvertTo32().
Input: pixs (32 bpp rgb) Return: pixd (24 bpp rgb), or null on error
Notes: (1) 24 bpp rgb pix are not supported in leptonica. The data is a byte array, with pixels in order r,g,b, and padded to 32 bit boundaries in each line. (2) This function is put here for completeness, and so that we can generate 24 bpp for testing. The test has two parts: (a) convert the 24 bpp pix back to 32 bpp, and test for pixel component equality (b) write the 24 bpp pix as a png and verify that it is identical to the file obtained by writing the 32 bpp pix.
Definition at line 2721 of file pixconv.c.
References ERROR_PTR, extractRGBValues(), NULL, pixCopyInputFormat(), pixCopyResolution(), pixCreateNoInit(), pixGetData(), pixGetDimensions(), pixGetWpl(), and PROCNAME.
Input: pixs (1, 2, 4, 8 bpp, not cmapped) d (destination depth: 2, 4 or 8) Return: pixd (2, 4 or 8 bpp), or null on error
Notes: (1) This is a lossless unpacking (depth-increasing) conversion. If ds is the depth of pixs, then
Definition at line 2776 of file pixconv.c.
References ERROR_PTR, GET_DATA_BIT, GET_DATA_DIBIT, NULL, pixCopy(), pixCopyResolution(), pixCreate(), pixGetColormap(), pixGetData(), pixGetDimensions(), pixGetWpl(), PROCNAME, SET_DATA_BYTE, SET_DATA_DIBIT, and SET_DATA_QBIT.
Referenced by pixEqual().
Input: pixs (1, 2, 4, 8, 16, 32 bpp) Return: pixd (1, 8, or 32 bpp), or null on error
Notes: (1) For wrapping in PostScript, we convert pixs to 1 bpp, 8 bpp (gray) and 32 bpp (RGB color). (2) Colormaps are removed. For pixs with colormaps, the images are converted to either 8 bpp gray or 32 bpp RGB, depending on whether the colormap has color content. (3) Images without colormaps, that are not 1 bpp or 32 bpp, are converted to 8 bpp gray.
Definition at line 2863 of file pixconv.c.
References ERROR_PTR, FALSE, NULL, pixClone(), pixConvert16To8(), pixConvert2To8(), pixConvert4To8(), pixGetColormap(), pixGetDepth(), pixRemoveColormap(), PROCNAME, and REMOVE_CMAP_BASED_ON_SRC.
Referenced by pixaWriteCompressedToPS(), pixWriteStreamPS(), and pixWriteStringPS().
Input: pixs (8 bpp grayscale, 32 bpp rgb, or colormapped) scalex, scaley (anisotropic scaling permitted between source and destination) order (of subpixel rgb color components in composition of pixd: L_SUBPIXEL_ORDER_RGB, L_SUBPIXEL_ORDER_BGR, L_SUBPIXEL_ORDER_VRGB, L_SUBPIXEL_ORDER_VBGR)
Return: pixd (32 bpp), or null on error
Notes: (1) If pixs has a colormap, it is removed based on its contents to either 8 bpp gray or rgb. (2) For horizontal subpixel splitting, the input image is rescaled by vertically and by 3.0 times horizontally. Then each horizontal triplet of pixels is mapped back to a single rgb pixel, with the r, g and b values being assigned based on the pixel triplet. For gray triplets, the r, g, and b values are set equal to the three gray values. For color triplets, the r, g and b values are set equal to the components from the appropriate subpixel. Vertical subpixel splitting is handled similarly. (3) See pixConvertGrayToSubpixelRGB() and pixConvertColorToSubpixelRGB() for further details.
Definition at line 2940 of file pixconv.c.
References ERROR_PTR, L_ERROR_INT, L_SUBPIXEL_ORDER_BGR, L_SUBPIXEL_ORDER_RGB, L_SUBPIXEL_ORDER_VBGR, L_SUBPIXEL_ORDER_VRGB, NULL, pixConvertColorToSubpixelRGB(), pixConvertGrayToSubpixelRGB(), pixDestroy(), pixGetColormap(), pixGetDepth(), pixRemoveColormap(), PROCNAME, and REMOVE_CMAP_BASED_ON_SRC.
Referenced by main().
Input: pixs (8 bpp or colormapped) scalex, scaley order (of subpixel rgb color components in composition of pixd: L_SUBPIXEL_ORDER_RGB, L_SUBPIXEL_ORDER_BGR, L_SUBPIXEL_ORDER_VRGB, L_SUBPIXEL_ORDER_VBGR)
Return: pixd (32 bpp), or null on error
Notes: (1) If pixs has a colormap, it is removed to 8 bpp. (2) For horizontal subpixel splitting, the input gray image is rescaled by vertically and by 3.0 times horizontally. Then each horizontal triplet of pixels is mapped back to a single rgb pixel, with the r, g and b values being assigned from the triplet of gray values. Similar operations are used for vertical subpixel splitting. (3) This is a form of subpixel rendering that tends to give the resulting text a sharper and somewhat chromatic display. For horizontal subpixel splitting, the observable difference between =L_SUBPIXEL_ORDER_RGB and =L_SUBPIXEL_ORDER_BGR is reduced by optical diffusers in the display that make the pixel color appear to emerge from the entire pixel.
Definition at line 3008 of file pixconv.c.
References composeRGBPixel(), ERROR_PTR, GET_DATA_BYTE, L_HORIZ, L_SUBPIXEL_ORDER_BGR, L_SUBPIXEL_ORDER_RGB, L_SUBPIXEL_ORDER_VBGR, L_SUBPIXEL_ORDER_VRGB, L_VERT, NULL, pixCreate(), pixDestroy(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixRemoveColormap(), pixScale(), PROCNAME, and REMOVE_CMAP_TO_GRAYSCALE.
Referenced by main(), and pixConvertToSubpixelRGB().
pixConvertColorToSubpixelRGB()
Input: pixs (32 bpp or colormapped) scalex, scaley order (of subpixel rgb color components in composition of pixd: L_SUBPIXEL_ORDER_RGB, L_SUBPIXEL_ORDER_BGR, L_SUBPIXEL_ORDER_VRGB, L_SUBPIXEL_ORDER_VBGR)
Return: pixd (32 bpp), or null on error
Notes: (1) If pixs has a colormap, it is removed to 32 bpp rgb. If the colormap has no color, pixConvertGrayToSubpixelRGB() should be called instead, because it will give the same result more efficiently. The function pixConvertToSubpixelRGB() will do the best thing for all cases. (2) For horizontal subpixel splitting, the input rgb image is rescaled by vertically and by 3.0 times horizontally. Then for each horizontal triplet of pixels, the r component of the final pixel is selected from the r component of the appropriate pixel in the triplet, and likewise for g and b. Vertical subpixel splitting is handled similarly.
Definition at line 3112 of file pixconv.c.
References composeRGBPixel(), ERROR_PTR, extractRGBValues(), L_HORIZ, L_SUBPIXEL_ORDER_BGR, L_SUBPIXEL_ORDER_RGB, L_SUBPIXEL_ORDER_VBGR, L_SUBPIXEL_ORDER_VRGB, L_VERT, NULL, pixCreate(), pixDestroy(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixRemoveColormap(), pixScale(), PROCNAME, and REMOVE_CMAP_TO_FULL_COLOR.
Referenced by pixConvertToSubpixelRGB().