--- joko/Uni/BSArch/04/bmp_fractal.c 2006/07/01 11:58:49 1.4 +++ joko/Uni/BSArch/04/bmp_fractal.c 2006/07/01 13:56:54 1.6 @@ -5,7 +5,7 @@ * Uebung 4.4 */ -// $Id: bmp_fractal.c,v 1.4 2006/07/01 11:58:49 joko Exp $ +// $Id: bmp_fractal.c,v 1.6 2006/07/01 13:56:54 joko Exp $ #include #include @@ -94,6 +94,58 @@ } +// arguments for each thread +typedef struct _WorkerArguments { + unsigned int start_row; + unsigned int number_of_rows; + unsigned char * pBitmap; +} WORKERARGS, *PWORKERARGS; + +// worker thread - main entry function +DWORD WINAPI fractal_thread (LPVOID lpParam) { + + // thread stuff + int thread_id; + PWORKERARGS args; + + // fractal calculation + int x, y; + char bgr[3]; + + thread_id = GetCurrentThreadId(); + + // get worker arguments + args = (PWORKERARGS)lpParam; + + printf("thread_id: %i\n", thread_id); + printf("arg.start_row: %i\n", args->start_row); + printf("arg.number_of_rows: %i\n", args->number_of_rows); + + // calculate fractal + for (y = (args->start_row + args->number_of_rows) - 1; y >= args->start_row; y--) { + for (x = 0; x < XSIZE; x++) { + getColorValuesAt(x * (2.0 / XSIZE) - 1.5, y * (2.0 / YSIZE) - 1.0, &bgr[2], &bgr[1], &bgr[0]); + + // debugging + //printf("pointer: %p\n", pDataBitmapCurrent); + + // transfer color values to current pixel + args->pBitmap[0] = bgr[0]; + args->pBitmap[1] = bgr[1]; + args->pBitmap[2] = bgr[2]; + + // move pointer to next pixel + args->pBitmap += 3; + + } + //no padding required because 1500%4 =0 + } + + return 0; + +} + + int main(int argc, char *argv[]) { // MMF support @@ -102,10 +154,13 @@ LPVOID pData; unsigned char *pDataBitmap, *pDataBitmapCurrent; - // fractal calculation - int x, y; - char bgr[3]; - + // workers + unsigned int workers = 3; + unsigned int worker_index, worker_rows, worker_startrow; + HANDLE *worker_handles; + //struct WorkerArguments *worker_args; + PWORKERARGS worker_args; + // create empty bmp-file (black background) write_blank_file("test.bmp"); @@ -149,26 +204,51 @@ } */ - // calculate fractal - for (y=YSIZE-1; y>=0; y--) { - for (x=0; x