5 #define _USE_MATH_DEFINES
8 #pragma warning(disable: 4996)
14 for (
int i = 0; i <
data->row; i++)
16 for (
int j = 0; j <
data->col; j++)
18 data->matrix[i][j] = ucColor;
25 return(
data->matrix[y0][x0]);
30 for (
int i = x0 - halfLen; i <= (x0 + halfLen); i++)
32 for (
int ii = -width / 2; ii <= width / 2; ii++)
34 for (
int jj = -width / 2; jj <= width / 2; jj++)
40 for (
int j = y0 - halfLen; j <= (y0 + halfLen); j++)
42 for (
int ii = -width / 2; ii <= width / 2; ii++)
44 for (
int jj = -width / 2; jj <= width / 2; jj++)
53 if ((y0 < 0) || (x0 < 0))
60 if ((x0 >=
data->col) || (y0 >=
data->row))
66 data->matrix[y0][x0] = ucColor;
71 void PGMLine(
PGMData *data,
int x0,
int y0,
int x1,
int y1,
unsigned char ucColor)
74 int dx = abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
75 int dy = abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
76 int err = (dx > dy ? dx : -dy) / 2, e2;
80 if (x0 == x1 && y0 == y1)
break;
82 if (e2 > -dx) { err -= dy; x0 += sx; }
83 if (e2 < dy) { err += dx; y0 += sy; }
94 ret_val = (
int **)malloc(
sizeof(
int *) * row);
95 if (ret_val ==
NULL) {
96 perror(
"memory allocation failure");
100 for (i = 0; i < row; ++i) {
101 ret_val[i] = (
int *)malloc(
sizeof(
int) * col);
102 if (ret_val[i] ==
NULL) {
103 perror(
"memory allocation failure");
115 for (i = 0; i < row; ++i) {
121 #define HI(num) (((num) & 0x0000FF00) << 8)
122 #define LO(num) ((num) & 0x000000FF)
128 while ((ch = fgetc(fp)) != EOF && isspace(ch)) {
137 fseek(fp, -1, SEEK_CUR);
148 pgmFile = fopen(file_name,
"rb");
149 if (pgmFile ==
NULL) {
150 perror(
"cannot open file to read");
155 fprintf(
stderr,
"Wrong file type!\n");
159 fscanf(pgmFile,
"%d", &
data->col);
161 fscanf(pgmFile,
"%d", &
data->row);
163 fscanf(pgmFile,
"%d", &
data->max_gray);
167 if (
data->max_gray > 255) {
168 for (i = 0; i <
data->row; ++i) {
169 for (j = 0; j <
data->col; ++j) {
172 data->matrix[i][j] = (hi << 8) + lo;
177 for (i = 0; i <
data->row; ++i) {
178 for (j = 0; j <
data->col; ++j) {
180 data->matrix[i][j] = lo;
199 if (pgmFile ==
NULL) {
200 perror(
"cannot open file to write");
204 fprintf(pgmFile,
"P5 ");
205 fprintf(pgmFile,
"%d %d ",
data->col,
data->row);
206 fprintf(pgmFile,
"%d ",
data->max_gray);
208 if (
data->max_gray > 255) {
209 for (i = 0; i <
data->row; ++i) {
210 for (j = 0; j <
data->col; ++j) {
211 hi =
HI(
data->matrix[i][j]);
212 lo =
LO(
data->matrix[i][j]);
220 for (i = 0; i <
data->row; ++i) {
221 for (j = 0; j <
data->col; ++j) {
222 lo =
LO(
data->matrix[i][j]);
250 int strLen = (int)strlen(szText);
252 for (
int i = 0; i < strLen; i++)
255 if ((ch >=
' ') && (ch < 0x80))
258 int offset = idx * 12;
259 for (
int ii = 0; ii < 12; ii++)
262 for (
int jj = 0; jj < 8; jj++)
264 if (ucBitMask & (0x01 << (7 - jj)))
279 double halfmajoraxissize = vecArr[0] * vecArr[0] + vecArr[2] * vecArr[2];
280 double halfminoraxissize = vecArr[1] * vecArr[1] + vecArr[3] * vecArr[3];
282 halfmajoraxissize = sqrt(halfmajoraxissize);
283 halfminoraxissize = sqrt(halfminoraxissize);
284 double halfBiggestSize = (halfminoraxissize > halfmajoraxissize) ? halfminoraxissize : halfmajoraxissize;
287 a = (float)halfmajoraxissize;
288 b = (float)halfminoraxissize;
289 float theta = (float)atan2(vecArr[2], vecArr[0]);
291 int numStepsEsti = (int)(halfBiggestSize * 6.28);
293 if (numStepsEsti < 1)
297 float stepWidth = (float)(2.0 * M_PI / numStepsEsti);
301 for (
int i = 0; i < numStepsEsti; i++)
303 float t = i * stepWidth;
304 int xcur = (int)(xc + a*cos(
t)*cos(theta) - b*sin(
t)*sin(theta));
305 int ycur = (int)(yc + b*sin(
t)*cos(theta) + a*cos(
t)*sin(theta));
322 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
323 0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x18,0x18,0x00,0x00 ,
324 0x00,0x36,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
325 0x00,0x00,0x14,0x14,0x3E,0x14,0x14,0x3E,0x14,0x14,0x00,0x00 ,
326 0x00,0x08,0x1C,0x32,0x30,0x1C,0x06,0x26,0x1C,0x08,0x08,0x00 ,
327 0x00,0x13,0x2B,0x2B,0x16,0x0C,0x1A,0x35,0x35,0x32,0x00,0x00 ,
328 0x00,0x1C,0x36,0x36,0x1C,0x1D,0x37,0x36,0x36,0x1B,0x00,0x00 ,
329 0x00,0x0C,0x0C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
330 0x00,0x0C,0x18,0x30,0x30,0x30,0x30,0x30,0x18,0x0C,0x00,0x00 ,
331 0x00,0x30,0x18,0x0C,0x0C,0x0C,0x0C,0x0C,0x18,0x30,0x00,0x00 ,
332 0x00,0x00,0x00,0x36,0x1C,0x7F,0x1C,0x36,0x00,0x00,0x00,0x00 ,
333 0x00,0x00,0x00,0x00,0x0C,0x0C,0x3F,0x0C,0x0C,0x00,0x00,0x00 ,
334 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x0C,0x18 ,
335 0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0x00,0x00,0x00,0x00 ,
336 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x00,0x00 ,
337 0x00,0x06,0x06,0x0C,0x0C,0x18,0x18,0x30,0x30,0x60,0x00,0x00 ,
338 0x00,0x1E,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x3C,0x00,0x00 ,
339 0x00,0x0C,0x1C,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x00,0x00 ,
340 0x00,0x1C,0x36,0x36,0x06,0x0C,0x0C,0x18,0x30,0x3E,0x00,0x00 ,
341 0x00,0x1C,0x36,0x06,0x06,0x1C,0x06,0x06,0x36,0x1C,0x00,0x00 ,
342 0x00,0x18,0x18,0x18,0x36,0x36,0x36,0x3F,0x06,0x06,0x00,0x00 ,
343 0x00,0x3E,0x30,0x30,0x30,0x3C,0x06,0x06,0x36,0x1C,0x00,0x00 ,
344 0x00,0x0C,0x18,0x18,0x30,0x3C,0x36,0x36,0x36,0x1C,0x00,0x00 ,
345 0x00,0x3E,0x06,0x06,0x0C,0x0C,0x0C,0x18,0x18,0x18,0x00,0x00 ,
346 0x00,0x1C,0x36,0x36,0x36,0x1C,0x36,0x36,0x36,0x1C,0x00,0x00 ,
347 0x00,0x1C,0x36,0x36,0x36,0x1E,0x0C,0x0C,0x18,0x30,0x00,0x00 ,
348 0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,0x1C,0x1C,0x00,0x00 ,
349 0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,0x1C,0x1C,0x0C,0x18 ,
350 0x00,0x02,0x06,0x0C,0x18,0x30,0x18,0x0C,0x06,0x02,0x00,0x00 ,
351 0x00,0x00,0x00,0x00,0x3E,0x00,0x00,0x3E,0x00,0x00,0x00,0x00 ,
352 0x00,0x20,0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x20,0x00,0x00 ,
353 0x00,0x1C,0x36,0x36,0x06,0x0C,0x18,0x00,0x18,0x18,0x00,0x00 ,
354 0x00,0x0E,0x19,0x33,0x35,0x35,0x35,0x32,0x18,0x0F,0x00,0x00 ,
355 0x00,0x08,0x1C,0x36,0x36,0x36,0x3E,0x36,0x36,0x36,0x00,0x00 ,
356 0x00,0x3C,0x36,0x36,0x36,0x3C,0x36,0x36,0x36,0x3C,0x00,0x00 ,
357 0x00,0x1C,0x36,0x36,0x30,0x30,0x30,0x36,0x36,0x1C,0x00,0x00 ,
358 0x00,0x3C,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x3C,0x00,0x00 ,
359 0x00,0x3E,0x30,0x30,0x30,0x3C,0x30,0x30,0x30,0x3E,0x00,0x00 ,
360 0x00,0x3E,0x30,0x30,0x30,0x3C,0x30,0x30,0x30,0x30,0x00,0x00 ,
361 0x00,0x1C,0x36,0x30,0x30,0x36,0x36,0x36,0x36,0x1C,0x00,0x00 ,
362 0x00,0x36,0x36,0x36,0x36,0x3E,0x36,0x36,0x36,0x36,0x00,0x00 ,
363 0x00,0x1E,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00,0x00 ,
364 0x00,0x06,0x06,0x06,0x06,0x06,0x06,0x36,0x36,0x1C,0x00,0x00 ,
365 0x00,0x36,0x36,0x36,0x3C,0x38,0x3C,0x36,0x36,0x36,0x00,0x00 ,
366 0x00,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x3E,0x00,0x00 ,
367 0x00,0x63,0x63,0x77,0x77,0x7F,0x6B,0x6B,0x63,0x63,0x00,0x00 ,
368 0x00,0x33,0x33,0x3B,0x3B,0x3F,0x37,0x33,0x33,0x33,0x00,0x00 ,
369 0x00,0x1C,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x1C,0x00,0x00 ,
370 0x00,0x3C,0x36,0x36,0x36,0x3C,0x30,0x30,0x30,0x30,0x00,0x00 ,
371 0x00,0x1C,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x1C,0x0C,0x06 ,
372 0x00,0x3C,0x36,0x36,0x36,0x3C,0x36,0x36,0x36,0x36,0x00,0x00 ,
373 0x00,0x1C,0x36,0x32,0x38,0x1C,0x0E,0x26,0x36,0x1C,0x00,0x00 ,
374 0x00,0x3F,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x00,0x00 ,
375 0x00,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x1C,0x00,0x00 ,
376 0x00,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x1C,0x08,0x00,0x00 ,
377 0x00,0x63,0x63,0x6B,0x6B,0x6B,0x6B,0x36,0x36,0x36,0x00,0x00 ,
378 0x00,0x36,0x36,0x36,0x1C,0x08,0x1C,0x36,0x36,0x36,0x00,0x00 ,
379 0x00,0x33,0x33,0x33,0x33,0x1E,0x0C,0x0C,0x0C,0x0C,0x00,0x00 ,
380 0x00,0x3E,0x06,0x0C,0x0C,0x18,0x18,0x30,0x30,0x3E,0x00,0x00 ,
381 0x00,0x1E,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x1E ,
382 0x00,0x30,0x30,0x18,0x18,0x0C,0x0C,0x06,0x06,0x03,0x00,0x00 ,
383 0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C ,
384 0x00,0x08,0x1C,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
385 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F ,
386 0x00,0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
387 0x00,0x00,0x00,0x00,0x1C,0x06,0x1E,0x36,0x36,0x1E,0x00,0x00 ,
388 0x00,0x30,0x30,0x30,0x3C,0x36,0x36,0x36,0x36,0x3C,0x00,0x00 ,
389 0x00,0x00,0x00,0x00,0x1C,0x36,0x30,0x30,0x36,0x1C,0x00,0x00 ,
390 0x00,0x06,0x06,0x06,0x1E,0x36,0x36,0x36,0x36,0x1E,0x00,0x00 ,
391 0x00,0x00,0x00,0x00,0x1C,0x36,0x3E,0x30,0x32,0x1C,0x00,0x00 ,
392 0x00,0x0E,0x18,0x18,0x3E,0x18,0x18,0x18,0x18,0x18,0x00,0x00 ,
393 0x00,0x00,0x00,0x00,0x1E,0x36,0x36,0x36,0x1E,0x06,0x26,0x1C ,
394 0x00,0x30,0x30,0x30,0x3C,0x36,0x36,0x36,0x36,0x36,0x00,0x00 ,
395 0x00,0x0C,0x00,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00,0x00 ,
396 0x00,0x0C,0x00,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x38 ,
397 0x00,0x30,0x30,0x30,0x36,0x3C,0x38,0x3C,0x36,0x36,0x00,0x00 ,
398 0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00,0x00 ,
399 0x00,0x00,0x00,0x00,0x76,0x7F,0x6B,0x6B,0x6B,0x63,0x00,0x00 ,
400 0x00,0x00,0x00,0x00,0x3C,0x36,0x36,0x36,0x36,0x36,0x00,0x00 ,
401 0x00,0x00,0x00,0x00,0x1C,0x36,0x36,0x36,0x36,0x1C,0x00,0x00 ,
402 0x00,0x00,0x00,0x00,0x3C,0x36,0x36,0x36,0x36,0x3C,0x30,0x30 ,
403 0x00,0x00,0x00,0x00,0x1E,0x36,0x36,0x36,0x36,0x1E,0x06,0x06 ,
404 0x00,0x00,0x00,0x00,0x36,0x3E,0x30,0x30,0x30,0x30,0x00,0x00 ,
405 0x00,0x00,0x00,0x00,0x1E,0x30,0x3C,0x1E,0x06,0x3C,0x00,0x00 ,
406 0x00,0x00,0x18,0x18,0x3C,0x18,0x18,0x18,0x18,0x0E,0x00,0x00 ,
407 0x00,0x00,0x00,0x00,0x36,0x36,0x36,0x36,0x36,0x1E,0x00,0x00 ,
408 0x00,0x00,0x00,0x00,0x36,0x36,0x36,0x36,0x1C,0x08,0x00,0x00 ,
409 0x00,0x00,0x00,0x00,0x63,0x6B,0x6B,0x6B,0x3E,0x36,0x00,0x00 ,
410 0x00,0x00,0x00,0x00,0x36,0x36,0x1C,0x1C,0x36,0x36,0x00,0x00 ,
411 0x00,0x00,0x00,0x00,0x36,0x36,0x36,0x36,0x1C,0x0C,0x18,0x30 ,
412 0x00,0x00,0x00,0x00,0x3E,0x06,0x0C,0x18,0x30,0x3E,0x00,0x00 ,
413 0x00,0x0E,0x18,0x18,0x18,0x30,0x18,0x18,0x18,0x0E,0x00,0x00 ,
414 0x00,0x18,0x18,0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x18,0x18 ,
415 0x00,0x30,0x18,0x18,0x18,0x0C,0x18,0x18,0x18,0x30,0x00,0x00 ,
416 0x00,0x1A,0x3E,0x2C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
417 0x00,0x00,0x00,0x08,0x1C,0x36,0x22,0x22,0x3E,0x3E,0x00,0x00 ,
422 void PGMEllipseRotated
423 t = linspace(0, 2 * pi, 100);
429 x = x0 + a*cos(t)*cos(theta) - b*sin(t)*sin(theta);
430 y = y0 + b*sin(t)*cos(theta) + a*cos(t)*sin(theta);