92 #include <config_auto.h>
95 #include "allheaders.h"
114 l_int32 wpl, l_int32 xstart,
115 l_int32 ystart, l_int32 *px, l_int32 *py);
119 l_int32
y, l_int32
dy, l_int32 ymax,
120 l_int32 *pminx, l_int32 *pmaxx,
121 l_int32 *pminy, l_int32 *pmaxy);
123 l_int32
y, l_int32
dy, l_int32 ymax);
125 l_int32 *py, l_int32 *pdy);
128 #ifndef NO_CONSOLE_IO
154 l_int32 connectivity)
157 if (ppixa) *ppixa = NULL;
158 if (!pixs || pixGetDepth(pixs) != 1)
159 return (
BOXA *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
160 if (connectivity != 4 && connectivity != 8)
161 return (
BOXA *)ERROR_PTR(
"connectivity not 4 or 8", __func__, NULL);
196 l_int32 connectivity)
199 l_int32 x,
y, xstart, ystart;
200 PIX *pix1, *pix2, *pix3, *pix4;
207 return (
BOXA *)ERROR_PTR(
"&pixa not defined", __func__, NULL);
209 if (!pixs || pixGetDepth(pixs) != 1)
210 return (
BOXA *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
211 if (connectivity != 4 && connectivity != 8)
212 return (
BOXA *)ERROR_PTR(
"connectivity not 4 or 8", __func__, NULL);
214 pix1 = pix2 = pix3 = pix4 = NULL;
226 if (!pix1 || !pix2) {
227 L_ERROR(
"pix1 or pix2 not made\n", __func__);
232 h = pixGetHeight(pixs);
234 L_ERROR(
"stack not made\n", __func__);
248 if ((box =
pixSeedfillBB(pix1, stack, x,
y, connectivity)) == NULL) {
251 L_ERROR(
"box not made\n", __func__);
271 lept_stderr(
"Number of remaining pixels = %d\n", iszero);
273 pixWriteDebug(
"/tmp/lept/cc/remain.png", pix1, IFF_PNG);
308 l_int32 connectivity)
311 l_int32 x,
y, xstart, ystart;
317 if (!pixs || pixGetDepth(pixs) != 1)
318 return (
BOXA *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
319 if (connectivity != 4 && connectivity != 8)
320 return (
BOXA *)ERROR_PTR(
"connectivity not 4 or 8", __func__, NULL);
330 if ((pix1 =
pixCopy(NULL, pixs)) == NULL)
331 return (
BOXA *)ERROR_PTR(
"pix1 not made", __func__, NULL);
333 h = pixGetHeight(pixs);
335 L_ERROR(
"stack not made\n", __func__);
348 if ((box =
pixSeedfillBB(pix1, stack, x,
y, connectivity)) == NULL) {
349 L_ERROR(
"box not made\n", __func__);
361 lept_stderr(
"Number of remaining pixels = %d\n", iszero);
363 pixWriteDebug(
"/tmp/lept/cc/remain.png", pix1, IFF_PNG);
390 l_int32 connectivity,
394 l_int32 x,
y, xstart, ystart;
399 return ERROR_INT(
"&count not defined", __func__, 1);
401 if (!pixs || pixGetDepth(pixs) != 1)
402 return ERROR_INT(
"pixs not defined or not 1 bpp", __func__, 1);
403 if (connectivity != 4 && connectivity != 8)
404 return ERROR_INT(
"connectivity not 4 or 8", __func__, 1);
412 if ((pix1 =
pixCopy(NULL, pixs)) == NULL)
413 return ERROR_INT(
"pix1 not made", __func__, 1);
414 h = pixGetHeight(pixs);
417 return ERROR_INT(
"stack not made\n", __func__, 1);
456 l_int32 w, h, d, wpl;
460 return ERROR_INT(
"pixs not defined", __func__, 0);
463 return ERROR_INT(
"pixs not 1 bpp", __func__, 0);
465 wpl = pixGetWpl(pixs);
491 l_int32 i, x,
y, xend, startword;
492 l_uint32 *line, *pword;
495 line = data + ystart * wpl;
496 pword = line + (xstart / 32);
498 xend = xstart - (xstart % 32) + 31;
499 for (x = xstart; x <= xend && x < w; x++) {
509 startword = (xstart / 32) + 1;
511 for (pword = line + startword; x < w; pword++, x += 32) {
513 for (i = 0; i < 32 && x < w; i++, x++) {
524 for (
y = ystart + 1;
y < h;
y++) {
525 line = data +
y * wpl;
526 for (pword = line, x = 0; x < w; pword++, x += 32) {
528 for (i = 0; i < 32 && x < w; i++, x++) {
563 l_int32 connectivity)
567 if (!pixs || pixGetDepth(pixs) != 1)
568 return (
BOX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
570 return (
BOX *)ERROR_PTR(
"stack not defined", __func__, NULL);
571 if (connectivity != 4 && connectivity != 8)
572 return (
BOX *)ERROR_PTR(
"connectivity not 4 or 8", __func__, NULL);
574 if (connectivity == 4) {
576 return (
BOX *)ERROR_PTR(
"box not made", __func__, NULL);
577 }
else if (connectivity == 8) {
579 return (
BOX *)ERROR_PTR(
"box not made", __func__, NULL);
581 return (
BOX *)ERROR_PTR(
"connectivity not 4 or 8", __func__, NULL);
625 l_int32 w, h, xstart, wpl, x1, x2,
dy;
627 l_int32 minx, maxx, miny, maxy;
628 l_uint32 *data, *line;
631 if (!pixs || pixGetDepth(pixs) != 1)
632 return (
BOX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
634 return (
BOX *)ERROR_PTR(
"stack not defined", __func__, NULL);
642 wpl = pixGetWpl(pixs);
643 line = data +
y * wpl;
646 if (x < 0 || x > xmax || y < 0 || y > ymax || (
GET_DATA_BIT(line, x) == 0))
652 minx = miny = 100000;
654 pushFillsegBB(stack, x, x,
y, 1, ymax, &minx, &maxx, &miny, &maxy);
655 pushFillsegBB(stack, x, x,
y + 1, -1, ymax, &minx, &maxx, &miny, &maxy);
662 line = data +
y * wpl;
675 for (x = x1; x >= 0 && (
GET_DATA_BIT(line, x) == 1); x--)
682 ymax, &minx, &maxx, &miny, &maxy);
689 ymax, &minx, &maxx, &miny, &maxy);
692 ymax, &minx, &maxx, &miny, &maxy);
693 skip:
for (x++; x <= x2 &&
698 }
while (x <= x2 && x <= xmax);
701 if ((box =
boxCreate(minx, miny, maxx - minx + 1, maxy - miny + 1))
703 return (
BOX *)ERROR_PTR(
"box not made", __func__, NULL);
738 l_int32 w, h, xstart, wpl, x1, x2,
dy;
740 l_int32 minx, maxx, miny, maxy;
741 l_uint32 *data, *line;
744 if (!pixs || pixGetDepth(pixs) != 1)
745 return (
BOX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
747 return (
BOX *)ERROR_PTR(
"stack not defined", __func__, NULL);
755 wpl = pixGetWpl(pixs);
756 line = data +
y * wpl;
759 if (x < 0 || x > xmax || y < 0 || y > ymax || (
GET_DATA_BIT(line, x) == 0))
765 minx = miny = 100000;
767 pushFillsegBB(stack, x, x,
y, 1, ymax, &minx, &maxx, &miny, &maxy);
768 pushFillsegBB(stack, x, x,
y + 1, -1, ymax, &minx, &maxx, &miny, &maxy);
775 line = data +
y * wpl;
788 for (x = x1 - 1; x >= 0 && (
GET_DATA_BIT(line, x) == 1); x--)
795 ymax, &minx, &maxx, &miny, &maxy);
802 ymax, &minx, &maxx, &miny, &maxy);
805 ymax, &minx, &maxx, &miny, &maxy);
806 skip:
for (x++; x <= x2 + 1 &&
811 }
while (x <= x2 + 1 && x <= xmax);
814 if ((box =
boxCreate(minx, miny, maxx - minx + 1, maxy - miny + 1))
816 return (
BOX *)ERROR_PTR(
"box not made", __func__, NULL);
841 l_int32 connectivity)
845 if (!pixs || pixGetDepth(pixs) != 1)
846 return ERROR_INT(
"pixs not defined or not 1 bpp", __func__, 1);
848 return ERROR_INT(
"stack not defined", __func__, 1);
849 if (connectivity != 4 && connectivity != 8)
850 return ERROR_INT(
"connectivity not 4 or 8", __func__, 1);
852 if (connectivity == 4)
884 l_int32 w, h, xstart, wpl, x1, x2,
dy;
886 l_uint32 *data, *line;
888 if (!pixs || pixGetDepth(pixs) != 1)
889 return ERROR_INT(
"pixs not defined or not 1 bpp", __func__, 1);
891 return ERROR_INT(
"stack not defined", __func__, 1);
899 wpl = pixGetWpl(pixs);
900 line = data +
y * wpl;
903 if (x < 0 || x > xmax || y < 0 || y > ymax || (
GET_DATA_BIT(line, x) == 0))
913 line = data +
y * wpl;
926 for (x = x1; x >= 0 && (
GET_DATA_BIT(line, x) == 1); x--)
941 skip:
for (x++; x <= x2 &&
946 }
while (x <= x2 && x <= xmax);
976 l_int32 w, h, xstart, wpl, x1, x2,
dy;
978 l_uint32 *data, *line;
980 if (!pixs || pixGetDepth(pixs) != 1)
981 return ERROR_INT(
"pixs not defined or not 1 bpp", __func__, 1);
983 return ERROR_INT(
"stack not defined", __func__, 1);
991 wpl = pixGetWpl(pixs);
992 line = data +
y * wpl;
995 if (x < 0 || x > xmax || y < 0 || y > ymax || (
GET_DATA_BIT(line, x) == 0))
1005 line = data +
y * wpl;
1018 for (x = x1 - 1; x >= 0 && (
GET_DATA_BIT(line, x) == 1); x--)
1033 skip:
for (x++; x <= x2 + 1 &&
1038 }
while (x <= x2 + 1 && x <= xmax);
1087 L_ERROR(
"stack not defined\n", __func__);
1091 *pminx = L_MIN(*pminx,
xleft);
1092 *pmaxx = L_MAX(*pmaxx,
xright);
1093 *pminy = L_MIN(*pminy,
y);
1094 *pmaxy = L_MAX(*pmaxy,
y);
1096 if (
y +
dy >= 0 &&
y +
dy <= ymax) {
1097 if ((auxstack = stack->
auxstack) == NULL) {
1098 L_ERROR(
"auxstack not defined\n", __func__);
1146 L_ERROR(
"stack not defined\n", __func__);
1150 if (
y +
dy >= 0 &&
y +
dy <= ymax) {
1151 if ((auxstack = stack->
auxstack) == NULL) {
1152 L_ERROR(
"auxstack not defined\n", __func__);
1198 L_ERROR(
"stack not defined\n", __func__);
1201 if ((auxstack = stack->
auxstack) == NULL) {
1202 L_ERROR(
"auxstack not defined\n", __func__);
1209 *pxleft = fseg->
xleft;
1211 *py = fseg->
y + fseg->
dy;
#define CLEAR_DATA_BIT(pdata, n)
#define GET_DATA_BIT(pdata, n)
BOXA * boxaCopy(BOXA *boxa, l_int32 copyflag)
boxaCopy()
l_ok boxaAddBox(BOXA *boxa, BOX *box, l_int32 copyflag)
boxaAddBox()
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
BOX * boxCreate(l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxCreate()
BOXA * boxaCreate(l_int32 n)
boxaCreate()
BOXA * pixConnCompBB(PIX *pixs, l_int32 connectivity)
pixConnCompBB()
l_ok pixSeedfill4(PIX *pixs, L_STACK *stack, l_int32 x, l_int32 y)
pixSeedfill4()
BOX * pixSeedfill4BB(PIX *pixs, L_STACK *stack, l_int32 x, l_int32 y)
pixSeedfill4BB()
BOXA * pixConnComp(PIX *pixs, PIXA **ppixa, l_int32 connectivity)
pixConnComp()
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()
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()
static void pushFillseg(L_STACK *stack, l_int32 xleft, l_int32 xright, l_int32 y, l_int32 dy, l_int32 ymax)
pushFillseg()
BOX * pixSeedfill8BB(PIX *pixs, L_STACK *stack, l_int32 x, l_int32 y)
pixSeedfill8BB()
l_int32 nextOnPixelInRaster(PIX *pixs, l_int32 xstart, l_int32 ystart, l_int32 *px, l_int32 *py)
nextOnPixelInRaster()
l_ok pixCountConnComp(PIX *pixs, l_int32 connectivity, l_int32 *pcount)
pixCountConnComp()
BOXA * pixConnCompPixa(PIX *pixs, PIXA **ppixa, l_int32 connectivity)
pixConnCompPixa()
static void popFillseg(L_STACK *stack, l_int32 *pxleft, l_int32 *pxright, l_int32 *py, l_int32 *pdy)
popFillseg()
l_ok pixSeedfill(PIX *pixs, L_STACK *stack, l_int32 x, l_int32 y, l_int32 connectivity)
pixSeedfill()
l_ok pixSeedfill8(PIX *pixs, L_STACK *stack, l_int32 x, l_int32 y)
pixSeedfill8()
BOX * pixSeedfillBB(PIX *pixs, L_STACK *stack, l_int32 x, l_int32 y, l_int32 connectivity)
pixSeedfillBB()
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 * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
l_ok pixSetPadBits(PIX *pix, l_int32 val)
pixSetPadBits()
l_ok pixZero(PIX *pix, l_int32 *pempty)
pixZero()
l_ok pixCountPixels(PIX *pixs, l_int32 *pcount, l_int32 *tab8)
pixCountPixels()
PIX * pixXor(PIX *pixd, PIX *pixs1, PIX *pixs2)
pixXor()
PIX * pixClipRectangle(PIX *pixs, BOX *box, BOX **pboxc)
pixClipRectangle()
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
void pixaDestroy(PIXA **ppixa)
pixaDestroy()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
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()
l_int32 lstackGetCount(L_STACK *lstack)
lstackGetCount()
void lstackDestroy(L_STACK **plstack, l_int32 freeflag)
lstackDestroy()
l_ok lstackAdd(L_STACK *lstack, void *item)
lstackAdd()
void * lstackRemove(L_STACK *lstack)
lstackRemove()
L_STACK * lstackCreate(l_int32 n)
lstackCreate()
The struct FillSeg is used by the Heckbert seedfill algorithm to hold information about image segment...
struct L_Stack * auxstack
void lept_stderr(const char *fmt,...)
lept_stderr()
l_int32 lept_mkdir(const char *subdir)
lept_mkdir()