@@ -17,32 +17,34 @@ long timer_end(struct timespec start_time){
1717 return diffInNanos ;
1818}
1919
20- int mandel (int x , int y , int max_iters , unsigned int * val );
21-
22- void create_fractal (unsigned int * image , int width , int height ,
23- int iters );
20+ #include "create_fractal.c"
2421
2522int main (int argc , const char * argv [], const char * env [])
2623{
2724 int width = 1500 ;
2825 int height = 1000 ;
2926 int iters = 20 ;
3027 FILE * fid = NULL ;
28+ Img img ;
3129 struct timespec vartime ;
3230 long time_elapsed_nanos ;
33- unsigned int * image = (unsigned int * )malloc (width * height * sizeof (unsigned int ));
34- if (NULL == image )
31+ img .width = width ;
32+ img .height = height ;
33+ img .data = (unsigned int * )malloc (width * height * sizeof (unsigned int ));
34+ if (NULL == img .data )
3535 return -1 ;
36- fid = fopen ("c.pgm" , "wb" );
37- if (NULL == fid )
38- return -2 ;
36+
3937 vartime = timer_start ();
40- create_fractal (image , width , height , iters );
38+ create_fractal (img , iters );
4139 time_elapsed_nanos = timer_end (vartime );
4240 fprintf (stdout , "create_fractal required %ld millisecs\n" , time_elapsed_nanos / 1000000 );
41+
42+ fid = fopen ("c.pgm" , "wb" );
43+ if (NULL == fid )
44+ return -2 ;
4345 pgm_writepgminit (fid , width , height , 255 , 0 );
4446 for (int i = 0 ; i < height ; i ++ )
45- pgm_writepgmrow (fid , image + width * i , width , 255 , 0 );
47+ pgm_writepgmrow (fid , img . data + width * i , width , 255 , 0 );
4648 fclose (fid );
4749 return 0 ;
4850}
0 commit comments