60 #include <config_auto.h>
65 #include "allheaders.h"
108 PIX *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);
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.0;
201 l_int32 w, h, diag, xoff, yoff;
202 PIX *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);
211 diag = (l_int32)(sqrt((l_float64)(w * w + h * h)) + 2.5);
212 xoff = (diag - w) / 2;
213 yoff = (diag - h) / 2;
222 pixg1 =
pixMinOrMax(NULL, pixh, pixv, L_CHOOSE_MIN);
266 l_int32 i, j, w, h, wpld, bufsize, maxsize, n;
267 l_int32 *start, *end, *buffer;
268 l_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);
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);
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));
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;
376 l_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);
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);
399 for (j = 0; j < w; j++) {
408 xend[index++] = j - 1;
416 xend[index++] = w - 1;
451 l_int32 index, w, h, d, i, wpl, val;
452 l_uint32 *data, *line;
455 return ERROR_INT(
"&n not defined", __func__, 1);
458 return ERROR_INT(
"pix not defined", __func__, 1);
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);
474 for (i = 0; i < h; i++) {
475 line = data + i * wpl;
484 yend[index++] = i - 1;
492 yend[index++] = h - 1;
522 l_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);
535 for (i = 0; i < h; i++) {
541 for (i = 0; i < w; i++) {
575 l_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);
586 return ERROR_INT(
"y not in [0 ... h - 1]", __func__, 1);
588 wpl = pixGetWpl(pix);
594 for (j = 0; j < w; j++) {
603 if (length > maxsize) {
613 if (length > maxsize) {
618 if (pxstart) *pxstart = maxstart;
647 l_int32 w, h, i, wpl, val, maxstart, maxsize, length, start;
648 l_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);
658 return ERROR_INT(
"x not in [0 ... w - 1]", __func__, 1);
660 wpl = pixGetWpl(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;
727 l_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)
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()