60 #include <config_auto.h>
65 #include "allheaders.h"
108 PIX *pixh, *pixv, *pixt, *pixg1, *pixg2, *pixg3, *pixg4;
110 PROCNAME(
"pixStrokeWidthTransform");
112 if (!pixs || pixGetDepth(pixs) != 1)
113 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", procName, NULL);
114 if (depth != 8 && depth != 16)
115 return (
PIX *)ERROR_PTR(
"depth must be 8 or 16 bpp", procName, NULL);
116 if (nangles != 2 && nangles != 4 && nangles != 6 && nangles != 8)
117 return (
PIX *)ERROR_PTR(
"nangles not in {2,4,6,8}", procName, NULL);
128 pixg1 =
pixMinOrMax(NULL, pixh, pixv, L_CHOOSE_MIN);
132 pixg2 = pixg3 = pixg4 = NULL;
134 if (nangles == 4 || nangles == 8) {
156 angle = 3.0 * pi / 8.0;
203 l_int32 w, h, diag, xoff, yoff;
204 PIX *pixb, *pixr, *pixh, *pixv, *pixg1, *pixg2, *pixd;
207 PROCNAME(
"pixFindMinRunsOrthogonal");
209 if (!pixs || pixGetDepth(pixs) != 1)
210 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", procName, NULL);
215 diag = (l_int32)(sqrt((l_float64)(w * w + h * h)) + 2.5);
216 xoff = (diag - w) / 2;
217 yoff = (diag - h) / 2;
226 pixg1 =
pixMinOrMax(NULL, pixh, pixv, L_CHOOSE_MIN);
270 l_int32 i, j, w, h, wpld, bufsize, maxsize, n;
271 l_int32 *start, *end, *buffer;
272 l_uint32 *datad, *lined;
275 PROCNAME(
"pixRunlengthTransform");
278 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
279 if (pixGetDepth(pixs) != 1)
280 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", procName, NULL);
281 if (depth != 8 && depth != 16)
282 return (
PIX *)ERROR_PTR(
"depth must be 8 or 16 bpp", procName, NULL);
290 return (
PIX *)ERROR_PTR(
"invalid direction", procName, NULL);
291 bufsize = L_MAX(w, h);
292 if (bufsize > 1000000) {
293 L_ERROR(
"largest image dimension = %d; too big\n", procName, bufsize);
297 if ((pixd =
pixCreate(w, h, depth)) == NULL)
298 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
300 wpld = pixGetWpl(pixd);
302 start = (l_int32 *)LEPT_CALLOC(maxsize,
sizeof(l_int32));
303 end = (l_int32 *)LEPT_CALLOC(maxsize,
sizeof(l_int32));
304 buffer = (l_int32 *)LEPT_CALLOC(bufsize,
sizeof(l_int32));
313 for (i = 0; i < h; i++) {
316 lined = datad + i * wpld;
318 for (j = 0; j < w; j++)
321 for (j = 0; j < w; j++)
326 for (j = 0; j < w; j++) {
330 for (i = 0; i < h; i++) {
331 lined = datad + i * wpld;
335 for (i = 0; i < h; i++) {
336 lined = datad + i * wpld;
382 l_int32 index, w, h, d, j, wpl, val;
385 PROCNAME(
"pixFindHorizontalRuns");
388 return ERROR_INT(
"&n not defined", procName, 1);
391 return ERROR_INT(
"pix not defined", procName, 1);
394 return ERROR_INT(
"pix not 1 bpp", procName, 1);
396 return ERROR_INT(
"y not in [0 ... h - 1]", procName, 1);
398 return ERROR_INT(
"xstart not defined", procName, 1);
400 return ERROR_INT(
"xend not defined", procName, 1);
402 wpl = pixGetWpl(pix);
407 for (j = 0; j < w; j++) {
416 xend[index++] = j - 1;
424 xend[index++] = w - 1;
459 l_int32 index, w, h, d, i, wpl, val;
460 l_uint32 *data, *line;
462 PROCNAME(
"pixFindVerticalRuns");
465 return ERROR_INT(
"&n not defined", procName, 1);
468 return ERROR_INT(
"pix not defined", procName, 1);
471 return ERROR_INT(
"pix not 1 bpp", procName, 1);
473 return ERROR_INT(
"x not in [0 ... w - 1]", procName, 1);
475 return ERROR_INT(
"ystart not defined", procName, 1);
477 return ERROR_INT(
"yend not defined", procName, 1);
479 wpl = pixGetWpl(pix);
484 for (i = 0; i < h; i++) {
485 line = data + i * wpl;
494 yend[index++] = i - 1;
502 yend[index++] = h - 1;
532 l_int32 w, h, i, start, size;
535 PROCNAME(
"pixFindMaxRuns");
537 if (pnastart) *pnastart = NULL;
539 return (
NUMA *)ERROR_PTR(
"direction invalid", procName, NULL);
540 if (!pix || pixGetDepth(pix) != 1)
541 return (
NUMA *)ERROR_PTR(
"pix undefined or not 1 bpp", procName, NULL);
547 for (i = 0; i < h; i++) {
553 for (i = 0; i < w; i++) {
587 l_int32 w, h, j, wpl, val, maxstart, maxsize, length, start;
590 PROCNAME(
"pixFindMaxHorizontalRunOnLine");
592 if (pxstart) *pxstart = 0;
594 return ERROR_INT(
"&size not defined", procName, 1);
596 if (!pix || pixGetDepth(pix) != 1)
597 return ERROR_INT(
"pix not defined or not 1 bpp", procName, 1);
600 return ERROR_INT(
"y not in [0 ... h - 1]", procName, 1);
602 wpl = pixGetWpl(pix);
608 for (j = 0; j < w; j++) {
617 if (length > maxsize) {
627 if (length > maxsize) {
632 if (pxstart) *pxstart = maxstart;
661 l_int32 w, h, i, wpl, val, maxstart, maxsize, length, start;
662 l_uint32 *data, *line;
664 PROCNAME(
"pixFindMaxVerticalRunOnLine");
666 if (pystart) *pystart = 0;
668 return ERROR_INT(
"&size not defined", procName, 1);
670 if (!pix || pixGetDepth(pix) != 1)
671 return ERROR_INT(
"pix not defined or not 1 bpp", procName, 1);
674 return ERROR_INT(
"x not in [0 ... w - 1]", procName, 1);
676 wpl = pixGetWpl(pix);
682 for (i = 0; i < h; i++) {
683 line = data + i * wpl;
692 if (length > maxsize) {
702 if (length > maxsize) {
707 if (pystart) *pystart = maxstart;
743 l_int32 i, j, first, last, diff, max;
745 PROCNAME(
"runlengthMembershipOnLine");
748 return ERROR_INT(
"buffer not defined", procName, 1);
750 return ERROR_INT(
"start not defined", procName, 1);
752 return ERROR_INT(
"end not defined", procName, 1);
759 memset(buffer, 0, 4 * size);
760 for (i = 0; i < n; i++) {
763 diff = last - first + 1;
764 diff = L_MIN(diff, max);
765 for (j = first; j <= last; j++)
798 tab = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
799 for (i = 0; i < 256; i++) {
805 for (j = 0; j < 8; j++) {
#define SET_DATA_TWO_BYTES(pdata, n, val)
#define SET_DATA_BYTE(pdata, n, val)
#define GET_DATA_BIT(pdata, n)
void boxDestroy(BOX **pbox)
boxDestroy()
BOX * boxCreate(l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxCreate()
l_ok numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
NUMA * numaCreate(l_int32 n)
numaCreate()
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()
PIX * pixClone(PIX *pixs)
pixClone()
PIX * pixInvert(PIX *pixd, PIX *pixs)
pixInvert()
PIX * pixClipRectangle(PIX *pixs, BOX *box, BOX **pboxc)
pixClipRectangle()
PIX * pixMinOrMax(PIX *pixd, PIX *pixs1, PIX *pixs2, l_int32 type)
pixMinOrMax()
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 * pixRotateShear(PIX *pixs, l_int32 xcen, l_int32 ycen, l_float32 angle, l_int32 incolor)
pixRotateShear()
l_ok runlengthMembershipOnLine(l_int32 *buffer, l_int32 size, l_int32 depth, l_int32 *start, l_int32 *end, l_int32 n)
runlengthMembershipOnLine()
l_ok pixFindHorizontalRuns(PIX *pix, l_int32 y, l_int32 *xstart, l_int32 *xend, l_int32 *pn)
pixFindHorizontalRuns()
l_int32 * makeMSBitLocTab(l_int32 bitval)
makeMSBitLocTab()
PIX * pixStrokeWidthTransform(PIX *pixs, l_int32 color, l_int32 depth, l_int32 nangles)
pixStrokeWidthTransform()
PIX * pixRunlengthTransform(PIX *pixs, l_int32 color, l_int32 direction, l_int32 depth)
pixRunlengthTransform()
l_ok pixFindMaxHorizontalRunOnLine(PIX *pix, l_int32 y, l_int32 *pxstart, l_int32 *psize)
pixFindMaxHorizontalRunOnLine()
NUMA * pixFindMaxRuns(PIX *pix, l_int32 direction, NUMA **pnastart)
pixFindMaxRuns()
l_ok pixFindVerticalRuns(PIX *pix, l_int32 x, l_int32 *ystart, l_int32 *yend, l_int32 *pn)
pixFindVerticalRuns()
l_ok pixFindMaxVerticalRunOnLine(PIX *pix, l_int32 x, l_int32 *pystart, l_int32 *psize)
pixFindMaxVerticalRunOnLine()
static PIX * pixFindMinRunsOrthogonal(PIX *pixs, l_float32 angle, l_int32 depth)
pixFindMinRunsOrthogonal()