Leptonica 1.68
C Image Processing Library

grayquantlow.c File Reference

Low-level implementation for some grayscale quantiziation functions. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "allheaders.h"

Go to the source code of this file.

Defines

#define DEBUG_UNROLLING   0

Functions

void ditherToBinaryLow (l_uint32 *datad, l_int32 w, l_int32 h, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_uint32 *bufs1, l_uint32 *bufs2, l_int32 lowerclip, l_int32 upperclip)
void ditherToBinaryLineLow (l_uint32 *lined, l_int32 w, l_uint32 *bufs1, l_uint32 *bufs2, l_int32 lowerclip, l_int32 upperclip, l_int32 lastlineflag)
void thresholdToBinaryLow (l_uint32 *datad, l_int32 w, l_int32 h, l_int32 wpld, l_uint32 *datas, l_int32 d, l_int32 wpls, l_int32 thresh)
void thresholdToBinaryLineLow (l_uint32 *lined, l_int32 w, l_uint32 *lines, l_int32 d, l_int32 thresh)
void ditherToBinaryLUTLow (l_uint32 *datad, l_int32 w, l_int32 h, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_uint32 *bufs1, l_uint32 *bufs2, l_int32 *tabval, l_int32 *tab38, l_int32 *tab14)
void ditherToBinaryLineLUTLow (l_uint32 *lined, l_int32 w, l_uint32 *bufs1, l_uint32 *bufs2, l_int32 *tabval, l_int32 *tab38, l_int32 *tab14, l_int32 lastlineflag)
l_int32 make8To1DitherTables (l_int32 **ptabval, l_int32 **ptab38, l_int32 **ptab14, l_int32 lowerclip, l_int32 upperclip)
void ditherTo2bppLow (l_uint32 *datad, l_int32 w, l_int32 h, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_uint32 *bufs1, l_uint32 *bufs2, l_int32 *tabval, l_int32 *tab38, l_int32 *tab14)
void ditherTo2bppLineLow (l_uint32 *lined, l_int32 w, l_uint32 *bufs1, l_uint32 *bufs2, l_int32 *tabval, l_int32 *tab38, l_int32 *tab14, l_int32 lastlineflag)
l_int32 make8To2DitherTables (l_int32 **ptabval, l_int32 **ptab38, l_int32 **ptab14, l_int32 cliptoblack, l_int32 cliptowhite)
void thresholdTo2bppLow (l_uint32 *datad, l_int32 h, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_int32 *tab)
void thresholdTo4bppLow (l_uint32 *datad, l_int32 h, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_int32 *tab)

Detailed Description

Low-level implementation for some grayscale quantiziation functions.

    Thresholding from 8 bpp to 1 bpp

        Floyd-Steinberg dithering to binary
            void       ditherToBinaryLow()
            void       ditherToBinaryLineLow()

        Simple (pixelwise) binarization
            void       thresholdToBinaryLow()
            void       thresholdToBinaryLineLow()

        A slower version of Floyd-Steinberg dithering that uses LUTs
            void       ditherToBinaryLUTLow()
            void       ditherToBinaryLineLUTLow()
            l_int32    make8To1DitherTables()

    Thresholding from 8 bpp to 2 bpp

        Floyd-Steinberg-like dithering to 2 bpp
            void       ditherTo2bppLow()
            void       ditherTo2bppLineLow()
            l_int32    make8To2DitherTables()

        Simple thresholding to 2 bpp
            void       thresholdTo2bppLow()

    Thresholding from 8 bpp to 4 bpp

        Simple thresholding to 4 bpp
            void       thresholdTo4bppLow()

Definition in file grayquantlow.c.


Define Documentation

#define DEBUG_UNROLLING   0

Definition at line 56 of file grayquantlow.c.


Function Documentation

void ditherToBinaryLow ( l_uint32 datad,
l_int32  w,
l_int32  h,
l_int32  wpld,
l_uint32 datas,
l_int32  wpls,
l_uint32 bufs1,
l_uint32 bufs2,
l_int32  lowerclip,
l_int32  upperclip 
)

Definition at line 69 of file grayquantlow.c.

References ditherToBinaryLineLow().

Referenced by pixDitherToBinarySpec().

void ditherToBinaryLineLow ( l_uint32 lined,
l_int32  w,
l_uint32 bufs1,
l_uint32 bufs2,
l_int32  lowerclip,
l_int32  upperclip,
l_int32  lastlineflag 
)
void thresholdToBinaryLow ( l_uint32 datad,
l_int32  w,
l_int32  h,
l_int32  wpld,
l_uint32 datas,
l_int32  d,
l_int32  wpls,
l_int32  thresh 
)

Definition at line 243 of file grayquantlow.c.

References thresholdToBinaryLineLow().

Referenced by pixThresholdToBinary().

