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 = %d) >= (num colors = %d)\n", __func__,
411 return ERROR_INT(
"cmap not defined", __func__, 1);
413 return ERROR_INT(
"no free color entries", __func__, 1);
416 cta[cmap->
n].
red = rval;
417 cta[cmap->
n].
green = gval;
418 cta[cmap->
n].
blue = bval;
448 return ERROR_INT(
"cmap not defined", __func__, 1);
450 return ERROR_INT(
"no free color entries", __func__, 1);
453 cta[cmap->
n].
red = rval;
454 cta[cmap->
n].
green = gval;
455 cta[cmap->
n].
blue = bval;
456 cta[cmap->
n].
alpha = aval;
488 return ERROR_INT(
"&index not defined", __func__, 1);
491 return ERROR_INT(
"cmap not defined", __func__, 1);
499 L_WARNING(
"no free color entries\n", __func__);
535 return ERROR_INT(
"&index not defined", __func__, 1);
538 return ERROR_INT(
"cmap not defined", __func__, 1);
582 return ERROR_INT(
"&usable not defined", __func__, 1);
585 return ERROR_INT(
"cmap not defined", __func__, 1);
624 if (pindex) *pindex = 0;
626 return ERROR_INT(
"cmap not defined", __func__, 1);
662 return ERROR_INT(
"cmap not defined", __func__, 1);
686 return ERROR_INT(
"cmap not defined", __func__, 0);
701 return ERROR_INT(
"cmap not defined", __func__, 0);
702 return (cmap->
nalloc - cmap->
n);
716 return ERROR_INT(
"cmap not defined", __func__, 0);
740 return ERROR_INT(
"&mindepth not defined", __func__, 1);
743 return ERROR_INT(
"cmap not defined", __func__, 1);
748 else if (ncolors <= 16)
771 return ERROR_INT(
"cmap not defined", __func__, 1);
797 if (!prval || !pgval || !pbval)
798 return ERROR_INT(
"&rval, &gval, &bval not all defined", __func__, 1);
799 *prval = *pgval = *pbval = 0;
801 return ERROR_INT(
"cmap not defined", __func__, 1);
802 if (index < 0 || index >= cmap->
n)
803 return ERROR_INT(
"index out of bounds", __func__, 1);
806 *prval = cta[index].
red;
807 *pgval = cta[index].
green;
808 *pbval = cta[index].
blue;
831l_int32 rval, gval, bval;
834 return ERROR_INT(
"&val32 not defined", __func__, 1);
838 return ERROR_INT(
"rgb values not found", __func__, 1);
839 composeRGBAPixel(rval, gval, bval, 255, pval32);
862 if (!prval || !pgval || !pbval || !paval)
863 return ERROR_INT(
"&rval, &gval, &bval, &aval not all defined",
865 *prval = *pgval = *pbval = *paval = 0;
867 return ERROR_INT(
"cmap not defined", __func__, 1);
868 if (index < 0 || index >= cmap->
n)
869 return ERROR_INT(
"index out of bounds", __func__, 1);
872 *prval = cta[index].
red;
873 *pgval = cta[index].
green;
874 *pbval = cta[index].
blue;
875 *paval = cta[index].
alpha;
893l_int32 rval, gval, bval, aval;
896 return ERROR_INT(
"&val32 not defined", __func__, 1);
900 return ERROR_INT(
"rgba values not found", __func__, 1);
901 composeRGBAPixel(rval, gval, bval, aval, pval32);
932 return ERROR_INT(
"cmap not defined", __func__, 1);
933 if (index < 0 || index >= cmap->
n)
934 return ERROR_INT(
"index out of bounds", __func__, 1);
937 cta[index].
red = rval;
938 cta[index].
green = gval;
939 cta[index].
blue = bval;
940 cta[index].
alpha = 255;
969 return ERROR_INT(
"cmap not defined", __func__, 1);
970 if (index < 0 || index >= cmap->
n)
971 return ERROR_INT(
"index out of bounds", __func__, 1);
974 cta[index].
alpha = aval;
999 return ERROR_INT(
"&index not defined", __func__, 1);
1002 return ERROR_INT(
"cmap not defined", __func__, 1);
1006 for (i = 0; i < n; i++) {
1007 if (rval == cta[i].red &&
1008 gval == cta[i].green &&
1009 bval == cta[i].blue) {
1030l_int32 *rmap, *gmap, *bmap;
1033 return ERROR_INT(
"&color not defined", __func__, 1);
1036 return ERROR_INT(
"cmap not defined", __func__, 1);
1039 return ERROR_INT(
"colormap arrays not made", __func__, 1);
1041 for (i = 0; i < n; i++) {
1042 if ((rmap[i] != gmap[i]) || (rmap[i] != bmap[i])) {
1070 return ERROR_INT(
"&opaque not defined", __func__, 1);
1073 return ERROR_INT(
"cmap not defined", __func__, 1);
1077 for (i = 0; i < n; i++) {
1078 if (cta[i].alpha != 255) {
1122 l_int32 *pmax_trans,
1123 l_int32 *pmin_opaque)
1125l_int32 i, n, ntrans, max_trans, min_opaque, opaque_found;
1128 if (pntrans) *pntrans = 0;
1129 if (pmax_trans) *pmax_trans = -1;
1130 if (pmin_opaque) *pmin_opaque = 256;
1132 return ERROR_INT(
"cmap not defined", __func__, 1);
1139 opaque_found = FALSE;
1140 for (i = 0; i < n; i++) {
1141 if (cta[i].alpha != 255) {
1144 }
else if (opaque_found == FALSE) {
1145 opaque_found = TRUE;
1149 if (pntrans) *pntrans = ntrans;
1150 if (pmax_trans) *pmax_trans = max_trans;
1151 if (pmin_opaque) *pmin_opaque = min_opaque;
1166 l_int32 *pblackwhite)
1168l_int32 val0, val1, hascolor;
1172 return ERROR_INT(
"&blackwhite not defined", __func__, 1);
1173 *pblackwhite = FALSE;
1175 return ERROR_INT(
"cmap not defined", __func__, 1);
1180 if (hascolor)
return 0;
1185 if ((val0 == 0 && val1 == 255) || (val0 == 255 && val1 == 0))
1186 *pblackwhite = TRUE;
1207l_int32 n, i, rval, gval, bval, count;
1211 return ERROR_INT(
"&ngray not defined", __func__, 1);
1214 return ERROR_INT(
"cmap not defined", __func__, 1);
1216 array = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
1219 for (i = 0; i < n; i++) {
1221 if ((rval == gval) && (rval == bval) && (array[rval] == 0)) {
1247l_int32 n, i, rval, gval, bval, rankindex;
1251 return ERROR_INT(
"&index not defined", __func__, 1);
1254 return ERROR_INT(
"cmap not defined", __func__, 1);
1255 if (rankval < 0.0 || rankval > 1.0)
1256 return ERROR_INT(
"rankval not in [0.0 ... 1.0]", __func__, 1);
1260 for (i = 0; i < n; i++) {
1262 numaAddNumber(na, rval + gval + bval);
1265 rankindex = (l_int32)(rankval * (n - 1) + 0.5);
1266 numaGetIValue(nasort, rankindex, pindex);
1269 numaDestroy(&nasort);
1298l_int32 i, n, delta, dist, mindist;
1302 return ERROR_INT(
"&index not defined", __func__, 1);
1305 return ERROR_INT(
"cmap not defined", __func__, 1);
1308 return ERROR_INT(
"cta not defined(!)", __func__, 1);
1311 mindist = 3 * 255 * 255 + 1;
1312 for (i = 0; i < n; i++) {
1313 delta = cta[i].
red - rval;
1314 dist = delta * delta;
1315 delta = cta[i].
green - gval;
1316 dist += delta * delta;
1317 delta = cta[i].
blue - bval;
1318 dist += delta * delta;
1319 if (dist < mindist) {
1352l_int32 i, n, dist, mindist;
1356 return ERROR_INT(
"&index not defined", __func__, 1);
1359 return ERROR_INT(
"cmap not defined", __func__, 1);
1360 if (val < 0 || val > 255)
1361 return ERROR_INT(
"val not in [0 ... 255]", __func__, 1);
1364 return ERROR_INT(
"cta not defined(!)", __func__, 1);
1368 for (i = 0; i < n; i++) {
1369 dist = cta[i].
green - val;
1371 if (dist < mindist) {
1406l_int32 n, delta, dist;
1410 return ERROR_INT(
"&dist not defined", __func__, 1);
1413 return ERROR_INT(
"cmap not defined", __func__, 1);
1416 return ERROR_INT(
"invalid index", __func__, 1);
1419 return ERROR_INT(
"cta not defined(!)", __func__, 1);
1421 delta = cta[index].
red - rval;
1422 dist = delta * delta;
1423 delta = cta[index].
green - gval;
1424 dist += delta * delta;
1425 delta = cta[index].
blue - bval;
1426 dist += delta * delta;
1460l_int32 i, n, imin, imax, minval, maxval, rval, gval, bval, aveval;
1462 if (pminval) *pminval = UNDEF;
1463 if (pmaxval) *pmaxval = UNDEF;
1464 if (pminindex) *pminindex = UNDEF;
1465 if (pmaxindex) *pmaxindex = UNDEF;
1466 if (!pminval && !pmaxval && !pminindex && !pmaxindex)
1467 return ERROR_INT(
"no result requested", __func__, 1);
1469 return ERROR_INT(
"cmap not defined", __func__, 1);
1476 for (i = 0; i < n; i++) {
1479 if (rval < minval) {
1483 if (rval > maxval) {
1488 if (gval < minval) {
1492 if (gval > maxval) {
1497 if (bval < minval) {
1501 if (bval > maxval) {
1506 aveval = (rval + gval + bval) / 3;
1507 if (aveval < minval) {
1511 if (aveval > maxval) {
1516 return ERROR_INT(
"invalid selection", __func__, 1);
1520 if (pminval) *pminval = minval;
1521 if (pmaxval) *pmaxval = maxval;
1522 if (pminindex) *pminindex = imin;
1523 if (pmaxindex) *pmaxindex = imax;
1547l_int32 i, rval, gval, bval;
1549l_float32 invgamma, x;
1552 if (gamma <= 0.0) gamma = 1.0;
1555 curve = (l_int32 *)LEPT_CALLOC(64,
sizeof(l_int32));
1556 invgamma = 1. / gamma;
1557 for (i = 0; i < 64; i++) {
1558 x = (l_float32)i / 64.;
1559 curve[i] = (l_int32)(255. * powf(x, invgamma) + 0.5);
1563 for (i = 0; i < 256; i++) {
1567 bval = curve[i + 32];
1568 }
else if (i < 96) {
1570 gval = curve[i - 32];
1572 }
else if (i < 160) {
1573 rval = curve[i - 96];
1575 bval = curve[159 - i];
1576 }
else if (i < 224) {
1578 gval = curve[223 - i];
1581 rval = curve[287 - i];
1611l_int32 i, rval, gval, bval;
1614 extractRGBValues(color, &rval, &gval, &bval);
1616 for (i = 0; i < 256; i++) {
1618 gval + (i * (255 - gval)) / 255,
1619 bval + (i * (255 - bval)) / 255);
1646l_int32 i, n, rval, gval, bval, val;
1651 return (
PIXCMAP *)ERROR_PTR(
"cmaps not defined", __func__, NULL);
1652 if (rwt < 0.0 || gwt < 0.0 || bwt < 0.0)
1653 return (
PIXCMAP *)ERROR_PTR(
"weights not all >= 0.0", __func__, NULL);
1657 sum = rwt + gwt + bwt;
1659 L_WARNING(
"all weights zero; setting equal to 1/3\n", __func__);
1660 rwt = gwt = bwt = 0.33333f;
1663 if (L_ABS(sum - 1.0) > 0.0001) {
1664 L_WARNING(
"weights don't sum to 1; maintaining ratios\n", __func__);
1671 return (
PIXCMAP *)ERROR_PTR(
"cmapd not made", __func__, NULL);
1673 for (i = 0; i < n; i++) {
1675 val = (l_int32)(rwt * rval + gwt * gval + bwt * bval + 0.5);
1698l_int32 i, n, rval, gval, bval;
1702 return (
PIXCMAP *)ERROR_PTR(
"cmaps not defined", __func__, NULL);
1704 return (
PIXCMAP *)ERROR_PTR(
"cmaps not for 2 bpp pix", __func__, NULL);
1708 for (i = 0; i < n; i++) {
1731l_int32 i, n, depth, rval, gval, bval;
1735 return (
PIXCMAP *)ERROR_PTR(
"cmaps not defined", __func__, NULL);
1738 if (depth != 2 && depth != 4)
1739 return (
PIXCMAP *)ERROR_PTR(
"cmaps not 2 or 4 bpp", __func__, NULL);
1743 for (i = 0; i < n; i++) {
1767 return (
PIXCMAP *)ERROR_PTR(
"filename not defined", __func__, NULL);
1769 if ((fp = fopenReadStream(filename)) == NULL)
1770 return (
PIXCMAP *)ERROR_PTR_1(
"stream not opened",
1771 filename, __func__, NULL);
1775 return (
PIXCMAP *)ERROR_PTR_1(
"cmap not read",
1776 filename, __func__, NULL);
1790l_int32 rval, gval, bval, aval, ignore;
1791l_int32 i, index, ret, depth, ncolors;
1795 return (
PIXCMAP *)ERROR_PTR(
"stream not defined", __func__, NULL);
1797 ret = fscanf(fp,
"\nPixcmap: depth = %d bpp; %d colors\n",
1800 (depth != 1 && depth != 2 && depth != 4 && depth != 8) ||
1801 (ncolors < 2 || ncolors > 256))
1802 return (
PIXCMAP *)ERROR_PTR(
"invalid cmap size", __func__, NULL);
1803 ignore = fscanf(fp,
"Color R-val G-val B-val Alpha\n");
1804 ignore = fscanf(fp,
"----------------------------------------\n");
1807 return (
PIXCMAP *)ERROR_PTR(
"cmap not made", __func__, NULL);
1808 for (i = 0; i < ncolors; i++) {
1809 if (fscanf(fp,
"%3d %3d %3d %3d %3d\n",
1810 &index, &rval, &gval, &bval, &aval) != 5) {
1812 return (
PIXCMAP *)ERROR_PTR(
"invalid entry", __func__, NULL);
1835 return (
PIXCMAP *)ERROR_PTR(
"data not defined", __func__, NULL);
1836 if ((fp = fopenReadFromMemory(data, size)) == NULL)
1837 return (
PIXCMAP *)ERROR_PTR(
"stream not opened", __func__, NULL);
1841 if (!cmap) L_ERROR(
"cmap not read\n", __func__);
1861 return ERROR_INT(
"filename not defined", __func__, 1);
1863 return ERROR_INT(
"cmap not defined", __func__, 1);
1865 if ((fp = fopenWriteStream(filename,
"w")) == NULL)
1866 return ERROR_INT_1(
"stream not opened", filename, __func__, 1);
1870 return ERROR_INT_1(
"cmap not written to stream", filename, __func__, 1);
1887l_int32 *rmap, *gmap, *bmap, *amap;
1891 return ERROR_INT(
"stream not defined", __func__, 1);
1893 return ERROR_INT(
"cmap not defined", __func__, 1);
1896 return ERROR_INT(
"colormap arrays not made", __func__, 1);
1898 fprintf(fp,
"\nPixcmap: depth = %d bpp; %d colors\n", cmap->
depth, cmap->
n);
1899 fprintf(fp,
"Color R-val G-val B-val Alpha\n");
1900 fprintf(fp,
"----------------------------------------\n");
1901 for (i = 0; i < cmap->
n; i++)
1902 fprintf(fp,
"%3d %3d %3d %3d %3d\n",
1903 i, rmap[i], gmap[i], bmap[i], amap[i]);
1935 if (pdata) *pdata = NULL;
1936 if (psize) *psize = 0;
1938 return ERROR_INT(
"&data not defined", __func__, 1);
1940 return ERROR_INT(
"&size not defined", __func__, 1);
1942 return ERROR_INT(
"cmap not defined", __func__, 1);
1945 if ((fp = open_memstream((
char **)pdata, psize)) == NULL)
1946 return ERROR_INT(
"stream not opened", __func__, 1);
1950 *psize = *psize - 1;
1952 L_INFO(
"no fmemopen API --> work-around: write to temp file\n", __func__);
1954 if ((fp = fopenWriteWinTempfile()) == NULL)
1955 return ERROR_INT(
"tmpfile stream not opened", __func__, 1);
1957 if ((fp = tmpfile()) == NULL)
1958 return ERROR_INT(
"tmpfile stream not opened", __func__, 1);
1962 *pdata = l_binaryReadStream(fp, psize);
1989l_int32 *rmap, *gmap, *bmap, *amap = NULL;
1993 if (!prmap || !pgmap || !pbmap)
1994 return ERROR_INT(
"&rmap, &gmap, &bmap not all defined", __func__, 1);
1995 *prmap = *pgmap = *pbmap = NULL;
1996 if (pamap) *pamap = NULL;
1998 return ERROR_INT(
"cmap not defined", __func__, 1);
2001 rmap = (l_int32 *)LEPT_CALLOC(ncolors,
sizeof(l_int32));
2002 gmap = (l_int32 *)LEPT_CALLOC(ncolors,
sizeof(l_int32));
2003 bmap = (l_int32 *)LEPT_CALLOC(ncolors,
sizeof(l_int32));
2008 amap = (l_int32 *)LEPT_CALLOC(ncolors,
sizeof(l_int32));
2013 for (i = 0; i < ncolors; i++) {
2014 rmap[i] = cta[i].
red;
2015 gmap[i] = cta[i].
green;
2016 bmap[i] = cta[i].
blue;
2018 amap[i] = cta[i].
alpha;
2038l_int32 i, ncolors, rval, gval, bval, aval;
2042 return ERROR_INT(
"&tab not defined", __func__, 1);
2045 return ERROR_INT(
"cmap not defined", __func__, 1);
2048 if (pncolors) *pncolors = ncolors;
2049 tab = (l_uint32 *)LEPT_CALLOC(ncolors,
sizeof(l_uint32));
2052 for (i = 0; i < ncolors; i++) {
2054 composeRGBAPixel(rval, gval, bval, aval, &tab[i]);
2080l_int32 i, ncolors, rval, gval, bval, aval;
2084 return ERROR_INT(
"&data not defined", __func__, 1);
2087 return ERROR_INT(
"&ncolors not defined", __func__, 1);
2090 return ERROR_INT(
"cmap not defined", __func__, 1);
2091 if (cpc != 3 && cpc != 4)
2092 return ERROR_INT(
"cpc not 3 or 4", __func__, 1);
2095 *pncolors = ncolors;
2096 data = (l_uint8 *)LEPT_CALLOC((
size_t)cpc * ncolors,
sizeof(l_uint8));
2099 for (i = 0; i < ncolors; i++) {
2101 data[cpc * i] = rval;
2102 data[cpc * i + 1] = gval;
2103 data[cpc * i + 2] = bval;
2105 data[cpc * i + 3] = aval;
2124l_int32 i, d, rval, gval, bval, aval;
2128 return (
PIXCMAP *)ERROR_PTR(
"data not defined", __func__, NULL);
2129 if (cpc != 3 && cpc != 4)
2130 return (
PIXCMAP *)ERROR_PTR(
"cpc not 3 or 4", __func__, NULL);
2132 return (
PIXCMAP *)ERROR_PTR(
"no entries", __func__, NULL);
2134 return (
PIXCMAP *)ERROR_PTR(
"ncolors > 256", __func__, NULL);
2138 else if (ncolors > 4)
2140 else if (ncolors > 2)
2145 for (i = 0; i < ncolors; i++) {
2146 rval = data[cpc * i];
2147 gval = data[cpc * i + 1];
2148 bval = data[cpc * i + 2];
2150 aval = data[cpc * i + 3];
2182l_int32 i, j, hexbytes;
2183char *hexdata = NULL;
2187 return (
char *)ERROR_PTR(
"data not defined", __func__, NULL);
2189 return (
char *)ERROR_PTR(
"no colors", __func__, NULL);
2191 hexbytes = 2 + (2 * 3 + 1) * ncolors + 2;
2192 hexdata = (
char *)LEPT_CALLOC(hexbytes,
sizeof(
char));
2196 for (i = 0; i < ncolors; i++) {
2197 j = 2 + (2 * 3 + 1) * i;
2198 snprintf(buf,
sizeof(buf),
"%02x", data[3 * i]);
2199 hexdata[j] = buf[0];
2200 hexdata[j + 1] = buf[1];
2201 snprintf(buf,
sizeof(buf),
"%02x", data[3 * i + 1]);
2202 hexdata[j + 2] = buf[0];
2203 hexdata[j + 3] = buf[1];
2204 snprintf(buf,
sizeof(buf),
"%02x", data[3 * i + 2]);
2205 hexdata[j + 4] = buf[0];
2206 hexdata[j + 5] = buf[1];
2207 hexdata[j + 6] =
' ';
2209 hexdata[j + 7] =
'>';
2210 hexdata[j + 8] =
'\0';
2240l_int32 rval, gval, bval, trval, tgval, tbval, i, ncolors;
2244 return ERROR_INT(
"cmap not defined", __func__, 1);
2246 L_WARNING(
"gamma must be > 0.0; setting to 1.0\n", __func__);
2249 if (minval >= maxval)
2250 return ERROR_INT(
"minval not < maxval", __func__, 1);
2252 if (gamma == 1.0 && minval == 0 && maxval == 255)
2255 if ((nag = numaGammaTRC(gamma, minval, maxval)) == NULL)
2256 return ERROR_INT(
"nag not made", __func__, 1);
2259 for (i = 0; i < ncolors; i++) {
2261 numaGetIValue(nag, rval, &trval);
2262 numaGetIValue(nag, gval, &tgval);
2263 numaGetIValue(nag, bval, &tbval);
2291l_int32 i, ncolors, rval, gval, bval, trval, tgval, tbval;
2295 return ERROR_INT(
"cmap not defined", __func__, 1);
2297 L_WARNING(
"factor must be >= 0.0; setting to 0.0\n", __func__);
2301 if ((nac = numaContrastTRC(factor)) == NULL)
2302 return ERROR_INT(
"nac not made", __func__, 1);
2305 for (i = 0; i < ncolors; i++) {
2307 numaGetIValue(nac, rval, &trval);
2308 numaGetIValue(nac, gval, &tgval);
2309 numaGetIValue(nac, bval, &tbval);
2341l_int32 i, ncolors, rval, gval, bval;
2344 return ERROR_INT(
"cmap not defined", __func__, 1);
2345 if (fraction < -1.0 || fraction > 1.0)
2346 return ERROR_INT(
"fraction not in [-1.0, 1.0]", __func__, 1);
2349 for (i = 0; i < ncolors; i++) {
2353 (l_int32)((1.0 + fraction) * rval),
2354 (l_int32)((1.0 + fraction) * gval),
2355 (l_int32)((1.0 + fraction) * bval));
2358 rval + (l_int32)(fraction * (255 - rval)),
2359 gval + (l_int32)(fraction * (255 - gval)),
2360 bval + (l_int32)(fraction * (255 - bval)));
2390l_int32 i, ncolors, rval, gval, bval;
2394 return ERROR_INT(
"cmap not defined", __func__, 1);
2397 for (i = 0; i < ncolors; i++) {
2399 pixelShiftByComponent(rval, gval, bval, srcval, dstval, &newval);
2400 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