| 95 |
|
|
| 96 |
|
|
| 97 |
int main(int argc, char *argv[]) { |
int main(int argc, char *argv[]) { |
|
int len,x,y; |
|
|
char bgr[3]; |
|
|
short svalue; |
|
|
int lvalue; |
|
| 98 |
|
|
| 99 |
|
// MMF support |
| 100 |
|
DWORD err; |
| 101 |
HANDLE hMap, hFile; |
HANDLE hMap, hFile; |
|
DWORD err, size; |
|
|
int elems; |
|
|
|
|
| 102 |
LPVOID pData; |
LPVOID pData; |
| 103 |
unsigned char *pDataBitmap, *pDataBitmapCurrent; |
unsigned char *pDataBitmap, *pDataBitmapCurrent; |
| 104 |
|
|
| 105 |
|
// workers |
| 106 |
|
unsigned int workers = 3; |
| 107 |
|
unsigned int worker_index, worker_rows, worker_startrow; |
| 108 |
|
|
| 109 |
|
// fractal calculation |
| 110 |
|
int x, y; |
| 111 |
|
char bgr[3]; |
| 112 |
|
|
|
int offset; |
|
| 113 |
|
|
| 114 |
// create empty file (black background) |
// create empty bmp-file (black background) |
| 115 |
write_blank_file("test.bmp"); |
write_blank_file("test.bmp"); |
|
|
|
| 116 |
|
|
| 117 |
/* open file for reading and writing */ |
/* open file for reading and writing */ |
| 118 |
hFile = CreateFile("test.bmp", GENERIC_WRITE|GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
hFile = CreateFile("test.bmp", GENERIC_WRITE|GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 153 |
} |
} |
| 154 |
*/ |
*/ |
| 155 |
|
|
| 156 |
|
// calculate segments of bitmap for worker threads/processes |
| 157 |
|
worker_rows = YSIZE / workers; |
| 158 |
|
printf("rows for each worker: %i\n", worker_rows); |
| 159 |
|
for (worker_index = 0; worker_index < workers; worker_index++) { |
| 160 |
|
|
| 161 |
|
// number of row to start for each worker |
| 162 |
|
worker_startrow = worker_index * worker_rows; |
| 163 |
|
|
| 164 |
|
// recalculate number of rows for last worker if (YSIZE mod workers) != 0 |
| 165 |
|
if (worker_index == workers - 1) { |
| 166 |
|
worker_rows = YSIZE - worker_startrow; |
| 167 |
|
printf("rows for last worker: %i\n", worker_rows); |
| 168 |
|
} |
| 169 |
|
} |
| 170 |
|
|
| 171 |
// calculate fractal |
// calculate fractal |
| 172 |
for (y=YSIZE-1; y>=0; y--) { |
for (y=YSIZE-1; y>=0; y--) { |
| 173 |
for (x=0; x<XSIZE; x++) { |
for (x=0; x<XSIZE; x++) { |
| 177 |
//printf("pointer: %p\n", pDataBitmapCurrent); |
//printf("pointer: %p\n", pDataBitmapCurrent); |
| 178 |
|
|
| 179 |
// transfer color values to current pixel |
// transfer color values to current pixel |
|
//*pDataBitmapCurrent = (unsigned char *)bgr; |
|
| 180 |
pDataBitmapCurrent[0] = bgr[0]; |
pDataBitmapCurrent[0] = bgr[0]; |
| 181 |
pDataBitmapCurrent[1] = bgr[1]; |
pDataBitmapCurrent[1] = bgr[1]; |
| 182 |
pDataBitmapCurrent[2] = bgr[2]; |
pDataBitmapCurrent[2] = bgr[2]; |