| Matrix Size | Range of Values Generated by bluenoiseex() | File Size | Range of Values Generated by bluenoise() |
|---|---|---|---|
| 256×256 | 0~0x0000ffff(0~65,535) | No file, as it is embedded data | 0~0x00007fff(0~32,767) |
| 512×512 | 0~0x0003ffff(0~262,143) | 1 Megabyte | 0~0x00007fff(0~32,767) |
| 1024×1024 | 0~0x000fffff(0~1,048,575) Sufficient for substitution of a million random sequence numbers | 4 Megabytes | 0~0x00007fff(0~32,767) |
| 2048×2048 | 0~0x003fffff(0~4,194,303) | 16 Megabytes | 0~0x00007fff(0~32,767) |
| 4096×4096 | 0~0x00ffffff(0~16,777,215) Number of colors in a 24-bit color image | 64 Megabytes | 0~0x00007fff(0~32,767) |
| 8192×8192 | 0~0x03ffffff(0~67,108,863) Only used with a special printer (for creating national treasure archives) with a printing width of 8 meters | 256 Megabytes | 0~0x00007fff(0~32,767) |
| 16384×16384 | 0~0x0fffffff(0~268,435,455) No examples found using this level of precision (possibility of dividing into four 8192×8192 matrices for CMYK use) | 1024 Megabytes (1 Gigabyte) | 0~0x00007fff(0~32,767) |
/////////////////////////////// // Setting the seed for the blue noise sequence // int seed; seed value // Return value // Negative....Error(INITIALIZE_ERROR...Initialization error(failed to create an instance of the class: insufficient memory)) typedef int (__stdcall* SBLUENOISE)(int seed); extern SBLUENOISE sbluenoise; ///////////////////////// // Obtaining the blue noise sequence (0~RAND_MAX) // RAND_MAX is 0x7fff(32767), so it is coarse // Return value // Negative....Error(INITIALIZE_ERROR...Initialization error(failed to create an instance of the class: insufficient memory)) // Blue noise sequence typedef int (__stdcall* BLUENOISE)(); extern BLUENOISE bluenoise; ///////////////////////// // Obtaining a detailed blue noise sequence (0~size*size) // Even without using a file (256*256), it can be fine-tuned from 0 to 65535 // 256* 256 0~0x0000ffff(0 to 65,536-1) Not using a file // 512* 512 0~0x0003ffff(0 to 262,144-1) 1MB // 1024* 1024 0~0x000fffff(0 to 1,048,576-1) 4MB // 2048* 2048 0~0x003fffff(0 to 4,194,304-1) 16MB // 4096* 4096 0~0x00ffffff(0 to 16,777,216-1) 64MB // 8192* 8192 0~0x03ffffff(0 to 67,108,864-1) 256MB // 16384*16384 0~0x0fffffff(0 to 268,435,456-1) 1024MB(1GB) // Return value // Negative....Error(INITIALIZE_ERROR...Initialization error(failed to create an instance of the class: insufficient memory)) // Blue noise sequence typedef int (__stdcall* BLUENOISEEX)(); extern BLUENOISEEX bluenoiseex; ///////////////////////// // Setting the folder for saving/loading blue noise matrices and the size of the matrix // Not set for generating blue noise in the normal range (0~RAND_MAX) // Set when there is a purpose to obtain a detailed blue noise using bluenoiseex() // Input // const char* pfolder; Folder name where the matrix file exists/should be generated // If it is NULL or "", use the built-in 256×256 matrix // int size; Matrix size (512/1024/2048/4096/8192/16384) // In the case of 1024, generate a 1024×1024 blue noise matrix. File size is 4MB // Return value // Negative....Error(INITIALIZE_ERROR...Initialization error(failed to create an instance of the class: insufficient memory)) // Negative....Error(FILE_OPEN_ERROR....Cannot save or load) // (MEMORY_SHORTAGE....Insufficient memory) // Read the file named sizexsizeraw.dat in the specified folder // If size is 1024, the file name will be 1024x1024raw.dat // If the file does not exist, create the file // The larger the size, the higher-quality bluenoise is generated typedef int (__stdcall* SETBLUENOISEMATRIX)(const char* pfolder,int size); extern SETBLUENOISEMATRIX setbluenoisematrix;
#include "bluenoisecallback.h"
HINSTANCE bn_dllinstance; // DLL instance
// DLL entry point
SBLUENOISE sbluenoise;
BLUENOISE bluenoise;
BLUENOISEEX bluenoiseex;
SETBLUENOISEMATRIX setbluenoisematrix;
{
// ....
// Loading
// gmodulepath contains the path of the executable file
// Assuming "bluenoisedll.dll" is in the path of the executable file
char filename[FILENAME_MAX];
sprintf(filename, "%sbluenoisedll.dll", gmodulepath);
bn_dllinstance = LoadLibrary(filename);
if (bn_dllinstance == NULL) {
char buffer[512];
sprintf(buffer, "Failed to load DLL file bluenoisedll.dll");
AfxMessageBox(buffer, MB_OK | MB_ICONEXCLAMATION);
return(2);
}
sbluenoise = (SBLUENOISE)GetProcAddress(bn_dllinstance, "sbluenoise");
bluenoise = (BLUENOISE)GetProcAddress(bn_dllinstance, "bluenoise");
bluenoiseex = (BLUENOISEEX)GetProcAddress(bn_dllinstance, "bluenoiseex");
setbluenoisematrix = (SETBLUENOISEMATRIX)GetProcAddress(bn_dllinstance, "setbluenoisematrix");
if (sbluenoise == NULL || bluenoise == NULL || bluenoiseex == NULL || setbluenoisematrix == NULL) {
char buffer[512];
sprintf(buffer, "The version of DLL file bluenoisedll.dll is different");
AfxMessageBox(buffer, MB_OK | MB_ICONEXCLAMATION);
FreeLibrary(bn_dllinstance);
return(2);
}
// ....
// Freeing
FreeLibrary(bn_dllinstance);
}
The calling of bluenoise() is performed as follows:
// Set bluenoise series to 1000 and display it in an edit box or other widgets
void CDlgBluenoise::OnBnClickedMakebluenoise100()
{
m_editresult = "";
char buffer[1024];
for (int i = 0; i < 1000; i++) {
if (i % 10 == 0) {
sprintf(buffer, "(%03d)", i / 10);
m_editresult += buffer;
}
if (i % 10 == 9) {
sprintf(buffer, "%10d\r\n", bluenoise());
}
else {
sprintf(buffer, "%10d, ", bluenoise());
}
m_editresult += buffer;
}
UpdateData(FALSE);
}
The calling of setbluenoisematrix() is performed as follows:
// The folder is "g:/tmp/", but usually, set a different folder.
// m_editsize contains a value in the range of 512 to 16384.
void CDlgBluenoise::OnBnClickedSetsize()
{
UpdateData(TRUE);
if (m_editsize == 256) {
setbluenoisematrix("", m_editsize);
}
else {
setbluenoisematrix("g:\\tmp\\", m_editsize);
}
UpdateData(FALSE);
}