![]() |
Leptonica
1.82.0
Image processing and image analysis suite
|
#include <string.h>
#include "allheaders.h"
Go to the source code of this file.
Macros | |
#define | DEBUG_OVERFLOW 0 |
#define | DEBUG_UNROLLING 0 |
Functions | |
static void | scaleColorLILow (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls) |
static void | scaleGrayLILow (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls) |
static void | scaleColor2xLILow (l_uint32 *datad, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls) |
static void | scaleColor2xLILineLow (l_uint32 *lined, l_int32 wpld, l_uint32 *lines, l_int32 ws, l_int32 wpls, l_int32 lastlineflag) |
static void | scaleGray2xLILow (l_uint32 *datad, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls) |
static void | scaleGray2xLILineLow (l_uint32 *lined, l_int32 wpld, l_uint32 *lines, l_int32 ws, l_int32 wpls, l_int32 lastlineflag) |
static void | scaleGray4xLILow (l_uint32 *datad, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls) |
static void | scaleGray4xLILineLow (l_uint32 *lined, l_int32 wpld, l_uint32 *lines, l_int32 ws, l_int32 wpls, l_int32 lastlineflag) |
static l_int32 | scaleBySamplingLow (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 d, l_int32 wpls) |
static l_int32 | scaleSmoothLow (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 d, l_int32 wpls, l_int32 size) |
static void | scaleRGBToGray2Low (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_float32 rwt, l_float32 gwt, l_float32 bwt) |
static void | scaleColorAreaMapLow (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls) |
static void | scaleGrayAreaMapLow (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls) |
static void | scaleAreaMapLow2 (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 d, l_int32 wpls) |
static l_int32 | scaleBinaryLow (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls) |
PIX * | pixScale (PIX *pixs, l_float32 scalex, l_float32 scaley) |
PIX * | pixScaleToSizeRel (PIX *pixs, l_int32 delw, l_int32 delh) |
PIX * | pixScaleToSize (PIX *pixs, l_int32 wd, l_int32 hd) |
PIX * | pixScaleToResolution (PIX *pixs, l_float32 target, l_float32 assumed, l_float32 *pscalefact) |
PIX * | pixScaleGeneral (PIX *pixs, l_float32 scalex, l_float32 scaley, l_float32 sharpfract, l_int32 sharpwidth) |
PIX * | pixScaleLI (PIX *pixs, l_float32 scalex, l_float32 scaley) |
PIX * | pixScaleColorLI (PIX *pixs, l_float32 scalex, l_float32 scaley) |
PIX * | pixScaleColor2xLI (PIX *pixs) |
PIX * | pixScaleColor4xLI (PIX *pixs) |
PIX * | pixScaleGrayLI (PIX *pixs, l_float32 scalex, l_float32 scaley) |
PIX * | pixScaleGray2xLI (PIX *pixs) |
PIX * | pixScaleGray4xLI (PIX *pixs) |
PIX * | pixScaleGray2xLIThresh (PIX *pixs, l_int32 thresh) |
PIX * | pixScaleGray2xLIDither (PIX *pixs) |
PIX * | pixScaleGray4xLIThresh (PIX *pixs, l_int32 thresh) |
PIX * | pixScaleGray4xLIDither (PIX *pixs) |
PIX * | pixScaleBySampling (PIX *pixs, l_float32 scalex, l_float32 scaley) |
PIX * | pixScaleBySamplingToSize (PIX *pixs, l_int32 wd, l_int32 hd) |
PIX * | pixScaleByIntSampling (PIX *pixs, l_int32 factor) |
PIX * | pixScaleRGBToGrayFast (PIX *pixs, l_int32 factor, l_int32 color) |
PIX * | pixScaleRGBToBinaryFast (PIX *pixs, l_int32 factor, l_int32 thresh) |
PIX * | pixScaleGrayToBinaryFast (PIX *pixs, l_int32 factor, l_int32 thresh) |
PIX * | pixScaleSmooth (PIX *pix, l_float32 scalex, l_float32 scaley) |
PIX * | pixScaleSmoothToSize (PIX *pixs, l_int32 wd, l_int32 hd) |
PIX * | pixScaleRGBToGray2 (PIX *pixs, l_float32 rwt, l_float32 gwt, l_float32 bwt) |
PIX * | pixScaleAreaMap (PIX *pix, l_float32 scalex, l_float32 scaley) |
PIX * | pixScaleAreaMap2 (PIX *pix) |
PIX * | pixScaleAreaMapToSize (PIX *pixs, l_int32 wd, l_int32 hd) |
PIX * | pixScaleBinary (PIX *pixs, l_float32 scalex, l_float32 scaley) |
Top-level scaling PIX *pixScale() PIX *pixScaleToSizeRel() PIX *pixScaleToSize() PIX *pixScaleToResolution() PIX *pixScaleGeneral() Linearly interpreted (usually up-) scaling PIX *pixScaleLI() PIX *pixScaleColorLI() PIX *pixScaleColor2xLI() PIX *pixScaleColor4xLI() PIX *pixScaleGrayLI() PIX *pixScaleGray2xLI() PIX *pixScaleGray4xLI() Upscale 2x followed by binarization PIX *pixScaleGray2xLIThresh() PIX *pixScaleGray2xLIDither() Upscale 4x followed by binarization PIX *pixScaleGray4xLIThresh() PIX *pixScaleGray4xLIDither() Scaling by closest pixel sampling PIX *pixScaleBySampling() PIX *pixScaleBySamplingToSize() PIX *pixScaleByIntSampling() Fast integer factor subsampling RGB to gray and to binary PIX *pixScaleRGBToGrayFast() PIX *pixScaleRGBToBinaryFast() PIX *pixScaleGrayToBinaryFast() Downscaling with (antialias) smoothing PIX *pixScaleSmooth() PIX *pixScaleSmoothToSize() PIX *pixScaleRGBToGray2() [special 2x reduction to gray] Downscaling with (antialias) area mapping PIX *pixScaleAreaMap() PIX *pixScaleAreaMap2() PIX *pixScaleAreaMapToSize() Binary scaling by closest pixel sampling PIX *pixScaleBinary() Low-level static functions: Color (interpolated) scaling: general case static void scaleColorLILow() Grayscale (interpolated) scaling: general case static void scaleGrayLILow() Color (interpolated) scaling: 2x upscaling static void scaleColor2xLILow() static void scaleColor2xLILineLow() Grayscale (interpolated) scaling: 2x upscaling static void scaleGray2xLILow() static void scaleGray2xLILineLow() Grayscale (interpolated) scaling: 4x upscaling static void scaleGray4xLILow() static void scaleGray4xLILineLow() Grayscale and color scaling by closest pixel sampling static l_int32 scaleBySamplingLow() Color and grayscale downsampling with (antialias) lowpass filter static l_int32 scaleSmoothLow() static void scaleRGBToGray2Low() Color and grayscale downsampling with (antialias) area mapping static l_int32 scaleColorAreaMapLow() static l_int32 scaleGrayAreaMapLow() static l_int32 scaleAreaMapLow2() Binary scaling by closest pixel sampling static l_int32 scaleBinaryLow()
Definition in file scale1.c.
[in] | pixs | 1, 2, 4, 8, 16 and 32 bpp |
[in] | scalex,scaley |
This function scales 32 bpp RGB; 2, 4 or 8 bpp palette color; 2, 4, 8 or 16 bpp gray; and binary images.
When the input has palette color, the colormap is removed and the result is either 8 bpp gray or 32 bpp RGB, depending on whether the colormap has color entries. Images with 2, 4 or 16 bpp are converted to 8 bpp.
Because pixScale is meant to be a very simple interface to a number of scaling functions, including the use of unsharp masking, the type of scaling and the sharpening parameters are chosen by default. Grayscale and color images are scaled using one of five methods, depending on the scale factors:
One could use subsampling for scale factors very close to 1.0, because it preserves sharp edges. Linear interpolation blurs edges because the dest pixels will typically straddle two src edge pixels. Subsmpling removes entire columns and rows, so the edge is not blurred. However, there are two reasons for not doing this. First, it moves edges, so that a straight line at a large angle to both horizontal and vertical will have noticeable kinks where horizontal and vertical rasters are removed. Second, although it is very fast, you get good results on sharp edges by applying a sharpening filter.
For images with sharp edges, sharpening substantially improves the image quality for scale factors between about 0.2 and about 2.0. pixScale uses a small amount of sharpening by default because it strengthens edge pixels that are weak due to anti-aliasing. The default sharpening factors are:
However, sharpening is computationally expensive, and one needs to consider the speed-quality tradeoff:
In many situations you will get a satisfactory result by scaling without sharpening: call pixScaleGeneral with sharpfract = 0.0. Alternatively, if you wish to sharpen but not use the default value, first call pixScaleGeneral with sharpfract = 0.0, and then sharpen explicitly using pixUnsharpMasking.
Binary images are scaled to binary by sampling the closest pixel, without any low-pass filtering averaging of neighboring pixels. This will introduce aliasing for reductions. Aliasing can be prevented by using pixScaleToGray instead.
Definition at line 250 of file scale1.c.
References pixScaleGeneral().
Referenced by pixaConvertToPdfData(), pixaDisplayPairTiledInColumns(), pixaDisplayTiledAndScaled(), pixaDisplayTiledInColumns(), pixaDisplayTiledInRows(), pixAffineSequential(), pixaScale(), pixaSplitIntoFiles(), pixDecideIfTable(), pixScaleToSize(), recogShowPath(), and saConvertFilesToPdfData().
[in] | pix | 2, 4, 8 or 32 bpp; and 2, 4, 8 bpp with colormap |
[in] | scalex | must be < 0.7; minimum is 0.02 |
[in] | scaley | must be < 0.7; minimum is 0.02 |
Notes: (1) This is a low-pass filter that averages over fractional pixels. It should only be used when the scale factors are less than 0.7. If either scale factor is greater than or equal to 0.7, we issue a warning and call pixScaleGeneral(), which will invoke linear interpolation without sharpening. (2) The minimum scale factor allowed for area mapping reduction is 0.02. Various overflows will occur when scale factors are less than about 1/256. If a scale factor smaller than 0.02 is given, we use pixScaleSmooth(), which is a low-pass filter that averages over entire pixels. (3) This works only on 2, 4, 8 and 32 bpp images. If there is a colormap, it is removed by converting to RGB. In other cases, we issue a warning and call pixScaleGeneral(). (4) This is faster than pixScale() because it does not do sharpening. (5) It does a relatively expensive area mapping computation, to avoid antialiasing. It is about 2x slower than pixScaleSmooth(), but the results are much better on fine text. (6) pixScaleAreaMap2() is typically about 7x faster for the special case of 2x reduction for color images, and about 9x faster for grayscale images. Surprisingly, the improvement in speed when using a cascade of 2x reductions for small scale factors is less than one might expect, and in most situations gives poorer image quality. But see (6). (7) For reductions between 0.35 and 0.5, a 2x area map reduction followed by using pixScaleGeneral() on a 2x larger scalefactor (which further reduces the image size using bilinear interpolation) would give a significant speed increase, with little loss of quality, but this is not enabled as it would break too many tests. For scaling factors below 0.35, scaling atomically is nearly as fast as using a cascade of 2x scalings, and gives better results.
Definition at line 1914 of file scale1.c.
Referenced by pixScaleAreaMapToSize().
[in] | pix | 2, 4, 8 or 32 bpp; and 2, 4, 8 bpp with colormap |
Notes: (1) This function does an area mapping (average) for 2x reduction. (2) This works only on 2, 4, 8 and 32 bpp images. If there is a colormap, it is removed by converting to RGB. (3) Compared to the general pixScaleAreaMap(), for this function gray processing is about 14x faster and color processing is about 4x faster. Consequently, pixScaleAreaMap2() is incorporated into the general area map scaling function, for the special cases of 2x, 4x, 8x and 16x reduction.
Definition at line 2047 of file scale1.c.
Referenced by bilateralCreate().
[in] | pixs | 2, 4, 8 or 32 bpp; and 2, 4, 8 bpp with colormap |
[in] | wd | target width; use 0 if using height as target |
[in] | hd | target height; use 0 if using width as target |
Notes: (1) See notes in pixScaleAreaMap(). (2) The output scaled image has the dimension(s) you specify:
Definition at line 2112 of file scale1.c.
References pixGetDimensions(), and pixScaleAreaMap().
[in] | pixs | 1 bpp |
[in] | scalex | must be > 0.0 |
[in] | scaley | must be > 0.0 |
Notes: (1) This function samples from the source without filtering. As a result, aliasing will occur for subsampling (scalex and scaley < 1.0).
[in] | pixs | 1, 2, 4, 8, 16, 32 bpp (all depths) |
[in] | factor | integer subsampling; >= 1 |
Notes: (1) Simple interface to pixScaleBySampling(), for isotropic integer reduction. If factor == 1, returns a copy.
Definition at line 1444 of file scale1.c.
References pixCopy(), and pixScaleBySampling().
Referenced by pixaAddPixWithText().
[in] | pixs | 1, 2, 4, 8, 16, 32 bpp |
[in] | scalex | must be > 0.0 |
[in] | scaley | must be > 0.0 |
Notes: (1) This function samples from the source without filtering. As a result, aliasing will occur for subsampling (scalex and/or scaley < 1.0). (2) If scalex == 1.0 and scaley == 1.0, returns a copy. (3) For upscaling by an integer, use pixExpandReplicate().
Definition at line 1338 of file scale1.c.
References pixCopy().
Referenced by dewarpaShowArrays(), pixaScaleBySampling(), pixConvertTo1BySampling(), pixConvertTo32BySampling(), pixConvertTo8BySampling(), pixScaleByIntSampling(), pixScaleBySamplingToSize(), selaAddCrossJunctions(), and selaAddTJunctions().
[in] | pixs | 1, 2, 4, 8, 16 and 32 bpp |
[in] | wd | target width; use 0 if using height as target |
[in] | hd | target height; use 0 if using width as target |
Notes: (1) This guarantees that the output scaled image has the dimension(s) you specify. ~ To specify the width with isotropic scaling, set hd = 0. ~ To specify the height with isotropic scaling, set wd = 0. ~ If both wd and hd are specified, the image is scaled (in general, anisotropically) to that size. ~ It is an error to set both wd and hd to 0.
Definition at line 1400 of file scale1.c.
References pixGetDimensions(), and pixScaleBySampling().
[in] | pixs | 32 bpp, representing rgb |
Notes: (1) This is a special case of linear interpolated scaling, for 2x upscaling. It is about 8x faster than using the generic pixScaleColorLI(), and about 4x faster than using the special 2x scale function pixScaleGray2xLI() on each of the three components separately.
[in] | pixs | 32 bpp, representing rgb |
Notes: (1) This is a special case of color linear interpolated scaling, for 4x upscaling. It is about 3x faster than using the generic pixScaleColorLI(). (2) This scales each component separately, using pixScaleGray4xLI(). It would be about 4x faster to inline the color code properly, in analogy to scaleColor4xLILow(), and I leave this as an exercise for someone who really needs it.
[in] | pixs | 32 bpp, representing rgb |
[in] | scalex | must be >= 0.7 |
[in] | scaley | must be >= 0.7 |
Notes: (1) If both scale factors are smaller than 0.7, we issue a warning and call pixScaleGeneral(), which will invoke area mapping without sharpening. This is particularly important for document images with sharp edges. (2) For the general case, it's about 4x faster to manipulate the color pixels directly, rather than to make images out of each of the 3 components, scale each component using the pixScaleGrayLI(), and combine the results back into an rgb image.
PIX* pixScaleGeneral | ( | PIX * | pixs, |
l_float32 | scalex, | ||
l_float32 | scaley, | ||
l_float32 | sharpfract, | ||
l_int32 | sharpwidth | ||
) |
[in] | pixs | 1, 2, 4, 8, 16 and 32 bpp |
[in] | scalex | must be > 0.0 |
[in] | scaley | must be > 0.0 |
[in] | sharpfract | use 0.0 to skip sharpening |
[in] | sharpwidth | halfwidth of low-pass filter; typ. 1 or 2 |
Notes: (1) See pixScale() for usage. (2) This interface may change in the future, as other special cases are added. (3) For tiny scaling factors minscale < 0.02: use a simple lowpass filter (4) The actual sharpening factors used depend on the maximum of the two scale factors (maxscale): maxscale <= 0.2: no sharpening 0.2 < maxscale < 1.4: uses the input parameters maxscale >= 1.4: no sharpening (5) To avoid sharpening for grayscale and color images with scaling factors between 0.2 and 1.4, call this function with sharpfract == 0.0. (6) To use arbitrary sharpening in conjunction with scaling, call this function with sharpfract = 0.0, and follow this with a call to pixUnsharpMasking() with your chosen parameters.
Definition at line 423 of file scale1.c.
Referenced by pixScale(), and pixScaleSmooth().
[in] | pixs | 8 bpp grayscale, not cmapped |
Notes: (1) This is a special case of gray linear interpolated scaling, for 2x upscaling. It is about 6x faster than using the generic pixScaleGrayLI().
[in] | pixs | 8 bpp, not cmapped |
Notes: (1) This does 2x upscale on pixs, using linear interpolation, followed by Floyd-Steinberg dithering to binary. (2) Buffers are used to avoid making a large grayscale image. ~ Two line buffers are used for the src, required for the 2x LI upscale. ~ Three line buffers are used for the intermediate image. Two are filled with each 2xLI row operation; the third is needed because the upscale and dithering ops are out of sync.
[in] | pixs | 8 bpp, not cmapped |
[in] | thresh | between 0 and 256 |
Notes: (1) This does 2x upscale on pixs, using linear interpolation, followed by thresholding to binary. (2) Buffers are used to avoid making a large grayscale image.
[in] | pixs | 8 bpp grayscale, not cmapped |
Notes: (1) This is a special case of gray linear interpolated scaling, for 4x upscaling. It is about 12x faster than using the generic pixScaleGrayLI().
[in] | pixs | 8 bpp, not cmapped |
Notes: (1) This does 4x upscale on pixs, using linear interpolation, followed by Floyd-Steinberg dithering to binary. (2) Buffers are used to avoid making a large grayscale image. ~ Two line buffers are used for the src, required for the 4xLI upscale. ~ Five line buffers are used for the intermediate image. Four are filled with each 4xLI row operation; the fifth is needed because the upscale and dithering ops are out of sync. (3) If a full 4x expanded grayscale image can be kept in memory, this function is only about 5% faster than separately doing a linear interpolation to a large grayscale image, followed by error-diffusion dithering to binary.
[in] | pixs | 8 bpp |
[in] | thresh | between 0 and 256 |
Notes: (1) This does 4x upscale on pixs, using linear interpolation, followed by thresholding to binary. (2) Buffers are used to avoid making a large grayscale image. (3) If a full 4x expanded grayscale image can be kept in memory, this function is only about 10% faster than separately doing a linear interpolation to a large grayscale image, followed by thresholding to binary.
[in] | pixs | 8 bpp grayscale, no cmap |
[in] | scalex | must be >= 0.7 |
[in] | scaley | must be >= 0.7 |
Notes: (1) This function is appropriate for upscaling magnification, where the scale factor is > 1, as well as for a small amount of downscaling reduction, with scale factor >= 0.7. If the scale factor is < 0.7, the best result is obtained by area mapping. (2) Here are some details:
[in] | pixs | 8 bpp grayscale |
[in] | factor | integer reduction factor >= 1 |
[in] | thresh | binarization threshold |
Notes: (1) This does simultaneous subsampling by an integer factor and thresholding from gray to binary. (2) It is designed for maximum speed, and is used for quickly generating a downsized binary image from a higher resolution gray image. This would typically be used for image analysis.
[in] | pixs | 2, 4, 8 or 32 bpp; with or without colormap |
[in] | scalex | must be >= 0.7 |
[in] | scaley | must be >= 0.7 |
Notes: (1) This function should only be used when the scale factors are greater than or equal to 0.7, and typically greater than 1. If both scale factors are smaller than 0.7, we issue a warning and call pixScaleGeneral(), which will invoke area mapping without sharpening. (2) This works on 2, 4, 8, 16 and 32 bpp images, as well as on 2, 4 and 8 bpp images that have a colormap. If there is a colormap, it is removed to either gray or RGB, depending on the colormap. (3) This does a linear interpolation on the src image. (4) It dispatches to much faster implementations for the special cases of 2x and 4x expansion.
[in] | pixs | 32 bpp RGB |
[in] | factor | integer reduction factor >= 1 |
[in] | thresh | binarization threshold |
Notes: (1) This does simultaneous subsampling by an integer factor and conversion from RGB to gray to binary. (2) It is designed for maximum speed, and is used for quickly generating a downsized binary image from a higher resolution RGB image. This would typically be used for image analysis. (3) It uses the green channel to represent the RGB pixel intensity.
[in] | pixs | 32 bpp rgb |
[in] | rwt,gwt,bwt | must sum to 1.0 |
[in] | pixs | 32 bpp rgb |
[in] | factor | integer reduction factor >= 1 |
[in] | color | one of COLOR_RED, COLOR_GREEN, COLOR_BLUE |
Notes: (1) This does simultaneous subsampling by an integer factor and extraction of the color from the RGB pix. (2) It is designed for maximum speed, and is used for quickly generating a downsized grayscale image from a higher resolution RGB image. This would typically be used for image analysis. (3) The standard color byte order (RGBA) is assumed.
[in] | pix | 2, 4, 8 or 32 bpp; and 2, 4, 8 bpp with colormap |
[in] | scalex | must be < 0.7 |
[in] | scaley | must be < 0.7 |
Notes: (1) This function should only be used when the scale factors are less than 0.7. If either scale factor is >= 0.7, issue a warning and call pixScaleGeneral(), which will invoke linear interpolation without sharpening. (2) This works only on 2, 4, 8 and 32 bpp images, and if there is a colormap, it is removed by converting to RGB. (3) It does simple (flat filter) convolution, with a filter size commensurate with the amount of reduction, to avoid antialiasing. (4) It does simple subsampling after smoothing, which is appropriate for this range of scaling. Linear interpolation gives essentially the same result with more computation for these scale factors, so we don't use it. (5) The result is the same as doing a full block convolution followed by subsampling, but this is faster because the results of the block convolution are only computed at the subsampling locations. In fact, the computation time is approximately independent of the scale factor, because the convolution kernel is adjusted so that each source pixel is summed approximately once.
Definition at line 1709 of file scale1.c.
References pixScaleGeneral().
Referenced by pixScaleSmoothToSize().
[in] | pixs | 2, 4, 8 or 32 bpp; and 2, 4, 8 bpp with colormap |
[in] | wd | target width; use 0 if using height as target |
[in] | hd | target height; use 0 if using width as target |
Notes: (1) See notes in pixScaleSmooth(). (2) The output scaled image has the dimension(s) you specify:
Definition at line 1795 of file scale1.c.
References pixGetDimensions(), and pixScaleSmooth().
PIX* pixScaleToResolution | ( | PIX * | pixs, |
l_float32 | target, | ||
l_float32 | assumed, | ||
l_float32 * | pscalefact | ||
) |
[in] | pixs | |
[in] | target | desired resolution |
[in] | assumed | assumed resolution if not defined; typ. 300. |
[out] | pscalefact | [optional] actual scaling factor used |
[in] | pixs | 1, 2, 4, 8, 16 and 32 bpp |
[in] | wd | target width; use 0 if using height as target |
[in] | hd | target height; use 0 if using width as target |
Notes: (1) The output scaled image has the dimension(s) you specify: * To specify the width with isotropic scaling, set hd = 0. * To specify the height with isotropic scaling, set wd = 0. * If both wd and hd are specified, the image is scaled (in general, anisotropically) to that size. * It is an error to set both wd and hd to 0.
Definition at line 323 of file scale1.c.
References pixGetDimensions(), and pixScale().
Referenced by pixaConvertToNUpPixa(), pixaDisplayTiledByIndex(), pixaScaleToSize(), pixCompareGrayByHisto(), pixScaleToSizeRel(), recogModifyTemplate(), and recogTrainFromBoot().
[in] | pixs | |
[in] | delw | change in width, in pixels; 0 means no change |
[in] | delh | change in height, in pixels; 0 means no change |
Definition at line 280 of file scale1.c.
References pixCopy(), pixGetDimensions(), and pixScaleToSize().
Referenced by pixaScaleToSizeRel().
|
static |
Notes: (1) This function is called with either 8 bpp gray or 32 bpp RGB. The result is a 2x reduced dest.
Definition at line 3628 of file scale1.c.
References GET_DATA_BYTE, and SET_DATA_BYTE.
|
static |
Notes: (1) The dest must be cleared prior to this operation, and we clear it here in the low-level code. (2) We reuse dest pixels and dest pixel rows whenever possible. This speeds the upscaling; downscaling is done by strict subsampling and is unaffected. (3) Because we are sampling and not interpolating, this routine works directly, without conversion to full RGB color, for 2, 4 or 8 bpp palette color images.
Definition at line 3064 of file scale1.c.
References GET_DATA_BYTE, GET_DATA_DIBIT, GET_DATA_QBIT, GET_DATA_TWO_BYTES, SET_DATA_BYTE, SET_DATA_DIBIT, SET_DATA_QBIT, and SET_DATA_TWO_BYTES.
|
static |
[in] | lined | ptr to top destline, to be made from current src line |
[in] | wpld | |
[in] | lines | ptr to current src line |
[in] | ws | |
[in] | wpls | |
[in] | lastlineflag | 1 if last src line; 0 otherwise |
Definition at line 2489 of file scale1.c.
Referenced by scaleColor2xLILow().
|
static |
Notes: (1) This is a special case of 2x expansion by linear interpolation. Each src pixel contains 4 dest pixels. The 4 dest pixels in src pixel 1 are numbered at their UL corners. The 4 dest pixels in src pixel 1 are related to that src pixel and its 3 neighboring src pixels as follows: 1-----2-----|-----|-----| | | | | | | | | | | src 1 --> 3-----4-----| | | <-- src 2 | | | | | | | | | | |-----|-----|-----|-----| | | | | | | | | | | src 3 --> | | | | | <-- src 4 | | | | | | | | | | |-----|-----|-----|-----| dest src ---- --- dp1 = sp1 dp2 = (sp1 + sp2) / 2 dp3 = (sp1 + sp3) / 2 dp4 = (sp1 + sp2 + sp3 + sp4) / 4 (2) We iterate over the src pixels, and unroll the calculation for each set of 4 dest pixels corresponding to that src pixel, caching pixels for the next src pixel whenever possible. The method is exactly analogous to the one we use for scaleGray2xLILow() and its line version.
Definition at line 2441 of file scale1.c.
References scaleColor2xLILineLow().
|
static |
Notes: (1) This should only be used for downscaling. We choose to divide each pixel into 16 x 16 sub-pixels. This is much slower than scaleSmoothLow(), but it gives a better representation, esp. for downscaling factors between 1.5 and 5. All src pixels are subdivided into 256 sub-pixels, and are weighted by the number of sub-pixels covered by the dest pixel. This is about 2x slower than scaleSmoothLow(), but the results are significantly better on small text.
|
static |
Notes: (1) We choose to divide each pixel into 16 x 16 sub-pixels. Linear interpolation is equivalent to finding the fractional area (i.e., number of sub-pixels divided by 256) associated with each of the four nearest src pixels, and weighting each pixel value by this fractional area.
|
static |
[in] | lined | ptr to top destline, to be made from current src line |
[in] | wpld | |
[in] | lines | ptr to current src line |
[in] | ws | |
[in] | wpls | |
[in] | lastlineflag | 1 if last src line; 0 otherwise |
Definition at line 2691 of file scale1.c.
References GET_DATA_BYTE, and SET_DATA_BYTE.
Referenced by scaleGray2xLILow().
|
static |
Notes: (1) This is a special case of 2x expansion by linear interpolation. Each src pixel contains 4 dest pixels. The 4 dest pixels in src pixel 1 are numbered at their UL corners. The 4 dest pixels in src pixel 1 are related to that src pixel and its 3 neighboring src pixels as follows: 1-----2-----|-----|-----| | | | | | | | | | | src 1 --> 3-----4-----| | | <-- src 2 | | | | | | | | | | |-----|-----|-----|-----| | | | | | | | | | | src 3 --> | | | | | <-- src 4 | | | | | | | | | | |-----|-----|-----|-----| dest src ---- --- dp1 = sp1 dp2 = (sp1 + sp2) / 2 dp3 = (sp1 + sp3) / 2 dp4 = (sp1 + sp2 + sp3 + sp4) / 4 (2) We iterate over the src pixels, and unroll the calculation for each set of 4 dest pixels corresponding to that src pixel, caching pixels for the next src pixel whenever possible.
Definition at line 2643 of file scale1.c.
References scaleGray2xLILineLow().
|
static |
[in] | lined | ptr to top destline, to be made from current src line |
[in] | wpld | |
[in] | lines | ptr to current src line |
[in] | ws | |
[in] | wpls | |
[in] | lastlineflag | 1 if last src line; 0 otherwise |
Definition at line 2930 of file scale1.c.
References GET_DATA_BYTE, and SET_DATA_BYTE.
Referenced by scaleGray4xLILow().
|
static |
Notes: (1) This is a special case of 4x expansion by linear interpolation. Each src pixel contains 16 dest pixels. The 16 dest pixels in src pixel 1 are numbered at their UL corners. The 16 dest pixels in src pixel 1 are related to that src pixel and its 3 neighboring src pixels as follows: 1---2---3---4---|---|---|---|---| | | | | | | | | | 5---6---7---8---|---|---|---|---| | | | | | | | | | src 1 --> 9---a---b---c---|---|---|---|---| <-- src 2 | | | | | | | | | d---e---f---g---|---|---|---|---| | | | | | | | | | |===|===|===|===|===|===|===|===| | | | | | | | | | |---|---|---|---|---|---|---|---| | | | | | | | | | src 3 --> |---|---|---|---|---|---|---|---| <-- src 4 | | | | | | | | | |---|---|---|---|---|---|---|---| | | | | | | | | | |---|---|---|---|---|---|---|---| dest src ---- --- dp1 = sp1 dp2 = (3 * sp1 + sp2) / 4 dp3 = (sp1 + sp2) / 2 dp4 = (sp1 + 3 * sp2) / 4 dp5 = (3 * sp1 + sp3) / 4 dp6 = (9 * sp1 + 3 * sp2 + 3 * sp3 + sp4) / 16 dp7 = (3 * sp1 + 3 * sp2 + sp3 + sp4) / 8 dp8 = (3 * sp1 + 9 * sp2 + 1 * sp3 + 3 * sp4) / 16 dp9 = (sp1 + sp3) / 2 dp10 = (3 * sp1 + sp2 + 3 * sp3 + sp4) / 8 dp11 = (sp1 + sp2 + sp3 + sp4) / 4 dp12 = (sp1 + 3 * sp2 + sp3 + 3 * sp4) / 8 dp13 = (sp1 + 3 * sp3) / 4 dp14 = (3 * sp1 + sp2 + 9 * sp3 + 3 * sp4) / 16 dp15 = (sp1 + sp2 + 3 * sp3 + 3 * sp4) / 8 dp16 = (sp1 + 3 * sp2 + 3 * sp3 + 9 * sp4) / 16 (2) We iterate over the src pixels, and unroll the calculation for each set of 16 dest pixels corresponding to that src pixel, caching pixels for the next src pixel whenever possible.
Definition at line 2884 of file scale1.c.
References scaleGray4xLILineLow().
|
static |
Notes: (1) This should only be used for downscaling. We choose to divide each pixel into 16 x 16 sub-pixels. This is about 2x slower than scaleSmoothLow(), but the results are significantly better on small text, esp. for downscaling factors between 1.5 and 5. All src pixels are subdivided into 256 sub-pixels, and are weighted by the number of sub-pixels covered by the dest pixel.
Definition at line 3521 of file scale1.c.
References GET_DATA_BYTE, lept_stderr(), and SET_DATA_BYTE.
|
static |
Notes: (1) We choose to divide each pixel into 16 x 16 sub-pixels. Linear interpolation is equivalent to finding the fractional area (i.e., number of sub-pixels divided by 256) associated with each of the four nearest src pixels, and weighting each pixel value by this fractional area.
Definition at line 2324 of file scale1.c.
References GET_DATA_BYTE, and SET_DATA_BYTE.
|
static |
Notes: (1) This function is called with 32 bpp RGB src and 8 bpp, half-resolution dest. The weights should add to 1.0.
|
static |
Notes: (1) This function is called on 8 or 32 bpp src and dest images. (2) size is the full width of the lowpass smoothing filter. It is correlated with the reduction ratio, being the nearest integer such that size is approximately equal to hs / hd.
Definition at line 3197 of file scale1.c.
References GET_DATA_BYTE, and SET_DATA_BYTE.