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

Function pixConvert4To8

deps/leptonica/src/pixconv.c:2566–2628  ·  view source on GitHub ↗

! * \brief pixConvert4To8() * * \param[in] pixs 4 bpp * \param[in] cmapflag TRUE if pixd is to have a colormap; FALSE otherwise * \return pixd 8 bpp, or NULL on error * * * Notes: * ~ If cmapflag is TRUE: * ~ pixd is made with a colormap. * ~ If pixs has a colormap, it is copied and the colormap * index values are placed in pixd.

Source from the content-addressed store, hash-verified

2564 * </pre>
2565 */
2566PIX *
2567pixConvert4To8(PIX *pixs,
2568 l_int32 cmapflag)
2569{
2570l_int32 w, h, i, j, wpls, wpld, byte, qbit;
2571l_uint32 *datas, *datad, *lines, *lined;
2572PIX *pixd;
2573PIXCMAP *cmaps, *cmapd;
2574
2575 PROCNAME("pixConvert4To8");
2576
2577 if (!pixs)
2578 return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
2579 if (pixGetDepth(pixs) != 4)
2580 return (PIX *)ERROR_PTR("pixs not 4 bpp", procName, NULL);
2581
2582 cmaps = pixGetColormap(pixs);
2583 if (cmaps && cmapflag == FALSE)
2584 return pixRemoveColormap(pixs, REMOVE_CMAP_TO_GRAYSCALE);
2585
2586 pixGetDimensions(pixs, &w, &h, NULL);
2587 if ((pixd = pixCreate(w, h, 8)) == NULL)
2588 return (PIX *)ERROR_PTR("pixd not made", procName, NULL);
2589 pixCopyResolution(pixd, pixs);
2590 pixCopyInputFormat(pixd, pixs);
2591 datas = pixGetData(pixs);
2592 wpls = pixGetWpl(pixs);
2593 datad = pixGetData(pixd);
2594 wpld = pixGetWpl(pixd);
2595
2596 if (cmapflag == TRUE) { /* pixd will have a colormap */
2597 if (cmaps) { /* use the existing colormap from pixs */
2598 cmapd = pixcmapConvertTo8(cmaps);
2599 } else { /* make a colormap with a linear trc */
2600 cmapd = pixcmapCreate(8);
2601 for (i = 0; i < 16; i++)
2602 pixcmapAddColor(cmapd, 17 * i, 17 * i, 17 * i);
2603 }
2604 pixSetColormap(pixd, cmapd);
2605 for (i = 0; i < h; i++) {
2606 lines = datas + i * wpls;
2607 lined = datad + i * wpld;
2608 for (j = 0; j < w; j++) {
2609 qbit = GET_DATA_QBIT(lines, j);
2610 SET_DATA_BYTE(lined, j, qbit);
2611 }
2612 }
2613 return pixd;
2614 }
2615
2616 /* Last case: no colormap in either pixs or pixd.
2617 * Replicate the qbit value into 8 bits. */
2618 for (i = 0; i < h; i++) {
2619 lines = datas + i * wpls;
2620 lined = datad + i * wpld;
2621 for (j = 0; j < w; j++) {
2622 qbit = GET_DATA_QBIT(lines, j);
2623 byte = (qbit << 4) | qbit;

Callers 4

pixConvertTo2Function · 0.85
pixConvertTo8Function · 0.85
pixConvertTo32Function · 0.85
pixConvertForPSWrapFunction · 0.85

Calls 13

pixGetDepthFunction · 0.85
pixGetColormapFunction · 0.85
pixRemoveColormapFunction · 0.85
pixGetDimensionsFunction · 0.85
pixCreateFunction · 0.85
pixCopyResolutionFunction · 0.85
pixCopyInputFormatFunction · 0.85
pixGetDataFunction · 0.85
pixGetWplFunction · 0.85
pixcmapConvertTo8Function · 0.85
pixcmapCreateFunction · 0.85
pixcmapAddColorFunction · 0.85

Tested by

no test coverage detected