----------------------------------------------------------------------* * Quantization tables for linear thresholds of grayscale images * *----------------------------------------------------------------------*/ ! * \brief makeGrayQuantIndexTable() * * \param[in] nlevels number of output levels * \return table maps input gray level to colormap index, * or NU
| 1840 | * </pre> |
| 1841 | */ |
| 1842 | l_int32 * |
| 1843 | makeGrayQuantIndexTable(l_int32 nlevels) |
| 1844 | { |
| 1845 | l_int32 *tab; |
| 1846 | l_int32 i, j, thresh; |
| 1847 | |
| 1848 | PROCNAME("makeGrayQuantIndexTable"); |
| 1849 | |
| 1850 | if ((tab = (l_int32 *)LEPT_CALLOC(256, sizeof(l_int32))) == NULL) |
| 1851 | return (l_int32 *)ERROR_PTR("calloc fail for tab", procName, NULL); |
| 1852 | for (i = 0; i < 256; i++) { |
| 1853 | for (j = 0; j < nlevels; j++) { |
| 1854 | thresh = 255 * (2 * j + 1) / (2 * nlevels - 2); |
| 1855 | if (i <= thresh) { |
| 1856 | tab[i] = j; |
| 1857 | /* fprintf(stderr, "tab[%d] = %d\n", i, j); */ |
| 1858 | break; |
| 1859 | } |
| 1860 | } |
| 1861 | } |
| 1862 | return tab; |
| 1863 | } |
| 1864 | |
| 1865 | |
| 1866 | /*! |
no outgoing calls
no test coverage detected