60#include <config_auto.h>
65#include "allheaders.h"
108PIX *pixh, *pixv, *pixt, *pixg1, *pixg2, *pixg3, *pixg4;
110 if (!pixs || pixGetDepth(pixs) != 1)
111 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
112 if (depth != 8 && depth != 16)
113 return (
PIX *)ERROR_PTR(
"depth must be 8 or 16 bpp", __func__, NULL);
114 if (nangles != 2 && nangles != 4 && nangles != 6 && nangles != 8)
115 return (
PIX *)ERROR_PTR(
"nangles not in {2,4,6,8}", __func__, NULL);
119 pixt = pixInvert(NULL, pixs);
121 pixt = pixClone(pixs);
126 pixg1 = pixMinOrMax(NULL, pixh, pixv, L_CHOOSE_MIN);
130 pixg2 = pixg3 = pixg4 = NULL;
132 if (nangles == 4 || nangles == 8) {
154 angle = 3.0 * pi / 8.0f;
160 pixMinOrMax(pixg1, pixg1, pixg2, L_CHOOSE_MIN);
162 pixMinOrMax(pixg1, pixg1, pixg3, L_CHOOSE_MIN);
164 pixMinOrMax(pixg1, pixg1, pixg4, L_CHOOSE_MIN);
201l_int32 w, h, diag, xoff, yoff;
202PIX *pixb, *pixr, *pixh, *pixv, *pixg1, *pixg2, *pixd;
205 if (!pixs || pixGetDepth(pixs) != 1)
206 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
210 pixGetDimensions(pixs, &w, &h, NULL);
211 diag = (l_int32)(sqrt((l_float64)(w * w + h * h)) + 2.5);
212 xoff = (diag - w) / 2;
213 yoff = (diag - h) / 2;
214 pixb = pixCreate(diag, diag, 1);
215 pixRasterop(pixb, xoff, yoff, w, h,
PIX_SRC, pixs, 0, 0);
222 pixg1 = pixMinOrMax(NULL, pixh, pixv, L_CHOOSE_MIN);
223 pixg2 = pixRotateShear(pixg1, diag / 2, diag / 2, -angle,
L_BRING_IN_WHITE);
224 box = boxCreate(xoff, yoff, w, h);
225 pixd = pixClipRectangle(pixg2, box, NULL);
266l_int32 i, j, w, h, wpld, bufsize, maxsize, n;
267l_int32 *start, *end, *buffer;
268l_uint32 *datad, *lined;
272 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
273 if (pixGetDepth(pixs) != 1)
274 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
275 if (depth != 8 && depth != 16)
276 return (
PIX *)ERROR_PTR(
"depth must be 8 or 16 bpp", __func__, NULL);
278 pixGetDimensions(pixs, &w, &h, NULL);
284 return (
PIX *)ERROR_PTR(
"invalid direction", __func__, NULL);
285 bufsize = L_MAX(w, h);
286 if (bufsize > 1000000) {
287 L_ERROR(
"largest image dimension = %d; too big\n", __func__, bufsize);
291 if ((pixd = pixCreate(w, h, depth)) == NULL)
292 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
293 datad = pixGetData(pixd);
294 wpld = pixGetWpl(pixd);
296 start = (l_int32 *)LEPT_CALLOC(maxsize,
sizeof(l_int32));
297 end = (l_int32 *)LEPT_CALLOC(maxsize,
sizeof(l_int32));
298 buffer = (l_int32 *)LEPT_CALLOC(bufsize,
sizeof(l_int32));
302 pixt = pixInvert(NULL, pixs);
304 pixt = pixClone(pixs);
307 for (i = 0; i < h; i++) {
310 lined = datad + i * wpld;
312 for (j = 0; j < w; j++)
315 for (j = 0; j < w; j++)
320 for (j = 0; j < w; j++) {
324 for (i = 0; i < h; i++) {
325 lined = datad + i * wpld;
329 for (i = 0; i < h; i++) {
330 lined = datad + i * wpld;
376l_int32 index, w, h, d, j, wpl, val;
380 return ERROR_INT(
"&n not defined", __func__, 1);
383 return ERROR_INT(
"pix not defined", __func__, 1);
384 pixGetDimensions(pix, &w, &h, &d);
386 return ERROR_INT(
"pix not 1 bpp", __func__, 1);
388 return ERROR_INT(
"y not in [0 ... h - 1]", __func__, 1);
390 return ERROR_INT(
"xstart not defined", __func__, 1);
392 return ERROR_INT(
"xend not defined", __func__, 1);
394 wpl = pixGetWpl(pix);
395 line = pixGetData(pix) + y * wpl;
399 for (j = 0; j < w; j++) {
408 xend[index++] = j - 1;
416 xend[index++] = w - 1;
451l_int32 index, w, h, d, i, wpl, val;
452l_uint32 *data, *line;
455 return ERROR_INT(
"&n not defined", __func__, 1);
458 return ERROR_INT(
"pix not defined", __func__, 1);
459 pixGetDimensions(pix, &w, &h, &d);
461 return ERROR_INT(
"pix not 1 bpp", __func__, 1);
463 return ERROR_INT(
"x not in [0 ... w - 1]", __func__, 1);
465 return ERROR_INT(
"ystart not defined", __func__, 1);
467 return ERROR_INT(
"yend not defined", __func__, 1);
469 wpl = pixGetWpl(pix);
470 data = pixGetData(pix);
474 for (i = 0; i < h; i++) {
475 line = data + i * wpl;
484 yend[index++] = i - 1;
492 yend[index++] = h - 1;
522l_int32 w, h, i, start, size;
525 if (pnastart) *pnastart = NULL;
527 return (
NUMA *)ERROR_PTR(
"direction invalid", __func__, NULL);
528 if (!pix || pixGetDepth(pix) != 1)
529 return (
NUMA *)ERROR_PTR(
"pix undefined or not 1 bpp", __func__, NULL);
531 pixGetDimensions(pix, &w, &h, NULL);
532 nasize = numaCreate(w);
533 if (pnastart) *pnastart = numaCreate(w);
535 for (i = 0; i < h; i++) {
537 numaAddNumber(nasize, size);
538 if (pnastart) numaAddNumber(*pnastart, start);
541 for (i = 0; i < w; i++) {
543 numaAddNumber(nasize, size);
544 if (pnastart) numaAddNumber(*pnastart, start);
575l_int32 w, h, j, wpl, val, maxstart, maxsize, length, start;
578 if (pxstart) *pxstart = 0;
580 return ERROR_INT(
"&size not defined", __func__, 1);
582 if (!pix || pixGetDepth(pix) != 1)
583 return ERROR_INT(
"pix not defined or not 1 bpp", __func__, 1);
584 pixGetDimensions(pix, &w, &h, NULL);
586 return ERROR_INT(
"y not in [0 ... h - 1]", __func__, 1);
588 wpl = pixGetWpl(pix);
589 line = pixGetData(pix) + y * wpl;
594 for (j = 0; j < w; j++) {
603 if (length > maxsize) {
613 if (length > maxsize) {
618 if (pxstart) *pxstart = maxstart;
647l_int32 w, h, i, wpl, val, maxstart, maxsize, length, start;
648l_uint32 *data, *line;
650 if (pystart) *pystart = 0;
652 return ERROR_INT(
"&size not defined", __func__, 1);
654 if (!pix || pixGetDepth(pix) != 1)
655 return ERROR_INT(
"pix not defined or not 1 bpp", __func__, 1);
656 pixGetDimensions(pix, &w, &h, NULL);
658 return ERROR_INT(
"x not in [0 ... w - 1]", __func__, 1);
660 wpl = pixGetWpl(pix);
661 data = pixGetData(pix);
666 for (i = 0; i < h; i++) {
667 line = data + i * wpl;
676 if (length > maxsize) {
686 if (length > maxsize) {
691 if (pystart) *pystart = maxstart;
727l_int32 i, j, first, last, diff, max;
730 return ERROR_INT(
"buffer not defined", __func__, 1);
732 return ERROR_INT(
"start not defined", __func__, 1);
734 return ERROR_INT(
"end not defined", __func__, 1);
741 memset(buffer, 0, 4 * size);
742 for (i = 0; i < n; i++) {
745 diff = last - first + 1;
746 diff = L_MIN(diff, max);
747 for (j = first; j <= last; j++)
780 tab = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
781 for (i = 0; i < 256; i++) {
787 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)
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()
NUMA * pixFindMaxRuns(PIX *pix, l_int32 direction, NUMA **pnastart)
pixFindMaxRuns()
l_ok pixFindMaxHorizontalRunOnLine(PIX *pix, l_int32 y, l_int32 *pxstart, l_int32 *psize)
pixFindMaxHorizontalRunOnLine()
PIX * pixRunlengthTransform(PIX *pixs, l_int32 color, l_int32 direction, l_int32 depth)
pixRunlengthTransform()
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()
PIX * pixStrokeWidthTransform(PIX *pixs, l_int32 color, l_int32 depth, l_int32 nangles)
pixStrokeWidthTransform()
l_int32 * makeMSBitLocTab(l_int32 bitval)
makeMSBitLocTab()