83 #include <config_auto.h>
88 #include "allheaders.h"
121 l_int32 i, n, index, w, h, xb, yb, wb, hb;
123 PIX *pix1, *pix2, *pixd;
126 if (!pixs || pixGetDepth(pixs) != 1)
127 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
128 if (connect != 4 && connect != 8)
129 return (
PIX *)ERROR_PTR(
"connectivity must be 4 or 8", __func__, NULL);
130 if (depth != 0 && depth != 8 && depth != 16 && depth != 32)
131 return (
PIX *)ERROR_PTR(
"depth must be 0, 8, 16 or 32", __func__, NULL);
153 for (i = 0; i < n; i++) {
157 index = 1 + (i % 254);
159 }
else if (depth == 16) {
160 index = 1 + (i % 0xfffe);
198 l_int32 i, n, npix, w, h, xb, yb, wb, hb;
201 PIX *pix1, *pix2, *pixd;
204 if (!pixs || pixGetDepth(pixs) != 1)
205 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
206 if (connect != 4 && connect != 8)
207 return (
PIX *)ERROR_PTR(
"connectivity must be 4 or 8", __func__, NULL);
222 for (i = 0; i < n; i++) {
272 l_int32 empty, w, h, ncc;
277 if (ppixd) *ppixd = NULL;
278 if (pptaa) *pptaa = NULL;
280 if (!ppixd || !pptaa || !pncc)
281 return ERROR_INT(
"&pixd, &ptaa, &ncc not all defined", __func__, 1);
282 if (!pixs || pixGetDepth(pixs) != 1)
283 return ERROR_INT(
"pixs undefined or not 1 bpp", __func__, 1);
284 if (conn != 4 && conn != 8)
285 return ERROR_INT(
"connectivity must be 4 or 8", __func__, 1);
291 pixSetSpp(*ppixd, 1);
292 pixSetSpecial(*ppixd, conn);
301 return ERROR_INT(
"pixd not made", __func__, 1);
302 pixSetSpecial(pixd, conn);
305 return ERROR_INT(
"ptaa not made", __func__, 1);
355 l_int32 conn, i, j, w, h, count, nvals, ns, firstindex;
360 if (!pixs || pixGetDepth(pixs) != 32)
361 return ERROR_INT(
"pixs not defined or not 32 bpp", __func__, 1);
363 return ERROR_INT(
"ptaa not defined", __func__, 1);
365 return ERROR_INT(
"&ncc not defined", __func__, 1);
367 if (conn != 4 && conn != 8)
368 return ERROR_INT(
"connectivity must be 4 or 8", __func__, 1);
371 return ERROR_INT(
"invalid x pixel location", __func__, 1);
373 return ERROR_INT(
"invalid y pixel location", __func__, 1);
400 firstindex = neigh[0];
405 lept_stderr(
"nvals = %d: neigh = (%d)\n", nvals, neigh[0]);
418 if (debug >= 1 && debug <= 2) {
419 lept_stderr(
"nvals = %d: neigh = (%d,%d)\n", nvals,
422 }
else if (nvals == 3) {
423 if (debug >= 1 && debug <= 3) {
424 lept_stderr(
"nvals = %d: neigh = (%d,%d,%d)\n", nvals,
425 neigh[0], neigh[1], neigh[2]);
428 if (debug >= 1 && debug <= 4) {
429 lept_stderr(
"nvals = %d: neigh = (%d,%d,%d,%d)\n", nvals,
430 neigh[0], neigh[1], neigh[2], neigh[3]);
434 for (i = 1; i < nvals; i++) {
437 for (j = 0; j < ns; j++) {
483 l_int32 i, npt, index;
492 if (pneigh) *pneigh = NULL;
493 if (pnvals) *pnvals = 0;
494 if (!pneigh || !pnvals)
495 return ERROR_INT(
"&neigh and &nvals not both defined", __func__, 1);
496 if (!pixs || pixGetDepth(pixs) < 8)
497 return ERROR_INT(
"pixs not defined or depth < 8", __func__, 1);
501 return ERROR_INT(
"pta of neighbors not made", __func__, 1);
504 aset = l_asetCreate(L_UINT_TYPE);
506 for (i = 0; i < npt; i++) {
510 l_asetInsert(aset, key);
516 node = l_asetGetFirst(aset);
519 val =
node->key.utype;
521 neigh[index++] = (l_int32)val;
526 *pneigh = (l_int32 *)LEPT_CALLOC(index,
sizeof(l_int32));
527 for (i = 0; i < index; i++)
528 (*pneigh)[i] = neigh[i];
532 l_asetDestroy(&aset);
562 l_int32 w, h, w2, h2, wpls, wplr, wplg, wplb, wplcc, i, j, rval, gval, bval;
563 l_float32 invw2, invh2;
564 l_uint32 *datas, *datar, *datag, *datab, *datacc;
565 l_uint32 *lines, *liner, *lineg, *lineb, *linecc;
566 PIX *pix1, *pixcc, *pixr, *pixg, *pixb, *pixd;
568 if (!pixs || pixGetDepth(pixs) != 1)
569 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
577 invw2 = 255.0 / (l_float32)w2;
578 invh2 = 255.0 / (l_float32)h2;
588 wpls = pixGetWpl(pixs);
589 wplr = pixGetWpl(pixr);
590 wplg = pixGetWpl(pixg);
591 wplb = pixGetWpl(pixb);
592 wplcc = pixGetWpl(pixcc);
598 for (i = 0; i < h; i++) {
599 lines = datas + i * wpls;
600 liner = datar + i * wplr;
601 lineg = datag + i * wplg;
602 lineb = datab + i * wplb;
603 linecc = datacc+ i * wplcc;
604 for (j = 0; j < w; j++) {
607 rval = invh2 * L_ABS((l_float32)(i - h2));
608 gval = invw2 * L_ABS((l_float32)(j - w2));
610 rval = invw2 * L_ABS((l_float32)(j - w2));
611 gval = invh2 * L_ABS((l_float32)(i - h2));
#define GET_DATA_BYTE(pdata, n)
#define SET_DATA_BYTE(pdata, n, val)
#define GET_DATA_BIT(pdata, n)
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
BOXA * pixConnComp(PIX *pixs, PIXA **ppixa, l_int32 connectivity)
pixConnComp()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
l_ok pixSetPixel(PIX *pix, l_int32 x, l_int32 y, l_uint32 val)
pixSetPixel()
l_ok pixGetPixel(PIX *pix, l_int32 x, l_int32 y, l_uint32 *pval)
pixGetPixel()
PIX * pixCreateRGBImage(PIX *pixr, PIX *pixg, PIX *pixb)
pixCreateRGBImage()
l_ok pixZero(PIX *pix, l_int32 *pempty)
pixZero()
l_ok pixCountPixels(PIX *pixs, l_int32 *pcount, l_int32 *tab8)
pixCountPixels()
l_int32 * makePixelSumTab8(void)
makePixelSumTab8()
void pixaDestroy(PIXA **ppixa)
pixaDestroy()
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
l_ok pixaGetBoxGeometry(PIXA *pixa, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
pixaGetBoxGeometry()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
PIX * pixConvert1To32(PIX *pixd, PIX *pixs, l_uint32 val0, l_uint32 val1)
pixConvert1To32()
PIX * pixConvert1To16(PIX *pixd, PIX *pixs, l_uint16 val0, l_uint16 val1)
pixConvert1To16()
PIX * pixConvert1To8(PIX *pixd, PIX *pixs, l_uint8 val0, l_uint8 val1)
pixConvert1To8()
PIX * pixConvert32To8(PIX *pixs, l_int32 type16, l_int32 type8)
pixConvert32To8()
l_ok pixConnCompIncrInit(PIX *pixs, l_int32 conn, PIX **ppixd, PTAA **pptaa, l_int32 *pncc)
pixConnCompIncrInit()
PIX * pixLocToColorTransform(PIX *pixs)
pixLocToColorTransform()
l_int32 pixConnCompIncrAdd(PIX *pixs, PTAA *ptaa, l_int32 *pncc, l_float32 x, l_float32 y, l_int32 debug)
pixConnCompIncrAdd()
PIX * pixConnCompTransform(PIX *pixs, l_int32 connect, l_int32 depth)
pixConnCompTransform()
l_ok pixGetSortedNeighborValues(PIX *pixs, l_int32 x, l_int32 y, l_int32 conn, l_int32 **pneigh, l_int32 *pnvals)
pixGetSortedNeighborValues()
PIX * pixConnCompAreaTransform(PIX *pixs, l_int32 connect)
pixConnCompAreaTransform()
PTAA * ptaaCreate(l_int32 n)
ptaaCreate()
l_ok ptaaAddPt(PTAA *ptaa, l_int32 ipta, l_float32 x, l_float32 y)
ptaaAddPt()
PTA * ptaaGetPta(PTAA *ptaa, l_int32 index, l_int32 accessflag)
ptaaGetPta()
l_ok ptaaAddPta(PTAA *ptaa, PTA *pta, l_int32 copyflag)
ptaaAddPta()
l_int32 ptaaGetCount(PTAA *ptaa)
ptaaGetCount()
l_ok ptaAddPt(PTA *pta, l_float32 x, l_float32 y)
ptaAddPt()
l_ok ptaGetPt(PTA *pta, l_int32 index, l_float32 *px, l_float32 *py)
ptaGetPt()
l_int32 ptaGetCount(PTA *pta)
ptaGetCount()
PTA * ptaCreate(l_int32 n)
ptaCreate()
void ptaDestroy(PTA **ppta)
ptaDestroy()
PTA * ptaGetNeighborPixLocs(PIX *pixs, l_int32 x, l_int32 y, l_int32 conn)
ptaGetNeighborPixLocs()
PTAA * ptaaIndexLabeledPixels(PIX *pixs, l_int32 *pncc)
ptaaIndexLabeledPixels()
l_ok ptaJoin(PTA *ptad, PTA *ptas, l_int32 istart, l_int32 iend)
ptaJoin()
l_ok pixRasterop(PIX *pixd, l_int32 dx, l_int32 dy, l_int32 dw, l_int32 dh, l_int32 op, PIX *pixs, l_int32 sx, l_int32 sy)
pixRasterop()
void lept_stderr(const char *fmt,...)
lept_stderr()