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

Function pixThresholdTo4bpp

deps/leptonica/src/grayquant.c:1514–1563  ·  view source on GitHub ↗

----------------------------------------------------------------------* * Simple (pixelwise) thresholding to 4 bpp * *----------------------------------------------------------------------*/ ! * \brief pixThresholdTo4bpp() * * \param[in] pixs 8 bpp, can have colormap * \param[in] nlevels equally spaced; must be between 2 and 16 * \param[in] cmapflag 1

Source from the content-addressed store, hash-verified

1512 * </pre>
1513 */
1514PIX *
1515pixThresholdTo4bpp(PIX *pixs,
1516 l_int32 nlevels,
1517 l_int32 cmapflag)
1518{
1519l_int32 *qtab;
1520l_int32 w, h, d, wplt, wpld;
1521l_uint32 *datat, *datad;
1522PIX *pixt, *pixd;
1523PIXCMAP *cmap;
1524
1525 PROCNAME("pixThresholdTo4bpp");
1526
1527 if (!pixs)
1528 return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
1529 pixGetDimensions(pixs, &w, &h, &d);
1530 if (d != 8)
1531 return (PIX *)ERROR_PTR("pixs not 8 bpp", procName, NULL);
1532 if (nlevels < 2 || nlevels > 16)
1533 return (PIX *)ERROR_PTR("nlevels not in [2,...,16]", procName, NULL);
1534
1535 if ((pixd = pixCreate(w, h, 4)) == NULL)
1536 return (PIX *)ERROR_PTR("pixd not made", procName, NULL);
1537 pixCopyResolution(pixd, pixs);
1538 pixCopyInputFormat(pixd, pixs);
1539 datad = pixGetData(pixd);
1540 wpld = pixGetWpl(pixd);
1541
1542 if (cmapflag) { /* hold out (16 - nlevels) cmap entries */
1543 cmap = pixcmapCreateLinear(4, nlevels);
1544 pixSetColormap(pixd, cmap);
1545 }
1546
1547 /* If there is a colormap in the src, remove it */
1548 pixt = pixRemoveColormap(pixs, REMOVE_CMAP_TO_GRAYSCALE);
1549 datat = pixGetData(pixt);
1550 wplt = pixGetWpl(pixt);
1551
1552 /* Make the appropriate table */
1553 if (cmapflag)
1554 qtab = makeGrayQuantIndexTable(nlevels);
1555 else
1556 qtab = makeGrayQuantTargetTable(16, 4);
1557
1558 thresholdTo4bppLow(datad, h, wpld, datat, wplt, qtab);
1559
1560 LEPT_FREE(qtab);
1561 pixDestroy(&pixt);
1562 return pixd;
1563}
1564
1565
1566/*!

Callers 3

pixThreshold8Function · 0.85
pixQuantizeIfFewColorsFunction · 0.85
pixDisplayMatchedPatternFunction · 0.85

Calls 13

pixGetDimensionsFunction · 0.85
pixCreateFunction · 0.85
pixCopyResolutionFunction · 0.85
pixCopyInputFormatFunction · 0.85
pixGetDataFunction · 0.85
pixGetWplFunction · 0.85
pixcmapCreateLinearFunction · 0.85
pixSetColormapFunction · 0.85
pixRemoveColormapFunction · 0.85
makeGrayQuantIndexTableFunction · 0.85
makeGrayQuantTargetTableFunction · 0.85
thresholdTo4bppLowFunction · 0.85

Tested by

no test coverage detected