本文整理汇总了C++中pixGetColormap函数的典型用法代码示例。如果您正苦于以下问题:C++ pixGetColormap函数的具体用法?C++ pixGetColormap怎么用?C++ pixGetColormap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pixGetColormap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pixAddRGB
/*!
* pixAddRGB()
*
* Input: pixs1, pixs2 (32 bpp RGB, or colormapped)
* Return: pixd, or null on error
*
* Notes:
* (1) Clips computation to the minimum size, aligning the UL corners.
* (2) Removes any colormap to RGB, and ignores the LSB of each
* pixel word (the alpha channel).
* (3) Adds each component value, pixelwise, clipping to 255.
* (4) This is useful to combine two images where most of the
* pixels are essentially black, such as in pixPerceptualDiff().
*/
PIX *
pixAddRGB(PIX *pixs1,
PIX *pixs2)
{
l_int32 i, j, w, h, d, w2, h2, d2, wplc1, wplc2, wpld;
l_int32 rval1, gval1, bval1, rval2, gval2, bval2, rval, gval, bval;
l_uint32 *datac1, *datac2, *datad, *linec1, *linec2, *lined;
PIX *pixc1, *pixc2, *pixd;
PROCNAME("pixAddRGB");
if (!pixs1)
return (PIX *)ERROR_PTR("pixs1 not defined", procName, NULL);
if (!pixs2)
return (PIX *)ERROR_PTR("pixs2 not defined", procName, NULL);
pixGetDimensions(pixs1, &w, &h, &d);
pixGetDimensions(pixs2, &w2, &h2, &d2);
if (!pixGetColormap(pixs1) && d != 32)
return (PIX *)ERROR_PTR("pixs1 not cmapped or rgb", procName, NULL);
if (!pixGetColormap(pixs2) && d2 != 32)
return (PIX *)ERROR_PTR("pixs2 not cmapped or rgb", procName, NULL);
if (pixGetColormap(pixs1))
pixc1 = pixRemoveColormap(pixs1, REMOVE_CMAP_TO_FULL_COLOR);
else
pixc1 = pixClone(pixs1);
if (pixGetColormap(pixs2))
pixc2 = pixRemoveColormap(pixs2, REMOVE_CMAP_TO_FULL_COLOR);
else
pixc2 = pixClone(pixs2);
w = L_MIN(w, w2);
h = L_MIN(h, h2);
pixd = pixCreate(w, h, 32);
pixCopyResolution(pixd, pixs1);
datac1 = pixGetData(pixc1);
datac2 = pixGetData(pixc2);
datad = pixGetData(pixd);
wplc1 = pixGetWpl(pixc1);
wplc2 = pixGetWpl(pixc2);
wpld = pixGetWpl(pixd);
for (i = 0; i < h; i++) {
linec1 = datac1 + i * wplc1;
linec2 = datac2 + i * wplc2;
lined = datad + i * wpld;
for (j = 0; j < w; j++) {
extractRGBValues(linec1[j], &rval1, &gval1, &bval1);
extractRGBValues(linec2[j], &rval2, &gval2, &bval2);
rval = L_MIN(255, rval1 + rval2);
gval = L_MIN(255, gval1 + gval2);
bval = L_MIN(255, bval1 + bval2);
composeRGBPixel(rval, gval, bval, lined + j);
}
}
pixDestroy(&pixc1);
pixDestroy(&pixc2);
return pixd;
}
示例2: pixRotateShearIP
/*!
* pixRotateShearIP()
*
* Input: pixs (any depth; not colormapped)
* xcen, ycen (center of rotation)
* angle (radians)
* incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK)
* Return: 0 if OK; 1 on error
*
* Notes:
* (1) This does an in-place rotation of the image
* about the image center, using the 3-shear method.
* (2) A positive angle gives a clockwise rotation.
* (3) 3-shear rotation by a specified angle is equivalent
* to the sequential transformations
* y' = y + tan(angle/2) * (x - xcen) for first y-shear
* x' = x + sin(angle) * (y - ycen) for x-shear
* y' = y + tan(angle/2) * (x - xcen) for second y-shear
* (4) Computation of tan(angle) is performed in the shear operations.
* (5) This brings in 'incolor' pixels from outside the image.
* (6) The pix cannot be colormapped, because the in-place operation
* only blits in 0 or 1 bits, not an arbitrary colormap index.
*/
l_int32
pixRotateShearIP(PIX *pixs,
l_int32 xcen,
l_int32 ycen,
l_float32 angle,
l_int32 incolor)
{
l_float32 hangle;
PROCNAME("pixRotateShearIP");
if (!pixs)
return ERROR_INT("pixs not defined", procName, 1);
if (incolor != L_BRING_IN_WHITE && incolor != L_BRING_IN_BLACK)
return ERROR_INT("invalid value for incolor", procName, 1);
if (pixGetColormap(pixs) != NULL)
return ERROR_INT("pixs is colormapped", procName, 1);
if (angle == 0.0)
return 0;
hangle = atan(sin(angle));
pixHShearIP(pixs, ycen, angle / 2., incolor);
pixVShearIP(pixs, xcen, hangle, incolor);
pixHShearIP(pixs, ycen, angle / 2., incolor);
return 0;
}
示例3: test_8bpp_trans
static l_int32
test_8bpp_trans(L_REGPARAMS *rp)
{
l_int32 same, transp;
FILE *fp;
PIX *pix1, *pix2, *pix3;
PIXCMAP *cmap;
pix1 = pixRead("wyom.jpg");
pix2 = pixColorSegment(pix1, 75, 10, 8, 7);
cmap = pixGetColormap(pix2);
pixcmapSetAlpha(cmap, 0, 0); /* set blueish sky color to transparent */
pixWrite("/tmp/regout/8bpp-trans.png", pix2, IFF_PNG);
pix3 = pixRead("/tmp/regout/8bpp-trans.png");
pixEqual(pix2, pix3, &same);
if (same)
fprintf(stderr, "8bpp_trans: success\n");
else
fprintf(stderr, "8bpp_trans: bad output\n");
pixDisplayWithTitle(pix3, 700, 0, NULL, rp->display);
pixDestroy(&pix1);
pixDestroy(&pix2);
pixDestroy(&pix3);
fp = fopenReadStream("/tmp/regout/8bpp-trans.png");
fgetPngColormapInfo(fp, &cmap, &transp);
fclose(fp);
if (transp)
fprintf(stderr, "8bpp_trans: correct -- transparency found\n");
else
fprintf(stderr, "8bpp_trans: error -- no transparency found!\n");
if (rp->display) pixcmapWriteStream(stderr, cmap);
pixcmapDestroy(&cmap);
return same;
}
示例4: pixRotateShearIP
/*!
* \brief pixRotateShearIP()
*
* \param[in] pixs any depth; not colormapped
* \param[in] xcen, ycen center of rotation
* \param[in] angle radians
* \param[in] incolor L_BRING_IN_WHITE, L_BRING_IN_BLACK
* \return 0 if OK; 1 on error
*
* <pre>
* Notes:
* (1) This does an in-place rotation of the image about the
* specified point, using the 3-shear method. It should only
* be used for angles smaller than LIMIT_SHEAR_ANGLE.
* For larger angles, a warning is issued.
* (2) A positive angle gives a clockwise rotation.
* (3) 3-shear rotation by a specified angle is equivalent
* to the sequential transformations
* y' = y + tan(angle/2) * (x - xcen) for first y-shear
* x' = x + sin(angle) * (y - ycen) for x-shear
* y' = y + tan(angle/2) * (x - xcen) for second y-shear
* (4) Computation of tan(angle) is performed in the shear operations.
* (5) This brings in 'incolor' pixels from outside the image.
* (6) The pix cannot be colormapped, because the in-place operation
* only blits in 0 or 1 bits, not an arbitrary colormap index.
* </pre>
*/
l_int32
pixRotateShearIP(PIX *pixs,
l_int32 xcen,
l_int32 ycen,
l_float32 angle,
l_int32 incolor)
{
l_float32 hangle;
PROCNAME("pixRotateShearIP");
if (!pixs)
return ERROR_INT("pixs not defined", procName, 1);
if (incolor != L_BRING_IN_WHITE && incolor != L_BRING_IN_BLACK)
return ERROR_INT("invalid value for incolor", procName, 1);
if (pixGetColormap(pixs) != NULL)
return ERROR_INT("pixs is colormapped", procName, 1);
if (angle == 0.0)
return 0;
if (L_ABS(angle) > LIMIT_SHEAR_ANGLE) {
L_WARNING("%6.2f radians; large angle for in-place 3-shear rotation\n",
procName, L_ABS(angle));
}
hangle = atan(sin(angle));
pixHShearIP(pixs, ycen, angle / 2., incolor);
pixVShearIP(pixs, xcen, hangle, incolor);
pixHShearIP(pixs, ycen, angle / 2., incolor);
return 0;
}
示例5: pixRankFilter
/*!
* pixRankFilter()
*
* Input: pixs (8 or 32 bpp; no colormap)
* wf, hf (width and height of filter; each is >= 1)
* rank (in [0.0 ... 1.0])
* Return: pixd (of rank values), or null on error
*
* Notes:
* (1) This defines, for each pixel in pixs, a neighborhood of
* pixels given by a rectangle "centered" on the pixel.
* This set of wf*hf pixels has a distribution of values.
* For each component, if the values are sorted in increasing
* order, we choose the component such that rank*(wf*hf-1)
* pixels have a lower or equal value and
* (1-rank)*(wf*hf-1) pixels have an equal or greater value.
* (2) See notes in pixRankFilterGray() for further details.
*/
PIX *
pixRankFilter(PIX *pixs,
l_int32 wf,
l_int32 hf,
l_float32 rank)
{
l_int32 d;
PROCNAME("pixRankFilter");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (pixGetColormap(pixs) != NULL)
return (PIX *)ERROR_PTR("pixs has colormap", procName, NULL);
d = pixGetDepth(pixs);
if (d != 8 && d != 32)
return (PIX *)ERROR_PTR("pixs not 8 or 32 bpp", procName, NULL);
if (wf < 1 || hf < 1)
return (PIX *)ERROR_PTR("wf < 1 || hf < 1", procName, NULL);
if (rank < 0.0 || rank > 1.0)
return (PIX *)ERROR_PTR("rank must be in [0.0, 1.0]", procName, NULL);
if (wf == 1 && hf == 1) /* no-op */
return pixCopy(NULL, pixs);
if (d == 8)
return pixRankFilterGray(pixs, wf, hf, rank);
else /* d == 32 */
return pixRankFilterRGB(pixs, wf, hf, rank);
}
示例6: pixaAnyColormaps
/*!
* pixaAnyColormaps()
*
* Input: pixa
* &hascmap (<return> 1 if any pix has a colormap; 0 otherwise)
* Return: 0 if OK; 1 on error
*/
l_int32
pixaAnyColormaps(PIXA *pixa,
l_int32 *phascmap)
{
l_int32 i, n;
PIX *pix;
PIXCMAP *cmap;
PROCNAME("pixaAnyColormaps");
if (!phascmap)
return ERROR_INT("&hascmap not defined", procName, 1);
*phascmap = 0;
if (!pixa)
return ERROR_INT("pixa not defined", procName, 1);
n = pixaGetCount(pixa);
for (i = 0; i < n; i++) {
pix = pixaGetPix(pixa, i, L_CLONE);
cmap = pixGetColormap(pix);
pixDestroy(&pix);
if (cmap) {
*phascmap = 1;
return 0;
}
}
return 0;
}
示例7: pixGetAutoFormat
/*!
* \brief pixGetAutoFormat()
*
* \param[in] pix
* \param[in] &format
* \return 0 if OK, 1 on error
*
* <pre>
* Notes:
* (1) The output formats are restricted to tiff, jpeg and png
* because these are the most commonly used image formats and
* the ones that are typically installed with leptonica.
* (2) This decides what compression to use based on the pix.
* It chooses tiff-g4 if 1 bpp without a colormap, jpeg with
* quality 75 if grayscale, rgb or rgba (where it loses
* the alpha layer), and lossless png for all other situations.
* </pre>
*/
l_int32
pixGetAutoFormat(PIX *pix,
l_int32 *pformat)
{
l_int32 d;
PIXCMAP *cmap;
PROCNAME("pixGetAutoFormat");
if (!pformat)
return ERROR_INT("&format not defined", procName, 0);
*pformat = IFF_UNKNOWN;
if (!pix)
return ERROR_INT("pix not defined", procName, 0);
d = pixGetDepth(pix);
cmap = pixGetColormap(pix);
if (d == 1 && !cmap) {
*pformat = IFF_TIFF_G4;
} else if ((d == 8 && !cmap) || d == 24 || d == 32) {
*pformat = IFF_JFIF_JPEG;
} else {
*pformat = IFF_PNG;
}
return 0;
}
示例8: pixPrintStreamInfo
/*!
* pixPrintStreamInfo()
*
* Input: fp (file stream)
* pix
* text (<optional> identifying string; can be null)
* Return: 0 if OK, 1 on error
*/
l_int32
pixPrintStreamInfo(FILE *fp,
PIX *pix,
const char *text)
{
PIXCMAP *cmap;
PROCNAME("pixPrintStreamInfo");
if (!fp)
return ERROR_INT("fp not defined", procName, 1);
if (!pix)
return ERROR_INT("pix not defined", procName, 1);
if (text)
fprintf(fp, " Pix Info for %s:\n", text);
fprintf(fp, " width = %d, height = %d, depth = %d\n",
pixGetWidth(pix), pixGetHeight(pix), pixGetDepth(pix));
fprintf(fp, " wpl = %d, data = %p, refcount = %d\n",
pixGetWpl(pix), pixGetData(pix), pixGetRefcount(pix));
if ((cmap = pixGetColormap(pix)) != NULL)
pixcmapWriteStream(fp, cmap);
else
fprintf(fp, " no colormap\n");
return 0;
}
示例9: pixBilateralGray
/*!
* pixBilateralGray()
*
* Input: pixs (8 bpp gray)
* spatial_stdev (of gaussian kernel; in pixels, > 0.5)
* range_stdev (of gaussian range kernel; > 5.0; typ. 50.0)
* ncomps (number of intermediate sums J(k,x); in [4 ... 30])
* reduction (1, 2 or 4)
* Return: pixd (8 bpp bilateral filtered image), or null on error
*
* Notes:
* (1) See pixBilateral() for constraints on the input parameters.
* (2) See pixBilateral() for algorithm details.
*/
PIX *
pixBilateralGray(PIX *pixs,
l_float32 spatial_stdev,
l_float32 range_stdev,
l_int32 ncomps,
l_int32 reduction) {
l_float32 sstdev; /* scaled spatial stdev */
PIX *pixd;
L_BILATERAL *bil;
PROCNAME("pixBilateralGray");
if (!pixs || pixGetColormap(pixs))
return (PIX *) ERROR_PTR("pixs not defined or cmapped", procName, NULL);
if (pixGetDepth(pixs) != 8)
return (PIX *) ERROR_PTR("pixs not 8 bpp gray", procName, NULL);
if (reduction != 1 && reduction != 2 && reduction != 4)
return (PIX *) ERROR_PTR("reduction invalid", procName, NULL);
sstdev = spatial_stdev / (l_float32) reduction; /* reduced spat. stdev */
if (sstdev < 0.5)
return (PIX *) ERROR_PTR("sstdev < 0.5", procName, NULL);
if (range_stdev <= 5.0)
return (PIX *) ERROR_PTR("range_stdev <= 5.0", procName, NULL);
if (ncomps < 4 || ncomps > 30)
return (PIX *) ERROR_PTR("ncomps not in [4 ... 30]", procName, NULL);
if (ncomps * range_stdev < 100.0)
return (PIX *) ERROR_PTR("ncomps * range_stdev < 100.0", procName, NULL);
bil = bilateralCreate(pixs, spatial_stdev, range_stdev, ncomps, reduction);
if (!bil) return (PIX *) ERROR_PTR("bil not made", procName, NULL);
pixd = bilateralApply(bil);
bilateralDestroy(&bil);
return pixd;
}
示例10: pixBlockBilateralExact
/*!
* pixBlockBilateralExact()
*
* Input: pixs (8 bpp gray or 32 bpp rgb)
* spatial_stdev (> 0.0)
* range_stdev (> 0.0)
* Return: pixd (8 bpp or 32 bpp bilateral filtered image)
*
* Notes:
* (1) See pixBilateralExact(). This provides an interface using
* the standard deviations of the spatial and range filters.
* (2) The convolution window halfwidth is 2 * spatial_stdev,
* and the square filter size is 4 * spatial_stdev + 1.
* The kernel captures 95% of total energy. This is compensated
* by normalization.
* (3) The range_stdev is analogous to spatial_halfwidth in the
* grayscale domain [0...255], and determines how much damping of the
* smoothing operation is applied across edges. The larger this
* value is, the smaller the damping. The smaller the value, the
* more edge details are preserved. These approximations are useful
* for deciding the appropriate cutoff.
* kernel[1 * stdev] ~= 0.6 * kernel[0]
* kernel[2 * stdev] ~= 0.14 * kernel[0]
* kernel[3 * stdev] ~= 0.01 * kernel[0]
* If range_stdev is infinite there is no damping, and this
* becomes a conventional gaussian smoothing.
* This value does not affect the run time.
* (4) If range_stdev is negative or zero, the range kernel is
* ignored and this degenerates to a straight gaussian convolution.
* (5) This is very slow for large spatial filters. The time
* on a 3GHz pentium is roughly
* T = 1.2 * 10^-8 * (A * sh^2) sec
* where A = # of pixels, sh = spatial halfwidth of filter.
*/
PIX *
pixBlockBilateralExact(PIX *pixs,
l_float32 spatial_stdev,
l_float32 range_stdev) {
l_int32 d, halfwidth;
L_KERNEL *spatial_kel, *range_kel;
PIX *pixd;
PROCNAME("pixBlockBilateralExact");
if (!pixs)
return (PIX *) ERROR_PTR("pixs not defined", procName, NULL);
d = pixGetDepth(pixs);
if (d != 8 && d != 32)
return (PIX *) ERROR_PTR("pixs not 8 or 32 bpp", procName, NULL);
if (pixGetColormap(pixs) != NULL)
return (PIX *) ERROR_PTR("pixs is cmapped", procName, NULL);
if (spatial_stdev <= 0.0)
return (PIX *) ERROR_PTR("invalid spatial stdev", procName, NULL);
if (range_stdev <= 0.0)
return (PIX *) ERROR_PTR("invalid range stdev", procName, NULL);
halfwidth = 2 * spatial_stdev;
spatial_kel = makeGaussianKernel(halfwidth, halfwidth, spatial_stdev, 1.0);
range_kel = makeRangeKernel(range_stdev);
pixd = pixBilateralExact(pixs, spatial_kel, range_kel);
kernelDestroy(&spatial_kel);
kernelDestroy(&range_kel);
return pixd;
}
示例11: pixSerializeToMemory
/*!
* pixSerializeToMemory()
*
* Input: pixs (all depths, colormap OK)
* &data (<return> serialized data in memory)
* &nbytes (<return> number of bytes in data string)
* Return: 0 if OK, 1 on error
*
* Notes:
* (1) This does a fast serialization of the principal elements
* of the pix, as follows:
* "spix" (4 bytes) -- ID for file type
* w (4 bytes)
* h (4 bytes)
* d (4 bytes)
* wpl (4 bytes)
* ncolors (4 bytes) -- in colormap; 0 if there is no colormap
* cdata (4 * ncolors) -- size of serialized colormap array
* rdatasize (4 bytes) -- size of serialized raster data
* = 4 * wpl * h
* rdata (rdatasize)
*/
l_int32
pixSerializeToMemory(PIX *pixs,
l_uint32 **pdata,
size_t *pnbytes)
{
char *id;
l_int32 w, h, d, wpl, rdatasize, ncolors, nbytes, index;
l_uint8 *cdata; /* data in colormap array (4 bytes/color table entry) */
l_uint32 *data;
l_uint32 *rdata; /* data in pix raster */
PIXCMAP *cmap;
PROCNAME("pixSerializeToMemory");
if (!pdata || !pnbytes)
return ERROR_INT("&data and &nbytes not both defined", procName, 1);
*pdata = NULL;
*pnbytes = 0;
if (!pixs)
return ERROR_INT("pixs not defined", procName, 1);
pixGetDimensions(pixs, &w, &h, &d);
wpl = pixGetWpl(pixs);
rdata = pixGetData(pixs);
rdatasize = 4 * wpl * h;
ncolors = 0;
cdata = NULL;
if ((cmap = pixGetColormap(pixs)) != NULL)
pixcmapSerializeToMemory(cmap, 4, &ncolors, &cdata);
nbytes = 24 + 4 * ncolors + 4 + rdatasize;
if ((data = (l_uint32 *)CALLOC(nbytes / 4, sizeof(l_uint32))) == NULL)
return ERROR_INT("data not made", procName, 1);
*pdata = data;
*pnbytes = nbytes;
id = (char *)data;
id[0] = 's';
id[1] = 'p';
id[2] = 'i';
id[3] = 'x';
data[1] = w;
data[2] = h;
data[3] = d;
data[4] = wpl;
data[5] = ncolors;
if (ncolors > 0)
memcpy((char *)(data + 6), (char *)cdata, 4 * ncolors);
index = 6 + ncolors;
data[index] = rdatasize;
memcpy((char *)(data + index + 1), (char *)rdata, rdatasize);
#if DEBUG_SERIALIZE
fprintf(stderr, "Serialize: "
"raster size = %d, ncolors in cmap = %d, total bytes = %d\n",
rdatasize, ncolors, nbytes);
#endif /* DEBUG_SERIALIZE */
FREE(cdata);
return 0;
}
示例12: pixDisplayWriteFormat
/*!
* pixDisplayWriteFormat()
*
* Input: pix (1, 2, 4, 8, 16, 32 bpp)
* reduction (-1 to reset/erase; 0 to disable;
* otherwise this is a reduction factor)
* format (IFF_PNG or IFF_JFIF_JPEG)
* Return: 0 if OK; 1 on error
*
* Notes:
* (1) This writes files if reduction > 0. These can be displayed using
* pixDisplayMultiple("/tmp/junk_write_display*");
* (2) All previously written files can be erased by calling with
* reduction < 0; the value of pixs is ignored.
* (3) If reduction > 1 and depth == 1, this does a scale-to-gray
* reduction.
* (4) This function uses a static internal variable to number
* output files written by a single process. Behavior
* with a shared library may be unpredictable.
* (5) Output file format is as follows:
* format == IFF_JFIF_JPEG:
* png if d < 8 or d == 16 or if the output pix
* has a colormap. Otherwise, output is jpg.
* format == IFF_PNG:
* png (lossless) on all images.
* (6) For 16 bpp, the choice of full dynamic range with log scale
* is the best for displaying these images. Alternative outputs are
* pix8 = pixMaxDynamicRange(pixt, L_LINEAR_SCALE);
* pix8 = pixConvert16To8(pixt, 0); // low order byte
* pix8 = pixConvert16To8(pixt, 1); // high order byte
*/
l_int32
pixDisplayWriteFormat(PIX *pixs,
l_int32 reduction,
l_int32 format)
{
char buffer[L_BUF_SIZE];
l_float32 scale;
PIX *pixt, *pix8;
static l_int32 index = 0; /* caution: not .so or thread safe */
PROCNAME("pixDisplayWriteFormat");
if (reduction == 0) return 0;
if (reduction < 0) {
index = 0; /* reset; this will cause erasure at next call to write */
return 0;
}
if (format != IFF_JFIF_JPEG && format != IFF_PNG)
return ERROR_INT("invalid format", procName, 1);
if (!pixs)
return ERROR_INT("pixs not defined", procName, 1);
if (index == 0) {
snprintf(buffer, L_BUF_SIZE,
"rm -f /tmp/junk_write_display.*.png /tmp/junk_write_display.*.jpg");
system(buffer);
}
index++;
if (reduction == 1)
pixt = pixClone(pixs);
else {
scale = 1. / (l_float32)reduction;
if (pixGetDepth(pixs) == 1)
pixt = pixScaleToGray(pixs, scale);
else
pixt = pixScale(pixs, scale, scale);
}
if (pixGetDepth(pixt) == 16) {
pix8 = pixMaxDynamicRange(pixt, L_LOG_SCALE);
snprintf(buffer, L_BUF_SIZE, "/tmp/junk_write_display.%03d.png", index);
pixWrite(buffer, pix8, IFF_PNG);
pixDestroy(&pix8);
}
else if (pixGetDepth(pixt) < 8 || pixGetColormap(pixt) ||
format == IFF_PNG) {
snprintf(buffer, L_BUF_SIZE, "/tmp/junk_write_display.%03d.png", index);
pixWrite(buffer, pixt, IFF_PNG);
}
else {
snprintf(buffer, L_BUF_SIZE, "/tmp/junk_write_display.%03d.jpg", index);
pixWrite(buffer, pixt, format);
}
pixDestroy(&pixt);
return 0;
}
示例13: pixCopyColormap
/*!
* pixCopyColormap()
*
* Input: src and dest Pix
* Return: 0 if OK, 1 on error
*
* Notes:
* (1) This always destroys any colormap in pixd (except if
* the operation is a no-op.
*/
l_int32
pixCopyColormap(PIX *pixd,
PIX *pixs)
{
PIXCMAP *cmaps, *cmapd;
PROCNAME("pixCopyColormap");
if (!pixs)
return ERROR_INT("pixs not defined", procName, 1);
if (!pixd)
return ERROR_INT("pixd not defined", procName, 1);
if (pixs == pixd)
return 0; /* no-op */
pixDestroyColormap(pixd);
if ((cmaps = pixGetColormap(pixs)) == NULL) /* not an error */
return 0;
if ((cmapd = pixcmapCopy(cmaps)) == NULL)
return ERROR_INT("cmapd not made", procName, 1);
pixSetColormap(pixd, cmapd);
return 0;
}
示例14: pixRasteropHip
/*!
* pixRasteropHip()
*
* Input: pixd (in-place operation)
* by (top of horizontal band)
* bh (height of horizontal band)
* hshift (horizontal shift of band; hshift > 0 is to right)
* incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK)
* Return: 0 if OK; 1 on error
*
* Notes:
* (1) This rasterop translates a horizontal band of the
* image either left or right, bringing in either white
* or black pixels from outside the image.
* (2) The horizontal band extends the full width of pixd.
* (3) If a colormap exists, the nearest color to white or black
* is brought in.
*/
l_int32
pixRasteropHip(PIX *pixd,
l_int32 by,
l_int32 bh,
l_int32 hshift,
l_int32 incolor)
{
l_int32 w, h, d, index, op;
PIX *pixt;
PIXCMAP *cmap;
PROCNAME("pixRasteropHip");
if (!pixd)
return ERROR_INT("pixd not defined", procName, 1);
if (incolor != L_BRING_IN_WHITE && incolor != L_BRING_IN_BLACK)
return ERROR_INT("invalid value for incolor", procName, 1);
if (bh <= 0)
return ERROR_INT("bh must be > 0", procName, 1);
if (hshift == 0)
return 0;
pixGetDimensions(pixd, &w, &h, &d);
rasteropHipLow(pixGetData(pixd), h, d, pixGetWpl(pixd), by, bh, hshift);
cmap = pixGetColormap(pixd);
if (!cmap) {
if ((d == 1 && incolor == L_BRING_IN_BLACK) ||
(d > 1 && incolor == L_BRING_IN_WHITE))
op = PIX_SET;
else
op = PIX_CLR;
/* Set the pixels brought in at left or right */
if (hshift > 0)
pixRasterop(pixd, 0, by, hshift, bh, op, NULL, 0, 0);
else /* hshift < 0 */
pixRasterop(pixd, w + hshift, by, -hshift, bh, op, NULL, 0, 0);
return 0;
}
/* Get the nearest index and fill with that */
if (incolor == L_BRING_IN_BLACK)
pixcmapGetRankIntensity(cmap, 0.0, &index);
else /* white */
pixcmapGetRankIntensity(cmap, 1.0, &index);
pixt = pixCreate(L_ABS(hshift), bh, d);
pixSetAllArbitrary(pixt, index);
if (hshift > 0)
pixRasterop(pixd, 0, by, hshift, bh, PIX_SRC, pixt, 0, 0);
else /* hshift < 0 */
pixRasterop(pixd, w + hshift, by, -hshift, bh, PIX_SRC, pixt, 0, 0);
pixDestroy(&pixt);
return 0;
}
示例15: main
l_int32 main(int argc,
char **argv)
{
l_uint32 *colors;
l_int32 ncolors;
PIX *pix1, *pix2, *pix3;
L_REGPARAMS *rp;
if (regTestSetup(argc, argv, &rp))
return 1;
/* Find the most populated colors */
pix1 = pixRead("fish24.jpg");
pixGetMostPopulatedColors(pix1, 2, 3, 10, &colors, NULL);
pix2 = pixDisplayColorArray(colors, 10, 190, 5, 1);
pixDisplayWithTitle(pix2, 0, 0, NULL, rp->display);
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 0 */
lept_free(colors);
pixDestroy(&pix2);
/* Do a simple color quantization with sigbits = 2 */
pix2 = pixSimpleColorQuantize(pix1, 2, 3, 10);
pixDisplayWithTitle(pix2, 0, 400, NULL, rp->display);
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 1 */
pix3 = pixRemoveColormap(pix2, REMOVE_CMAP_TO_FULL_COLOR);
regTestComparePix(rp, pix2, pix3); /* 2 */
pixNumColors(pix3, 1, &ncolors);
regTestCompareValues(rp, ncolors, 10, 0.0); /* 3 */
pixDestroy(&pix1);
pixDestroy(&pix2);
pixDestroy(&pix3);
/* Do a simple color quantization with sigbits = 3 */
pix1 = pixRead("wyom.jpg");
pixNumColors(pix1, 1, &ncolors); /* >255, so should give 0 */
regTestCompareValues(rp, ncolors, 0, 0.0); /* 4 */
pix2 = pixSimpleColorQuantize(pix1, 3, 3, 20);
pixDisplayWithTitle(pix2, 1000, 0, NULL, rp->display);
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 5 */
ncolors = pixcmapGetCount(pixGetColormap(pix2));
regTestCompareValues(rp, ncolors, 20, 0.0); /* 6 */
pixDestroy(&pix1);
pixDestroy(&pix2);
/* Find the number of perceptually significant gray intensities */
pix1 = pixRead("marge.jpg");
pix2 = pixConvertTo8(pix1, 0);
pixNumSignificantGrayColors(pix2, 20, 236, 0.0001, 1, &ncolors);
regTestCompareValues(rp, ncolors, 219, 0.0); /* 7 */
pixDestroy(&pix1);
pixDestroy(&pix2);
return regTestCleanup(rp);
}