Execution of Ordered Dithering
Debug utility.
// 1...Ordered Dither Utility
// Performs ordered dithering using the generated matrix
// (Typically, the matrix is obtained by the application and used for dithering)
// Input
// The image is a 256-level image for one plane
// int no; Specifies the plane number of the mask to be used (0 to plane number - 1)
// Specifying the same plane number results in dot-on-dot blue noise matrix processing
// For RGB, it does not have to be R=0, G=1, B=2. Any combination is acceptable.
// int width; Width of the image (in pixels)
// int height; Height of the image (in pixels)
// int scanlinesize1; Number of bytes in one line of the image
// unsigned char* pdata1; 256-level image
// int scanlinesize2; Number of bytes in one line of the output 2/4-level image
// Output
// unsigned char* pdata2; 2/4-level image
// Returns (0/255) for 2-level, and (0/85/170/255) for 4-level.
// The library is not limited to one plane with 256 levels, but this is a debug utility, so it takes shortcuts
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
// Version that processes one line at a time
// Input
// int y; Line number
// Other arguments are the same as 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;
// Greater than or equal to the matrix value (threshold or above)
if(ps3[x] <= *ps1) {
*ps2 = 255;
}
else {
*ps2 = 0;
}
}
}
}
else {
mppchild[no]->mordereddither2(0, width, height, scanlinesize1, pdata1, scanlinesize2, pdata2);
}
}
Execution of Error Diffusion Method
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 (for 256-shade images)
// For RGB, the process is performed three times for each plane
// int width; width of the image (in pixels)
// int height; height of the image (in pixels)
// int scanlinesize1; byte size of one line of the image
// unsigned char* pdata1; 256-shade image
// float* pdata2; work area for calculations, requires sizeof(float) * width * height bytes
// Output
// unsigned char* pdata3; 2/4-shade 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);