108#include <config_auto.h>
113#include "allheaders.h"
131 if (depth != 1 && depth != 2 && depth !=4 && depth != 8)
132 return (
PIXCMAP *)ERROR_PTR(
"depth not in {1,2,4,8}", __func__, NULL);
136 cmap->
nalloc = 1 << depth;
176l_int32 red[256], green[256], blue[256];
179 if (depth != 2 && depth != 4 && depth != 8)
180 return (
PIXCMAP *)ERROR_PTR(
"depth not in {2, 4, 8}", __func__, NULL);
181 if (hasblack != 0) hasblack = 1;
182 if (haswhite != 0) haswhite = 1;
185 ncolors = 1 << depth;
188 for (i = hasblack; i < ncolors - haswhite; i++) {
189 red[i] = (l_uint32)rand() & 0xff;
190 green[i] = (l_uint32)rand() & 0xff;
191 blue[i] = (l_uint32)rand() & 0xff;
218l_int32 maxlevels, i, val;
221 if (d != 1 && d != 2 && d !=4 && d != 8)
222 return (
PIXCMAP *)ERROR_PTR(
"d not in {1, 2, 4, 8}", __func__, NULL);
224 if (nlevels < 2 || nlevels > maxlevels)
225 return (
PIXCMAP *)ERROR_PTR(
"invalid nlevels", __func__, NULL);
228 for (i = 0; i < nlevels; i++) {
229 val = (255 * i) / (nlevels - 1);
245l_int32 nbytes, valid;
249 return (
PIXCMAP *)ERROR_PTR(
"cmaps not defined", __func__, NULL);
252 return (
PIXCMAP *)ERROR_PTR(
"invalid cmap", __func__, NULL);
256 cmapd->
array = (
void *)LEPT_CALLOC(1, nbytes);
277 L_WARNING(
"ptr address is null!\n", __func__);
281 if ((cmap = *pcmap) == NULL)
284 LEPT_FREE(cmap->
array);
312l_int32 d, depth, nalloc, maxindex, maxcolors;
315 return ERROR_INT(
"&valid not defined", __func__, 1);
318 return ERROR_INT(
"cmap not defined", __func__, 1);
320 return ERROR_INT(
"cmap array not defined", __func__, 1);
322 if (d != 1 && d != 2 && d != 4 && d != 8) {
323 L_ERROR(
"invalid cmap depth: %d\n", __func__, d);
327 if (nalloc != (1 << d)) {
328 L_ERROR(
"invalid cmap nalloc = %d; d = %d\n", __func__, nalloc, d);
331 if (cmap->
n < 0 || cmap->
n > nalloc) {
332 L_ERROR(
"invalid cmap n: %d; nalloc = %d\n", __func__, cmap->
n, nalloc);
338 depth = pixGetDepth(pix);
340 L_ERROR(
"pix depth %d > 8\n", __func__, depth);
343 maxcolors = 1 << depth;
350 if (pix && (depth > d)) {
351 L_ERROR(
"(pix depth = %d) > (cmap depth = %d)\n", __func__, depth, d);
354 if (pix && cmap->
n < 1) {
355 L_ERROR(
"cmap array is empty; invalid with any pix\n", __func__);
364 if (pix && (cmap->
n > maxcolors)) {
365 L_ERROR(
"cmap entries = %d > max colors for pix = %d\n", __func__,
375 pixGetMaxColorIndex(pix, &maxindex);
376 if (maxindex >= cmap->
n) {
377 L_ERROR(
"(max index in image = %d) >= "
378 "(number entries in colormap = %d)\n", __func__,
412 return ERROR_INT(
"cmap not defined", __func__, 1);
414 return ERROR_INT(
"no free color entries", __func__, 1);
417 cta[cmap->
n].
red = rval;
418 cta[cmap->
n].
green = gval;
419 cta[cmap->
n].
blue = bval;
449 return ERROR_INT(
"cmap not defined", __func__, 1);
451 return ERROR_INT(
"no free color entries", __func__, 1);
454 cta[cmap->
n].
red = rval;
455 cta[cmap->
n].
green = gval;
456 cta[cmap->
n].
blue = bval;
457 cta[cmap->
n].
alpha = aval;
489 return ERROR_INT(
"&index not defined", __func__, 1);
492 return ERROR_INT(
"cmap not defined", __func__, 1);
500 L_WARNING(
"no free color entries\n", __func__);
536 return ERROR_INT(
"&index not defined", __func__, 1);
539 return ERROR_INT(
"cmap not defined", __func__, 1);
583 return ERROR_INT(
"&usable not defined", __func__, 1);
586 return ERROR_INT(
"cmap not defined", __func__, 1);
625 if (pindex) *pindex = 0;
627 return ERROR_INT(
"cmap not defined", __func__, 1);
663 return ERROR_INT(
"cmap not defined", __func__, 1);
687 return ERROR_INT(
"cmap not defined", __func__, 0);
702 return ERROR_INT(
"cmap not defined", __func__, 0);
703 return (cmap->
nalloc - cmap->
n);
717 return ERROR_INT(
"cmap not defined", __func__, 0);
741 return ERROR_INT(
"&mindepth not defined", __func__, 1);
744 return ERROR_INT(
"cmap not defined", __func__, 1);
749 else if (ncolors <= 16)
772 return ERROR_INT(
"cmap not defined", __func__, 1);
798 if (!prval || !pgval || !pbval)
799 return ERROR_INT(
"&rval, &gval, &bval not all defined", __func__, 1);
800 *prval = *pgval = *pbval = 0;
802 return ERROR_INT(
"cmap not defined", __func__, 1);
803 if (index < 0 || index >= cmap->
n)
804 return ERROR_INT(
"index out of bounds", __func__, 1);
807 *prval = cta[index].
red;
808 *pgval = cta[index].
green;
809 *pbval = cta[index].
blue;
832l_int32 rval, gval, bval;
835 return ERROR_INT(
"&val32 not defined", __func__, 1);
839 return ERROR_INT(
"rgb values not found", __func__, 1);
840 composeRGBAPixel(rval, gval, bval, 255, pval32);
863 if (!prval || !pgval || !pbval || !paval)
864 return ERROR_INT(
"&rval, &gval, &bval, &aval not all defined",
866 *prval = *pgval = *pbval = *paval = 0;
868 return ERROR_INT(
"cmap not defined", __func__, 1);
869 if (index < 0 || index >= cmap->
n)
870 return ERROR_INT(
"index out of bounds", __func__, 1);
873 *prval = cta[index].
red;
874 *pgval = cta[index].
green;
875 *pbval = cta[index].
blue;
876 *paval = cta[index].
alpha;
894l_int32 rval, gval, bval, aval;
897 return ERROR_INT(
"&val32 not defined", __func__, 1);
901 return ERROR_INT(
"rgba values not found", __func__, 1);
902 composeRGBAPixel(rval, gval, bval, aval, pval32);
933 return ERROR_INT(
"cmap not defined", __func__, 1);
934 if (index < 0 || index >= cmap->
n)
935 return ERROR_INT(
"index out of bounds", __func__, 1);
938 cta[index].
red = rval;
939 cta[index].
green = gval;
940 cta[index].
blue = bval;
941 cta[index].
alpha = 255;
970 return ERROR_INT(
"cmap not defined", __func__, 1);
971 if (index < 0 || index >= cmap->
n)
972 return ERROR_INT(
"index out of bounds", __func__, 1);
975 cta[index].
alpha = aval;
1000 return ERROR_INT(
"&index not defined", __func__, 1);
1003 return ERROR_INT(
"cmap not defined", __func__, 1);
1007 for (i = 0; i < n; i++) {
1008 if (rval == cta[i].red &&
1009 gval == cta[i].green &&
1010 bval == cta[i].blue) {
1031l_int32 *rmap, *gmap, *bmap;
1034 return ERROR_INT(
"&color not defined", __func__, 1);
1037 return ERROR_INT(
"cmap not defined", __func__, 1);
1040 return ERROR_INT(
"colormap arrays not made", __func__, 1);
1042 for (i = 0; i < n; i++) {
1043 if ((rmap[i] != gmap[i]) || (rmap[i] != bmap[i])) {
1071 return ERROR_INT(
"&opaque not defined", __func__, 1);
1074 return ERROR_INT(
"cmap not defined", __func__, 1);
1078 for (i = 0; i < n; i++) {
1079 if (cta[i].alpha != 255) {
1123 l_int32 *pmax_trans,
1124 l_int32 *pmin_opaque)
1126l_int32 i, n, ntrans, max_trans, min_opaque, opaque_found;
1129 if (pntrans) *pntrans = 0;
1130 if (pmax_trans) *pmax_trans = -1;
1131 if (pmin_opaque) *pmin_opaque = 256;
1133 return ERROR_INT(
"cmap not defined", __func__, 1);
1140 opaque_found = FALSE;
1141 for (i = 0; i < n; i++) {
1142 if (cta[i].alpha != 255) {
1145 }
else if (opaque_found == FALSE) {
1146 opaque_found = TRUE;
1150 if (pntrans) *pntrans = ntrans;
1151 if (pmax_trans) *pmax_trans = max_trans;
1152 if (pmin_opaque) *pmin_opaque = min_opaque;
1167 l_int32 *pblackwhite)
1169l_int32 val0, val1, hascolor;
1173 return ERROR_INT(
"&blackwhite not defined", __func__, 1);
1174 *pblackwhite = FALSE;
1176 return ERROR_INT(
"cmap not defined", __func__, 1);
1181 if (hascolor)
return 0;
1186 if ((val0 == 0 && val1 == 255) || (val0 == 255 && val1 == 0))
1187 *pblackwhite = TRUE;
1208l_int32 n, i, rval, gval, bval, count;
1212 return ERROR_INT(
"&ngray not defined", __func__, 1);
1215 return ERROR_INT(
"cmap not defined", __func__, 1);
1217 array = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
1220 for (i = 0; i < n; i++) {
1222 if ((rval == gval) && (rval == bval) && (array[rval] == 0)) {
1248l_int32 n, i, rval, gval, bval, rankindex;
1252 return ERROR_INT(
"&index not defined", __func__, 1);
1255 return ERROR_INT(
"cmap not defined", __func__, 1);
1256 if (rankval < 0.0 || rankval > 1.0)
1257 return ERROR_INT(
"rankval not in [0.0 ... 1.0]", __func__, 1);
1261 for (i = 0; i < n; i++) {
1263 numaAddNumber(na, rval + gval + bval);
1266 rankindex = (l_int32)(rankval * (n - 1) + 0.5);
1267 numaGetIValue(nasort, rankindex, pindex);
1270 numaDestroy(&nasort);
1299l_int32 i, n, delta, dist, mindist;
1303 return ERROR_INT(
"&index not defined", __func__, 1);
1306 return ERROR_INT(
"cmap not defined", __func__, 1);
1309 return ERROR_INT(
"cta not defined(!)", __func__, 1);
1312 mindist = 3 * 255 * 255 + 1;
1313 for (i = 0; i < n; i++) {
1314 delta = cta[i].
red - rval;
1315 dist = delta * delta;
1316 delta = cta[i].
green - gval;
1317 dist += delta * delta;
1318 delta = cta[i].
blue - bval;
1319 dist += delta * delta;
1320 if (dist < mindist) {
1353l_int32 i, n, dist, mindist;
1357 return ERROR_INT(
"&index not defined", __func__, 1);
1360 return ERROR_INT(
"cmap not defined", __func__, 1);
1361 if (val < 0 || val > 255)
1362 return ERROR_INT(
"val not in [0 ... 255]", __func__, 1);
1365 return ERROR_INT(
"cta not defined(!)", __func__, 1);
1369 for (i = 0; i < n; i++) {
1370 dist = cta[i].
green - val;
1372 if (dist < mindist) {
1407l_int32 n, delta, dist;
1411 return ERROR_INT(
"&dist not defined", __func__, 1);
1414 return ERROR_INT(
"cmap not defined", __func__, 1);
1417 return ERROR_INT(
"invalid index", __func__, 1);
1420 return ERROR_INT(
"cta not defined(!)", __func__, 1);
1422 delta = cta[index].
red - rval;
1423 dist = delta * delta;
1424 delta = cta[index].
green - gval;
1425 dist += delta * delta;
1426 delta = cta[index].
blue - bval;
1427 dist += delta * delta;
1461l_int32 i, n, imin, imax, minval, maxval, rval, gval, bval, aveval;
1463 if (pminval) *pminval = UNDEF;
1464 if (pmaxval) *pmaxval = UNDEF;
1465 if (pminindex) *pminindex = UNDEF;
1466 if (pmaxindex) *pmaxindex = UNDEF;
1467 if (!pminval && !pmaxval && !pminindex && !pmaxindex)
1468 return ERROR_INT(
"no result requested", __func__, 1);
1470 return ERROR_INT(
"cmap not defined", __func__, 1);
1477 for (i = 0; i < n; i++) {
1480 if (rval < minval) {
1484 if (rval > maxval) {
1489 if (gval < minval) {
1493 if (gval > maxval) {
1498 if (bval < minval) {
1502 if (bval > maxval) {
1507 aveval = (rval + gval + bval) / 3;
1508 if (aveval < minval) {
1512 if (aveval > maxval) {
1517 return ERROR_INT(
"invalid selection", __func__, 1);
1521 if (pminval) *pminval = minval;
1522 if (pmaxval) *pmaxval = maxval;
1523 if (pminindex) *pminindex = imin;
1524 if (pmaxindex) *pmaxindex = imax;
1548l_int32 i, rval, gval, bval;
1550l_float32 invgamma, x;
1553 if (gamma <= 0.0) gamma = 1.0;
1556 curve = (l_int32 *)LEPT_CALLOC(64,
sizeof(l_int32));
1557 invgamma = 1. / gamma;
1558 for (i = 0; i < 64; i++) {
1559 x = (l_float32)i / 64.;
1560 curve[i] = (l_int32)(255. * powf(x, invgamma) + 0.5);
1564 for (i = 0; i < 256; i++) {
1568 bval = curve[i + 32];
1569 }
else if (i < 96) {
1571 gval = curve[i - 32];
1573 }
else if (i < 160) {
1574 rval = curve[i - 96];
1576 bval = curve[159 - i];
1577 }
else if (i < 224) {
1579 gval = curve[223 - i];
1582 rval = curve[287 - i];
1612l_int32 i, rval, gval, bval;
1615 extractRGBValues(color, &rval, &gval, &bval);
1617 for (i = 0; i < 256; i++) {
1619 gval + (i * (255 - gval)) / 255,
1620 bval + (i * (255 - bval)) / 255);
1647l_int32 i, n, rval, gval, bval, val;
1652 return (
PIXCMAP *)ERROR_PTR(
"cmaps not defined", __func__, NULL);
1653 if (rwt < 0.0 || gwt < 0.0 || bwt < 0.0)
1654 return (
PIXCMAP *)ERROR_PTR(
"weights not all >= 0.0", __func__, NULL);
1658 sum = rwt + gwt + bwt;
1660 L_WARNING(
"all weights zero; setting equal to 1/3\n", __func__);
1661 rwt = gwt = bwt = 0.33333f;
1664 if (L_ABS(sum - 1.0) > 0.0001) {
1665 L_WARNING(
"weights don't sum to 1; maintaining ratios\n", __func__);
1672 return (
PIXCMAP *)ERROR_PTR(
"cmapd not made", __func__, NULL);
1674 for (i = 0; i < n; i++) {
1676 val = (l_int32)(rwt * rval + gwt * gval + bwt * bval + 0.5);
1699l_int32 i, n, rval, gval, bval;
1703 return (
PIXCMAP *)ERROR_PTR(
"cmaps not defined", __func__, NULL);
1705 return (
PIXCMAP *)ERROR_PTR(
"cmaps not for 2 bpp pix", __func__, NULL);
1709 for (i = 0; i < n; i++) {
1732l_int32 i, n, depth, rval, gval, bval;
1736 return (
PIXCMAP *)ERROR_PTR(
"cmaps not defined", __func__, NULL);
1739 if (depth != 2 && depth != 4)
1740 return (
PIXCMAP *)ERROR_PTR(
"cmaps not 2 or 4 bpp", __func__, NULL);
1744 for (i = 0; i < n; i++) {
1768 return (
PIXCMAP *)ERROR_PTR(
"filename not defined", __func__, NULL);
1770 if ((fp = fopenReadStream(filename)) == NULL)
1771 return (
PIXCMAP *)ERROR_PTR_1(
"stream not opened",
1772 filename, __func__, NULL);
1776 return (
PIXCMAP *)ERROR_PTR_1(
"cmap not read",
1777 filename, __func__, NULL);
1791l_int32 rval, gval, bval, aval, ignore;
1792l_int32 i, index, ret, depth, ncolors;
1796 return (
PIXCMAP *)ERROR_PTR(
"stream not defined", __func__, NULL);
1798 ret = fscanf(fp,
"\nPixcmap: depth = %d bpp; %d colors\n",
1801 (depth != 1 && depth != 2 && depth != 4 && depth != 8) ||
1802 (ncolors < 2 || ncolors > 256))
1803 return (
PIXCMAP *)ERROR_PTR(
"invalid cmap size", __func__, NULL);
1804 ignore = fscanf(fp,
"Color R-val G-val B-val Alpha\n");
1805 ignore = fscanf(fp,
"----------------------------------------\n");
1808 return (
PIXCMAP *)ERROR_PTR(
"cmap not made", __func__, NULL);
1809 for (i = 0; i < ncolors; i++) {
1810 if (fscanf(fp,
"%3d %3d %3d %3d %3d\n",
1811 &index, &rval, &gval, &bval, &aval) != 5) {
1813 return (
PIXCMAP *)ERROR_PTR(
"invalid entry", __func__, NULL);
1836 return (
PIXCMAP *)ERROR_PTR(
"data not defined", __func__, NULL);
1837 if ((fp = fopenReadFromMemory(data, size)) == NULL)
1838 return (
PIXCMAP *)ERROR_PTR(
"stream not opened", __func__, NULL);
1842 if (!cmap) L_ERROR(
"cmap not read\n", __func__);
1862 return ERROR_INT(
"filename not defined", __func__, 1);
1864 return ERROR_INT(
"cmap not defined", __func__, 1);
1866 if ((fp = fopenWriteStream(filename,
"w")) == NULL)
1867 return ERROR_INT_1(
"stream not opened", filename, __func__, 1);
1871 return ERROR_INT_1(
"cmap not written to stream", filename, __func__, 1);
1888l_int32 *rmap, *gmap, *bmap, *amap;
1892 return ERROR_INT(
"stream not defined", __func__, 1);
1894 return ERROR_INT(
"cmap not defined", __func__, 1);
1897 return ERROR_INT(
"colormap arrays not made", __func__, 1);
1899 fprintf(fp,
"\nPixcmap: depth = %d bpp; %d colors\n", cmap->
depth, cmap->
n);
1900 fprintf(fp,
"Color R-val G-val B-val Alpha\n");
1901 fprintf(fp,
"----------------------------------------\n");
1902 for (i = 0; i < cmap->
n; i++)
1903 fprintf(fp,
"%3d %3d %3d %3d %3d\n",
1904 i, rmap[i], gmap[i], bmap[i], amap[i]);
1936 if (pdata) *pdata = NULL;
1937 if (psize) *psize = 0;
1939 return ERROR_INT(
"&data not defined", __func__, 1);
1941 return ERROR_INT(
"&size not defined", __func__, 1);
1943 return ERROR_INT(
"cmap not defined", __func__, 1);
1946 if ((fp = open_memstream((
char **)pdata, psize)) == NULL)
1947 return ERROR_INT(
"stream not opened", __func__, 1);
1951 if (*psize > 0) *psize = *psize - 1;
1953 L_INFO(
"no fmemopen API --> work-around: write to temp file\n", __func__);
1955 if ((fp = fopenWriteWinTempfile()) == NULL)
1956 return ERROR_INT(
"tmpfile stream not opened", __func__, 1);
1958 if ((fp = tmpfile()) == NULL)
1959 return ERROR_INT(
"tmpfile stream not opened", __func__, 1);
1963 *pdata = l_binaryReadStream(fp, psize);
1990l_int32 *rmap, *gmap, *bmap, *amap = NULL;
1994 if (!prmap || !pgmap || !pbmap)
1995 return ERROR_INT(
"&rmap, &gmap, &bmap not all defined", __func__, 1);
1996 *prmap = *pgmap = *pbmap = NULL;
1997 if (pamap) *pamap = NULL;
1999 return ERROR_INT(
"cmap not defined", __func__, 1);
2002 rmap = (l_int32 *)LEPT_CALLOC(ncolors,
sizeof(l_int32));
2003 gmap = (l_int32 *)LEPT_CALLOC(ncolors,
sizeof(l_int32));
2004 bmap = (l_int32 *)LEPT_CALLOC(ncolors,
sizeof(l_int32));
2009 amap = (l_int32 *)LEPT_CALLOC(ncolors,
sizeof(l_int32));
2014 for (i = 0; i < ncolors; i++) {
2015 rmap[i] = cta[i].
red;
2016 gmap[i] = cta[i].
green;
2017 bmap[i] = cta[i].
blue;
2019 amap[i] = cta[i].
alpha;
2039l_int32 i, ncolors, rval, gval, bval, aval;
2043 return ERROR_INT(
"&tab not defined", __func__, 1);
2046 return ERROR_INT(
"cmap not defined", __func__, 1);
2049 if (pncolors) *pncolors = ncolors;
2050 tab = (l_uint32 *)LEPT_CALLOC(ncolors,
sizeof(l_uint32));
2053 for (i = 0; i < ncolors; i++) {
2055 composeRGBAPixel(rval, gval, bval, aval, &tab[i]);
2081l_int32 i, ncolors, rval, gval, bval, aval;
2085 return ERROR_INT(
"&data not defined", __func__, 1);
2088 return ERROR_INT(
"&ncolors not defined", __func__, 1);
2091 return ERROR_INT(
"cmap not defined", __func__, 1);
2092 if (cpc != 3 && cpc != 4)
2093 return ERROR_INT(
"cpc not 3 or 4", __func__, 1);
2096 *pncolors = ncolors;
2097 data = (l_uint8 *)LEPT_CALLOC((
size_t)cpc * ncolors,
sizeof(l_uint8));
2100 for (i = 0; i < ncolors; i++) {
2102 data[cpc * i] = rval;
2103 data[cpc * i + 1] = gval;
2104 data[cpc * i + 2] = bval;
2106 data[cpc * i + 3] = aval;
2125l_int32 i, d, rval, gval, bval, aval;
2129 return (
PIXCMAP *)ERROR_PTR(
"data not defined", __func__, NULL);
2130 if (cpc != 3 && cpc != 4)
2131 return (
PIXCMAP *)ERROR_PTR(
"cpc not 3 or 4", __func__, NULL);
2133 return (
PIXCMAP *)ERROR_PTR(
"no entries", __func__, NULL);
2135 return (
PIXCMAP *)ERROR_PTR(
"ncolors > 256", __func__, NULL);
2139 else if (ncolors > 4)
2141 else if (ncolors > 2)
2146 for (i = 0; i < ncolors; i++) {
2147 rval = data[cpc * i];
2148 gval = data[cpc * i + 1];
2149 bval = data[cpc * i + 2];
2151 aval = data[cpc * i + 3];
2183l_int32 i, j, hexbytes;
2184char *hexdata = NULL;
2188 return (
char *)ERROR_PTR(
"data not defined", __func__, NULL);
2190 return (
char *)ERROR_PTR(
"no colors", __func__, NULL);
2192 hexbytes = 2 + (2 * 3 + 1) * ncolors + 2;
2193 hexdata = (
char *)LEPT_CALLOC(hexbytes,
sizeof(
char));
2197 for (i = 0; i < ncolors; i++) {
2198 j = 2 + (2 * 3 + 1) * i;
2199 snprintf(buf,
sizeof(buf),
"%02x", data[3 * i]);
2200 hexdata[j] = buf[0];
2201 hexdata[j + 1] = buf[1];
2202 snprintf(buf,
sizeof(buf),
"%02x", data[3 * i + 1]);
2203 hexdata[j + 2] = buf[0];
2204 hexdata[j + 3] = buf[1];
2205 snprintf(buf,
sizeof(buf),
"%02x", data[3 * i + 2]);
2206 hexdata[j + 4] = buf[0];
2207 hexdata[j + 5] = buf[1];
2208 hexdata[j + 6] =
' ';
2210 hexdata[j + 7] =
'>';
2211 hexdata[j + 8] =
'\0';
2241l_int32 rval, gval, bval, trval, tgval, tbval, i, ncolors;
2245 return ERROR_INT(
"cmap not defined", __func__, 1);
2247 L_WARNING(
"gamma must be > 0.0; setting to 1.0\n", __func__);
2250 if (minval >= maxval)
2251 return ERROR_INT(
"minval not < maxval", __func__, 1);
2253 if (gamma == 1.0 && minval == 0 && maxval == 255)
2256 if ((nag = numaGammaTRC(gamma, minval, maxval)) == NULL)
2257 return ERROR_INT(
"nag not made", __func__, 1);
2260 for (i = 0; i < ncolors; i++) {
2262 numaGetIValue(nag, rval, &trval);
2263 numaGetIValue(nag, gval, &tgval);
2264 numaGetIValue(nag, bval, &tbval);
2292l_int32 i, ncolors, rval, gval, bval, trval, tgval, tbval;
2296 return ERROR_INT(
"cmap not defined", __func__, 1);
2298 L_WARNING(
"factor must be >= 0.0; setting to 0.0\n", __func__);
2302 if ((nac = numaContrastTRC(factor)) == NULL)
2303 return ERROR_INT(
"nac not made", __func__, 1);
2306 for (i = 0; i < ncolors; i++) {
2308 numaGetIValue(nac, rval, &trval);
2309 numaGetIValue(nac, gval, &tgval);
2310 numaGetIValue(nac, bval, &tbval);
2342l_int32 i, ncolors, rval, gval, bval;
2345 return ERROR_INT(
"cmap not defined", __func__, 1);
2346 if (fraction < -1.0 || fraction > 1.0)
2347 return ERROR_INT(
"fraction not in [-1.0, 1.0]", __func__, 1);
2350 for (i = 0; i < ncolors; i++) {
2354 (l_int32)((1.0 + fraction) * rval),
2355 (l_int32)((1.0 + fraction) * gval),
2356 (l_int32)((1.0 + fraction) * bval));
2359 rval + (l_int32)(fraction * (255 - rval)),
2360 gval + (l_int32)(fraction * (255 - gval)),
2361 bval + (l_int32)(fraction * (255 - bval)));
2391l_int32 i, ncolors, rval, gval, bval;
2395 return ERROR_INT(
"cmap not defined", __func__, 1);
2398 for (i = 0; i < ncolors; i++) {
2400 pixelShiftByComponent(rval, gval, bval, srcval, dstval, &newval);
2401 extractRGBValues(newval, &rval, &gval, &bval);
l_ok pixcmapSetAlpha(PIXCMAP *cmap, l_int32 index, l_int32 aval)
pixcmapSetAlpha()
void pixcmapDestroy(PIXCMAP **pcmap)
pixcmapDestroy()
l_ok pixcmapContrastTRC(PIXCMAP *cmap, l_float32 factor)
pixcmapContrastTRC()
l_ok pixcmapHasColor(PIXCMAP *cmap, l_int32 *pcolor)
pixcmapHasColor()
l_int32 pixcmapGetCount(const PIXCMAP *cmap)
pixcmapGetCount()
PIXCMAP * pixcmapCreateRandom(l_int32 depth, l_int32 hasblack, l_int32 haswhite)
pixcmapCreateRandom()
l_ok pixcmapGetDistanceToColor(PIXCMAP *cmap, l_int32 index, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pdist)
pixcmapGetDistanceToColor()
l_ok pixcmapSetBlackAndWhite(PIXCMAP *cmap, l_int32 setblack, l_int32 setwhite)
pixcmapSetBlackAndWhite()
l_ok pixcmapIsValid(const PIXCMAP *cmap, PIX *pix, l_int32 *pvalid)
pixcmapIsValid()
PIXCMAP * pixcmapCopy(const PIXCMAP *cmaps)
pixcmapCopy()
l_ok pixcmapWriteStream(FILE *fp, const PIXCMAP *cmap)
pixcmapWriteStream()
l_ok pixcmapAddNewColor(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
pixcmapAddNewColor()
l_ok pixcmapGetNearestIndex(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
pixcmapGetNearestIndex()
PIXCMAP * pixcmapGrayToColor(l_uint32 color)
pixcmapGrayToColor()
l_ok pixcmapGetColor32(PIXCMAP *cmap, l_int32 index, l_uint32 *pval32)
pixcmapGetColor32()
l_ok pixcmapSerializeToMemory(PIXCMAP *cmap, l_int32 cpc, l_int32 *pncolors, l_uint8 **pdata)
pixcmapSerializeToMemory()
l_ok pixcmapWrite(const char *filename, const PIXCMAP *cmap)
pixcmapWrite()
PIXCMAP * pixcmapCreate(l_int32 depth)
pixcmapCreate()
l_ok pixcmapWriteMem(l_uint8 **pdata, size_t *psize, const PIXCMAP *cmap)
pixcmapWriteMem()
l_ok pixcmapAddRGBA(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 aval)
pixcmapAddRGBA()
PIXCMAP * pixcmapDeserializeFromMemory(l_uint8 *data, l_int32 cpc, l_int32 ncolors)
pixcmapDeserializeFromMemory()
l_ok pixcmapAddBlackOrWhite(PIXCMAP *cmap, l_int32 color, l_int32 *pindex)
pixcmapAddBlackOrWhite()
PIXCMAP * pixcmapCreateLinear(l_int32 d, l_int32 nlevels)
pixcmapCreateLinear()
l_ok pixcmapAddNearestColor(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
pixcmapAddNearestColor()
PIXCMAP * pixcmapColorToGray(PIXCMAP *cmaps, l_float32 rwt, l_float32 gwt, l_float32 bwt)
pixcmapColorToGray()
l_ok pixcmapResetColor(PIXCMAP *cmap, l_int32 index, l_int32 rval, l_int32 gval, l_int32 bval)
pixcmapResetColor()
l_ok pixcmapGammaTRC(PIXCMAP *cmap, l_float32 gamma, l_int32 minval, l_int32 maxval)
pixcmapGammaTRC()
PIXCMAP * pixcmapConvertTo4(PIXCMAP *cmaps)
pixcmapConvertTo4()
l_int32 pixcmapGetIndex(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
pixcmapGetIndex()
PIXCMAP * pixcmapReadStream(FILE *fp)
pixcmapReadStream()
l_ok pixcmapCountGrayColors(PIXCMAP *cmap, l_int32 *pngray)
pixcmapCountGrayColors()
l_int32 pixcmapGetDepth(PIXCMAP *cmap)
pixcmapGetDepth()
l_ok pixcmapNonOpaqueColorsInfo(PIXCMAP *cmap, l_int32 *pntrans, l_int32 *pmax_trans, l_int32 *pmin_opaque)
pixcmapNonOpaqueColorsInfo()
l_ok pixcmapUsableColor(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pusable)
pixcmapUsableColor()
l_ok pixcmapShiftIntensity(PIXCMAP *cmap, l_float32 fraction)
pixcmapShiftIntensity()
l_ok pixcmapGetColor(PIXCMAP *cmap, l_int32 index, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
pixcmapGetColor()
l_ok pixcmapIsOpaque(PIXCMAP *cmap, l_int32 *popaque)
pixcmapIsOpaque()
l_ok pixcmapGetMinDepth(PIXCMAP *cmap, l_int32 *pmindepth)
pixcmapGetMinDepth()
PIXCMAP * pixcmapGrayToFalseColor(l_float32 gamma)
pixcmapGrayToFalseColor()
l_int32 pixcmapGetFreeCount(PIXCMAP *cmap)
pixcmapGetFreeCount()
l_ok pixcmapGetRangeValues(PIXCMAP *cmap, l_int32 select, l_int32 *pminval, l_int32 *pmaxval, l_int32 *pminindex, l_int32 *pmaxindex)
pixcmapGetRangeValues()
l_ok pixcmapClear(PIXCMAP *cmap)
pixcmapClear()
char * pixcmapConvertToHex(l_uint8 *data, l_int32 ncolors)
pixcmapConvertToHex()
l_ok pixcmapGetRankIntensity(PIXCMAP *cmap, l_float32 rankval, l_int32 *pindex)
pixcmapGetRankIntensity()
PIXCMAP * pixcmapReadMem(const l_uint8 *data, size_t size)
pixcmapReadMem()
l_ok pixcmapGetRGBA(PIXCMAP *cmap, l_int32 index, l_int32 *prval, l_int32 *pgval, l_int32 *pbval, l_int32 *paval)
pixcmapGetRGBA()
PIXCMAP * pixcmapConvertTo8(PIXCMAP *cmaps)
pixcmapConvertTo8()
l_ok pixcmapToArrays(const PIXCMAP *cmap, l_int32 **prmap, l_int32 **pgmap, l_int32 **pbmap, l_int32 **pamap)
pixcmapToArrays()
l_ok pixcmapShiftByComponent(PIXCMAP *cmap, l_uint32 srcval, l_uint32 dstval)
pixcmapShiftByComponent()
l_ok pixcmapIsBlackAndWhite(PIXCMAP *cmap, l_int32 *pblackwhite)
pixcmapIsBlackAndWhite()
PIXCMAP * pixcmapRead(const char *filename)
pixcmapRead()
l_ok pixcmapAddColor(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval)
pixcmapAddColor()
l_ok pixcmapGetNearestGrayIndex(PIXCMAP *cmap, l_int32 val, l_int32 *pindex)
pixcmapGetNearestGrayIndex()
l_ok pixcmapToRGBTable(PIXCMAP *cmap, l_uint32 **ptab, l_int32 *pncolors)
pixcmapToRGBTable()
l_ok pixcmapGetRGBA32(PIXCMAP *cmap, l_int32 index, l_uint32 *pval32)
pixcmapGetRGBA32()
struct RGBA_Quad RGBA_QUAD