-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMandelBrotGen.cpp
221 lines (180 loc) · 4.4 KB
/
MandelBrotGen.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#include "MandelBrotGen.h"
#include "MandelBrotThread.h"
#include "MandelBrotCommon.h"
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
/** @brief ChkMandelBrotSet
*
* @todo: document this function
*/
bool MandelBrotGen::ChkMandelBrotSet(double a, double b, int * reqIncrement)
{
return false;
}
/** @brief MandelBrotGen
*
* @todo: document this function
*/
MandelBrotGen::MandelBrotGen(int x_Res, int y_Res, SDL_Surface * screen)
{
numBlksThreads = MB_THREADS_NUM;
this->xRes = x_Res;
this->yRes = y_Res;
drawScreen = screen;
if(MB_THREADS_NUM % 2)
{
numBlksThreads = MB_THREADS_NUM + 1;
}
xDiv = 2;
yDiv = numBlksThreads / xDiv;
a_increment = (A_END - A_BEGIN)/(double)xRes;
b_increment = (B_END - B_BEGIN)/(double)yRes;
printf("\r\n Creating threads for Mandel Brot : %d", numBlksThreads);
}
/** @brief StartGeneratingMB
*
* @todo: document this function
*/
void MandelBrotGen::StartGeneratingMB()
{
CreateMBThreads();
}
/** @brief StartGeneratingMB
*
* @todo: document this function
*/
void MandelBrotGen::StartGeneratingMB(int xBegin, int yBegin, int xEnd, int yEnd)
{
}
/** @brief MandelBrotGen
*
* @todo: document this function
*/
MandelBrotGen::MandelBrotGen()
{
}
/** @brief CreateMBThreads
*
* @todo: document this function
*/
int MandelBrotGen::CreateMBThreads()
{
int thrd_Num;
int xBegin, xEnd, yBegin, yEnd;
MandelBrotThread * createdThread[MB_THREADS_NUM + 1];
//(void *) (MandelBrotGen::*thrd_Entry) (void *) = NULL;
//thrd_Entry = ;
for( thrd_Num=0; thrd_Num < numBlksThreads; thrd_Num++)
{
CalculateThreadBounds( thrd_Num, &xBegin, &xEnd, &yBegin, &yEnd);
createdThread[thrd_Num] = new MandelBrotThread(thrd_Num, xBegin, xEnd, yBegin, yEnd, this);
}
for( thrd_Num=0; thrd_Num < numBlksThreads; thrd_Num++)
{
if( (createdThread[thrd_Num])->GetThreadExecStatus())
{
if(pthread_join((createdThread[thrd_Num])->GetThreadID(), NULL) == 0)
{
//printf("\r\n Waiting for thread %d successfully", thrd_Num);
//SDL_Flip(drawScreen);
//SDL_Delay(100);
}
else
printf("\r\n Pthread_joing failed");
}
}
return thrd_Num;
}
/** @brief CalculateThreadBounds
*
* @todo: document this function
*/
void MandelBrotGen::CalculateThreadBounds(int threadNum, int * xBegin, int * xEnd, int * yBegin, int * yEnd)
{
*(xBegin) = (threadNum % xDiv) * (xRes / xDiv);
*(xEnd) = ((threadNum % xDiv) + 1) * (xRes / xDiv) ;
*(yBegin) = (threadNum / yDiv) * (yRes / yDiv);
*(yEnd) = ((threadNum / yDiv) + 1) * (yRes / yDiv);
}
/** @brief ~MandelBrotGen
*
* @todo: document this function
*/
MandelBrotGen::~MandelBrotGen()
{
}
/** @brief GetYRes
*
* @todo: document this function
*/
int MandelBrotGen::GetXRes()
{
return xRes;
}
/** @brief GetXRes
*
* @todo: document this function
*/
int MandelBrotGen::GetYRes()
{
return yRes;
}
/** @brief OnPixel
*
* @todo: document this function
*/
void MandelBrotGen::OnPixel(int x, int y, int iter)
{
//printf("\r\n Set Pixel ON[%d,%d]", x, y);
SetPixelWithAttrib( x, y, IN_MBSET, iter);
}
/** @brief OffPixel
*
* @todo: document this function
*/
void MandelBrotGen::OffPixel(int x, int y, int iter)
{
//printf("\r\n Set Pixel OFF[%d,%d]", x, y);
SetPixelWithAttrib( x, y, OUT_MBSET, iter);
}
/** @brief SetPixelWithAttrib
*
* @todo: document this function
*/
void MandelBrotGen::SetPixelWithAttrib(int x, int y, Attrib enAttrib, int iter)
{
int ytimesw;
int bytesPerPix;
Uint16 * pixMem;
Uint32 colour;
int r, g, b;
bytesPerPix = drawScreen->format->BytesPerPixel;
ytimesw = y*drawScreen->pitch/bytesPerPix;
r = (iter%5)*50;
g = (iter/2)*10;
b = (iter+1)/9*100;
colour = SDL_MapRGB(drawScreen->format, r, g, b);
pixMem = (Uint16 *) drawScreen->pixels + ytimesw + x;
//printf("\r\n [%d,%d]", x,ytimesw);
*pixMem = colour;
//printf("\r\n [%d,%d, %x]", x,ytimesw, pixMem);
//SDL_Flip(drawScreen);
//SDL_Delay(10);
}
/** @brief GetBIncrement
*
* @todo: document this function
*/
double MandelBrotGen::GetAIncrement()
{
return a_increment;
}
/** @brief GetAIncrement
*
* @todo: document this function
*/
double MandelBrotGen::GetBIncrement()
{
return b_increment;
}