235 #include <config_auto.h>
240 #include "allheaders.h"
242 extern l_float32 AlphaMaskBorderVals[2];
244 #ifndef NO_CONSOLE_IO
291 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
293 return (
PIX *)ERROR_PTR(
"ptas not defined", __func__, NULL);
295 return (
PIX *)ERROR_PTR(
"ptad not defined", __func__, NULL);
297 return (
PIX *)ERROR_PTR(
"invalid incolor", __func__, NULL);
299 return (
PIX *)ERROR_PTR(
"ptas count not 3", __func__, NULL);
301 return (
PIX *)ERROR_PTR(
"ptad count not 3", __func__, NULL);
334 l_int32 i, j, w, h, d, x, y, wpls, wpld, color, cmapindex;
336 l_uint32 *datas, *datad, *lines, *lined;
341 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
343 return (
PIX *)ERROR_PTR(
"vc not defined", __func__, NULL);
345 return (
PIX *)ERROR_PTR(
"invalid incolor", __func__, NULL);
347 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 32)
348 return (
PIX *)ERROR_PTR(
"depth not 1, 2, 4, 8 or 16", __func__, NULL);
352 if ((cmap = pixGetColormap(pixs)) != NULL) {
370 wpls = pixGetWpl(pixs);
372 wpld = pixGetWpl(pixd);
373 for (i = 0; i < h; i++) {
374 lined = datad + i * wpld;
375 for (j = 0; j < w; j++) {
377 if (x < 0 || y < 0 || x >=w || y >= h)
379 lines = datas + y * wpls;
386 }
else if (d == 32) {
428 PIX *pixt1, *pixt2, *pixd;
431 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
433 return (
PIX *)ERROR_PTR(
"ptas not defined", __func__, NULL);
435 return (
PIX *)ERROR_PTR(
"ptad not defined", __func__, NULL);
437 return (
PIX *)ERROR_PTR(
"invalid incolor", __func__, NULL);
439 return (
PIX *)ERROR_PTR(
"ptas count not 3", __func__, NULL);
441 return (
PIX *)ERROR_PTR(
"ptad count not 3", __func__, NULL);
443 if (pixGetDepth(pixs) == 1)
448 d = pixGetDepth(pixt1);
453 d = pixGetDepth(pixt2);
461 colorval = 0xffffff00;
495 PIX *pixt1, *pixt2, *pixd;
498 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
500 return (
PIX *)ERROR_PTR(
"vc not defined", __func__, NULL);
502 if (pixGetDepth(pixs) == 1)
507 d = pixGetDepth(pixt1);
512 d = pixGetDepth(pixt2);
520 colorval = 0xffffff00;
552 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
554 return (
PIX *)ERROR_PTR(
"ptas not defined", __func__, NULL);
556 return (
PIX *)ERROR_PTR(
"ptad not defined", __func__, NULL);
557 if (pixGetDepth(pixs) != 32)
558 return (
PIX *)ERROR_PTR(
"pixs must be 32 bpp", __func__, NULL);
560 return (
PIX *)ERROR_PTR(
"ptas count not 3", __func__, NULL);
562 return (
PIX *)ERROR_PTR(
"ptad count not 3", __func__, NULL);
586 l_int32 i, j, w, h, d, wpls, wpld;
588 l_uint32 *datas, *datad, *lined;
590 PIX *pix1, *pix2, *pixd;
593 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
596 return (
PIX *)ERROR_PTR(
"pixs must be 32 bpp", __func__, NULL);
598 return (
PIX *)ERROR_PTR(
"vc not defined", __func__, NULL);
601 wpls = pixGetWpl(pixs);
605 wpld = pixGetWpl(pixd);
608 for (i = 0; i < h; i++) {
609 lined = datad + i * wpld;
610 for (j = 0; j < w; j++) {
620 if (pixGetSpp(pixs) == 4) {
651 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
653 return (
PIX *)ERROR_PTR(
"ptas not defined", __func__, NULL);
655 return (
PIX *)ERROR_PTR(
"ptad not defined", __func__, NULL);
656 if (pixGetDepth(pixs) != 8)
657 return (
PIX *)ERROR_PTR(
"pixs must be 8 bpp", __func__, NULL);
659 return (
PIX *)ERROR_PTR(
"ptas count not 3", __func__, NULL);
661 return (
PIX *)ERROR_PTR(
"ptad count not 3", __func__, NULL);
686 l_int32 i, j, w, h, wpls, wpld, val;
687 l_uint32 *datas, *datad, *lined;
692 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
694 if (pixGetDepth(pixs) != 8)
695 return (
PIX *)ERROR_PTR(
"pixs must be 8 bpp", __func__, NULL);
697 return (
PIX *)ERROR_PTR(
"vc not defined", __func__, NULL);
700 wpls = pixGetWpl(pixs);
704 wpld = pixGetWpl(pixd);
707 for (i = 0; i < h; i++) {
708 lined = datad + i * wpld;
709 for (j = 0; j < w; j++) {
776 PIX *pixd, *pixb1, *pixb2, *pixg2, *pixga;
780 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
782 if (d != 32 && pixGetColormap(pixs) == NULL)
783 return (
PIX *)ERROR_PTR(
"pixs not cmapped or 32 bpp", __func__, NULL);
784 if (pixg && pixGetDepth(pixg) != 8) {
785 L_WARNING(
"pixg not 8 bpp; using 'fract' transparent alpha\n",
789 if (!pixg && (fract < 0.0 || fract > 1.0)) {
790 L_WARNING(
"invalid fract; using 1.0 (fully transparent)\n", __func__);
793 if (!pixg && fract == 0.0)
794 L_WARNING(
"fully opaque alpha; image will not be blended\n", __func__);
796 return (
PIX *)ERROR_PTR(
"ptad not defined", __func__, NULL);
798 return (
PIX *)ERROR_PTR(
"ptas not defined", __func__, NULL);
818 if (ws > 10 && hs > 10) {
820 (l_int32)(255.0 * fract * AlphaMaskBorderVals[0]));
822 (l_int32)(255.0 * fract * AlphaMaskBorderVals[1]));
920 l_float32 x1, y1, x2, y2, x3, y3;
925 return ERROR_INT(
"ptas not defined", __func__, 1);
927 return ERROR_INT(
"ptad not defined", __func__, 1);
929 return ERROR_INT(
"&vc not defined", __func__, 1);
931 b = (l_float32 *)LEPT_CALLOC(6,
sizeof(l_float32));
941 for (i = 0; i < 6; i++)
942 a[i] = (l_float32 *)LEPT_CALLOC(6,
sizeof(l_float32));
964 for (i = 0; i < 6; i++)
1009 l_float32 b[3] = {1.0, 1.0, 1.0};
1012 return ERROR_INT(
"&vci not defined", __func__, 1);
1015 return ERROR_INT(
"vc not defined", __func__, 1);
1018 for (i = 0; i < 3; i++)
1019 a[i] = (l_float32 *)LEPT_CALLOC(3,
sizeof(l_float32));
1028 vci = (l_float32 *)LEPT_CALLOC(6,
sizeof(l_float32));
1036 for (i = 0; i < 3; i++)
1043 for (i = 0; i < 2; i++)
1044 a2[i] = (l_float32 *)LEPT_CALLOC(2,
sizeof(l_float32));
1052 vci = (l_float32 *)LEPT_CALLOC(6,
sizeof(l_float32));
1060 for (i = 0; i < 2; i++)
1091 return ERROR_INT(
"vc not defined", __func__, 1);
1093 *pxp = (l_int32)(vc[0] * x + vc[1] * y + vc[2] + 0.5);
1094 *pyp = (l_int32)(vc[3] * x + vc[4] * y + vc[5] + 0.5);
1121 return ERROR_INT(
"vc not defined", __func__, 1);
1123 *pxp = vc[0] * x + vc[1] * y + vc[2];
1124 *pyp = vc[3] * x + vc[4] * y + vc[5];
1162 l_int32 valid, xpm, ypm, xp, xp2, yp, xf, yf;
1163 l_int32 rval, gval, bval;
1164 l_uint32 word00, word01, word10, word11;
1168 return ERROR_INT(
"&val not defined", __func__, 1);
1171 return ERROR_INT(
"datas not defined", __func__, 1);
1177 valid = (x >= 0.0 && y >= 0.0 && x < w && y < h);
1178 if (!valid)
return 0;
1180 xpm = (l_int32)(16.0 * x);
1181 ypm = (l_int32)(16.0 * y);
1183 xp2 = xp + 1 < w ? xp + 1 : xp;
1185 if (yp + 1 >= h) wpls = 0;
1190 if (xf < 0 || yf < 0)
1191 lept_stderr(
"xp = %d, yp = %d, xf = %d, yf = %d\n", xp, yp, xf, yf);
1195 lines = datas + yp * wpls;
1196 word00 = *(lines + xp);
1197 word10 = *(lines + xp2);
1198 word01 = *(lines + wpls + xp);
1199 word11 = *(lines + wpls + xp2);
1200 rval = ((16 - xf) * (16 - yf) * ((word00 >> L_RED_SHIFT) & 0xff) +
1201 xf * (16 - yf) * ((word10 >> L_RED_SHIFT) & 0xff) +
1202 (16 - xf) * yf * ((word01 >> L_RED_SHIFT) & 0xff) +
1203 xf * yf * ((word11 >> L_RED_SHIFT) & 0xff)) / 256;
1204 gval = ((16 - xf) * (16 - yf) * ((word00 >> L_GREEN_SHIFT) & 0xff) +
1205 xf * (16 - yf) * ((word10 >> L_GREEN_SHIFT) & 0xff) +
1206 (16 - xf) * yf * ((word01 >> L_GREEN_SHIFT) & 0xff) +
1207 xf * yf * ((word11 >> L_GREEN_SHIFT) & 0xff)) / 256;
1208 bval = ((16 - xf) * (16 - yf) * ((word00 >> L_BLUE_SHIFT) & 0xff) +
1209 xf * (16 - yf) * ((word10 >> L_BLUE_SHIFT) & 0xff) +
1210 (16 - xf) * yf * ((word01 >> L_BLUE_SHIFT) & 0xff) +
1211 xf * yf * ((word11 >> L_BLUE_SHIFT) & 0xff)) / 256;
1246 l_int32 valid, xpm, ypm, xp, xp2, yp, xf, yf, v00, v10, v01, v11;
1250 return ERROR_INT(
"&val not defined", __func__, 1);
1253 return ERROR_INT(
"datas not defined", __func__, 1);
1259 valid = (x >= 0.0 && y >= 0.0 && x < w && y < h);
1260 if (!valid)
return 0;
1262 xpm = (l_int32)(16.0 * x);
1263 ypm = (l_int32)(16.0 * y);
1265 xp2 = xp + 1 < w ? xp + 1 : xp;
1267 if (yp + 1 >= h) wpls = 0;
1272 if (xf < 0 || yf < 0)
1273 lept_stderr(
"xp = %d, yp = %d, xf = %d, yf = %d\n", xp, yp, xf, yf);
1277 lines = datas + yp * wpls;
1282 *pval = (v00 + v01 + v10 + v11) / 256;
1291 #define SWAP(a,b) {temp = (a); (a) = (b); (b) = temp;}
1318 l_int32 i, icol, irow, j, k, col, row, success;
1319 l_int32 *indexc, *indexr, *ipiv;
1320 l_float32 maxval, val, pivinv, temp;
1323 return ERROR_INT(
"a not defined", __func__, 1);
1325 return ERROR_INT(
"b not defined", __func__, 1);
1328 indexc = (l_int32 *)LEPT_CALLOC(n,
sizeof(l_int32));
1329 indexr = (l_int32 *)LEPT_CALLOC(n,
sizeof(l_int32));
1330 ipiv = (l_int32 *)LEPT_CALLOC(n,
sizeof(l_int32));
1331 if (!indexc || !indexr || !ipiv) {
1332 L_ERROR(
"array not made\n", __func__);
1334 goto cleanup_arrays;
1338 for (i = 0; i < n; i++) {
1340 for (j = 0; j < n; j++) {
1342 for (k = 0; k < n; k++) {
1344 if (fabs(a[j][k]) >= maxval) {
1345 maxval = fabs(a[j][k]);
1349 }
else if (ipiv[k] > 1) {
1350 L_ERROR(
"singular matrix\n", __func__);
1352 goto cleanup_arrays;
1360 for (col = 0; col < n; col++)
1361 SWAP(a[irow][col], a[icol][col]);
1362 SWAP(b[irow], b[icol]);
1367 if (a[icol][icol] == 0.0) {
1368 L_ERROR(
"singular matrix\n", __func__);
1370 goto cleanup_arrays;
1372 pivinv = 1.0 / a[icol][icol];
1373 a[icol][icol] = 1.0;
1374 for (col = 0; col < n; col++)
1375 a[icol][col] *= pivinv;
1378 for (row = 0; row < n; row++) {
1382 for (col = 0; col < n; col++)
1383 a[row][col] -= a[icol][col] * val;
1384 b[row] -= b[icol] * val;
1389 for (col = n - 1; col >= 0; col--) {
1390 if (indexr[col] != indexc[col]) {
1391 for (k = 0; k < n; k++)
1392 SWAP(a[k][indexr[col]], a[k][indexc[col]]);
1400 return (success) ? 0 : 1;
1442 l_int32 x1, y1, x2, y2, x3, y3;
1443 l_int32 x1p, y1p, x2p, y2p, x3p, y3p;
1445 l_float32 x2s, x2sp, scalex, scaley;
1446 l_float32 th3, th3p, ph2, ph2p;
1450 PIX *pix1, *pix2, *pixd;
1453 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1455 return (
PIX *)ERROR_PTR(
"ptas not defined", __func__, NULL);
1457 return (
PIX *)ERROR_PTR(
"ptad not defined", __func__, NULL);
1460 return (
PIX *)ERROR_PTR(
"ptas count not 3", __func__, NULL);
1462 return (
PIX *)ERROR_PTR(
"ptad count not 3", __func__, NULL);
1470 pix1 = pix2 = pixd = NULL;
1473 return (
PIX *)ERROR_PTR(
"y1 == y3!", __func__, NULL);
1475 return (
PIX *)ERROR_PTR(
"y1p == y3p!", __func__, NULL);
1477 if (bw != 0 || bh != 0) {
1493 return (
PIX *)ERROR_PTR(
"pix1 not made", __func__, NULL);
1510 th3 = atan2((l_float64)(x1 - x3), (l_float64)(y1 - y3));
1511 x2s = (l_float32)(x2 - ((l_float32)(y1 - y2) * (x3 - x1)) / (y1 - y3));
1512 if (x2s == (l_float32)x1) {
1513 L_ERROR(
"x2s == x1!\n", __func__);
1516 ph2 = atan2((l_float64)(y1 - y2), (l_float64)(x2s - x1));
1522 th3p = atan2((l_float64)(x1p - x3p), (l_float64)(y1p - y3p));
1523 x2sp = (l_float32)(x2p -
1524 ((l_float32)(y1p - y2p) * (x3p - x1p)) / (y1p - y3p));
1525 if (x2sp == (l_float32)x1p) {
1526 L_ERROR(
"x2sp == x1p!\n", __func__);
1529 ph2p = atan2((l_float64)(y1p - y2p), (l_float64)(x2sp - x1p));
1540 scalex = (l_float32)(x2sp - x1p) / (x2s - x1);
1541 scaley = (l_float32)(y3p - y1p) / (y3 - y1);
1542 if ((pix2 =
pixScale(pix1, scalex, scaley)) == NULL) {
1543 L_ERROR(
"pix2 not made\n", __func__);
1548 rad2deg = 180. / 3.1415926535;
1550 rad2deg * th3, rad2deg * ph2);
1551 lept_stderr(
"th3' = %5.1f deg, ph2' = %5.1f deg\n",
1552 rad2deg * th3p, rad2deg * ph2p);
1553 lept_stderr(
"scalex = %6.3f, scaley = %6.3f\n", scalex, scaley);
1567 x1sc = (l_int32)(scalex * x1 + 0.5);
1568 y1sc = (l_int32)(scaley * y1 + 0.5);
1576 if (bw != 0 || bh != 0) {
1578 L_ERROR(
"pixd not made\n", __func__);
PIX * pixAffineColor(PIX *pixs, l_float32 *vc, l_uint32 colorval)
pixAffineColor()
l_ok affineInvertXform(l_float32 *vc, l_float32 **pvci)
affineInvertXform()
PIX * pixAffineSequential(PIX *pixs, PTA *ptad, PTA *ptas, l_int32 bw, l_int32 bh)
pixAffineSequential()
l_ok affineXformSampledPt(l_float32 *vc, l_int32 x, l_int32 y, l_int32 *pxp, l_int32 *pyp)
affineXformSampledPt()
PIX * pixAffinePta(PIX *pixs, PTA *ptad, PTA *ptas, l_int32 incolor)
pixAffinePta()
l_ok linearInterpolatePixelColor(l_uint32 *datas, l_int32 wpls, l_int32 w, l_int32 h, l_float32 x, l_float32 y, l_uint32 colorval, l_uint32 *pval)
linearInterpolatePixelColor()
l_int32 gaussjordan(l_float32 **a, l_float32 *b, l_int32 n)
gaussjordan()
PIX * pixAffineGray(PIX *pixs, l_float32 *vc, l_uint8 grayval)
pixAffineGray()
PIX * pixAffinePtaGray(PIX *pixs, PTA *ptad, PTA *ptas, l_uint8 grayval)
pixAffinePtaGray()
PIX * pixAffine(PIX *pixs, l_float32 *vc, l_int32 incolor)
pixAffine()
l_ok linearInterpolatePixelGray(l_uint32 *datas, l_int32 wpls, l_int32 w, l_int32 h, l_float32 x, l_float32 y, l_int32 grayval, l_int32 *pval)
linearInterpolatePixelGray()
PIX * pixAffineSampledPta(PIX *pixs, PTA *ptad, PTA *ptas, l_int32 incolor)
pixAffineSampledPta()
l_ok affineXformPt(l_float32 *vc, l_int32 x, l_int32 y, l_float32 *pxp, l_float32 *pyp)
affineXformPt()
PIX * pixAffineSampled(PIX *pixs, l_float32 *vc, l_int32 incolor)
pixAffineSampled()
l_ok getAffineXformCoeffs(PTA *ptas, PTA *ptad, l_float32 **pvc)
getAffineXformCoeffs()
PIX * pixAffinePtaColor(PIX *pixs, PTA *ptad, PTA *ptas, l_uint32 colorval)
pixAffinePtaColor()
PIX * pixAffinePtaWithAlpha(PIX *pixs, PTA *ptad, PTA *ptas, PIX *pixg, l_float32 fract, l_int32 border)
pixAffinePtaWithAlpha()
#define GET_DATA_QBIT(pdata, n)
#define SET_DATA_DIBIT(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 GET_DATA_BIT(pdata, n)
#define SET_DATA_QBIT(pdata, n, val)
l_ok pixcmapAddBlackOrWhite(PIXCMAP *cmap, l_int32 color, l_int32 *pindex)
pixcmapAddBlackOrWhite()
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()
PIX * pixCreateTemplate(const PIX *pixs)
pixCreateTemplate()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
PIX * pixClone(PIX *pixs)
pixClone()
l_ok pixSetBorderRingVal(PIX *pixs, l_int32 dist, l_uint32 val)
pixSetBorderRingVal()
PIX * pixGetRGBComponent(PIX *pixs, l_int32 comp)
pixGetRGBComponent()
l_ok pixClearAll(PIX *pix)
pixClearAll()
PIX * pixRemoveBorderGeneral(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
pixRemoveBorderGeneral()
PIX * pixAddBorder(PIX *pixs, l_int32 npix, l_uint32 val)
pixAddBorder()
PIX * pixAddBorderGeneral(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot, l_uint32 val)
pixAddBorderGeneral()
l_ok pixSetAll(PIX *pix)
pixSetAll()
l_ok composeRGBPixel(l_int32 rval, l_int32 gval, l_int32 bval, l_uint32 *ppixel)
composeRGBPixel()
l_ok pixSetRGBComponent(PIX *pixd, PIX *pixs, l_int32 comp)
pixSetRGBComponent()
l_ok pixSetAllArbitrary(PIX *pix, l_uint32 val)
pixSetAllArbitrary()
PIX * pixResizeToMatch(PIX *pixs, PIX *pixt, l_int32 w, l_int32 h)
pixResizeToMatch()
@ REMOVE_CMAP_BASED_ON_SRC
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
PIX * pixConvertTo8(PIX *pixs, l_int32 cmapflag)
pixConvertTo8()
l_ok ptaGetIPt(PTA *pta, l_int32 index, l_int32 *px, l_int32 *py)
ptaGetIPt()
l_ok ptaGetPt(PTA *pta, l_int32 index, l_float32 *px, l_float32 *py)
ptaGetPt()
l_int32 ptaGetCount(PTA *pta)
ptaGetCount()
void ptaDestroy(PTA **ppta)
ptaDestroy()
PTA * ptaTransform(PTA *ptas, l_int32 shiftx, l_int32 shifty, l_float32 scalex, l_float32 scaley)
ptaTransform()
l_ok pixRasteropIP(PIX *pixd, l_int32 hshift, l_int32 vshift, l_int32 incolor)
pixRasteropIP()
PIX * pixScale(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScale()
l_ok pixHShearIP(PIX *pixs, l_int32 yloc, l_float32 radang, l_int32 incolor)
pixHShearIP()
l_ok pixVShearIP(PIX *pixs, l_int32 xloc, l_float32 radang, l_int32 incolor)
pixVShearIP()
void lept_stderr(const char *fmt,...)
lept_stderr()