void thresholdToBinaryLineLow ( l_uint32 lined,
l_int32  w,
l_uint32 lines,
l_int32  d,
l_int32  thresh 
)
void ditherToBinaryLUTLow ( l_uint32 datad,
l_int32  w,
l_int32  h,
l_int32  wpld,
l_uint32 datas,
l_int32  wpls,
l_uint32 bufs1,
l_uint32 bufs2,
l_int32 tabval,
l_int32 tab38,
l_int32 tab14 
)

ditherToBinaryLUTLow()

Low-level function for doing Floyd-Steinberg error diffusion dithering from 8 bpp (datas) to 1 bpp (datad). Two source line buffers, bufs1 and bufs2, are provided, along with three 256-entry lookup tables: tabval gives the output pixel value, tab38 gives the extra (plus or minus) transferred to the pixels directly to the left and below, and tab14 gives the extra transferred to the diagonal below. The choice of 3/8 and 1/4 is traditional but arbitrary when you use a lookup table; the only constraint is that the sum is 1. See other comments below.

Definition at line 402 of file grayquantlow.c.

References ditherToBinaryLineLUTLow().

Referenced by pixDitherToBinaryLUT().

void ditherToBinaryLineLUTLow ( l_uint32 lined,
l_int32  w,
l_uint32 bufs1,
l_uint32 bufs2,
l_int32 tabval,
l_int32 tab38,
l_int32 tab14,
l_int32  lastlineflag 
)

ditherToBinaryLineLUTLow()

Input: lined (ptr to beginning of dest line w (width of image in pixels) bufs1 (buffer of current source line) bufs2 (buffer of next source line) tabval (value to assign for current pixel) tab38 (excess value to give to neighboring 3/8 pixels) tab14 (excess value to give to neighboring 1/4 pixel) lastlineflag (0 if not last dest line, 1 if last dest line) Return: void

Definition at line 449 of file grayquantlow.c.

References GET_DATA_BYTE, L_MAX, L_MIN, SET_DATA_BIT, and SET_DATA_BYTE.

Referenced by ditherToBinaryLUTLow().

l_int32 make8To1DitherTables ( l_int32 **  ptabval,
l_int32 **  ptab38,
l_int32 **  ptab14,
l_int32  lowerclip,
l_int32  upperclip 
)

make8To1DitherTables()

Input: &tabval (value assigned to output pixel; 0 or 1) &tab38 (amount propagated to pixels left and below) &tab14 (amount propagated to pixel to left and down) lowerclip (values near 0 where the excess is not propagated) upperclip (values near 255 where the deficit is not propagated)

Return: 0 if OK, 1 on error

Definition at line 542 of file grayquantlow.c.

References CALLOC, ERROR_INT, NULL, and PROCNAME.

Referenced by pixDitherToBinaryLUT().

void ditherTo2bppLow ( l_uint32 datad,
l_int32  w,
l_int32  h,
l_int32  wpld,
l_uint32 datas,
l_int32  wpls,
l_uint32 bufs1,
l_uint32 bufs2,
l_int32 tabval,
l_int32 tab38,
l_int32 tab14 
)

Definition at line 612 of file grayquantlow.c.

References ditherTo2bppLineLow().

Referenced by pixDitherTo2bppSpec().

void ditherTo2bppLineLow ( l_uint32 lined,
l_int32  w,
l_uint32 bufs1,
l_uint32 bufs2,
l_int32 tabval,
l_int32 tab38,
l_int32 tab14,
l_int32  lastlineflag 
)

Definition at line 671 of file grayquantlow.c.

References GET_DATA_BYTE, L_MAX, L_MIN, SET_DATA_BYTE, and SET_DATA_DIBIT.

Referenced by ditherTo2bppLow().

l_int32 make8To2DitherTables ( l_int32 **  ptabval,
l_int32 **  ptab38,
l_int32 **  ptab14,
l_int32  cliptoblack,
l_int32  cliptowhite 
)

make8To2DitherTables()

Input: &tabval (value assigned to output pixel; 0, 1, 2 or 3) &tab38 (amount propagated to pixels left and below) &tab14 (amount propagated to pixel to left and down) cliptoblack (values near 0 where the excess is not propagated) cliptowhite (values near 255 where the deficit is not propagated)

Return: 0 if OK, 1 on error

Definition at line 753 of file grayquantlow.c.

References CALLOC, ERROR_INT, NULL, and PROCNAME.

Referenced by pixDitherTo2bppSpec().

void thresholdTo2bppLow ( l_uint32 datad,
l_int32  h,
l_int32  wpld,
l_uint32 datas,
l_int32  wpls,
l_int32 tab 
)

Definition at line 844 of file grayquantlow.c.

References GET_DATA_BYTE, and SET_DATA_BYTE.

Referenced by pixThresholdGrayArb(), and pixThresholdTo2bpp().

void thresholdTo4bppLow ( l_uint32 datad,
l_int32  h,
l_int32  wpld,
l_uint32 datas,
l_int32  wpls,
l_int32 tab 
)

Definition at line 889 of file grayquantlow.c.

References GET_DATA_BYTE, and SET_DATA_TWO_BYTES.

Referenced by pixThresholdGrayArb(), and pixThresholdTo4bpp().

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines