137 #include <config_auto.h>
141 #include "allheaders.h"
144 static const l_uint32 rmask32[] = {0x0,
145 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
146 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff,
147 0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff,
148 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff,
149 0x0001ffff, 0x0003ffff, 0x0007ffff, 0x000fffff,
150 0x001fffff, 0x003fffff, 0x007fffff, 0x00ffffff,
151 0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff,
152 0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff};
157 LEPT_DLL l_float32 AlphaMaskBorderVals[2] = {0.0, 0.5};
160 #ifndef NO_CONSOLE_IO
161 #define DEBUG_SERIALIZE 0
197 l_int32 w, h, d, wpl, val;
198 l_uint32 *line, *data;
201 return ERROR_INT(
"&val not defined", __func__, 1);
204 return ERROR_INT(
"pix not defined", __func__, 1);
207 if (x < 0 || x >= w || y < 0 || y >= h)
210 wpl = pixGetWpl(pix);
212 line = data + y * wpl;
234 return ERROR_INT(
"depth must be in {1,2,4,8,16,32} bpp", __func__, 1);
268 l_int32 w, h, d, wpl;
269 l_uint32 *line, *data;
272 return ERROR_INT(
"pix not defined", __func__, 1);
274 if (x < 0 || x >= w || y < 0 || y >= h)
278 wpl = pixGetWpl(pix);
279 line = data + y * wpl;
304 return ERROR_INT(
"depth must be in {1,2,4,8,16,32} bpp", __func__, 1);
335 l_int32 w, h, d, wpl;
336 l_uint32 *data, *ppixel;
338 if (prval) *prval = 0;
339 if (pgval) *pgval = 0;
340 if (pbval) *pbval = 0;
341 if (!prval && !pgval && !pbval)
342 return ERROR_INT(
"no output requested", __func__, 1);
344 return ERROR_INT(
"pix not defined", __func__, 1);
347 return ERROR_INT(
"pix not 32 bpp", __func__, 1);
348 if (x < 0 || x >= w || y < 0 || y >= h)
351 wpl = pixGetWpl(pix);
353 ppixel = data + y * wpl + x;
385 l_int32 w, h, d, wpl;
387 l_uint32 *data, *line;
390 return ERROR_INT(
"pix not defined", __func__, 1);
393 return ERROR_INT(
"pix not 32 bpp", __func__, 1);
394 if (x < 0 || x >= w || y < 0 || y >= h)
397 wpl = pixGetWpl(pix);
399 line = data + y * wpl;
441 l_int32 w, h, d, index;
445 return ERROR_INT(
"pix not defined", __func__, 1);
446 if ((cmap = pixGetColormap(pix)) == NULL)
447 return ERROR_INT(
"pix is not colormapped", __func__, 1);
449 if (d != 2 && d != 4 && d != 8)
450 return ERROR_INT(
"pix depth not 2, 4 or 8", __func__, 1);
451 if (x < 0 || x >= w || y < 0 || y >= h)
458 return ERROR_INT(
"colormap is full", __func__, 2);
485 l_int32 w, h, x, y, rval, gval, bval;
492 if (!pval && !px && !py)
493 return ERROR_INT(
"no output requested", __func__, 1);
495 return ERROR_INT(
"pix not defined", __func__, 1);
504 if ((cmap = pixGetColormap(pix)) != NULL) {
534 l_int32 w, h, d, wpl;
535 l_uint32 *line, *data;
538 return ERROR_INT(
"pix not defined", __func__, 1);
539 if (pixGetColormap(pix))
540 L_WARNING(
"cmapped: setting to 0 may not be intended\n", __func__);
542 if (x < 0 || x >= w || y < 0 || y >= h)
545 wpl = pixGetWpl(pix);
547 line = data + y * wpl;
569 return ERROR_INT(
"depth must be in {1,2,4,8,16,32} bpp", __func__, 1);
594 l_int32 w, h, d, wpl;
596 l_uint32 *line, *data;
599 return ERROR_INT(
"pix not defined", __func__, 1);
600 if (pixGetColormap(pix))
601 L_WARNING(
"cmapped: setting to 0 may not be intended\n", __func__);
603 if (x < 0 || x >= w || y < 0 || y >= h)
607 wpl = pixGetWpl(pix);
608 line = data + y * wpl;
639 val = line[x] ^ 0xffffffff;
643 return ERROR_INT(
"depth must be in {1,2,4,8,16,32} bpp", __func__, 1);
727 return ERROR_INT(
"&val not defined", __func__, 1);
730 return ERROR_INT(
"pixs not defined", __func__, 1);
732 return ERROR_INT(
"invalid op", __func__, 1);
734 cmap = pixGetColormap(pixs);
735 d = pixGetDepth(pixs);
741 val = (d == 32) ? 0xffffff00 : (1 << d) - 1;
776 return ERROR_INT(
"pix not defined", __func__, 1);
778 memset(pix->
data, 0, 4LL * pix->
wpl * pix->
h);
805 return ERROR_INT(
"pix not defined", __func__, 1);
806 if ((cmap = pixGetColormap(pix)) != NULL) {
808 if (n < cmap->nalloc)
809 return ERROR_INT(
"cmap entry does not exist", __func__, 1);
812 memset(pix->
data, 0xff, 4LL * pix->
wpl * pix->
h);
842 l_int32 d, spp, index;
848 return ERROR_INT(
"pix not defined", __func__, 1);
850 L_WARNING(
"grayval < 0; setting to 0\n", __func__);
852 }
else if (grayval > 255) {
853 L_WARNING(
"grayval > 255; setting to 255\n", __func__);
858 cmap = pixGetColormap(pix);
866 d = pixGetDepth(pix);
867 spp = pixGetSpp(pix);
878 }
else if (d == 16) {
879 grayval |= (grayval << 8);
881 }
else if (d == 32 && spp == 3) {
884 }
else if (d == 32 && spp == 4) {
891 L_ERROR(
"invalid depth: %d\n", __func__, d);
932 l_int32 n, i, j, w, h, d, wpl, npix;
933 l_uint32 maxval, wordval;
934 l_uint32 *data, *line;
938 return ERROR_INT(
"pix not defined", __func__, 1);
942 if ((cmap = pixGetColormap(pix)) != NULL) {
945 L_WARNING(
"index not in colormap; using last color\n", __func__);
954 maxval = (1 << d) - 1;
956 L_WARNING(
"val = %d too large for depth; using maxval = %d\n",
957 __func__, val, maxval);
965 for (j = 0; j < npix; j++)
966 wordval |= (val << (j * d));
967 wpl = pixGetWpl(pix);
969 for (i = 0; i < h; i++) {
970 line = data + i * wpl;
971 for (j = 0; j < wpl; j++) {
972 *(line + j) = wordval;
1004 return ERROR_INT(
"pix not defined", __func__, 1);
1006 return ERROR_INT(
"invalid op", __func__, 1);
1008 cmap = pixGetColormap(pixs);
1009 d = pixGetDepth(pixs);
1047 l_uint32 mask1, mask2;
1050 if (!pix || pixGetDepth(pix) != 32)
1051 return ERROR_INT(
"pix not defined or not 32 bpp", __func__, 1);
1054 return ERROR_INT(
"invalid component", __func__, 1);
1055 if (val < 0 || val > 255)
1056 return ERROR_INT(
"val not in [0 ... 255]", __func__, 1);
1058 mask1 = ~(255 << (8 * (3 - comp)));
1059 mask2 = val << (8 * (3 - comp));
1060 nwords = pixGetHeight(pix) * pixGetWpl(pix);
1062 for (i = 0; i < nwords; i++) {
1096 return ERROR_INT(
"pix not defined", __func__, 1);
1098 return ERROR_INT(
"box not defined", __func__, 1);
1126 l_int32 n, x, y, w, h;
1130 return ERROR_INT(
"pix not defined", __func__, 1);
1132 return ERROR_INT(
"box not defined", __func__, 1);
1133 if ((cmap = pixGetColormap(pix)) != NULL) {
1135 if (n < cmap->nalloc)
1136 return ERROR_INT(
"cmap entry does not exist", __func__, 1);
1167 l_int32 n, x, y, xstart, xend, ystart, yend, bw, bh, w, h, d, wpl, maxval;
1168 l_uint32 *data, *line;
1173 return ERROR_INT(
"pix not defined", __func__, 1);
1175 return ERROR_INT(
"box not defined", __func__, 1);
1177 if (d != 1 && d != 2 && d != 4 && d !=8 && d != 16 && d != 32)
1178 return ERROR_INT(
"depth must be in {1,2,4,8,16,32} bpp", __func__, 1);
1179 if ((cmap = pixGetColormap(pix)) != NULL) {
1182 L_WARNING(
"index not in colormap; using last color\n", __func__);
1187 maxval = (d == 32) ? 0xffffff00 : (1 << d) - 1;
1188 if (val > maxval) val = maxval;
1196 (d == 2 && val == 3) ||
1197 (d == 4 && val == 0xf) ||
1198 (d == 8 && val == 0xff) ||
1199 (d == 16 && val == 0xffff) ||
1200 (d == 32 && ((val ^ 0xffffff00) >> 8 == 0))) {
1207 return ERROR_INT(
"no overlap of box with image", __func__, 1);
1209 xend = xstart + bw - 1;
1210 yend = ystart + bh - 1;
1213 wpl = pixGetWpl(pix);
1215 for (y = ystart; y <= yend; y++) {
1216 line = data + y * wpl;
1217 for (x = xstart; x <= xend; x++) {
1236 return ERROR_INT(
"depth not 2|4|8|16|32 bpp", __func__, 1);
1267 l_int32 i, j, bx, by, bw, bh, w, h, wpls;
1268 l_int32 prval, pgval, pbval, rval, gval, bval;
1270 l_uint32 *datas, *lines;
1272 if (!pixs || pixGetDepth(pixs) != 32)
1273 return ERROR_INT(
"pixs not defined or not 32 bpp", __func__, 1);
1278 wpls = pixGetWpl(pixs);
1280 for (i = 0; i < h; i++) {
1281 lines = datas + i * wpls;
1282 for (j = 0; j < w; j++) {
1283 val32 = *(lines + j);
1285 prval = (l_int32)((1. - fract) * prval + fract * rval);
1286 pgval = (l_int32)((1. - fract) * pgval + fract * gval);
1287 pbval = (l_int32)((1. - fract) * pbval + fract * bval);
1289 *(lines + j) = val32;
1296 for (i = 0; i < bh; i++) {
1297 if (by + i < 0 || by + i >= h)
continue;
1298 lines = datas + (by + i) * wpls;
1299 for (j = 0; j < bw; j++) {
1300 if (bx + j < 0 || bx + j >= w)
continue;
1301 val32 = *(lines + bx + j);
1303 prval = (l_int32)((1. - fract) * prval + fract * rval);
1304 pgval = (l_int32)((1. - fract) * pgval + fract * gval);
1305 pbval = (l_int32)((1. - fract) * pbval + fract * bval);
1307 *(lines + bx + j) = val32;
1349 l_int32 i, w, h, d, wpl, endbits, fullwords;
1351 l_uint32 *data, *pword;
1354 return ERROR_INT(
"pix not defined", __func__, 1);
1361 wpl = pixGetWpl(pix);
1362 endbits = 32 - (((l_int64)w * d) % 32);
1365 fullwords = (1LL * w * d) / 32;
1366 mask = rmask32[endbits];
1370 for (i = 0; i < h; i++) {
1371 pword = data + i * wpl + fullwords;
1373 *pword = *pword & mask;
1375 *pword = *pword | mask;
1409 l_int32 i, w, h, d, wpl, endbits, fullwords;
1411 l_uint32 *data, *pword;
1414 return ERROR_INT(
"pix not defined", __func__, 1);
1423 return ERROR_INT(
"start y not in image", __func__, 1);
1428 wpl = pixGetWpl(pix);
1429 endbits = 32 - (((l_int64)w * d) % 32);
1432 fullwords = (l_int64)w * d / 32;
1434 mask = rmask32[endbits];
1438 for (i = by; i < by + bh; i++) {
1439 pword = data + i * wpl + fullwords;
1441 *pword = *pword & mask;
1443 *pword = *pword | mask;
1484 return ERROR_INT(
"pixs not defined", __func__, 1);
1486 return ERROR_INT(
"op must be PIX_SET or PIX_CLR", __func__, 1);
1490 pixRasterop(pixs, w - right, 0, right, h, op, NULL, 0, 0);
1492 pixRasterop(pixs, 0, h - bot, w, bot, op, NULL, 0, 0);
1528 l_int32 w, h, d, wpls, i, j, bstart, rstart;
1529 l_uint32 *datas, *lines;
1532 return ERROR_INT(
"pixs not defined", __func__, 1);
1534 if (d != 8 && d != 16 && d != 32)
1535 return ERROR_INT(
"depth must be 8, 16 or 32 bpp", __func__, 1);
1538 wpls = pixGetWpl(pixs);
1541 for (i = 0; i < top; i++) {
1542 lines = datas + i * wpls;
1543 for (j = 0; j < w; j++)
1548 for (i = top; i < bstart; i++) {
1549 lines = datas + i * wpls;
1550 for (j = 0; j < left; j++)
1552 for (j = rstart; j < w; j++)
1555 for (i = bstart; i < h; i++) {
1556 lines = datas + i * wpls;
1557 for (j = 0; j < w; j++)
1560 }
else if (d == 16) {
1562 for (i = 0; i < top; i++) {
1563 lines = datas + i * wpls;
1564 for (j = 0; j < w; j++)
1569 for (i = top; i < bstart; i++) {
1570 lines = datas + i * wpls;
1571 for (j = 0; j < left; j++)
1573 for (j = rstart; j < w; j++)
1576 for (i = bstart; i < h; i++) {
1577 lines = datas + i * wpls;
1578 for (j = 0; j < w; j++)
1582 for (i = 0; i < top; i++) {
1583 lines = datas + i * wpls;
1584 for (j = 0; j < w; j++)
1589 for (i = top; i < bstart; i++) {
1590 lines = datas + i * wpls;
1591 for (j = 0; j < left; j++)
1593 for (j = rstart; j < w; j++)
1596 for (i = bstart; i < h; i++) {
1597 lines = datas + i * wpls;
1598 for (j = 0; j < w; j++)
1627 l_int32 w, h, d, i, j, xend, yend;
1630 return ERROR_INT(
"pixs not defined", __func__, 1);
1632 return ERROR_INT(
"dist must be > 0", __func__, 1);
1634 if (w < 2 * dist + 1 || h < 2 * dist + 1)
1635 return ERROR_INT(
"ring doesn't exist", __func__, 1);
1636 if (d < 32 && (val >= (1 << d)))
1637 return ERROR_INT(
"invalid pixel value", __func__, 1);
1641 for (j = dist - 1; j <= xend; j++)
1643 for (j = dist - 1; j <= xend; j++)
1645 for (i = dist - 1; i <= yend; i++)
1647 for (i = dist - 1; i <= yend; i++)
1681 return ERROR_INT(
"pixs not defined", __func__, 1);
1684 for (j = 0; j < left; j++)
1686 pixs, left + j, top);
1687 for (j = 0; j < right; j++)
1689 pixs, w - right - 1 - j, top);
1690 for (i = 0; i < top; i++)
1693 for (i = 0; i < bot; i++)
1695 pixs, 0, h - bot - 1 - i);
1731 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, pixd);
1735 L_WARNING(
"same: nothing to do\n", __func__);
1738 return (
PIX *)ERROR_PTR(
"pixs and pixd sizes differ",
1743 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, pixd);
1778 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1821 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1823 return (
PIX *)ERROR_PTR(
"invalid op", __func__, NULL);
1870 l_int32 ws, hs, wd, hd, d, maxval, op;
1874 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1875 if (left < 0 || right < 0 || top < 0 || bot < 0)
1876 return (
PIX *)ERROR_PTR(
"negative border added!", __func__, NULL);
1879 wd = ws + left + right;
1880 hd = hs + top + bot;
1881 if ((pixd =
pixCreate(wd, hd, d)) == NULL)
1882 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1883 pixCopyResolution(pixd, pixs);
1887 maxval = (d == 32) ? 0xffffff00 : (1 << d) - 1;
1891 else if (val >= maxval)
1896 pixRasterop(pixd, 0, 0, left, hd, op, NULL, 0, 0);
1897 pixRasterop(pixd, wd - right, 0, right, hd, op, NULL, 0, 0);
1899 pixRasterop(pixd, 0, hd - bot, wd, bot, op, NULL, 0, 0);
1944 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1953 for (i = 0; i < 6; i++) {
1955 L_WARNING(
"w = %d > 500; skipping\n", __func__, w[i]);
1956 if (w[i] > 0 && w[i] <= 500) {
1981 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2002 l_int32 ws, hs, wd, hd, d;
2006 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2007 if (left < 0 || right < 0 || top < 0 || bot < 0)
2008 return (
PIX *)ERROR_PTR(
"negative border removed!", __func__, NULL);
2011 wd = ws - left - right;
2012 hd = hs - top - bot;
2014 return (
PIX *)ERROR_PTR(
"width must be > 0", __func__, NULL);
2016 return (
PIX *)ERROR_PTR(
"height must be > 0", __func__, NULL);
2017 if ((pixd =
pixCreate(wd, hd, d)) == NULL)
2018 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2019 pixCopyResolution(pixd, pixs);
2024 if (pixGetDepth(pixs) == 32 && pixGetSpp(pixs) == 4)
2051 l_int32 w, h, top, bot, left, right, delta;
2054 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2057 if ((wd <= 0 || wd >= w) && (hd <= 0 || hd >= h))
2060 left = right = (w - wd) / 2;
2061 delta = w - 2 * left - wd;
2063 top = bot = (h - hd) / 2;
2064 delta = h - hd - 2 * top;
2066 if (wd <= 0 || wd > w)
2068 else if (hd <= 0 || hd > h)
2110 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2112 if (left > w || right > w || top > h || bot > h)
2113 return (
PIX *)ERROR_PTR(
"border too large", __func__, NULL);
2117 for (j = 0; j < left; j++)
2119 pixd, left + j, top);
2120 for (j = 0; j < right; j++)
2122 pixd, left + w - 1 - j, top);
2123 for (i = 0; i < top; i++)
2126 for (i = 0; i < bot; i++)
2128 pixd, 0, top + h - 1 - i);
2161 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2163 if (left > w || right > w || top > h || bot > h)
2164 return (
PIX *)ERROR_PTR(
"border too large", __func__, NULL);
2215 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2217 if (left > w || right > w || top > h || bot > h)
2218 return (
PIX *)ERROR_PTR(
"border too large", __func__, NULL);
2223 for (j = 0; j < left; j++)
2225 pixd, left + j, top);
2226 for (j = 0; j < right; j++)
2228 pixd, left + w - 1 - j, top);
2260 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2264 for (j = 0; j < left; j++)
2266 for (j = 0; j < right; j++)
2268 PIX_SRC, pixd, left + w - 1, top);
2269 for (i = 0; i < top; i++)
2271 for (i = 0; i < bot; i++)
2272 pixRasterop(pixd, 0, top + h + i, left + w + right, 1,
2273 PIX_SRC, pixd, 0, top + h - 1);
2300 return ERROR_INT(
"pixs and pixd not both defined", __func__, 1);
2301 if (pixGetDepth(pixs) != 32 || pixGetSpp(pixs) != 4)
2302 return ERROR_INT(
"pixs not 32 bpp and 4 spp", __func__, 1);
2303 if (pixGetDepth(pixd) != 32)
2304 return ERROR_INT(
"pixd not 32 bpp", __func__, 1);
2306 if (shiftx == 0 && shifty == 0) {
2345 l_float32 scalefact;
2346 PIX *pix1, *pix2, *pixd;
2351 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2352 cmap = pixGetColormap(pixs);
2353 if (!cmap && !(pixGetDepth(pixs) == 32 && pixGetSpp(pixs) == 4))
2354 return (
PIX *)ERROR_PTR(
"pixs not cmap and not 32 bpp rgba",
2356 if ((w = pixGetWidth(pixs)) == 0)
2357 return (
PIX *)ERROR_PTR(
"pixs width 0 !!", __func__, NULL);
2365 scalefact = (maxw == 0) ? 1.0 : L_MIN(1.0, (l_float32)(maxw) / w);
2366 width = (l_int32)(scalefact * w);
2414 l_int32 wr, wg, wb, hr, hg, hb, dr, dg, db;
2418 return (
PIX *)ERROR_PTR(
"pixr not defined", __func__, NULL);
2420 return (
PIX *)ERROR_PTR(
"pixg not defined", __func__, NULL);
2422 return (
PIX *)ERROR_PTR(
"pixb not defined", __func__, NULL);
2426 if (dr != 8 || dg != 8 || db != 8)
2427 return (
PIX *)ERROR_PTR(
"input pix not all 8 bpp", __func__, NULL);
2428 if (wr != wg || wr != wb)
2429 return (
PIX *)ERROR_PTR(
"widths not the same", __func__, NULL);
2430 if (hr != hg || hr != hb)
2431 return (
PIX *)ERROR_PTR(
"heights not the same", __func__, NULL);
2433 if ((pixd =
pixCreate(wr, hr, 32)) == NULL)
2434 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2435 pixCopyResolution(pixd, pixr);
2467 l_int32 i, j, w, h, wpls, wpld, val;
2468 l_uint32 *lines, *lined;
2469 l_uint32 *datas, *datad;
2473 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2474 if (pixGetColormap(pixs))
2476 if (pixGetDepth(pixs) != 32)
2477 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, NULL);
2480 return (
PIX *)ERROR_PTR(
"invalid comp", __func__, NULL);
2483 if ((pixd =
pixCreate(w, h, 8)) == NULL)
2484 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2485 pixCopyResolution(pixd, pixs);
2486 wpls = pixGetWpl(pixs);
2487 wpld = pixGetWpl(pixd);
2490 for (i = 0; i < h; i++) {
2491 lines = datas + i * wpls;
2492 lined = datad + i * wpld;
2493 for (j = 0; j < w; j++) {
2526 l_int32 i, j, w, h, ws, hs, wd, hd;
2528 l_uint32 *lines, *lined;
2529 l_uint32 *datas, *datad;
2532 return ERROR_INT(
"pixd not defined", __func__, 1);
2534 return ERROR_INT(
"pixs not defined", __func__, 1);
2535 if (pixGetDepth(pixd) != 32)
2536 return ERROR_INT(
"pixd not 32 bpp", __func__, 1);
2537 if (pixGetDepth(pixs) != 8)
2538 return ERROR_INT(
"pixs not 8 bpp", __func__, 1);
2541 return ERROR_INT(
"invalid comp", __func__, 1);
2544 if (ws != wd || hs != hd)
2545 L_WARNING(
"images sizes not equal\n", __func__);
2552 wpls = pixGetWpl(pixs);
2553 wpld = pixGetWpl(pixd);
2554 for (i = 0; i < h; i++) {
2555 lines = datas + i * wpls;
2556 lined = datad + i * wpld;
2557 for (j = 0; j < w; j++) {
2584 l_int32 i, j, w, h, val, index, valid;
2586 l_uint32 *linec, *lined;
2587 l_uint32 *datac, *datad;
2593 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2594 if ((cmap = pixGetColormap(pixs)) == NULL)
2595 return (
PIX *)ERROR_PTR(
"pixs not cmapped", __func__, NULL);
2597 return (
PIX *)ERROR_PTR(
"alpha in cmaps not supported", __func__, NULL);
2599 return (
PIX *)ERROR_PTR(
"invalid comp", __func__, NULL);
2602 if (pixGetDepth(pixs) == 8)
2609 return (
PIX *)ERROR_PTR(
"invalid colormap", __func__, NULL);
2613 if ((pixd =
pixCreate(w, h, 8)) == NULL) {
2615 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2617 pixCopyResolution(pixd, pixs);
2618 wplc = pixGetWpl(pixc);
2619 wpld = pixGetWpl(pixd);
2624 for (i = 0; i < h; i++) {
2625 linec = datac + i * wplc;
2626 lined = datad + i * wpld;
2628 for (j = 0; j < w; j++) {
2630 val = cta[index].
red;
2634 for (j = 0; j < w; j++) {
2636 val = cta[index].
green;
2640 for (j = 0; j < w; j++) {
2642 val = cta[index].
blue;
2673 l_int32 i, j, w, h, ws, hs, wd, hd, val;
2675 l_uint32 *lines, *lined;
2676 l_uint32 *datas, *datad;
2678 if (!pixd && pixGetDepth(pixd) != 32)
2679 return ERROR_INT(
"pixd not defined or not 32 bpp", __func__, 1);
2680 if (!pixs && pixGetDepth(pixs) != 32)
2681 return ERROR_INT(
"pixs not defined or not 32 bpp", __func__, 1);
2684 return ERROR_INT(
"invalid component", __func__, 1);
2687 if (ws != wd || hs != hd)
2688 L_WARNING(
"images sizes not equal\n", __func__);
2693 wpls = pixGetWpl(pixs);
2694 wpld = pixGetWpl(pixd);
2697 for (i = 0; i < h; i++) {
2698 lines = datas + i * wpls;
2699 lined = datad + i * wpld;
2700 for (j = 0; j < w; j++) {
2734 return ERROR_INT(
"&pixel not defined", __func__, 1);
2736 *ppixel = ((l_uint32)rval << L_RED_SHIFT) |
2737 ((l_uint32)gval << L_GREEN_SHIFT) |
2738 ((l_uint32)bval << L_BLUE_SHIFT);
2765 return ERROR_INT(
"&pixel not defined", __func__, 1);
2767 *ppixel = ((l_uint32)rval << L_RED_SHIFT) |
2768 ((l_uint32)gval << L_GREEN_SHIFT) |
2769 ((l_uint32)bval << L_BLUE_SHIFT) |
2798 if (prval) *prval = (pixel >> L_RED_SHIFT) & 0xff;
2799 if (pgval) *pgval = (pixel >> L_GREEN_SHIFT) & 0xff;
2800 if (pbval) *pbval = (pixel >> L_BLUE_SHIFT) & 0xff;
2821 if (prval) *prval = (pixel >> L_RED_SHIFT) & 0xff;
2822 if (pgval) *pgval = (pixel >> L_GREEN_SHIFT) & 0xff;
2823 if (pbval) *pbval = (pixel >> L_BLUE_SHIFT) & 0xff;
2824 if (paval) *paval = (pixel >> L_ALPHA_SHIFT) & 0xff;
2839 l_int32 rval, gval, bval, val;
2842 if (type == L_CHOOSE_MIN) {
2843 val = L_MIN(rval, gval);
2844 val = L_MIN(val, bval);
2846 val = L_MAX(rval, gval);
2847 val = L_MAX(val, bval);
2881 return ERROR_INT(
"pixs not defined", __func__, 1);
2882 if (pixGetDepth(pixs) != 32)
2883 return ERROR_INT(
"pixs not 32 bpp", __func__, 1);
2884 if (!bufr || !bufg || !bufb)
2885 return ERROR_INT(
"buffer not defined", __func__, 1);
2888 if (row < 0 || row >= h)
2889 return ERROR_INT(
"row out of bounds", __func__, 1);
2890 wpls = pixGetWpl(pixs);
2893 for (j = 0; j < w; j++) {
2929 return ERROR_INT(
"line not defined", __func__, 1);
2931 return ERROR_INT(
"j must be >= 0", __func__, 1);
2932 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 32)
2933 return ERROR_INT(
"invalid d", __func__, 1);
2981 l_uint32 *datas, *datad;
2982 l_int32 i, j, h, wpl;
2993 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2996 wpl = pixGetWpl(pixs);
2997 h = pixGetHeight(pixs);
2999 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
3001 for (i = 0; i < h; i++) {
3002 for (j = 0; j < wpl; j++, datas++, datad++) {
3004 *datad = (word >> 24) |
3005 ((word >> 8) & 0x0000ff00) |
3006 ((word << 8) & 0x00ff0000) |
3044 l_int32 i, j, h, wpl;
3054 return ERROR_INT(
"pixs not defined", __func__, 1);
3057 wpl = pixGetWpl(pixs);
3058 h = pixGetHeight(pixs);
3059 for (i = 0; i < h; i++) {
3060 for (j = 0; j < wpl; j++, data++) {
3062 *data = (word >> 24) |
3063 ((word >> 8) & 0x0000ff00) |
3064 ((word << 8) & 0x00ff0000) |
3104 if (!datad || !datas)
3105 return ERROR_INT(
"datad and datas not both defined", __func__, 1);
3109 memcpy(datad, datas, 4 * wpl);
3114 for (j = 0; j < wpl; j++, datas++, datad++) {
3116 *datad = (word >> 24) |
3117 ((word >> 8) & 0x0000ff00) |
3118 ((word << 8) & 0x00ff0000) |
3150 l_uint32 *datas, *datad;
3151 l_int32 i, j, h, wpl;
3162 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3165 wpl = pixGetWpl(pixs);
3166 h = pixGetHeight(pixs);
3168 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
3170 for (i = 0; i < h; i++) {
3171 for (j = 0; j < wpl; j++, datas++, datad++) {
3173 *datad = (word << 16) | (word >> 16);
3203 l_int32 i, j, h, wpl;
3213 return ERROR_INT(
"pixs not defined", __func__, 1);
3216 wpl = pixGetWpl(pixs);
3217 h = pixGetHeight(pixs);
3218 for (i = 0; i < h; i++) {
3219 for (j = 0; j < wpl; j++, data++) {
3221 *data = (word << 16) | (word >> 16);
3256 l_int32 w, h, d, wpl, i, j, rval, gval, bval;
3258 l_uint8 *line, *data;
3259 l_uint32 *rline, *rdata;
3261 if (pdata) *pdata = NULL;
3262 if (pnbytes) *pnbytes = 0;
3263 if (!pdata || !pnbytes)
3264 return ERROR_INT(
"&data and &nbytes not both defined", __func__, 1);
3266 return ERROR_INT(
"pixs not defined", __func__, 1);
3268 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 32)
3269 return ERROR_INT(
"depth not in {1,2,4,8,16,32}", __func__, 1);
3273 wpl = pixGetWpl(pixs);
3275 databpl = (w + 7) / 8;
3277 databpl = (w + 3) / 4;
3279 databpl = (w + 1) / 2;
3280 else if (d == 8 || d == 16)
3281 databpl = w * (d / 8);
3284 if ((data = (l_uint8 *)LEPT_CALLOC((
size_t)databpl * h,
sizeof(l_uint8)))
3286 return ERROR_INT(
"data not allocated", __func__, 1);
3288 *pnbytes = (size_t)databpl * h;
3290 for (i = 0; i < h; i++) {
3291 rline = rdata + i * wpl;
3292 line = data + i * databpl;
3294 for (j = 0; j < databpl; j++)
3296 }
else if (d == 16) {
3297 for (j = 0; j < w; j++)
3300 for (j = 0; j < w; j++) {
3302 *(line + 3 * j) = rval;
3303 *(line + 3 * j + 1) = gval;
3304 *(line + 3 * j + 2) = bval;
3338 l_int32 w, h, maxdim, res;
3341 return ERROR_INT(
"&res not defined", __func__, 1);
3344 return ERROR_INT(
"pix not defined", __func__, 1);
3345 if (longside <= 0.0)
3346 return ERROR_INT(
"longside not > 0", __func__, 1);
3349 maxdim = L_MAX(w, h);
3350 res = (l_int32)(maxdim / longside + 0.5);
3351 res = L_MAX(res, 1);
3353 L_WARNING(
"low inferred resolution: %d ppi\n", __func__, res);
3355 L_WARNING(
"high inferred resolution: %d ppi\n", __func__, res);
3381 l_int32 w, h, wpl, i, j, alpha;
3382 l_uint32 *data, *line;
3385 return ERROR_INT(
"&opaque not defined", __func__, 1);
3388 return ERROR_INT(
"&pix not defined", __func__, 1);
3389 if (pixGetDepth(pix) != 32)
3390 return ERROR_INT(
"&pix not 32 bpp", __func__, 1);
3391 if (pixGetSpp(pix) != 4)
3392 return ERROR_INT(
"&pix not 4 spp", __func__, 1);
3395 wpl = pixGetWpl(pix);
3397 for (i = 0; i < h; i++) {
3398 line = data + i * wpl;
3399 for (j = 0; j < w; j++) {
3449 if (!pix || pixGetDepth(pix) != 8)
3450 return (l_uint8 **)ERROR_PTR(
"pix not defined or not 8 bpp",
3455 if (pixGetColormap(pix))
3456 return (l_uint8 **)ERROR_PTR(
"pix has colormap", __func__, NULL);
3481 return ERROR_INT(
"pix not defined", __func__, 1);
3483 return ERROR_INT(
"lineptrs not defined", __func__, 1);
3486 LEPT_FREE(lineptrs);
3520 val1 = L_MAX(0.0, L_MIN(1.0, val1));
3521 val2 = L_MAX(0.0, L_MIN(1.0, val2));
3522 AlphaMaskBorderVals[0] = val1;
3523 AlphaMaskBorderVals[1] = val2;
#define GET_DATA_QBIT(pdata, n)
#define GET_DATA_TWO_BYTES(pdata, n)
#define CLEAR_DATA_QBIT(pdata, n)
#define CLEAR_DATA_DIBIT(pdata, n)
#define SET_DATA_BIT(pdata, n)
#define SET_DATA_DIBIT(pdata, n, val)
#define SET_DATA_TWO_BYTES(pdata, n, val)
#define SET_DATA_BIT_VAL(pdata, n, val)
#define GET_DATA_BYTE(pdata, n)
#define GET_DATA_DIBIT(pdata, n)
#define SET_DATA_BYTE(pdata, n, val)
#define CLEAR_DATA_BIT(pdata, n)
#define GET_DATA_BIT(pdata, n)
#define SET_DATA_QBIT(pdata, n, val)
PIX * pixAlphaBlendUniform(PIX *pixs, l_uint32 color)
pixAlphaBlendUniform()
l_ok boxGetGeometry(const BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
void boxDestroy(BOX **pbox)
boxDestroy()
BOX * boxClipToRectangle(BOX *box, l_int32 wi, l_int32 hi)
boxClipToRectangle()
l_int32 pixcmapGetCount(const PIXCMAP *cmap)
pixcmapGetCount()
l_ok pixcmapIsValid(const PIXCMAP *cmap, PIX *pix, l_int32 *pvalid)
pixcmapIsValid()
l_ok pixcmapAddNewColor(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
pixcmapAddNewColor()
l_ok pixcmapAddBlackOrWhite(PIXCMAP *cmap, l_int32 color, l_int32 *pindex)
pixcmapAddBlackOrWhite()
l_ok pixcmapAddNearestColor(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
pixcmapAddNearestColor()
l_ok pixcmapGetColor(PIXCMAP *cmap, l_int32 index, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
pixcmapGetColor()
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()
l_int32 pixSizesEqual(const PIX *pix1, const PIX *pix2)
pixSizesEqual()
l_ok pixCopySpp(PIX *pixd, const PIX *pixs)
pixCopySpp()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
PIX * pixCreateTemplate(const PIX *pixs)
pixCreateTemplate()
l_ok pixCopyColormap(PIX *pixd, const PIX *pixs)
pixCopyColormap()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
PIX * pixClone(PIX *pixs)
pixClone()
void ** pixGetLinePtrs(PIX *pix, l_int32 *psize)
pixGetLinePtrs()
l_ok pixSetInRectArbitrary(PIX *pix, BOX *box, l_uint32 val)
pixSetInRectArbitrary()
l_ok pixSetBorderRingVal(PIX *pixs, l_int32 dist, l_uint32 val)
pixSetBorderRingVal()
l_ok pixAlphaIsOpaque(PIX *pix, l_int32 *popaque)
pixAlphaIsOpaque()
l_int32 lineEndianByteSwap(l_uint32 *datad, l_uint32 *datas, l_int32 wpl)
lineEndianByteSwap()
PIX * pixGetRGBComponent(PIX *pixs, l_int32 comp)
pixGetRGBComponent()
PIX * pixDisplayLayersRGBA(PIX *pixs, l_uint32 val, l_int32 maxw)
pixDisplayLayersRGBA()
PIX * pixEndianByteSwapNew(PIX *pixs)
pixEndianByteSwapNew()
l_ok pixSetPixel(PIX *pix, l_int32 x, l_int32 y, l_uint32 val)
pixSetPixel()
l_int32 extractMinMaxComponent(l_uint32 pixel, l_int32 type)
extractMinMaxComponent()
l_ok pixClearAll(PIX *pix)
pixClearAll()
l_ok pixShiftAndTransferAlpha(PIX *pixd, PIX *pixs, l_float32 shiftx, l_float32 shifty)
pixShiftAndTransferAlpha()
l_ok pixGetPixel(PIX *pix, l_int32 x, l_int32 y, l_uint32 *pval)
pixGetPixel()
l_ok pixClearInRect(PIX *pix, BOX *box)
pixClearInRect()
PIX * pixCreateRGBImage(PIX *pixr, PIX *pixg, PIX *pixb)
pixCreateRGBImage()
PIX * pixRemoveBorderGeneral(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
pixRemoveBorderGeneral()
l_ok pixGetRGBLine(PIX *pixs, l_int32 row, l_uint8 *bufr, l_uint8 *bufg, l_uint8 *bufb)
pixGetRGBLine()
l_ok pixClearPixel(PIX *pix, l_int32 x, l_int32 y)
pixClearPixel()
PIX * pixRemoveBorderToSize(PIX *pixs, l_int32 wd, l_int32 hd)
pixRemoveBorderToSize()
PIX * pixAddBorder(PIX *pixs, l_int32 npix, l_uint32 val)
pixAddBorder()
PIX * pixAddContinuedBorder(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
pixAddContinuedBorder()
l_ok pixInferResolution(PIX *pix, l_float32 longside, l_int32 *pres)
pixInferResolution()
PIX * pixAddBorderGeneral(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot, l_uint32 val)
pixAddBorderGeneral()
PIX * pixAddMultipleBlackWhiteBorders(PIX *pixs, l_int32 nblack1, l_int32 nwhite1, l_int32 nblack2, l_int32 nwhite2, l_int32 nblack3, l_int32 nwhite3)
pixAddMultipleBlackWhiteBorders()
void extractRGBAValues(l_uint32 pixel, l_int32 *prval, l_int32 *pgval, l_int32 *pbval, l_int32 *paval)
extractRGBAValues()
l_ok pixEndianTwoByteSwap(PIX *pixs)
pixEndianTwoByteSwap()
l_ok pixSetAllGray(PIX *pix, l_int32 grayval)
pixSetAllGray()
l_ok pixSetBorderVal(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot, l_uint32 val)
pixSetBorderVal()
l_uint8 ** pixSetupByteProcessing(PIX *pix, l_int32 *pw, l_int32 *ph)
pixSetupByteProcessing()
l_ok pixCopyRGBComponent(PIX *pixd, PIX *pixs, l_int32 comp)
pixCopyRGBComponent()
l_ok pixSetInRect(PIX *pix, BOX *box)
pixSetInRect()
void setPixelLow(l_uint32 *line, l_int32 x, l_int32 depth, l_uint32 val)
setPixelLow()
void l_setAlphaMaskBorder(l_float32 val1, l_float32 val2)
l_setAlphaMaskBorder()
l_ok pixGetRandomPixel(PIX *pix, l_uint32 *pval, l_int32 *px, l_int32 *py)
pixGetRandomPixel()
l_ok pixGetBlackOrWhiteVal(PIX *pixs, l_int32 op, l_uint32 *pval)
pixGetBlackOrWhiteVal()
PIX * pixRemoveBorder(PIX *pixs, l_int32 npix)
pixRemoveBorder()
l_ok pixSetAll(PIX *pix)
pixSetAll()
PIX * pixAddBlackOrWhiteBorder(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot, l_int32 op)
pixAddBlackOrWhiteBorder()
l_ok pixSetPadBits(PIX *pix, l_int32 val)
pixSetPadBits()
PIX * pixAddMixedBorder(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
pixAddMixedBorder()
l_ok pixSetOrClearBorder(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot, l_int32 op)
pixSetOrClearBorder()
l_ok pixSetCmapPixel(PIX *pix, l_int32 x, l_int32 y, l_int32 rval, l_int32 gval, l_int32 bval)
pixSetCmapPixel()
l_ok composeRGBAPixel(l_int32 rval, l_int32 gval, l_int32 bval, l_int32 aval, l_uint32 *ppixel)
composeRGBAPixel()
PIX * pixCopyBorder(PIX *pixd, PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
pixCopyBorder()
l_ok pixFlipPixel(PIX *pix, l_int32 x, l_int32 y)
pixFlipPixel()
l_ok pixBlendInRect(PIX *pixs, BOX *box, l_uint32 val, l_float32 fract)
pixBlendInRect()
PIX * pixEndianTwoByteSwapNew(PIX *pixs)
pixEndianTwoByteSwapNew()
l_ok composeRGBPixel(l_int32 rval, l_int32 gval, l_int32 bval, l_uint32 *ppixel)
composeRGBPixel()
l_ok pixCleanupByteProcessing(PIX *pix, l_uint8 **lineptrs)
pixCleanupByteProcessing()
void extractRGBValues(l_uint32 pixel, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
extractRGBValues()
l_ok setLineDataVal(l_uint32 *line, l_int32 j, l_int32 d, l_uint32 val)
setLineDataVal()
l_ok pixGetRGBPixel(PIX *pix, l_int32 x, l_int32 y, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
pixGetRGBPixel()
l_ok pixSetMirroredBorder(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
pixSetMirroredBorder()
l_ok pixSetPadBitsBand(PIX *pix, l_int32 by, l_int32 bh, l_int32 val)
pixSetPadBitsBand()
l_ok pixEndianByteSwap(PIX *pixs)
pixEndianByteSwap()
l_ok pixSetBlackOrWhite(PIX *pixs, l_int32 op)
pixSetBlackOrWhite()
l_ok pixSetRGBComponent(PIX *pixd, PIX *pixs, l_int32 comp)
pixSetRGBComponent()
l_ok pixSetRGBPixel(PIX *pix, l_int32 x, l_int32 y, l_int32 rval, l_int32 gval, l_int32 bval)
pixSetRGBPixel()
PIX * pixAddMirroredBorder(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
pixAddMirroredBorder()
l_ok pixSetComponentArbitrary(PIX *pix, l_int32 comp, l_int32 val)
pixSetComponentArbitrary()
l_ok pixSetAllArbitrary(PIX *pix, l_uint32 val)
pixSetAllArbitrary()
l_ok pixGetRasterData(PIX *pixs, l_uint8 **pdata, size_t *pnbytes)
pixGetRasterData()
PIX * pixGetRGBComponentCmap(PIX *pixs, l_int32 comp)
pixGetRGBComponentCmap()
PIX * pixAddRepeatedBorder(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
pixAddRepeatedBorder()
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
void pixaDestroy(PIXA **ppixa)
pixaDestroy()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
PIX * pixaDisplayTiledInRows(PIXA *pixa, l_int32 outdepth, l_int32 maxwidth, l_float32 scalefactor, l_int32 background, l_int32 spacing, l_int32 border)
pixaDisplayTiledInRows()
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
PIX * pixConvertTo8(PIX *pixs, l_int32 cmapflag)
pixConvertTo8()
PIX * pixConvertTo32(PIX *pixs)
pixConvertTo32()
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()
void lept_stderr(const char *fmt,...)
lept_stderr()