92 #include <config_auto.h> 95 #include "allheaders.h" 113 l_int32 wpl, l_int32 xstart,
114 l_int32 ystart, l_int32 *px, l_int32 *py);
118 l_int32
y, l_int32
dy, l_int32 ymax,
119 l_int32 *pminx, l_int32 *pmaxx,
120 l_int32 *pminy, l_int32 *pmaxy);
122 l_int32
y, l_int32
dy, l_int32 ymax);
124 l_int32 *py, l_int32 *pdy);
127 #ifndef NO_CONSOLE_IO 153 l_int32 connectivity)
156 PROCNAME(
"pixConnComp");
158 if (ppixa) *ppixa = NULL;
159 if (!pixs || pixGetDepth(pixs) != 1)
160 return (
BOXA *)ERROR_PTR(
"pixs undefined or not 1 bpp", procName, NULL);
161 if (connectivity != 4 && connectivity != 8)
162 return (
BOXA *)ERROR_PTR(
"connectivity not 4 or 8", procName, NULL);
197 l_int32 connectivity)
200 l_int32 x,
y, xstart, ystart;
201 PIX *pix1, *pix2, *pix3, *pix4;
207 PROCNAME(
"pixConnCompPixa");
210 return (
BOXA *)ERROR_PTR(
"&pixa not defined", procName, NULL);
212 if (!pixs || pixGetDepth(pixs) != 1)
213 return (
BOXA *)ERROR_PTR(
"pixs undefined or not 1 bpp", procName, NULL);
214 if (connectivity != 4 && connectivity != 8)
215 return (
BOXA *)ERROR_PTR(
"connectivity not 4 or 8", procName, NULL);
217 pix1 = pix2 = pix3 = pix4 = NULL;
229 if (!pix1 || !pix2) {
230 L_ERROR(
"pix1 or pix2 not made\n", procName);
235 h = pixGetHeight(pixs);
237 L_ERROR(
"stack not made\n", procName);
251 if ((box =
pixSeedfillBB(pix1, stack, x,
y, connectivity)) == NULL) {
254 L_ERROR(
"box not made\n", procName);
274 lept_stderr(
"Number of remaining pixels = %d\n", iszero);
276 pixWriteDebug(
"/tmp/lept/cc/remain.png", pix1, IFF_PNG);
311 l_int32 connectivity)
314 l_int32 x,
y, xstart, ystart;
320 PROCNAME(
"pixConnCompBB");
322 if (!pixs || pixGetDepth(pixs) != 1)
323 return (
BOXA *)ERROR_PTR(
"pixs undefined or not 1 bpp", procName, NULL);
324 if (connectivity != 4 && connectivity != 8)
325 return (
BOXA *)ERROR_PTR(
"connectivity not 4 or 8", procName, NULL);
335 if ((pix1 =
pixCopy(NULL, pixs)) == NULL)
336 return (
BOXA *)ERROR_PTR(
"pix1 not made", procName, NULL);
338 h = pixGetHeight(pixs);
340 L_ERROR(
"stack not made\n", procName);
353 if ((box =
pixSeedfillBB(pix1, stack, x,
y, connectivity)) == NULL) {
354 L_ERROR(
"box not made\n", procName);
366 lept_stderr(
"Number of remaining pixels = %d\n", iszero);
368 pixWriteDebug(
"/tmp/lept/cc/remain.png", pix1, IFF_PNG);
395 l_int32 connectivity,
399 l_int32 x,
y, xstart, ystart;
403 PROCNAME(
"pixCountConnComp");
406 return ERROR_INT(
"&count not defined", procName, 1);
408 if (!pixs || pixGetDepth(pixs) != 1)
409 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
410 if (connectivity != 4 && connectivity != 8)
411 return ERROR_INT(
"connectivity not 4 or 8", procName, 1);
419 if ((pix1 =
pixCopy(NULL, pixs)) == NULL)
420 return ERROR_INT(
"pix1 not made", procName, 1);
421 h = pixGetHeight(pixs);
424 return ERROR_INT(
"stack not made\n", procName, 1);
463 l_int32 w, h, d, wpl;
466 PROCNAME(
"nextOnPixelInRaster");
469 return ERROR_INT(
"pixs not defined", procName, 0);
472 return ERROR_INT(
"pixs not 1 bpp", procName, 0);
474 wpl = pixGetWpl(pixs);
500 l_int32 i, x,
y, xend, startword;
501 l_uint32 *line, *pword;
504 line = data + ystart * wpl;
505 pword = line + (xstart / 32);
507 xend = xstart - (xstart % 32) + 31;
508 for (x = xstart; x <= xend && x < w; x++) {
518 startword = (xstart / 32) + 1;
520 for (pword = line + startword; x < w; pword++, x += 32) {
522 for (i = 0; i < 32 && x < w; i++, x++) {
533 for (
y = ystart + 1;
y < h;
y++) {
534 line = data +
y * wpl;
535 for (pword = line, x = 0; x < w; pword++, x += 32) {
537 for (i = 0; i < 32 && x < w; i++, x++) {
572 l_int32 connectivity)
576 PROCNAME(
"pixSeedfillBB");
578 if (!pixs || pixGetDepth(pixs) != 1)
579 return (
BOX *)ERROR_PTR(
"pixs undefined or not 1 bpp", procName, NULL);
581 return (
BOX *)ERROR_PTR(
"stack not defined", procName, NULL);
582 if (connectivity != 4 && connectivity != 8)
583 return (
BOX *)ERROR_PTR(
"connectivity not 4 or 8", procName, NULL);
585 if (connectivity == 4) {
587 return (
BOX *)ERROR_PTR(
"box not made", procName, NULL);
588 }
else if (connectivity == 8) {
590 return (
BOX *)ERROR_PTR(
"box not made", procName, NULL);
592 return (
BOX *)ERROR_PTR(
"connectivity not 4 or 8", procName, NULL);
636 l_int32 w, h, xstart, wpl, x1, x2,
dy;
638 l_int32 minx, maxx, miny, maxy;
639 l_uint32 *data, *line;
642 PROCNAME(
"pixSeedfill4BB");
644 if (!pixs || pixGetDepth(pixs) != 1)
645 return (
BOX *)ERROR_PTR(
"pixs undefined or not 1 bpp", procName, NULL);
647 return (
BOX *)ERROR_PTR(
"stack not defined", procName, NULL);
655 wpl = pixGetWpl(pixs);
656 line = data +
y * wpl;
659 if (x < 0 || x > xmax || y < 0 || y > ymax || (
GET_DATA_BIT(line, x) == 0))
665 minx = miny = 100000;
667 pushFillsegBB(stack, x, x,
y, 1, ymax, &minx, &maxx, &miny, &maxy);
668 pushFillsegBB(stack, x, x,
y + 1, -1, ymax, &minx, &maxx, &miny, &maxy);
675 line = data +
y * wpl;
688 for (x = x1; x >= 0 && (
GET_DATA_BIT(line, x) == 1); x--)
695 ymax, &minx, &maxx, &miny, &maxy);
702 ymax, &minx, &maxx, &miny, &maxy);
705 ymax, &minx, &maxx, &miny, &maxy);
706 skip:
for (x++; x <= x2 &&
711 }
while (x <= x2 && x <= xmax);
714 if ((box =
boxCreate(minx, miny, maxx - minx + 1, maxy - miny + 1))
716 return (
BOX *)ERROR_PTR(
"box not made", procName, NULL);
751 l_int32 w, h, xstart, wpl, x1, x2,
dy;
753 l_int32 minx, maxx, miny, maxy;
754 l_uint32 *data, *line;
757 PROCNAME(
"pixSeedfill8BB");
759 if (!pixs || pixGetDepth(pixs) != 1)
760 return (
BOX *)ERROR_PTR(
"pixs undefined or not 1 bpp", procName, NULL);
762 return (
BOX *)ERROR_PTR(
"stack not defined", procName, NULL);
770 wpl = pixGetWpl(pixs);
771 line = data +
y * wpl;
774 if (x < 0 || x > xmax || y < 0 || y > ymax || (
GET_DATA_BIT(line, x) == 0))
780 minx = miny = 100000;
782 pushFillsegBB(stack, x, x,
y, 1, ymax, &minx, &maxx, &miny, &maxy);
783 pushFillsegBB(stack, x, x,
y + 1, -1, ymax, &minx, &maxx, &miny, &maxy);
790 line = data +
y * wpl;
803 for (x = x1 - 1; x >= 0 && (
GET_DATA_BIT(line, x) == 1); x--)
810 ymax, &minx, &maxx, &miny, &maxy);
817 ymax, &minx, &maxx, &miny, &maxy);
820 ymax, &minx, &maxx, &miny, &maxy);
821 skip:
for (x++; x <= x2 + 1 &&
826 }
while (x <= x2 + 1 && x <= xmax);
829 if ((box =
boxCreate(minx, miny, maxx - minx + 1, maxy - miny + 1))
831 return (
BOX *)ERROR_PTR(
"box not made", procName, NULL);
856 l_int32 connectivity)
860 PROCNAME(
"pixSeedfill");
862 if (!pixs || pixGetDepth(pixs) != 1)
863 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
865 return ERROR_INT(
"stack not defined", procName, 1);
866 if (connectivity != 4 && connectivity != 8)
867 return ERROR_INT(
"connectivity not 4 or 8", procName, 1);
869 if (connectivity == 4)
901 l_int32 w, h, xstart, wpl, x1, x2,
dy;
903 l_uint32 *data, *line;
905 PROCNAME(
"pixSeedfill4");
907 if (!pixs || pixGetDepth(pixs) != 1)
908 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
910 return ERROR_INT(
"stack not defined", procName, 1);
918 wpl = pixGetWpl(pixs);
919 line = data +
y * wpl;
922 if (x < 0 || x > xmax || y < 0 || y > ymax || (
GET_DATA_BIT(line, x) == 0))
932 line = data +
y * wpl;
945 for (x = x1; x >= 0 && (
GET_DATA_BIT(line, x) == 1); x--)
960 skip:
for (x++; x <= x2 &&
965 }
while (x <= x2 && x <= xmax);
995 l_int32 w, h, xstart, wpl, x1, x2,
dy;
997 l_uint32 *data, *line;
999 PROCNAME(
"pixSeedfill8");
1001 if (!pixs || pixGetDepth(pixs) != 1)
1002 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
1004 return ERROR_INT(
"stack not defined", procName, 1);
1012 wpl = pixGetWpl(pixs);
1013 line = data +
y * wpl;
1016 if (x < 0 || x > xmax || y < 0 || y > ymax || (
GET_DATA_BIT(line, x) == 0))
1026 line = data +
y * wpl;
1039 for (x = x1 - 1; x >= 0 && (
GET_DATA_BIT(line, x) == 1); x--)
1054 skip:
for (x++; x <= x2 + 1 &&
1059 }
while (x <= x2 + 1 && x <= xmax);
1107 PROCNAME(
"pushFillsegBB");
1110 L_ERROR(
"stack not defined\n", procName);
1114 *pminx = L_MIN(*pminx,
xleft);
1115 *pmaxx = L_MAX(*pmaxx,
xright);
1116 *pminy = L_MIN(*pminy,
y);
1117 *pmaxy = L_MAX(*pmaxy,
y);
1119 if (
y +
dy >= 0 &&
y +
dy <= ymax) {
1120 if ((auxstack = stack->
auxstack) == NULL) {
1121 L_ERROR(
"auxstack not defined\n", procName);
1168 PROCNAME(
"pushFillseg");
1171 L_ERROR(
"stack not defined\n", procName);
1175 if (
y +
dy >= 0 &&
y +
dy <= ymax) {
1176 if ((auxstack = stack->
auxstack) == NULL) {
1177 L_ERROR(
"auxstack not defined\n", procName);
1222 PROCNAME(
"popFillseg");
1225 L_ERROR(
"stack not defined\n", procName);
1228 if ((auxstack = stack->
auxstack) == NULL) {
1229 L_ERROR(
"auxstack not defined\n", procName);
1236 *pxleft = fseg->
xleft;
1238 *py = fseg->
y + fseg->
dy;
BOX * pixSeedfill4BB(PIX *pixs, L_STACK *stack, l_int32 x, l_int32 y)
pixSeedfill4BB()
l_ok pixSeedfill4(PIX *pixs, L_STACK *stack, l_int32 x, l_int32 y)
pixSeedfill4()
l_int32 lept_mkdir(const char *subdir)
lept_mkdir()
The struct FillSeg is used by the Heckbert seedfill algorithm to hold information about image segment...
BOX * pixSeedfillBB(PIX *pixs, L_STACK *stack, l_int32 x, l_int32 y, l_int32 connectivity)
pixSeedfillBB()
void lstackDestroy(L_STACK **plstack, l_int32 freeflag)
lstackDestroy()
l_int32 nextOnPixelInRaster(PIX *pixs, l_int32 xstart, l_int32 ystart, l_int32 *px, l_int32 *py)
nextOnPixelInRaster()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
BOX * pixSeedfill8BB(PIX *pixs, L_STACK *stack, l_int32 x, l_int32 y)
pixSeedfill8BB()
l_int32 lstackGetCount(L_STACK *lstack)
lstackGetCount()
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()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
void lept_stderr(const char *fmt,...)
lept_stderr()
static void pushFillsegBB(L_STACK *stack, l_int32 xleft, l_int32 xright, l_int32 y, l_int32 dy, l_int32 ymax, l_int32 *pminx, l_int32 *pmaxx, l_int32 *pminy, l_int32 *pmaxy)
pushFillsegBB()
BOXA * boxaCopy(BOXA *boxa, l_int32 copyflag)
boxaCopy()
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
static l_int32 nextOnPixelInRasterLow(l_uint32 *data, l_int32 w, l_int32 h, l_int32 wpl, l_int32 xstart, l_int32 ystart, l_int32 *px, l_int32 *py)
nextOnPixelInRasterLow()
#define GET_DATA_BIT(pdata, n)
PIX * pixClipRectangle(PIX *pixs, BOX *box, BOX **pboxc)
pixClipRectangle()
l_ok pixSeedfill(PIX *pixs, L_STACK *stack, l_int32 x, l_int32 y, l_int32 connectivity)
pixSeedfill()
l_ok lstackAdd(L_STACK *lstack, void *item)
lstackAdd()
#define CLEAR_DATA_BIT(pdata, n)
BOXA * pixConnComp(PIX *pixs, PIXA **ppixa, l_int32 connectivity)
pixConnComp()
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
PIX * pixXor(PIX *pixd, PIX *pixs1, PIX *pixs2)
pixXor()
void * lstackRemove(L_STACK *lstack)
lstackRemove()
BOXA * pixConnCompBB(PIX *pixs, l_int32 connectivity)
pixConnCompBB()
l_ok pixCountPixels(PIX *pixs, l_int32 *pcount, l_int32 *tab8)
pixCountPixels()
l_ok boxaAddBox(BOXA *boxa, BOX *box, l_int32 copyflag)
boxaAddBox()
L_STACK * lstackCreate(l_int32 n)
lstackCreate()
l_ok pixSetPadBits(PIX *pix, l_int32 val)
pixSetPadBits()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
BOXA * pixConnCompPixa(PIX *pixs, PIXA **ppixa, l_int32 connectivity)
pixConnCompPixa()
static void pushFillseg(L_STACK *stack, l_int32 xleft, l_int32 xright, l_int32 y, l_int32 dy, l_int32 ymax)
pushFillseg()
struct L_Stack * auxstack
static void popFillseg(L_STACK *stack, l_int32 *pxleft, l_int32 *pxright, l_int32 *py, l_int32 *pdy)
popFillseg()
l_ok pixZero(PIX *pix, l_int32 *pempty)
pixZero()
BOXA * boxaCreate(l_int32 n)
boxaCreate()
l_ok pixSeedfill8(PIX *pixs, L_STACK *stack, l_int32 x, l_int32 y)
pixSeedfill8()
void pixaDestroy(PIXA **ppixa)
pixaDestroy()
BOX * boxCreate(l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxCreate()
l_ok pixCountConnComp(PIX *pixs, l_int32 connectivity, l_int32 *pcount)
pixCountConnComp()