Mercurial > hg > Game > Cerium
annotate example/cuda_fft/pgm.h @ 2048:6796d85f3d6b draft
remove error
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 28 Jan 2016 00:05:49 +0900 |
parents | 2c8eab01cc78 |
children |
rev | line source |
---|---|
2008
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #ifndef _PGM_H_ |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 #define _PGM_H_ |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 #include <math.h> |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 #include <string.h> |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 #define PGM_MAGIC "P5" |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 #ifdef _WIN32 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 #define STRTOK_R(ptr, del, saveptr) strtok_s(ptr, del, saveptr) |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 #else |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 #define STRTOK_R(ptr, del, saveptr) strtok_r(ptr, del, saveptr) |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 #endif |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 typedef struct _pgm_t { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 int width; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 int height; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 unsigned char *buf; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 } pgm_t; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 int readPGM(pgm_t* pgm, const char* filename) |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 char *token, *pc, *saveptr; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 char *buf; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 size_t bufsize; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 char del[] = " \t\n"; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 unsigned char *dot; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 long begin, end; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 int filesize; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 int i, w, h, luma, pixs; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 FILE* fp; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 if ((fp = fopen(filename, "rb"))==NULL) { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 fprintf(stderr, "Failed to open file\n"); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 return -1; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 fseek(fp, 0, SEEK_SET); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 begin = ftell(fp); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 fseek(fp, 0, SEEK_END); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 end = ftell(fp); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 filesize = (int)(end - begin); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 buf = (char*)malloc(filesize * sizeof(char)); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 fseek(fp, 0, SEEK_SET); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 bufsize = fread(buf, filesize * sizeof(char), 1, fp); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 fclose(fp); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 token = (char *)STRTOK_R(buf, del, &saveptr); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 if (strncmp(token, PGM_MAGIC, 2) != 0) { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 return -1; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 token = (char *)STRTOK_R(NULL, del, &saveptr); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 if (token[0] == '#' ) { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 token = (char *)STRTOK_R(NULL, "\n", &saveptr); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 token = (char *)STRTOK_R(NULL, del, &saveptr); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 w = strtoul(token, &pc, 10); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 token = (char *)STRTOK_R(NULL, del, &saveptr); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 h = strtoul(token, &pc, 10); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 token = (char *)STRTOK_R(NULL, del, &saveptr); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 luma = strtoul(token, &pc, 10); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 token = pc + 1; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 pixs = w * h; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 pgm->buf = (unsigned char *)malloc(pixs * sizeof(unsigned char)); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 dot = pgm->buf; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 for (i=0; i< pixs; i++, dot++) { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 *dot = *token++; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 pgm->width = w; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 pgm->height = h; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 return 0; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
86 int writePGM(pgm_t* pgm, const char* filename) |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
87 { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 int i, w, h, pixs; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 FILE* fp; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 unsigned char* dot; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92 w = pgm->width; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 h = pgm->height; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94 pixs = w * h; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
95 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
96 if ((fp = fopen(filename, "wb+")) ==NULL) { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 fprintf(stderr, "Failed to open file\n"); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 return -1; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101 fprintf (fp, "%s\n%d %d\n255\n", PGM_MAGIC, w, h); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
103 dot = pgm->buf; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
104 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
105 for (i=0; i<pixs; i++, dot++) { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
106 putc((unsigned char)*dot, fp); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
108 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
109 fclose(fp); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
110 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
111 return 0; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
112 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
113 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
114 int normalizeD2PGM(pgm_t* pgm, double* x) |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
115 { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
116 int i, j, w, h; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
117 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
118 w = pgm->width; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
119 h = pgm->height; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
120 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
121 pgm->buf = (unsigned char*)malloc(w * h * sizeof(unsigned char)); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
122 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
123 double min = 0; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
124 double max = 0; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
125 for (i=0; i < h; i++) { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
126 for (j=0; j < w; j++) { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
127 if (max < x[i*w+j]) |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
128 max = x[i*w+j]; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
129 if (min > x[i*w+j]) |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
130 min = x[i*w+j]; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
131 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
132 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
133 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
134 for (i=0; i < h; i++) { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
135 for (j=0; j < w; j++) { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
136 if((max-min)!=0) |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
137 pgm->buf[i*w+j] = (unsigned char)(255*(x[i*w+j]-min)/(max-min)); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
138 else |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
139 pgm->buf[i*w+j]= 0; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
140 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
141 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
142 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
143 return 0; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
144 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
145 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
146 int normalizeF2PGM(pgm_t* pgm, float* x) |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
147 { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
148 int i, j, w, h; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
149 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
150 w = pgm->width; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
151 h = pgm->height; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
152 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
153 pgm->buf = (unsigned char*)malloc(w * h * sizeof(unsigned char)); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
154 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
155 float min = 0; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
156 float max = 0; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
157 for (i=0; i < h; i++) { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
158 for (j=0; j < w; j++) { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
159 if (max < x[i*w+j]) |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
160 max = x[i*w+j]; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
161 if (min > x[i*w+j]) |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
162 min = x[i*w+j]; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
163 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
164 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
165 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
166 for (i=0; i < h; i++) { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
167 for (j=0; j < w; j++) { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
168 if((max-min)!=0) |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
169 pgm->buf[i*w+j] = (unsigned char)(255*(x[i*w+j]-min)/(max-min)); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
170 else |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
171 pgm->buf[i*w+j]= 0; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
172 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
173 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
174 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
175 return 0; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
176 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
177 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
178 int destroyPGM(pgm_t* pgm) |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
179 { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
180 if (pgm->buf) { |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
181 free(pgm->buf); |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
182 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
183 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
184 return 0; |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
185 } |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
186 |
2c8eab01cc78
implement fft using cuda
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
187 #endif /* _PGM_H_ */ |