Execution of Ordered Dithering
Debug utility.
// 1...Ordered Dither Utility
// Executes ordered dithering using the generated matrix
// (Normally, the application retrieves the matrix and performs dithering)
// Input
// The image is a single-plane image (256 grayscale levels)
// int no; Specifies the plane number of the mask to use (0 to number of planes - 1).
// Using the same plane number results in dot-on-dot blue noise matrix processing.
// For RGB, R is not necessarily 0, G is not necessarily 1, B is not necessarily 2; any combination is allowed.
// int width; Width of the image (in pixels)
// int height; Height of the image (in pixels)
// int scanlinesize1; Number of bytes per line of the input image
// unsigned char* pdata1; 256 grayscale image
// int scanlinesize2; Number of bytes per line of the output 2/4 grayscale image
// Output
// unsigned char* pdata2; 2/4 grayscale image
// For 2 levels, returns (0/255); for 4 levels, returns (0/85/170/255).
// The library is not limited to 256 grayscale levels per plane, but this is simplified for debugging purposes.
void mordereddither2(int no,int width,int height,int scanlinesize1,unsigned char* pdata1,
int scanlinesize2,unsigned char* pdata2);
void mordereddither4(int no,int width,int height,int scanlinesize1,unsigned char* pdata1,
int scanlinesize2,unsigned char* pdata2);
// 2...Ordered Dither Utility
// Line-by-line processing version
// Input
// int y; Line number
// Other arguments are the same as for mordereddither2/mordereddither4
void morderedditherline2(int no,int width,int y,unsigned char* pdata1,unsigned char* pdata2);
void morderedditherline4(int no,int width,int y,unsigned char* pdata1,unsigned char* pdata2);
Source code for 2-level dithering
void CBNMask::mordereddither2(int no,int width,int height,int scanlinesize1,unsigned char* pdata1,
int scanlinesize2,unsigned char* pdata2)
{
if(mcomponentnum == 1) {
int total = mwidth * mheight;
for(int i = 0 ; i < height ; i++) {
unsigned char* ps1 = pdata1 + scanlinesize1 * i;
unsigned char* ps2 = pdata2 + scanlinesize2 * i;
int y = i % mheight;
unsigned int* ps3 = mpmatrix + mwidth * y;
for(int j = 0 ; j < width ; j++,ps1++,ps2++) {
int x = j % mwidth;
// If the matrix value is greater than or equal to the pixel value (threshold)
if(ps3[x] <= *ps1) {
*ps2 = 255;
}
else {
*ps2 = 0;
}
}
}
}
else {
mppchild[no]->mordereddither2(0,width,height,scanlinesize1,pdata1,scanlinesize2,pdata2);
}
}
Execution of Error Diffusion
Error diffusion program for comparing image quality and speed.
// Error diffusion program for quality and speed comparison
// Floyd & Steinberg method
// Input
// The image is a single-plane image (256 grayscale levels only).
// For RGB, process each plane three times.
// int width; Width of the image (in pixels)
// int height; Height of the image (in pixels)
// int scanlinesize1; Number of bytes per line of the image
// unsigned char* pdata1; 256 grayscale image
// float* pdata2; Work area for computation, requires sizeof(float) * width * height bytes
// Output
// unsigned char* pdata3; 2/4 grayscale image
void mfloydsteinberg2(int width,int height,int scanlinesize1,unsigned char* pdata1,float* pdata2,unsigned char* pdata3);
void mfloydsteinberg4(int width,int height,int scanlinesize1,unsigned char* pdata1,float* pdata2,unsigned char* pdata3);