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

Function pixThresholdOn8bpp

deps/leptonica/src/grayquant.c:1631–1683  ·  view source on GitHub ↗

----------------------------------------------------------------------* * Simple (pixelwise) thresholding on 8 bpp with optional colormap * *----------------------------------------------------------------------*/ ! * \brief pixThresholdOn8bpp() * * \param[in] pixs 8 bpp, can have colormap * \param[in] nlevels equally spaced; must be between 2 and 256 * \param[in] cmapflag 1

Source from the content-addressed store, hash-verified

1629 * </pre>
1630 */
1631PIX *
1632pixThresholdOn8bpp(PIX *pixs,
1633 l_int32 nlevels,
1634 l_int32 cmapflag)
1635{
1636l_int32 *qtab; /* quantization table */
1637l_int32 i, j, w, h, wpld, val, newval;
1638l_uint32 *datad, *lined;
1639PIX *pixd;
1640PIXCMAP *cmap;
1641
1642 PROCNAME("pixThresholdOn8bpp");
1643
1644 if (!pixs)
1645 return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
1646 if (pixGetDepth(pixs) != 8)
1647 return (PIX *)ERROR_PTR("pixs not 8 bpp", procName, NULL);
1648 if (nlevels < 2 || nlevels > 256)
1649 return (PIX *)ERROR_PTR("nlevels not in [2,...,256]", procName, NULL);
1650
1651 /* Get a new pixd; if there is a colormap in the src, remove it */
1652 if (pixGetColormap(pixs))
1653 pixd = pixRemoveColormap(pixs, REMOVE_CMAP_TO_GRAYSCALE);
1654 else
1655 pixd = pixCopy(NULL, pixs);
1656
1657 if (cmapflag) { /* hold out (256 - nlevels) cmap entries */
1658 cmap = pixcmapCreateLinear(8, nlevels);
1659 pixSetColormap(pixd, cmap);
1660 }
1661
1662 if (cmapflag)
1663 qtab = makeGrayQuantIndexTable(nlevels);
1664 else
1665 qtab = makeGrayQuantTargetTable(nlevels, 8);
1666
1667 pixGetDimensions(pixd, &w, &h, NULL);
1668 pixCopyResolution(pixd, pixs);
1669 pixCopyInputFormat(pixd, pixs);
1670 datad = pixGetData(pixd);
1671 wpld = pixGetWpl(pixd);
1672 for (i = 0; i < h; i++) {
1673 lined = datad + i * wpld;
1674 for (j = 0; j < w; j++) {
1675 val = GET_DATA_BYTE(lined, j);
1676 newval = qtab[val];
1677 SET_DATA_BYTE(lined, j, newval);
1678 }
1679 }
1680
1681 LEPT_FREE(qtab);
1682 return pixd;
1683}
1684
1685
1686/*----------------------------------------------------------------------*

Callers 4

pixMedianCutQuantMixedFunction · 0.85
pixThreshold8Function · 0.85
pixQuantizeIfFewColorsFunction · 0.85

Calls 13

pixGetDepthFunction · 0.85
pixGetColormapFunction · 0.85
pixRemoveColormapFunction · 0.85
pixCopyFunction · 0.85
pixcmapCreateLinearFunction · 0.85
pixSetColormapFunction · 0.85
makeGrayQuantIndexTableFunction · 0.85
makeGrayQuantTargetTableFunction · 0.85
pixGetDimensionsFunction · 0.85
pixCopyResolutionFunction · 0.85
pixCopyInputFormatFunction · 0.85
pixGetDataFunction · 0.85

Tested by

no test coverage detected