----------------------------------------------------------------------* * 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
| 1512 | * </pre> |
| 1513 | */ |
| 1514 | PIX * |
| 1515 | pixThresholdTo4bpp(PIX *pixs, |
| 1516 | l_int32 nlevels, |
| 1517 | l_int32 cmapflag) |
| 1518 | { |
| 1519 | l_int32 *qtab; |
| 1520 | l_int32 w, h, d, wplt, wpld; |
| 1521 | l_uint32 *datat, *datad; |
| 1522 | PIX *pixt, *pixd; |
| 1523 | PIXCMAP *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 | /*! |
no test coverage detected