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

Function pixThresholdTo2bpp

deps/leptonica/src/grayquant.c:1372–1421  ·  view source on GitHub ↗

--------------------------------------------------------------------* * Simple (pixelwise) thresholding to 2 bpp with optional colormap * *--------------------------------------------------------------------*/ ! * \brief pixThresholdTo2bpp() * * \param[in] pixs 8 bpp * \param[in] nlevels equally spaced; must be between 2 and 4 * \param[in] cmapflag 1 to build colormap; 0 other

Source from the content-addressed store, hash-verified

1370 * </pre>
1371 */
1372PIX *
1373pixThresholdTo2bpp(PIX *pixs,
1374 l_int32 nlevels,
1375 l_int32 cmapflag)
1376{
1377l_int32 *qtab;
1378l_int32 w, h, d, wplt, wpld;
1379l_uint32 *datat, *datad;
1380PIX *pixt, *pixd;
1381PIXCMAP *cmap;
1382
1383 PROCNAME("pixThresholdTo2bpp");
1384
1385 if (!pixs)
1386 return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
1387 pixGetDimensions(pixs, &w, &h, &d);
1388 if (d != 8)
1389 return (PIX *)ERROR_PTR("pixs not 8 bpp", procName, NULL);
1390 if (nlevels < 2 || nlevels > 4)
1391 return (PIX *)ERROR_PTR("nlevels not in {2, 3, 4}", procName, NULL);
1392
1393 if ((pixd = pixCreate(w, h, 2)) == NULL)
1394 return (PIX *)ERROR_PTR("pixd not made", procName, NULL);
1395 pixCopyResolution(pixd, pixs);
1396 pixCopyInputFormat(pixd, pixs);
1397 datad = pixGetData(pixd);
1398 wpld = pixGetWpl(pixd);
1399
1400 if (cmapflag) { /* hold out (4 - nlevels) cmap entries */
1401 cmap = pixcmapCreateLinear(2, nlevels);
1402 pixSetColormap(pixd, cmap);
1403 }
1404
1405 /* If there is a colormap in the src, remove it */
1406 pixt = pixRemoveColormap(pixs, REMOVE_CMAP_TO_GRAYSCALE);
1407 datat = pixGetData(pixt);
1408 wplt = pixGetWpl(pixt);
1409
1410 /* Make the appropriate table */
1411 if (cmapflag)
1412 qtab = makeGrayQuantIndexTable(nlevels);
1413 else
1414 qtab = makeGrayQuantTargetTable(4, 2);
1415
1416 thresholdTo2bppLow(datad, h, wpld, datat, wplt, qtab);
1417
1418 LEPT_FREE(qtab);
1419 pixDestroy(&pixt);
1420 return pixd;
1421}
1422
1423
1424/*!

Callers 1

pixThreshold8Function · 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
thresholdTo2bppLowFunction · 0.85

Tested by

no test coverage detected