MCPcopy Create free account
hub / github.com/creatale/node-dv / makeGrayQuantTargetTable

Function makeGrayQuantTargetTable

deps/leptonica/src/grayquant.c:1894–1921  ·  view source on GitHub ↗

! * \brief makeGrayQuantTargetTable() * * \param[in] nlevels number of output levels * \param[in] depth of dest pix, in bpp; 2, 4 or 8 bpp * \return table maps input gray level to thresholded gray level, * or NULL on error * * * Notes: * (1) nlevels is some number between 2 and 2^(depth) * (2) The table is used in two similar ways: *

Source from the content-addressed store, hash-verified

1892 * </pre>
1893 */
1894static l_int32 *
1895makeGrayQuantTargetTable(l_int32 nlevels,
1896 l_int32 depth)
1897{
1898l_int32 *tab;
1899l_int32 i, j, thresh, maxval, quantval;
1900
1901 PROCNAME("makeGrayQuantTargetTable");
1902
1903 if ((tab = (l_int32 *)LEPT_CALLOC(256, sizeof(l_int32))) == NULL)
1904 return (l_int32 *)ERROR_PTR("calloc fail for tab", procName, NULL);
1905
1906 maxval = (1 << depth) - 1;
1907 if (depth < 8)
1908 nlevels = 1 << depth;
1909 for (i = 0; i < 256; i++) {
1910 for (j = 0; j < nlevels; j++) {
1911 thresh = 255 * (2 * j + 1) / (2 * nlevels - 2);
1912 if (i <= thresh) {
1913 quantval = maxval * j / (nlevels - 1);
1914 tab[i] = quantval;
1915/* fprintf(stderr, "tab[%d] = %d\n", i, tab[i]); */
1916 break;
1917 }
1918 }
1919 }
1920 return tab;
1921}
1922
1923
1924/*----------------------------------------------------------------------*

Callers 3

pixThresholdTo2bppFunction · 0.85
pixThresholdTo4bppFunction · 0.85
pixThresholdOn8bppFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected