148 #include <config_auto.h>
151 #include "allheaders.h"
153 static l_int32 blendComponents(l_int32 a, l_int32 b, l_float32 fract);
154 static l_int32 blendHardLightComponents(l_int32 a, l_int32 b, l_float32 fract);
182 l_int32 w1, h1, d1, d2;
184 PIX *pixc, *pixt, *pixd;
187 return (
PIX *)ERROR_PTR(
"pixs1 not defined", __func__, NULL);
189 return (
PIX *)ERROR_PTR(
"pixs2 not defined", __func__, NULL);
192 d1 = pixGetDepth(pixs1);
193 d2 = pixGetDepth(pixs2);
194 if (d1 == 1 && d2 > 1)
195 return (
PIX *)ERROR_PTR(
"mixing gray or color with 1 bpp",
200 d2 = pixGetDepth(pixt);
213 L_WARNING(
"box doesn't overlap pix\n", __func__);
223 }
else if (d2 == 8) {
271 l_int32 i, j, d, wc, hc, w, h, wplc;
272 l_int32 val, rval, gval, bval;
274 l_uint32 *linec, *datac;
275 PIX *pixc, *pix1, *pix2;
278 return (
PIX *)ERROR_PTR(
"pixs1 not defined", __func__, NULL);
280 return (
PIX *)ERROR_PTR(
"pixs2 not defined", __func__, NULL);
281 if (pixGetDepth(pixs1) == 1)
282 return (
PIX *)ERROR_PTR(
"pixs1 is 1 bpp", __func__, NULL);
283 if (pixGetDepth(pixs2) != 1)
284 return (
PIX *)ERROR_PTR(
"pixs2 not 1 bpp", __func__, NULL);
285 if (pixd == pixs1 && pixGetColormap(pixs1))
286 return (
PIX *)ERROR_PTR(
"inplace; pixs1 has colormap", __func__, NULL);
287 if (pixd && (pixd != pixs1))
288 return (
PIX *)ERROR_PTR(
"pixd must be NULL or pixs1", __func__, NULL);
289 if (fract < 0.0 || fract > 1.0) {
290 L_WARNING(
"fract must be in [0.0, 1.0]; setting to 0.5\n", __func__);
295 L_WARNING(
"invalid blend type; setting to L_BLEND_WITH_INVERSE\n",
307 if (pixGetDepth(pix1) < 8)
318 wc = pixGetWidth(pixc);
319 hc = pixGetHeight(pixc);
321 wplc = pixGetWpl(pixc);
334 for (i = 0; i < hc; i++) {
335 if (i + y < 0 || i + y >= h)
continue;
336 linec = datac + i * wplc;
337 for (j = 0; j < wc; j++) {
338 if (j + x < 0 || j + x >= w)
continue;
345 val = (l_int32)(pixval + fract * (255 - 2 * pixval));
351 rval = (l_int32)(rval + fract * (255 - 2 * rval));
352 gval = (l_int32)(gval + fract * (255 - 2 * gval));
353 bval = (l_int32)(bval + fract * (255 - 2 * bval));
358 L_WARNING(
"d neither 8 nor 32 bpp; no blend\n",
370 for (i = 0; i < hc; i++) {
371 if (i + y < 0 || i + y >= h)
continue;
372 linec = datac + i * wplc;
373 for (j = 0; j < wc; j++) {
374 if (j + x < 0 || j + x >= w)
continue;
381 val = (l_int32)(pixval + fract * (255 - pixval));
387 rval = (l_int32)(rval + fract * (255 - rval));
388 gval = (l_int32)(gval + fract * (255 - gval));
389 bval = (l_int32)(bval + fract * (255 - bval));
394 L_WARNING(
"d neither 8 nor 32 bpp; no blend\n",
406 for (i = 0; i < hc; i++) {
407 if (i + y < 0 || i + y >= h)
continue;
408 linec = datac + i * wplc;
409 for (j = 0; j < wc; j++) {
410 if (j + x < 0 || j + x >= w)
continue;
417 val = (l_int32)((1. - fract) * pixval);
423 rval = (l_int32)((1. - fract) * rval);
424 gval = (l_int32)((1. - fract) * gval);
425 bval = (l_int32)((1. - fract) * bval);
430 L_WARNING(
"d neither 8 nor 32 bpp; no blend\n",
438 L_WARNING(
"invalid binary mask blend type\n", __func__);
500 l_int32 i, j, d, wc, hc, w, h, wplc, wpld, delta;
501 l_int32 ival, irval, igval, ibval, cval, dval;
503 l_uint32 *linec, *lined, *datac, *datad;
504 PIX *pixc, *pix1, *pix2;
507 return (
PIX *)ERROR_PTR(
"pixs1 not defined", __func__, pixd);
509 return (
PIX *)ERROR_PTR(
"pixs2 not defined", __func__, pixd);
510 if (pixGetDepth(pixs1) == 1)
511 return (
PIX *)ERROR_PTR(
"pixs1 is 1 bpp", __func__, pixd);
512 if (pixd == pixs1 && pixGetColormap(pixs1))
513 return (
PIX *)ERROR_PTR(
"can't do in-place with cmap", __func__, pixd);
514 if (pixd && (pixd != pixs1))
515 return (
PIX *)ERROR_PTR(
"pixd must be NULL or pixs1", __func__, pixd);
516 if (fract < 0.0 || fract > 1.0) {
517 L_WARNING(
"fract must be in [0.0, 1.0]; setting to 0.5\n", __func__);
521 L_WARNING(
"invalid blend type; setting to L_BLEND_GRAY\n", __func__);
532 if (pixGetDepth(pix1) < 8)
542 wpld = pixGetWpl(pixd);
547 wplc = pixGetWpl(pixc);
556 for (i = 0; i < hc; i++) {
557 if (i + y < 0 || i + y >= h)
continue;
558 linec = datac + i * wplc;
559 lined = datad + (i + y) * wpld;
563 for (j = 0; j < wc; j++) {
564 if (j + x < 0 || j + x >= w)
continue;
566 if (transparent == 0 || cval != transpix) {
568 ival = (l_int32)((1. - fract) * dval + fract * cval);
574 for (j = 0; j < wc; j++) {
575 if (j + x < 0 || j + x >= w)
continue;
577 if (transparent == 0 || cval != transpix) {
578 val32 = *(lined + j + x);
580 irval = (l_int32)((1. - fract) * irval + fract * cval);
581 igval = (l_int32)((1. - fract) * igval + fract * cval);
582 ibval = (l_int32)((1. - fract) * ibval + fract * cval);
584 *(lined + j + x) = val32;
593 for (i = 0; i < hc; i++) {
594 if (i + y < 0 || i + y >= h)
continue;
595 linec = datac + i * wplc;
596 lined = datad + (i + y) * wpld;
610 for (j = 0; j < wc; j++) {
611 if (j + x < 0 || j + x >= w)
continue;
613 if (transparent == 0 || cval != transpix) {
615 delta = (128 - ival) * (255 - cval) / 256;
616 ival += (l_int32)(fract * delta + 0.5);
623 for (j = 0; j < wc; j++) {
624 if (j + x < 0 || j + x >= w)
continue;
626 if (transparent == 0 || cval != transpix) {
627 val32 = *(lined + j + x);
629 delta = (128 - irval) * (255 - cval) / 256;
630 irval += (l_int32)(fract * delta + 0.5);
631 delta = (128 - igval) * (255 - cval) / 256;
632 igval += (l_int32)(fract * delta + 0.5);
633 delta = (128 - ibval) * (255 - cval) / 256;
634 ibval += (l_int32)(fract * delta + 0.5);
636 *(lined + j + x) = val32;
695 l_int32 i, j, d, wc, hc, w, h, wplc, wpld;
696 l_int32 irval, igval, ibval, cval, dval;
699 l_uint32 *linec, *lined, *datac, *datad;
700 PIX *pixc, *pix1, *pix2;
703 return (
PIX *)ERROR_PTR(
"pixs1 not defined", __func__, pixd);
705 return (
PIX *)ERROR_PTR(
"pixs2 not defined", __func__, pixd);
706 if (pixGetDepth(pixs1) == 1)
707 return (
PIX *)ERROR_PTR(
"pixs1 is 1 bpp", __func__, pixd);
708 if (pixd == pixs1 && pixGetColormap(pixs1))
709 return (
PIX *)ERROR_PTR(
"can't do in-place with cmap", __func__, pixd);
710 if (pixd && (pixd != pixs1))
711 return (
PIX *)ERROR_PTR(
"pixd must be NULL or pixs1", __func__, pixd);
712 if (fract < 0.0 || fract > 1.0) {
713 L_WARNING(
"fract must be in [0.0, 1.0]; setting to 0.5\n", __func__);
724 if (pixGetDepth(pix1) < 8)
734 wpld = pixGetWpl(pixd);
739 wplc = pixGetWpl(pixc);
742 for (i = 0; i < hc; i++) {
743 if (i + y < 0 || i + y >= h)
continue;
744 linec = datac + i * wplc;
745 lined = datad + (i + y) * wpld;
749 for (j = 0; j < wc; j++) {
750 if (j + x < 0 || j + x >= w)
continue;
753 a = (1.0 - fract) * dval + fract * (255.0 - dval);
754 dval = (l_int32)(cval * dval / 255.0 +
755 a * (255.0 - cval) / 255.0);
760 for (j = 0; j < wc; j++) {
761 if (j + x < 0 || j + x >= w)
continue;
763 val32 = *(lined + j + x);
765 a = (1.0 - fract) * irval + fract * (255.0 - irval);
766 irval = (l_int32)(cval * irval / 255.0 +
767 a * (255.0 - cval) / 255.0);
768 a = (1.0 - fract) * igval + fract * (255.0 - igval);
769 igval = (l_int32)(cval * igval / 255.0 +
770 a * (255.0 - cval) / 255.0);
771 a = (1.0 - fract) * ibval + fract * (255.0 - ibval);
772 ibval = (l_int32)(cval * ibval / 255.0 +
773 a * (255.0 - cval) / 255.0);
775 *(lined + j + x) = val32;
829 l_int32 i, j, wc, hc, w, h, wplc, wpld;
830 l_int32 rval, gval, bval, rcval, gcval, bcval;
831 l_uint32 cval32, val32;
832 l_uint32 *linec, *lined, *datac, *datad;
836 return (
PIX *)ERROR_PTR(
"pixs1 not defined", __func__, NULL);
838 return (
PIX *)ERROR_PTR(
"pixs2 not defined", __func__, NULL);
839 if (pixGetDepth(pixs1) == 1)
840 return (
PIX *)ERROR_PTR(
"pixs1 is 1 bpp", __func__, NULL);
841 if (pixd == pixs1 && pixGetDepth(pixs1) != 32)
842 return (
PIX *)ERROR_PTR(
"inplace; pixs1 not 32 bpp", __func__, NULL);
843 if (pixd && (pixd != pixs1))
844 return (
PIX *)ERROR_PTR(
"pixd must be NULL or pixs1", __func__, NULL);
845 if (fract < 0.0 || fract > 1.0) {
846 L_WARNING(
"fract must be in [0.0, 1.0]; setting to 0.5\n", __func__);
858 wpld = pixGetWpl(pixd);
863 wplc = pixGetWpl(pixc);
866 for (i = 0; i < hc; i++) {
873 if (i + y < 0 || i + y >= h)
continue;
874 linec = datac + i * wplc;
875 lined = datad + (i + y) * wpld;
876 for (j = 0; j < wc; j++) {
877 if (j + x < 0 || j + x >= w)
continue;
878 cval32 = *(linec + j);
879 if (transparent == 0 ||
880 ((cval32 & 0xffffff00) != (transpix & 0xffffff00))) {
881 val32 = *(lined + j + x);
884 rval = (l_int32)((1. - fract) * rval + fract * rcval);
885 gval = (l_int32)((1. - fract) * gval + fract * gcval);
886 bval = (l_int32)((1. - fract) * bval + fract * bcval);
888 *(lined + j + x) = val32;
936 pixBlendColorByChannel(
PIX *pixd,
947 l_int32 i, j, wc, hc, w, h, wplc, wpld;
948 l_int32 rval, gval, bval, rcval, gcval, bcval;
949 l_uint32 cval32, val32;
950 l_uint32 *linec, *lined, *datac, *datad;
954 return (
PIX *)ERROR_PTR(
"pixs1 not defined", __func__, pixd);
956 return (
PIX *)ERROR_PTR(
"pixs2 not defined", __func__, pixd);
957 if (pixGetDepth(pixs1) == 1)
958 return (
PIX *)ERROR_PTR(
"pixs1 is 1 bpp", __func__, pixd);
959 if (pixd == pixs1 && pixGetDepth(pixs1) != 32)
960 return (
PIX *)ERROR_PTR(
"inplace; pixs1 not 32 bpp", __func__, pixd);
961 if (pixd && (pixd != pixs1))
962 return (
PIX *)ERROR_PTR(
"pixd must be NULL or pixs1", __func__, pixd);
972 wpld = pixGetWpl(pixd);
977 wplc = pixGetWpl(pixc);
980 for (i = 0; i < hc; i++) {
981 if (i + y < 0 || i + y >= h)
continue;
982 linec = datac + i * wplc;
983 lined = datad + (i + y) * wpld;
984 for (j = 0; j < wc; j++) {
985 if (j + x < 0 || j + x >= w)
continue;
986 cval32 = *(linec + j);
987 if (transparent == 0 ||
988 ((cval32 & 0xffffff00) != (transpix & 0xffffff00))) {
989 val32 = *(lined + j + x);
992 rval = blendComponents(rval, rcval, rfract);
993 gval = blendComponents(gval, gcval, gfract);
994 bval = blendComponents(bval, bcval, bfract);
996 *(lined + j + x) = val32;
1007 blendComponents(l_int32 a,
1012 return ((a < b) ? a : b);
1014 return ((a > b) ? a : b);
1015 return (l_int32)((1. - fract) * a + fract * b);
1072 l_int32 i, j, d, wc, hc, w, h, wplc, wpld, delta, overlap;
1073 l_int32 rval, gval, bval, cval, dval, mval, median, pivot;
1075 l_uint32 *linec, *lined, *datac, *datad;
1076 l_float32 fmedian, factor;
1078 PIX *pixc, *pix1, *pix2;
1081 return (
PIX *)ERROR_PTR(
"pixs1 not defined", __func__, pixd);
1083 return (
PIX *)ERROR_PTR(
"pixs2 not defined", __func__, pixd);
1084 if (pixGetDepth(pixs1) == 1)
1085 return (
PIX *)ERROR_PTR(
"pixs1 is 1 bpp", __func__, pixd);
1086 if (pixd == pixs1 && pixGetColormap(pixs1))
1087 return (
PIX *)ERROR_PTR(
"can't do in-place with cmap", __func__, pixd);
1088 if (pixd && (pixd != pixs1))
1089 return (
PIX *)ERROR_PTR(
"pixd must be NULL or pixs1", __func__, pixd);
1090 if (fract < 0.0 || fract > 1.0) {
1091 L_WARNING(
"fract must be in [0.0, 1.0]; setting to 0.5\n", __func__);
1094 if (shift == -1) shift = 64;
1095 if (shift < 0 || shift > 127) {
1096 L_WARNING(
"invalid shift; setting to 64\n", __func__);
1109 return (
PIX *)ERROR_PTR(
"no image overlap", __func__, pixd);
1119 if (pixGetDepth(pix1) < 8)
1132 median = (l_int32)(fmedian + 0.5);
1134 pivot = median + shift;
1136 pivot = median - shift;
1142 d = pixGetDepth(pixd);
1143 wpld = pixGetWpl(pixd);
1147 wplc = pixGetWpl(pixc);
1148 for (i = 0; i < hc; i++) {
1149 if (i + y < 0 || i + y >= h)
continue;
1150 linec = datac + i * wplc;
1151 lined = datad + (i + y) * wpld;
1166 for (j = 0; j < wc; j++) {
1167 if (j + x < 0 || j + x >= w)
continue;
1170 delta = (pivot - dval) * (255 - cval) / 256;
1171 dval += (l_int32)(fract * delta + 0.5);
1189 for (j = 0; j < wc; j++) {
1190 if (j + x < 0 || j + x >= w)
continue;
1192 val32 = *(lined + j + x);
1194 mval = L_MAX(rval, gval);
1195 mval = L_MAX(mval, bval);
1196 mval = L_MAX(mval, 1);
1197 delta = (pivot - mval) * (255 - cval) / 256;
1198 factor = fract * delta / mval;
1199 rval += (l_int32)(factor * rval + 0.5);
1200 gval += (l_int32)(factor * gval + 0.5);
1201 bval += (l_int32)(factor * bval + 0.5);
1203 *(lined + j + x) = val32;
1241 l_int32 i, j, w, h, d, wb, hb, db, wd, hd, wplb, wpld;
1242 l_int32 valb, vald, nvald, rval, gval, bval, nrval, ngval, nbval;
1243 l_float32 nfactor, fract;
1244 l_uint32 val32, nval32;
1245 l_uint32 *lined, *datad, *lineb, *datab;
1249 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1251 return (
PIX *)ERROR_PTR(
"pixb not defined", __func__, NULL);
1252 if (pixGetDepth(pixs) == 1)
1253 return (
PIX *)ERROR_PTR(
"pixs is 1 bpp", __func__, NULL);
1256 return (
PIX *)ERROR_PTR(
"pixb not 8 bpp", __func__, NULL);
1257 if (factor < 0.0 || factor > 255.0)
1258 return (
PIX *)ERROR_PTR(
"factor not in [0.0...255.0]", __func__, NULL);
1260 return (
PIX *)ERROR_PTR(
"invalid fade type", __func__, NULL);
1268 wpld = pixGetWpl(pixd);
1270 wplb = pixGetWpl(pixb);
1277 nfactor = factor / 255.;
1278 for (i = 0; i < h; i++) {
1279 lineb = datab + i * wplb;
1280 lined = datad + i * wpld;
1281 for (j = 0; j < w; j++) {
1283 fract = nfactor * (l_float32)valb;
1284 fract = L_MIN(fract, 1.0);
1288 nvald = vald + (l_int32)(fract * (255. - (l_float32)vald));
1290 nvald = vald - (l_int32)(fract * (l_float32)vald);
1296 nrval = rval + (l_int32)(fract * (255. - (l_float32)rval));
1297 ngval = gval + (l_int32)(fract * (255. - (l_float32)gval));
1298 nbval = bval + (l_int32)(fract * (255. - (l_float32)bval));
1300 nrval = rval - (l_int32)(fract * (l_float32)rval);
1301 ngval = gval - (l_int32)(fract * (l_float32)gval);
1302 nbval = bval - (l_int32)(fract * (l_float32)bval);
1350 pixBlendHardLight(
PIX *pixd,
1357 l_int32 i, j, w, h, d, wc, hc, dc, wplc, wpld;
1358 l_int32 cval, dval, rcval, gcval, bcval, rdval, gdval, bdval;
1359 l_uint32 cval32, dval32;
1360 l_uint32 *linec, *lined, *datac, *datad;
1364 return (
PIX *)ERROR_PTR(
"pixs1 not defined", __func__, pixd);
1366 return (
PIX *)ERROR_PTR(
"pixs2 not defined", __func__, pixd);
1370 return (
PIX *)ERROR_PTR(
"pixs1 is 1 bpp", __func__, pixd);
1371 if (dc != 8 && dc != 32)
1372 return (
PIX *)ERROR_PTR(
"pixs2 not 8 or 32 bpp", __func__, pixd);
1373 if (pixd && (pixd != pixs1))
1374 return (
PIX *)ERROR_PTR(
"inplace and pixd != pixs1", __func__, pixd);
1375 if (pixd == pixs1 && pixGetColormap(pixs1))
1376 return (
PIX *)ERROR_PTR(
"inplace and pixs1 cmapped", __func__, pixd);
1377 if (pixd && d != 8 && d != 32)
1378 return (
PIX *)ERROR_PTR(
"inplace and not 8 or 32 bpp", __func__, pixd);
1380 if (fract < 0.0 || fract > 1.0) {
1381 L_WARNING(
"fract must be in [0.0, 1.0]; setting to 0.5\n", __func__);
1387 dc = pixGetDepth(pixc);
1395 if (pixGetColormap(pixs1)) {
1408 if (pixGetColormap(pixs1))
1412 d = pixGetDepth(pixd);
1415 if (!(d == 8 && dc == 8) &&
1416 !(d == 32 && dc == 8) &&
1417 !(d == 32 && dc == 32)) {
1419 return (
PIX *)ERROR_PTR(
"bad! -- invalid depth combo!", __func__, pixd);
1422 wpld = pixGetWpl(pixd);
1425 wplc = pixGetWpl(pixc);
1426 for (i = 0; i < hc; i++) {
1427 if (i + y < 0 || i + y >= h)
continue;
1428 linec = datac + i * wplc;
1429 lined = datad + (i + y) * wpld;
1430 for (j = 0; j < wc; j++) {
1431 if (j + x < 0 || j + x >= w)
continue;
1432 if (d == 8 && dc == 8) {
1435 dval = blendHardLightComponents(dval, cval, fract);
1437 }
else if (d == 32 && dc == 8) {
1438 dval32 = *(lined + x + j);
1441 rdval = blendHardLightComponents(rdval, cval, fract);
1442 gdval = blendHardLightComponents(gdval, cval, fract);
1443 bdval = blendHardLightComponents(bdval, cval, fract);
1445 *(lined + x + j) = dval32;
1446 }
else if (d == 32 && dc == 32) {
1447 dval32 = *(lined + x + j);
1449 cval32 = *(linec + j);
1451 rdval = blendHardLightComponents(rdval, rcval, fract);
1452 gdval = blendHardLightComponents(gdval, gcval, fract);
1453 bdval = blendHardLightComponents(bdval, bcval, fract);
1455 *(lined + x + j) = dval32;
1512 static l_int32 blendHardLightComponents(l_int32 a,
1517 b = 0x80 - (l_int32)(fract * (0x80 - b));
1518 return (a * b) >> 7;
1520 b = 0x80 + (l_int32)(fract * (b - 0x80));
1521 return 0xff - (((0xff - b) * (0xff - a)) >> 7);
1563 l_int32 rval, gval, bval;
1564 l_int32 i, j, w, h, d, ncb, wb, hb, wpls;
1565 l_int32 index, val, nadded;
1568 l_uint32 *lines, *datas;
1569 PIXCMAP *cmaps, *cmapb, *cmapsc;
1572 return ERROR_INT(
"pixs not defined", __func__, 1);
1574 return ERROR_INT(
"pixb not defined", __func__, 1);
1575 if ((cmaps = pixGetColormap(pixs)) == NULL)
1576 return ERROR_INT(
"no colormap in pixs", __func__, 1);
1577 if ((cmapb = pixGetColormap(pixb)) == NULL)
1578 return ERROR_INT(
"no colormap in pixb", __func__, 1);
1582 if (d != 2 && d != 4 && d != 8)
1583 return ERROR_INT(
"depth not in {2,4,8}", __func__, 1);
1592 for (i = 0, nadded = 0; i < ncb; i++) {
1597 return ERROR_INT(
"not enough room in cmaps", __func__, 1);
1615 wpls = pixGetWpl(pixs);
1617 for (i = 0; i < hb; i++) {
1618 if (i + y < 0 || i + y >= h)
continue;
1619 lines = datas + (y + i) * wpls;
1620 for (j = 0; j < wb; j++) {
1621 if (j + x < 0 || j + x >= w)
continue;
1625 if (val == sindex) {
1632 if (val == sindex) {
1639 if (val == sindex) {
1645 return ERROR_INT(
"depth not in {2,4,8}", __func__, 1);
1698 l_int32 w1, h1, d1, w2, h2, d2, spp, wg, hg, wmin, hmin, wpld, wpls, wplg;
1699 l_int32 i, j, val, dval, sval;
1700 l_int32 drval, dgval, dbval, srval, sgval, sbval;
1701 l_uint32 dval32, sval32;
1702 l_uint32 *datad, *datas, *datag, *lined, *lines, *lineg;
1704 PIX *pixr1, *pixr2, *pix1, *pix2, *pixg2, *pixd;
1707 return (
PIX *)ERROR_PTR(
"pixs1 not defined", __func__, NULL);
1709 return (
PIX *)ERROR_PTR(
"pixs2 not defined", __func__, NULL);
1712 if (d1 == 1 || d2 == 1)
1713 return (
PIX *)ERROR_PTR(
"pixs1 or pixs2 is 1 bpp", __func__, NULL);
1715 if (pixGetDepth(pixg) != 8)
1716 return (
PIX *)ERROR_PTR(
"pixg not 8 bpp", __func__, NULL);
1718 wmin = L_MIN(w2, wg);
1719 hmin = L_MIN(h2, hg);
1722 spp = pixGetSpp(pixs2);
1723 if (d2 != 32 || spp != 4)
1724 return (
PIX *)ERROR_PTR(
"no alpha; pixs2 not rgba", __func__, NULL);
1735 d1 = pixGetDepth(pixr1);
1736 d2 = pixGetDepth(pixr2);
1743 }
else if (d2 == 32) {
1758 d1 = pixGetDepth(pixd);
1759 d2 = pixGetDepth(pix2);
1760 if (!pixd || d1 != d2 || (d1 != 8 && d1 != 32)) {
1764 return (
PIX *)ERROR_PTR(
"depths not regularized! bad!", __func__, NULL);
1777 wpld = pixGetWpl(pixd);
1778 wpls = pixGetWpl(pix2);
1779 wplg = pixGetWpl(pixg2);
1780 for (i = 0; i < hmin; i++) {
1781 if (i + y < 0 || i + y >= h1)
continue;
1782 lined = datad + (i + y) * wpld;
1783 lines = datas + i * wpls;
1784 lineg = datag + i * wplg;
1785 for (j = 0; j < wmin; j++) {
1786 if (j + x < 0 || j + x >= w1)
continue;
1788 if (val == 0)
continue;
1789 fract = (l_float32)val / 255.;
1793 dval = (l_int32)((1.0 - fract) * dval + fract * sval);
1796 dval32 = *(lined + j + x);
1797 sval32 = *(lines + j);
1800 drval = (l_int32)((1.0 - fract) * drval + fract * srval);
1801 dgval = (l_int32)((1.0 - fract) * dgval + fract * sgval);
1802 dbval = (l_int32)((1.0 - fract) * dbval + fract * sbval);
1804 *(lined + j + x) = dval32;
1854 PIX *pixt, *pixc, *pixr, *pixg;
1857 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, pixd);
1858 if (pixGetDepth(pixs) != 32)
1859 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, pixd);
1860 if (pixd && (pixd != pixs))
1861 return (
PIX *)ERROR_PTR(
"pixd neither null nor pixs", __func__, pixd);
1927 l_int32 i, j, bx, by, w, h, wpl;
1928 l_int32 red, green, blue, rval, gval, bval, nrval, ngval, nbval;
1929 l_float32 frval, fgval, fbval;
1930 l_uint32 *data, *line;
1934 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, pixd);
1935 if (pixGetDepth(pixs) != 32)
1936 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, pixd);
1937 if (pixd && (pixd != pixs))
1938 return (
PIX *)ERROR_PTR(
"pixd neither null nor pixs", __func__, pixd);
1951 frval = (1. / 255.) * red;
1952 fgval = (1. / 255.) * green;
1953 fbval = (1. / 255.) * blue;
1955 wpl = pixGetWpl(pixt);
1957 for (i = 0; i < h; i++) {
1958 line = data + i * wpl;
1959 for (j = 0; j < w; j++) {
1961 nrval = (l_int32)(frval * rval + 0.5);
1962 ngval = (l_int32)(fgval * gval + 0.5);
1963 nbval = (l_int32)(fbval * bval + 0.5);
2004 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2005 if (pixGetDepth(pixs) != 32)
2006 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, NULL);
2007 if (pixGetSpp(pixs) != 4) {
2008 L_WARNING(
"no alpha channel; returning clone\n", __func__);
2053 PIX *pixd, *pix1, *pix2;
2056 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2057 if (fract < 0.0 || fract > 1.0)
2058 return (
PIX *)ERROR_PTR(
"invalid fract", __func__, NULL);
2061 if (pixGetColormap(pixs))
2108 PIX *pixd, *pix1, *pix2, *pix3, *pix4;
2111 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2112 if (!(pixGetDepth(pixs) == 32 || pixGetColormap(pixs)))
2113 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp or cmapped", __func__, NULL);
2169 l_float32 distfract,
2172 l_int32 i, j, w, h, d, wpl, xmin, ymin, range, val, rval, gval, bval;
2173 l_float32 slope, limit, del;
2174 l_uint32 *data, *line;
2177 return ERROR_INT(
"pixs not defined", __func__, 1);
2178 if (pixGetColormap(pixs) != NULL)
2179 return ERROR_INT(
"pixs has a colormap", __func__, 1);
2181 if (d != 8 && d != 32)
2182 return ERROR_INT(
"pixs not 8 or 32 bpp", __func__, 1);
2185 return ERROR_INT(
"invalid fade direction from edge", __func__, 1);
2187 return ERROR_INT(
"invalid fadeto photometry", __func__, 1);
2188 if (maxfade <= 0)
return 0;
2190 return ERROR_INT(
"invalid maxfade", __func__, 1);
2191 if (distfract <= 0 || distfract * L_MIN(w, h) < 1.0) {
2192 L_INFO(
"distfract is too small\n", __func__);
2195 if (distfract > 1.0)
2196 return ERROR_INT(
"invalid distfract", __func__, 1);
2200 range = (l_int32)(distfract * w);
2202 slope = maxfade / (l_float32)range;
2204 range = (l_int32)(distfract * w);
2206 slope = maxfade / (l_float32)range;
2208 range = (l_int32)(distfract * h);
2210 slope = maxfade / (l_float32)range;
2212 range = (l_int32)(distfract * h);
2214 slope = maxfade / (l_float32)range;
2219 wpl = pixGetWpl(pixs);
2221 for (j = 0; j < range; j++) {
2223 : maxfade - slope * (range - j);
2224 for (i = 0; i < h; i++) {
2225 line = data + i * wpl;
2228 val += (limit - val) * del + 0.5;
2232 rval += (limit - rval) * del + 0.5;
2233 gval += (limit - gval) * del + 0.5;
2234 bval += (limit - bval) * del + 0.5;
2240 for (i = 0; i < range; i++) {
2241 del = (dir ==
L_FROM_TOP) ? maxfade - slope * i
2242 : maxfade - slope * (range - i);
2243 line = data + (ymin + i) * wpl;
2244 for (j = 0; j < w; j++) {
2247 val += (limit - val) * del + 0.5;
2251 rval += (limit - rval) * del + 0.5;
2252 gval += (limit - gval) * del + 0.5;
2253 bval += (limit - bval) * del + 0.5;
#define GET_DATA_QBIT(pdata, n)
#define SET_DATA_DIBIT(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)
PIX * pixAlphaBlendUniform(PIX *pixs, l_uint32 color)
pixAlphaBlendUniform()
PIX * pixBlendGrayAdapt(PIX *pixd, PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 fract, l_int32 shift)
pixBlendGrayAdapt()
PIX * pixBlendColor(PIX *pixd, PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 fract, l_int32 transparent, l_uint32 transpix)
pixBlendColor()
PIX * pixMultiplyByColor(PIX *pixd, PIX *pixs, BOX *box, l_uint32 color)
pixMultiplyByColor()
PIX * pixBlendGray(PIX *pixd, PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 fract, l_int32 type, l_int32 transparent, l_uint32 transpix)
pixBlendGray()
PIX * pixBlendWithGrayMask(PIX *pixs1, PIX *pixs2, PIX *pixg, l_int32 x, l_int32 y)
pixBlendWithGrayMask()
l_ok pixLinearEdgeFade(PIX *pixs, l_int32 dir, l_int32 fadeto, l_float32 distfract, l_float32 maxfade)
pixLinearEdgeFade()
PIX * pixAddAlphaToBlend(PIX *pixs, l_float32 fract, l_int32 invert)
pixAddAlphaToBlend()
PIX * pixFadeWithGray(PIX *pixs, PIX *pixb, l_float32 factor, l_int32 type)
pixFadeWithGray()
PIX * pixSetAlphaOverWhite(PIX *pixs)
pixSetAlphaOverWhite()
PIX * pixBlendMask(PIX *pixd, PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 fract, l_int32 type)
pixBlendMask()
PIX * pixBlend(PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 fract)
pixBlend()
PIX * pixBlendGrayInverse(PIX *pixd, PIX *pixs1, PIX *pixs2, l_int32 x, l_int32 y, l_float32 fract)
pixBlendGrayInverse()
PIX * pixBlendBackgroundToColor(PIX *pixd, PIX *pixs, BOX *box, l_uint32 color, l_float32 gamma, l_int32 minval, l_int32 maxval)
pixBlendBackgroundToColor()
l_ok pixBlendCmap(PIX *pixs, PIX *pixb, l_int32 x, l_int32 y, l_int32 sindex)
pixBlendCmap()
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 * boxCreate(l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxCreate()
l_ok boxIntersects(BOX *box1, BOX *box2, l_int32 *presult)
boxIntersects()
void pixcmapDestroy(PIXCMAP **pcmap)
pixcmapDestroy()
l_int32 pixcmapGetCount(const PIXCMAP *cmap)
pixcmapGetCount()
l_int32 pixcmapGetIndex(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
pixcmapGetIndex()
l_ok pixcmapGetColor(PIXCMAP *cmap, l_int32 index, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
pixcmapGetColor()
PIXCMAP * pixcmapCopy(const PIXCMAP *cmaps)
pixcmapCopy()
l_ok pixcmapAddColor(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval)
pixcmapAddColor()
PIX * pixGammaTRC(PIX *pixd, PIX *pixs, l_float32 gamma, l_int32 minval, l_int32 maxval)
pixGammaTRC()
PIX * pixThresholdToBinary(PIX *pixs, l_int32 thresh)
pixThresholdToBinary()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
l_ok pixSetColormap(PIX *pix, PIXCMAP *colormap)
pixSetColormap()
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()
l_ok pixTransferAllData(PIX *pixd, PIX **ppixs, l_int32 copytext, l_int32 copyformat)
pixTransferAllData()
PIX * pixCreateTemplate(const PIX *pixs)
pixCreateTemplate()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
PIX * pixClone(PIX *pixs)
pixClone()
PIX * pixGetRGBComponent(PIX *pixs, l_int32 comp)
pixGetRGBComponent()
l_ok pixSetPixel(PIX *pix, l_int32 x, l_int32 y, l_uint32 val)
pixSetPixel()
l_ok pixGetPixel(PIX *pix, l_int32 x, l_int32 y, l_uint32 *pval)
pixGetPixel()
l_ok composeRGBPixel(l_int32 rval, l_int32 gval, l_int32 bval, l_uint32 *ppixel)
composeRGBPixel()
void extractRGBValues(l_uint32 pixel, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
extractRGBValues()
l_ok pixSetRGBComponent(PIX *pixd, PIX *pixs, l_int32 comp)
pixSetRGBComponent()
l_ok pixSetAllArbitrary(PIX *pix, l_uint32 val)
pixSetAllArbitrary()
PIX * pixInvert(PIX *pixd, PIX *pixs)
pixInvert()
l_ok pixGetRankValueMasked(PIX *pixs, PIX *pixm, l_int32 x, l_int32 y, l_int32 factor, l_float32 rank, l_float32 *pval, NUMA **pna)
pixGetRankValueMasked()
PIX * pixClipRectangle(PIX *pixs, BOX *box, BOX **pboxc)
pixClipRectangle()
@ L_BLEND_GRAY_WITH_INVERSE
@ REMOVE_CMAP_TO_FULL_COLOR
@ REMOVE_CMAP_BASED_ON_SRC
l_ok pixMultConstantGray(PIX *pixs, l_float32 val)
pixMultConstantGray()
PIX * pixConvertRGBToGrayMinMax(PIX *pixs, l_int32 type)
pixConvertRGBToGrayMinMax()
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
PIX * pixConvertTo8(PIX *pixs, l_int32 cmapflag)
pixConvertTo8()
PIX * pixRemoveColormapGeneral(PIX *pixs, l_int32 type, l_int32 ifnocmap)
pixRemoveColormapGeneral()
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()
PIX * pixDistanceFunction(PIX *pixs, l_int32 connectivity, l_int32 outdepth, l_int32 boundcond)
pixDistanceFunction()