92 #include <config_auto.h>
97 #include "allheaders.h"
122 l_int32 i, j, w, h, d, wpl, pval;
123 l_uint32 *data, *line;
126 return ERROR_INT(
"pixs not defined", __func__, 1);
128 if (d != 8 && d != 16 && d != 32)
129 return ERROR_INT(
"pixs not 8, 16 or 32 bpp", __func__, 1);
132 wpl = pixGetWpl(pixs);
133 for (i = 0; i < h; i++) {
134 line = data + i * wpl;
137 for (j = 0; j < w; j++) {
139 pval = L_MAX(0, pval + val);
143 for (j = 0; j < w; j++) {
145 pval = L_MIN(255, pval + val);
149 }
else if (d == 16) {
151 for (j = 0; j < w; j++) {
153 pval = L_MAX(0, pval + val);
157 for (j = 0; j < w; j++) {
159 pval = L_MIN(0xffff, pval + val);
164 for (j = 0; j < w; j++)
191 l_int32 i, j, w, h, d, wpl, pval;
193 l_uint32 *data, *line;
196 return ERROR_INT(
"pixs not defined", __func__, 1);
198 if (d != 8 && d != 16 && d != 32)
199 return ERROR_INT(
"pixs not 8, 16 or 32 bpp", __func__, 1);
201 return ERROR_INT(
"val < 0.0", __func__, 1);
204 wpl = pixGetWpl(pixs);
205 for (i = 0; i < h; i++) {
206 line = data + i * wpl;
208 for (j = 0; j < w; j++) {
210 pval = (l_int32)(val * pval);
211 pval = L_MIN(255, pval);
214 }
else if (d == 16) {
215 for (j = 0; j < w; j++) {
217 pval = (l_int32)(val * pval);
218 pval = L_MIN(0xffff, pval);
222 for (j = 0; j < w; j++) {
224 upval = (l_uint32)(val * upval);
265 l_int32 i, j, d, ws, hs, w, h, wpls, wpld, val, sum;
266 l_uint32 *datas, *datad, *lines, *lined;
269 return (
PIX *)ERROR_PTR(
"pixs1 not defined", __func__, pixd);
271 return (
PIX *)ERROR_PTR(
"pixs2 not defined", __func__, pixd);
273 return (
PIX *)ERROR_PTR(
"pixs2 and pixs1 must differ", __func__, pixd);
275 return (
PIX *)ERROR_PTR(
"pixs2 and pixd must differ", __func__, pixd);
276 d = pixGetDepth(pixs1);
277 if (d != 8 && d != 16 && d != 32)
278 return (
PIX *)ERROR_PTR(
"pix are not 8, 16 or 32 bpp", __func__, pixd);
279 if (pixGetDepth(pixs2) != d)
280 return (
PIX *)ERROR_PTR(
"depths differ (pixs1, pixs2)", __func__, pixd);
281 if (pixd && (pixGetDepth(pixd) != d))
282 return (
PIX *)ERROR_PTR(
"depths differ (pixs1, pixd)", __func__, pixd);
285 L_WARNING(
"pixs1 and pixs2 not equal in size\n", __func__);
287 L_WARNING(
"pixs1 and pixd not equal in size\n", __func__);
295 wpls = pixGetWpl(pixs2);
296 wpld = pixGetWpl(pixd);
301 for (i = 0; i < h; i++) {
302 lined = datad + i * wpld;
303 lines = datas + i * wpls;
305 for (j = 0; j < w; j++) {
307 val = L_MIN(sum, 255);
310 }
else if (d == 16) {
311 for (j = 0; j < w; j++) {
314 val = L_MIN(sum, 0xffff);
318 for (j = 0; j < w; j++)
319 *(lined + j) += *(lines + j);
355 l_int32 i, j, w, h, ws, hs, d, wpls, wpld, val, diff;
356 l_uint32 *datas, *datad, *lines, *lined;
359 return (
PIX *)ERROR_PTR(
"pixs1 not defined", __func__, pixd);
361 return (
PIX *)ERROR_PTR(
"pixs2 not defined", __func__, pixd);
363 return (
PIX *)ERROR_PTR(
"pixs2 and pixs1 must differ", __func__, pixd);
365 return (
PIX *)ERROR_PTR(
"pixs2 and pixd must differ", __func__, pixd);
366 d = pixGetDepth(pixs1);
367 if (d != 8 && d != 16 && d != 32)
368 return (
PIX *)ERROR_PTR(
"pix are not 8, 16 or 32 bpp", __func__, pixd);
369 if (pixGetDepth(pixs2) != d)
370 return (
PIX *)ERROR_PTR(
"depths differ (pixs1, pixs2)", __func__, pixd);
371 if (pixd && (pixGetDepth(pixd) != d))
372 return (
PIX *)ERROR_PTR(
"depths differ (pixs1, pixd)", __func__, pixd);
375 L_WARNING(
"pixs1 and pixs2 not equal in size\n", __func__);
377 L_WARNING(
"pixs1 and pixd not equal in size\n", __func__);
385 wpls = pixGetWpl(pixs2);
386 wpld = pixGetWpl(pixd);
391 for (i = 0; i < h; i++) {
392 lined = datad + i * wpld;
393 lines = datas + i * wpls;
395 for (j = 0; j < w; j++) {
397 val = L_MAX(diff, 0);
400 }
else if (d == 16) {
401 for (j = 0; j < w; j++) {
404 val = L_MAX(diff, 0);
408 for (j = 0; j < w; j++)
409 *(lined + j) -= *(lines + j);
445 l_int32 i, j, w, h, d, ws, hs, ds, wpls, wplg, wpld;
446 l_int32 rval, gval, bval, rval2, gval2, bval2, vals, valg, val, maxgray;
448 l_uint32 *datas, *datag, *datad, *lines, *lineg, *lined;
452 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
454 if (ds != 8 && ds != 32)
455 return (
PIX *)ERROR_PTR(
"pixs not 8 or 32 bpp", __func__, NULL);
457 return (
PIX *)ERROR_PTR(
"pixg not defined", __func__, NULL);
460 return (
PIX *)ERROR_PTR(
"pixg not 8 bpp", __func__, NULL);
464 norm = (maxgray > 0) ? 1.0 / (l_float32)maxgray : 1.0;
468 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
472 wpls = pixGetWpl(pixs);
473 wplg = pixGetWpl(pixg);
474 wpld = pixGetWpl(pixd);
477 for (i = 0; i < h; i++) {
478 lines = datas + i * wpls;
479 lineg = datag + i * wplg;
480 lined = datad + i * wpld;
482 for (j = 0; j < w; j++) {
485 val = (l_int32)(vals * valg * norm + 0.5);
486 val = L_MIN(255, val);
490 for (j = 0; j < w; j++) {
491 val32 = *(lines + j);
494 rval2 = (l_int32)(rval * valg * norm + 0.5);
495 rval2 = L_MIN(255, rval2);
496 gval2 = (l_int32)(gval * valg * norm + 0.5);
497 gval2 = L_MIN(255, gval2);
498 bval2 = (l_int32)(bval * valg * norm + 0.5);
499 bval2 = L_MIN(255, bval2);
535 l_int32 i, j, w, h, d, wpld, setabove;
536 l_uint32 *datad, *lined;
539 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, pixd);
540 d = pixGetDepth(pixs);
541 if (d != 8 && d != 16 && d != 32)
542 return (
PIX *)ERROR_PTR(
"pixs not 8, 16 or 32 bpp", __func__, pixd);
543 if (pixd && (pixs != pixd))
544 return (
PIX *)ERROR_PTR(
"pixd exists and is not pixs", __func__, pixd);
545 if (threshval < 0 || setval < 0)
546 return (
PIX *)ERROR_PTR(
"threshval & setval not < 0", __func__, pixd);
547 if (d == 8 && setval > 255)
548 return (
PIX *)ERROR_PTR(
"setval > 255 for 8 bpp", __func__, pixd);
549 if (d == 16 && setval > 0xffff)
550 return (
PIX *)ERROR_PTR(
"setval > 0xffff for 16 bpp", __func__, pixd);
554 if (setval == threshval) {
555 L_WARNING(
"setval == threshval; no operation\n", __func__);
561 wpld = pixGetWpl(pixd);
562 if (setval > threshval)
567 for (i = 0; i < h; i++) {
568 lined = datad + i * wpld;
569 if (setabove == TRUE) {
571 for (j = 0; j < w; j++) {
575 }
else if (d == 16) {
576 for (j = 0; j < w; j++) {
581 for (j = 0; j < w; j++) {
582 if (*(lined + j) >= threshval)
583 *(lined + j) = setval;
588 for (j = 0; j < w; j++) {
592 }
else if (d == 16) {
593 for (j = 0; j < w; j++) {
598 for (j = 0; j < w; j++) {
599 if (*(lined + j) <= threshval)
600 *(lined + j) = setval;
643 if ((pixd =
pixCreate(w, h, 32)) == NULL)
644 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
645 if (offset > 0x40000000)
673 l_int32 i, j, w, h, wpls, wpld, val;
674 l_uint32 *datas, *datad, *lines, *lined;
678 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
679 if (pixGetDepth(pixs) != 32)
680 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, NULL);
681 if (depth != 8 && depth != 16 && depth != 32)
682 return (
PIX *)ERROR_PTR(
"dest depth not 8, 16, 32 bpp", __func__, NULL);
683 if (offset > 0x40000000)
687 if ((pixd =
pixCreate(w, h, depth)) == NULL)
688 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
689 pixCopyResolution(pixd, pixs);
692 wpls = pixGetWpl(pixs);
693 wpld = pixGetWpl(pixd);
695 for (i = 0; i < h; i++) {
696 lines = datas + i * wpls;
697 lined = datad + i * wpld;
698 for (j = 0; j < w; j++) {
699 val = lines[j] - offset;
701 val = L_MIN(255, val);
705 }
else if (depth == 16) {
706 for (i = 0; i < h; i++) {
707 lines = datas + i * wpls;
708 lined = datad + i * wpld;
709 for (j = 0; j < w; j++) {
710 val = lines[j] - offset;
712 val = L_MIN(0xffff, val);
717 for (i = 0; i < h; i++) {
718 lines = datas + i * wpls;
719 lined = datad + i * wpld;
720 for (j = 0; j < w; j++)
721 lined[j] = lines[j] - offset;
748 l_int32 i, j, w, h, wpls, wpld, val;
749 l_uint32 *datas, *datad, *lines, *lined;
753 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
754 if (pixGetDepth(pixs) != 32)
755 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, NULL);
756 if (offset > 0x40000000)
761 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
762 pixCopyResolution(pixd, pixs);
765 wpls = pixGetWpl(pixs);
766 wpld = pixGetWpl(pixd);
767 for (i = 0; i < h; i++) {
768 lines = datas + i * wpls;
769 lined = datad + i * wpld;
770 for (j = 0; j < w; j++) {
771 val = lines[j] - offset;
772 if (val >= threshold) {
803 l_int32 i, j, w, h, d, wd, hd, wpls, wpld;
804 l_uint32 *datas, *datad, *lines, *lined;
807 if (!pixd || (pixGetDepth(pixd) != 32))
808 return ERROR_INT(
"pixd not defined or not 32 bpp", __func__, 1);
810 return ERROR_INT(
"pixs not defined", __func__, 1);
811 d = pixGetDepth(pixs);
812 if (d != 1 && d != 8 && d != 16 && d != 32)
813 return ERROR_INT(
"pixs not 1, 8, 16 or 32 bpp", __func__, 1);
814 if (op != L_ARITH_ADD && op != L_ARITH_SUBTRACT)
815 return ERROR_INT(
"op must be in {L_ARITH_ADD, L_ARITH_SUBTRACT}",
820 wpls = pixGetWpl(pixs);
821 wpld = pixGetWpl(pixd);
827 for (i = 0; i < h; i++) {
828 lines = datas + i * wpls;
829 lined = datad + i * wpld;
830 if (op == L_ARITH_ADD) {
831 for (j = 0; j < w; j++)
834 for (j = 0; j < w; j++)
839 for (i = 0; i < h; i++) {
840 lines = datas + i * wpls;
841 lined = datad + i * wpld;
842 if (op == L_ARITH_ADD) {
843 for (j = 0; j < w; j++)
846 for (j = 0; j < w; j++)
850 }
else if (d == 16) {
851 for (i = 0; i < h; i++) {
852 lines = datas + i * wpls;
853 lined = datad + i * wpld;
854 if (op == L_ARITH_ADD) {
855 for (j = 0; j < w; j++)
858 for (j = 0; j < w; j++)
863 for (i = 0; i < h; i++) {
864 lines = datas + i * wpls;
865 lined = datad + i * wpld;
866 if (op == L_ARITH_ADD) {
867 for (j = 0; j < w; j++)
868 lined[j] += lines[j];
870 for (j = 0; j < w; j++)
871 lined[j] -= lines[j];
900 l_int32 i, j, w, h, wpl, val;
901 l_uint32 *data, *line;
904 return ERROR_INT(
"pixs not defined", __func__, 1);
905 if (pixGetDepth(pixs) != 32)
906 return ERROR_INT(
"pixs not 32 bpp", __func__, 1);
907 if (offset > 0x40000000)
912 wpl = pixGetWpl(pixs);
913 for (i = 0; i < h; i++) {
914 line = data + i * wpl;
915 for (j = 0; j < w; j++) {
916 val = line[j] - offset;
917 val = (l_int32)(val * factor);
919 line[j] = (l_uint32)val;
951 l_int32 i, j, w, h, w2, h2, d, wpls1, wpls2, wpld, val1, val2, diff;
952 l_int32 rval1, gval1, bval1, rval2, gval2, bval2, rdiff, gdiff, bdiff;
953 l_uint32 *datas1, *datas2, *datad, *lines1, *lines2, *lined;
957 return (
PIX *)ERROR_PTR(
"pixs1 not defined", __func__, NULL);
959 return (
PIX *)ERROR_PTR(
"pixs2 not defined", __func__, NULL);
960 d = pixGetDepth(pixs1);
961 if (d != pixGetDepth(pixs2))
962 return (
PIX *)ERROR_PTR(
"src1 and src2 depths unequal", __func__, NULL);
963 if (d != 8 && d != 16 && d != 32)
964 return (
PIX *)ERROR_PTR(
"depths not in {8, 16, 32}", __func__, NULL);
971 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
972 pixCopyResolution(pixd, pixs1);
976 wpls1 = pixGetWpl(pixs1);
977 wpls2 = pixGetWpl(pixs2);
978 wpld = pixGetWpl(pixd);
980 for (i = 0; i < h; i++) {
981 lines1 = datas1 + i * wpls1;
982 lines2 = datas2 + i * wpls2;
983 lined = datad + i * wpld;
984 for (j = 0; j < w; j++) {
987 diff = L_ABS(val1 - val2);
991 }
else if (d == 16) {
992 for (i = 0; i < h; i++) {
993 lines1 = datas1 + i * wpls1;
994 lines2 = datas2 + i * wpls2;
995 lined = datad + i * wpld;
996 for (j = 0; j < w; j++) {
999 diff = L_ABS(val1 - val2);
1004 for (i = 0; i < h; i++) {
1005 lines1 = datas1 + i * wpls1;
1006 lines2 = datas2 + i * wpls2;
1007 lined = datad + i * wpld;
1008 for (j = 0; j < w; j++) {
1011 rdiff = L_ABS(rval1 - rval2);
1012 gdiff = L_ABS(gval1 - gval2);
1013 bdiff = L_ABS(bval1 - bval2);
1046 l_int32 i, j, w, h, d, w2, h2, d2, wplc1, wplc2, wpld;
1047 l_int32 rval1, gval1, bval1, rval2, gval2, bval2, rval, gval, bval;
1048 l_uint32 *datac1, *datac2, *datad, *linec1, *linec2, *lined;
1049 PIX *pixc1, *pixc2, *pixd;
1052 return (
PIX *)ERROR_PTR(
"pixs1 not defined", __func__, NULL);
1054 return (
PIX *)ERROR_PTR(
"pixs2 not defined", __func__, NULL);
1057 if (!pixGetColormap(pixs1) && d != 32)
1058 return (
PIX *)ERROR_PTR(
"pixs1 not cmapped or rgb", __func__, NULL);
1059 if (!pixGetColormap(pixs2) && d2 != 32)
1060 return (
PIX *)ERROR_PTR(
"pixs2 not cmapped or rgb", __func__, NULL);
1061 if (pixGetColormap(pixs1))
1065 if (pixGetColormap(pixs2))
1073 pixCopyResolution(pixd, pixs1);
1077 wplc1 = pixGetWpl(pixc1);
1078 wplc2 = pixGetWpl(pixc2);
1079 wpld = pixGetWpl(pixd);
1080 for (i = 0; i < h; i++) {
1081 linec1 = datac1 + i * wplc1;
1082 linec2 = datac2 + i * wplc2;
1083 lined = datad + i * wpld;
1084 for (j = 0; j < w; j++) {
1087 rval = L_MIN(255, rval1 + rval2);
1088 gval = L_MIN(255, gval1 + gval2);
1089 bval = L_MIN(255, bval1 + bval2);
1131 l_int32 d, ws, hs, w, h, wpls, wpld, i, j, vals, vald, val;
1132 l_int32 rval1, gval1, bval1, rval2, gval2, bval2, rval, gval, bval;
1133 l_uint32 *datas, *datad, *lines, *lined;
1136 return (
PIX *)ERROR_PTR(
"pixs1 not defined", __func__, pixd);
1138 return (
PIX *)ERROR_PTR(
"pixs2 not defined", __func__, pixd);
1140 return (
PIX *)ERROR_PTR(
"pixs1 and pixs2 must differ", __func__, pixd);
1141 if (type != L_CHOOSE_MIN && type != L_CHOOSE_MAX)
1142 return (
PIX *)ERROR_PTR(
"invalid type", __func__, pixd);
1143 d = pixGetDepth(pixs1);
1144 if (pixGetDepth(pixs2) != d)
1145 return (
PIX *)ERROR_PTR(
"depths unequal", __func__, pixd);
1146 if (d != 8 && d != 16 && d != 32)
1147 return (
PIX *)ERROR_PTR(
"depth not 8, 16 or 32 bpp", __func__, pixd);
1158 wpls = pixGetWpl(pixs2);
1159 wpld = pixGetWpl(pixd);
1160 for (i = 0; i < h; i++) {
1161 lines = datas + i * wpls;
1162 lined = datad + i * wpld;
1164 for (j = 0; j < w; j++) {
1167 if (type == L_CHOOSE_MIN)
1168 val = L_MIN(vals, vald);
1170 val = L_MAX(vals, vald);
1173 }
else if (d == 16) {
1174 for (j = 0; j < w; j++) {
1177 if (type == L_CHOOSE_MIN)
1178 val = L_MIN(vals, vald);
1180 val = L_MAX(vals, vald);
1184 for (j = 0; j < w; j++) {
1187 if (type == L_CHOOSE_MIN) {
1188 rval = L_MIN(rval1, rval2);
1189 gval = L_MIN(gval1, gval2);
1190 bval = L_MIN(bval1, bval2);
1192 rval = L_MAX(rval1, rval2);
1193 gval = L_MAX(gval1, gval2);
1194 bval = L_MAX(bval1, bval2);
1229 l_int32 i, j, w, h, d, wpls, wpld, max;
1230 l_uint32 *datas, *datad;
1231 l_uint32 word, sval;
1232 l_uint32 *lines, *lined;
1238 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1240 if (d != 4 && d != 8 && d != 16 && d != 32)
1241 return (
PIX *)ERROR_PTR(
"pixs not in {4,8,16,32} bpp", __func__, NULL);
1242 if (type != L_LINEAR_SCALE && type != L_LOG_SCALE)
1243 return (
PIX *)ERROR_PTR(
"invalid type", __func__, NULL);
1245 if ((pixd =
pixCreate(w, h, 8)) == NULL)
1246 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1247 pixCopyResolution(pixd, pixs);
1250 wpls = pixGetWpl(pixs);
1251 wpld = pixGetWpl(pixd);
1255 for (i = 0; i < h; i++) {
1256 lines = datas + i * wpls;
1257 for (j = 0; j < wpls; j++) {
1258 word = *(lines + j);
1260 max = L_MAX(max, word >> 28);
1261 max = L_MAX(max, (word >> 24) & 0xf);
1262 max = L_MAX(max, (word >> 20) & 0xf);
1263 max = L_MAX(max, (word >> 16) & 0xf);
1264 max = L_MAX(max, (word >> 12) & 0xf);
1265 max = L_MAX(max, (word >> 8) & 0xf);
1266 max = L_MAX(max, (word >> 4) & 0xf);
1267 max = L_MAX(max, word & 0xf);
1268 }
else if (d == 8) {
1269 max = L_MAX(max, word >> 24);
1270 max = L_MAX(max, (word >> 16) & 0xff);
1271 max = L_MAX(max, (word >> 8) & 0xff);
1272 max = L_MAX(max, word & 0xff);
1273 }
else if (d == 16) {
1274 max = L_MAX(max, word >> 16);
1275 max = L_MAX(max, word & 0xffff);
1277 max = L_MAX(max, word);
1284 if (type == L_LINEAR_SCALE) {
1285 factor = 255. / (l_float32)max;
1286 for (i = 0; i < h; i++) {
1287 lines = datas + i * wpls;
1288 lined = datad + i * wpld;
1289 for (j = 0; j < w; j++) {
1291 dval = (l_uint8)(factor * (l_float32)sval + 0.5);
1296 tab = makeLogBase2Tab();
1297 factor = 255. / getLogBase2(max, tab);
1298 for (i = 0; i < h; i++) {
1299 lines = datas + i * wpls;
1300 lined = datad + i * wpld;
1301 for (j = 0; j < w; j++) {
1303 dval = (l_uint8)(factor * getLogBase2(sval, tab) + 0.5);
1309 }
else if (d == 8) {
1310 if (type == L_LINEAR_SCALE) {
1311 factor = 255. / (l_float32)max;
1312 for (i = 0; i < h; i++) {
1313 lines = datas + i * wpls;
1314 lined = datad + i * wpld;
1315 for (j = 0; j < w; j++) {
1317 dval = (l_uint8)(factor * (l_float32)sval + 0.5);
1322 tab = makeLogBase2Tab();
1323 factor = 255. / getLogBase2(max, tab);
1324 for (i = 0; i < h; i++) {
1325 lines = datas + i * wpls;
1326 lined = datad + i * wpld;
1327 for (j = 0; j < w; j++) {
1329 dval = (l_uint8)(factor * getLogBase2(sval, tab) + 0.5);
1335 }
else if (d == 16) {
1336 if (type == L_LINEAR_SCALE) {
1337 factor = 255. / (l_float32)max;
1338 for (i = 0; i < h; i++) {
1339 lines = datas + i * wpls;
1340 lined = datad + i * wpld;
1341 for (j = 0; j < w; j++) {
1343 dval = (l_uint8)(factor * (l_float32)sval + 0.5);
1348 tab = makeLogBase2Tab();
1349 factor = 255. / getLogBase2(max, tab);
1350 for (i = 0; i < h; i++) {
1351 lines = datas + i * wpls;
1352 lined = datad + i * wpld;
1353 for (j = 0; j < w; j++) {
1355 dval = (l_uint8)(factor * getLogBase2(sval, tab) + 0.5);
1362 if (type == L_LINEAR_SCALE) {
1363 factor = 255. / (l_float32)max;
1364 for (i = 0; i < h; i++) {
1365 lines = datas + i * wpls;
1366 lined = datad + i * wpld;
1367 for (j = 0; j < w; j++) {
1369 dval = (l_uint8)(factor * (l_float32)sval + 0.5);
1374 tab = makeLogBase2Tab();
1375 factor = 255. / getLogBase2(max, tab);
1376 for (i = 0; i < h; i++) {
1377 lines = datas + i * wpls;
1378 lined = datad + i * wpld;
1379 for (j = 0; j < w; j++) {
1381 dval = (l_uint8)(factor * getLogBase2(sval, tab) + 0.5);
1414 l_int32 i, j, w, h, wpls, wpld, max;
1415 l_uint32 sval, dval, word;
1416 l_uint32 *datas, *datad;
1417 l_uint32 *lines, *lined;
1422 if (!pixs || pixGetDepth(pixs) != 32)
1423 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", __func__, NULL);
1424 if (type != L_LINEAR_SCALE && type != L_LOG_SCALE)
1425 return (
PIX *)ERROR_PTR(
"invalid type", __func__, NULL);
1431 wpls = pixGetWpl(pixs);
1432 wpld = pixGetWpl(pixd);
1435 for (i = 0; i < h; i++) {
1436 lines = datas + i * wpls;
1437 for (j = 0; j < wpls; j++) {
1439 max = L_MAX(max, word >> 24);
1440 max = L_MAX(max, (word >> 16) & 0xff);
1441 max = L_MAX(max, (word >> 8) & 0xff);
1445 L_WARNING(
"max = 0; setting to 1\n", __func__);
1450 if (type == L_LINEAR_SCALE) {
1451 factor = 255. / (l_float32)max;
1452 for (i = 0; i < h; i++) {
1453 lines = datas + i * wpls;
1454 lined = datad + i * wpld;
1455 for (j = 0; j < w; j++) {
1462 tab = makeLogBase2Tab();
1463 factor = 255. / getLogBase2(max, tab);
1464 for (i = 0; i < h; i++) {
1465 lines = datas + i * wpls;
1466 lined = datad + i * wpld;
1467 for (j = 0; j < w; j++) {
1505 dval = ((l_uint8)(factor * (sval >> 24) + 0.5) << 24) |
1506 ((l_uint8)(factor * ((sval >> 16) & 0xff) + 0.5) << 16) |
1507 ((l_uint8)(factor * ((sval >> 8) & 0xff) + 0.5) << 8) |
1539 dval = ((l_uint8)(factor * getLogBase2(sval >> 24, tab) + 0.5) << 24) |
1540 ((l_uint8)(factor * getLogBase2(((sval >> 16) & 0xff), tab) + 0.5)
1542 ((l_uint8)(factor * getLogBase2(((sval >> 8) & 0xff), tab) + 0.5)
1558 makeLogBase2Tab(
void)
1564 if ((tab = (l_float32 *)LEPT_CALLOC(256,
sizeof(l_float32))) == NULL)
1565 return (l_float32 *)ERROR_PTR(
"tab not made", __func__, NULL);
1567 log2 = (l_float32)log((l_float32)2);
1568 for (i = 0; i < 256; i++)
1569 tab[i] = (l_float32)log((l_float32)i) / log2;
1583 getLogBase2(l_int32 val,
1587 return ERROR_INT(
"logtab not defined", __func__, 0);
1591 else if (val < 0x10000)
1592 return 8.0 + logtab[val >> 8];
1593 else if (val < 0x1000000)
1594 return 16.0 + logtab[val >> 16];
1596 return 24.0 + logtab[val >> 24];
#define GET_DATA_QBIT(pdata, n)
#define GET_DATA_TWO_BYTES(pdata, n)
#define SET_DATA_BIT(pdata, n)
#define SET_DATA_TWO_BYTES(pdata, n, val)
#define GET_DATA_BYTE(pdata, n)
#define SET_DATA_BYTE(pdata, n, val)
#define GET_DATA_BIT(pdata, n)
#define SET_DATA_QBIT(pdata, n, val)
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()
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 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 pixSetAllArbitrary(PIX *pix, l_uint32 val)
pixSetAllArbitrary()
l_ok pixGetExtremeValue(PIX *pixs, l_int32 factor, l_int32 type, l_int32 *prval, l_int32 *pgval, l_int32 *pbval, l_int32 *pgrayval)
pixGetExtremeValue()
@ REMOVE_CMAP_TO_FULL_COLOR
PIX * pixMaxDynamicRange(PIX *pixs, l_int32 type)
pixMaxDynamicRange()
l_ok pixMultConstAccumulate(PIX *pixs, l_float32 factor, l_uint32 offset)
pixMultConstAccumulate()
PIX * pixInitAccumulate(l_int32 w, l_int32 h, l_uint32 offset)
pixInitAccumulate()
l_ok pixAddConstantGray(PIX *pixs, l_int32 val)
pixAddConstantGray()
l_uint32 logScaleRGBVal(l_uint32 sval, l_float32 *tab, l_float32 factor)
logScaleRGBVal()
PIX * pixAddRGB(PIX *pixs1, PIX *pixs2)
pixAddRGB()
l_ok pixMultConstantGray(PIX *pixs, l_float32 val)
pixMultConstantGray()
PIX * pixSubtractGray(PIX *pixd, PIX *pixs1, PIX *pixs2)
pixSubtractGray()
PIX * pixThresholdToValue(PIX *pixd, PIX *pixs, l_int32 threshval, l_int32 setval)
pixThresholdToValue()
l_uint32 linearScaleRGBVal(l_uint32 sval, l_float32 factor)
linearScaleRGBVal()
PIX * pixFinalAccumulate(PIX *pixs, l_uint32 offset, l_int32 depth)
pixFinalAccumulate()
PIX * pixAddGray(PIX *pixd, PIX *pixs1, PIX *pixs2)
pixAddGray()
PIX * pixFinalAccumulateThreshold(PIX *pixs, l_uint32 offset, l_uint32 threshold)
pixFinalAccumulateThreshold()
PIX * pixMaxDynamicRangeRGB(PIX *pixs, l_int32 type)
pixMaxDynamicRangeRGB()
PIX * pixMultiplyGray(PIX *pixs, PIX *pixg, l_float32 norm)
pixMultiplyGray()
l_ok pixAccumulate(PIX *pixd, PIX *pixs, l_int32 op)
pixAccumulate()
PIX * pixMinOrMax(PIX *pixd, PIX *pixs1, PIX *pixs2, l_int32 type)
pixMinOrMax()
PIX * pixAbsDifference(PIX *pixs1, PIX *pixs2)
pixAbsDifference()
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()