質問編集履歴
5
imageをpimageに更新、呼び出し時のvoid削除、グローバル変数pimageの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -36,7 +36,7 @@
|
|
36
36
|
int set;
|
37
37
|
|
38
38
|
//メモリ確保
|
39
|
-
memory(
|
39
|
+
memory();
|
40
40
|
|
41
41
|
//標準設定
|
42
42
|
set=Setting();
|
@@ -102,9 +102,12 @@
|
|
102
102
|
//画像枚数
|
103
103
|
#define MAX_NUM_OF_IMAGES 5
|
104
104
|
|
105
|
+
char pimage;
|
106
|
+
|
105
107
|
typedef unsigned char (*pimage_type)[MAX_IMAGESIZE][MAX_IMAGESIZE][3];
|
106
108
|
int width[MAX_NUM_OF_IMAGES],height[MAX_NUM_OF_IMAGES];
|
107
109
|
|
110
|
+
|
108
111
|
void memory(void);
|
109
112
|
void load_color_image( int n, int no, int set );
|
110
113
|
void save_color_image( int n, char name[] );
|
@@ -185,7 +188,7 @@
|
|
185
188
|
for(y=0;y<height[n];y++){
|
186
189
|
for(x=0;x<width[n];x++){
|
187
190
|
for(col=0;col<3;col++){
|
188
|
-
|
191
|
+
pimage[n][x][y][col] = (unsigned char)fgetc( fp );
|
189
192
|
}
|
190
193
|
}
|
191
194
|
}
|
@@ -215,7 +218,7 @@
|
|
215
218
|
for(y=0;y<height[n];y++){
|
216
219
|
for(x=0;x<width[n];x++){
|
217
220
|
for(col=0;col<3;col++){
|
218
|
-
fputc(
|
221
|
+
fputc( pimage[n][x][y][col], fp );
|
219
222
|
}
|
220
223
|
}
|
221
224
|
}
|
@@ -232,7 +235,7 @@
|
|
232
235
|
for(y=0;y<height[n1];y++){
|
233
236
|
for(x=0;x<width[n1];x++){
|
234
237
|
for(col=0;col<3;col++){
|
235
|
-
|
238
|
+
pimage[n2][x][y][col] = pimage[n1][x][y][col];
|
236
239
|
}
|
237
240
|
}
|
238
241
|
}
|
@@ -244,9 +247,9 @@
|
|
244
247
|
|
245
248
|
for(y=0;y<height[n];y++){
|
246
249
|
for(x=0;x<width[n];x++){
|
247
|
-
if (red != -1)
|
250
|
+
if (red != -1) pimage[n][x][y][0] = red;
|
248
|
-
if (green != -1)
|
251
|
+
if (green != -1) pimage[n][x][y][1] = green;
|
249
|
-
if (blue != -1)
|
252
|
+
if (blue != -1) pimage[n][x][y][2] = blue;
|
250
253
|
}
|
251
254
|
}
|
252
255
|
}
|
4
mallocを含む関数名をmemoryに変更、free関数の書き直し
title
CHANGED
File without changes
|
body
CHANGED
@@ -36,7 +36,7 @@
|
|
36
36
|
int set;
|
37
37
|
|
38
38
|
//メモリ確保
|
39
|
-
|
39
|
+
memory(void);
|
40
40
|
|
41
41
|
//標準設定
|
42
42
|
set=Setting();
|
@@ -48,7 +48,7 @@
|
|
48
48
|
SaveImage();
|
49
49
|
|
50
50
|
//メモリの開放
|
51
|
-
free();
|
51
|
+
free(pimage);
|
52
52
|
return 0;
|
53
53
|
}
|
54
54
|
|
@@ -105,21 +105,16 @@
|
|
105
105
|
typedef unsigned char (*pimage_type)[MAX_IMAGESIZE][MAX_IMAGESIZE][3];
|
106
106
|
int width[MAX_NUM_OF_IMAGES],height[MAX_NUM_OF_IMAGES];
|
107
107
|
|
108
|
-
void
|
108
|
+
void memory(void);
|
109
|
-
void free(void);
|
110
109
|
void load_color_image( int n, int no, int set );
|
111
110
|
void save_color_image( int n, char name[] );
|
112
111
|
void copy_color_image( int n1, int n2 );
|
113
112
|
void init_color_image( int n, int red, int green, int blue );
|
114
113
|
|
115
|
-
void
|
114
|
+
void memory(void){
|
116
115
|
pimage_type pimage = (pimage_type)malloc(MAX_NUM_OF_IMAGES * MAX_IMAGESIZE * MAX_IMAGESIZE * 3);
|
117
116
|
}
|
118
117
|
|
119
|
-
void free(void){
|
120
|
-
free(pimage);
|
121
|
-
}
|
122
|
-
|
123
118
|
void load_color_image( int n, int no, int set ){
|
124
119
|
|
125
120
|
char fname[MAX_FILENAME];
|
@@ -255,7 +250,6 @@
|
|
255
250
|
}
|
256
251
|
}
|
257
252
|
}
|
258
|
-
|
259
253
|
```
|
260
254
|
|
261
255
|
以上よろしくお願いします
|
3
malloc()とfree()の実装
title
CHANGED
File without changes
|
body
CHANGED
@@ -32,53 +32,55 @@
|
|
32
32
|
void SaveImage(void);
|
33
33
|
|
34
34
|
int main(void){
|
35
|
-
|
35
|
+
//標準設定パラメータ
|
36
|
-
|
36
|
+
int set;
|
37
|
-
|
38
|
-
//標準設定
|
39
|
-
set=Setting();
|
40
|
-
|
41
|
-
//画像読込
|
42
|
-
ReadImage(set);
|
43
|
-
|
44
|
-
//画像の出力
|
45
|
-
SaveImage();
|
46
|
-
|
47
|
-
//メモリの開放
|
48
|
-
free(pimage);
|
49
37
|
|
38
|
+
//メモリ確保
|
39
|
+
malloc();
|
40
|
+
|
41
|
+
//標準設定
|
42
|
+
set=Setting();
|
43
|
+
|
44
|
+
//画像読込
|
45
|
+
ReadImage(set);
|
46
|
+
|
47
|
+
//画像の出力
|
48
|
+
SaveImage();
|
49
|
+
|
50
|
+
//メモリの開放
|
51
|
+
free();
|
50
|
-
|
52
|
+
return 0;
|
51
53
|
}
|
52
54
|
|
53
55
|
//標準設定
|
54
56
|
int Setting(void){
|
55
|
-
|
57
|
+
int set_flag;
|
56
|
-
|
58
|
+
printf("標準設定→1\n");
|
57
|
-
|
59
|
+
printf("詳細設定→0\n");
|
58
|
-
|
60
|
+
scanf("%d",&set_flag);
|
59
|
-
|
61
|
+
|
60
|
-
|
62
|
+
return set_flag;
|
61
63
|
}
|
62
64
|
|
63
65
|
|
64
66
|
|
65
67
|
//画像の読み込み
|
66
68
|
void ReadImage(set){
|
67
|
-
|
69
|
+
|
68
|
-
|
70
|
+
load_color_image(0,1,set);
|
69
|
-
|
71
|
+
load_color_image(1,2,set);
|
70
|
-
|
72
|
+
load_color_image(2,3,set);
|
71
|
-
|
73
|
+
load_color_image(3,4,set);
|
72
|
-
|
74
|
+
load_color_image(4,5,set);
|
73
|
-
|
75
|
+
|
74
76
|
}
|
75
77
|
|
76
78
|
//画像の出力
|
77
79
|
void SaveImage(void){
|
78
|
-
|
80
|
+
save_color_image(0,"");
|
79
|
-
|
81
|
+
save_color_image(1,"");
|
80
|
-
|
82
|
+
save_color_image(3,"");
|
81
|
-
|
83
|
+
save_color_image(4,"");
|
82
84
|
}
|
83
85
|
```
|
84
86
|
|
@@ -100,45 +102,49 @@
|
|
100
102
|
//画像枚数
|
101
103
|
#define MAX_NUM_OF_IMAGES 5
|
102
104
|
|
103
|
-
//以下訂正前
|
104
|
-
//unsigned char image[MAX_NUM_OF_IMAGES][MAX_IMAGESIZE][MAX_IMAGESIZE][3];
|
105
|
-
|
106
|
-
//以下訂正後
|
107
105
|
typedef unsigned char (*pimage_type)[MAX_IMAGESIZE][MAX_IMAGESIZE][3];
|
108
|
-
pimage_type pimage = (pimage_type)malloc(MAX_NUM_OF_IMAGES * MAX_IMAGESIZE * MAX_IMAGESIZE * 3);
|
109
|
-
|
110
106
|
int width[MAX_NUM_OF_IMAGES],height[MAX_NUM_OF_IMAGES];
|
111
107
|
|
108
|
+
void malloc(void);
|
109
|
+
void free(void);
|
112
110
|
void load_color_image( int n, int no, int set );
|
113
111
|
void save_color_image( int n, char name[] );
|
114
112
|
void copy_color_image( int n1, int n2 );
|
115
113
|
void init_color_image( int n, int red, int green, int blue );
|
116
114
|
|
115
|
+
void malloc(void){
|
116
|
+
pimage_type pimage = (pimage_type)malloc(MAX_NUM_OF_IMAGES * MAX_IMAGESIZE * MAX_IMAGESIZE * 3);
|
117
|
+
}
|
118
|
+
|
119
|
+
void free(void){
|
120
|
+
free(pimage);
|
121
|
+
}
|
122
|
+
|
117
123
|
void load_color_image( int n, int no, int set ){
|
118
|
-
|
124
|
+
|
119
125
|
char fname[MAX_FILENAME];
|
120
126
|
char buffer[MAX_BUFFERSIZE];
|
121
127
|
FILE *fp;
|
122
128
|
int max_gray=0,x,y,col;
|
123
|
-
|
129
|
+
|
124
130
|
if( no==1 && set==1){
|
125
|
-
|
131
|
+
printf("INPUT FILE : white1.ppm\n");
|
126
132
|
strcpy(fname,"white1.ppm");
|
127
133
|
}
|
128
134
|
else if( no==2 && set==1){
|
129
|
-
|
135
|
+
printf("INPUT FILE : white2.ppm\n");
|
130
136
|
strcpy(fname,"white2.ppm");
|
131
137
|
}
|
132
138
|
else if( no==3 && set==1){
|
133
|
-
|
139
|
+
printf("INPUT FILE : white3.ppm\n");
|
134
140
|
strcpy(fname,"white3.ppm");
|
135
141
|
}
|
136
142
|
else if( no==4 && set==1){
|
137
|
-
|
143
|
+
printf("INPUT FILE : white4.ppm\n");
|
138
144
|
strcpy(fname,"white4.ppm");
|
139
145
|
}
|
140
146
|
else if( no==5 && set==1){
|
141
|
-
|
147
|
+
printf("INPUT FILE : white5.ppm\n");
|
142
148
|
strcpy(fname,"white5.ppm");
|
143
149
|
}
|
144
150
|
else{
|
@@ -152,7 +158,7 @@
|
|
152
158
|
fgets( buffer, MAX_BUFFERSIZE, fp );
|
153
159
|
//check P6
|
154
160
|
if ( buffer[0]!='P' || buffer[1]!='6' ){
|
155
|
-
|
161
|
+
printf("FILE TIPE WRONG!\n");
|
156
162
|
exit(1);
|
157
163
|
}
|
158
164
|
width[n] = 0;
|
@@ -163,7 +169,7 @@
|
|
163
169
|
sscanf( buffer, "%d %d", &width[n], &height[n] );
|
164
170
|
}
|
165
171
|
}
|
166
|
-
|
172
|
+
|
167
173
|
while ( max_gray == 0 ){
|
168
174
|
fgets( buffer, MAX_BUFFERSIZE, fp );
|
169
175
|
if ( buffer[0] != '#' ){
|
@@ -171,7 +177,7 @@
|
|
171
177
|
}
|
172
178
|
}
|
173
179
|
printf("----------------------------\n");
|
174
|
-
printf("WIDTH :%d\n",width[n]);
|
180
|
+
printf("WIDTH :%d\n",width[n]);
|
175
181
|
printf("HEIGHT :%d\n",height[n]);
|
176
182
|
printf("MAX RGB:%d\n",max_gray);
|
177
183
|
printf("----------------------------\n");
|
@@ -184,13 +190,12 @@
|
|
184
190
|
for(y=0;y<height[n];y++){
|
185
191
|
for(x=0;x<width[n];x++){
|
186
192
|
for(col=0;col<3;col++){
|
187
|
-
|
188
193
|
image[n][x][y][col] = (unsigned char)fgetc( fp );
|
189
194
|
}
|
190
195
|
}
|
191
196
|
}
|
192
197
|
printf("COMPLETE! ---> image[%d]\n",n);
|
193
|
-
printf("----------------------------\n");
|
198
|
+
printf("----------------------------\n");
|
194
199
|
fclose(fp);
|
195
200
|
}
|
196
201
|
|
@@ -211,7 +216,7 @@
|
|
211
216
|
fputs( "# Created by Image Processing\n", fp );
|
212
217
|
fprintf( fp, "%d %d\n", width[n], height[n] );
|
213
218
|
fprintf( fp, "%d\n", MAX_BRIGHTNESS );
|
214
|
-
|
219
|
+
|
215
220
|
for(y=0;y<height[n];y++){
|
216
221
|
for(x=0;x<width[n];x++){
|
217
222
|
for(col=0;col<3;col++){
|
@@ -226,7 +231,7 @@
|
|
226
231
|
|
227
232
|
void copy_color_image( int n1, int n2 ){
|
228
233
|
int x,y,col;
|
229
|
-
|
234
|
+
|
230
235
|
width[n2] = width[n1];
|
231
236
|
height[n2] = height[n1];
|
232
237
|
for(y=0;y<height[n1];y++){
|
2
image.cにfreeの追加、ヘッダファイルの綴りミスの訂正
title
CHANGED
File without changes
|
body
CHANGED
@@ -44,6 +44,9 @@
|
|
44
44
|
//画像の出力
|
45
45
|
SaveImage();
|
46
46
|
|
47
|
+
//メモリの開放
|
48
|
+
free(pimage);
|
49
|
+
|
47
50
|
return 0;
|
48
51
|
}
|
49
52
|
|
@@ -101,8 +104,8 @@
|
|
101
104
|
//unsigned char image[MAX_NUM_OF_IMAGES][MAX_IMAGESIZE][MAX_IMAGESIZE][3];
|
102
105
|
|
103
106
|
//以下訂正後
|
104
|
-
typedef unsigned char (*pimage_type)[
|
107
|
+
typedef unsigned char (*pimage_type)[MAX_IMAGESIZE][MAX_IMAGESIZE][3];
|
105
|
-
pimage_type pimage = (pimage_type)malloc(
|
108
|
+
pimage_type pimage = (pimage_type)malloc(MAX_NUM_OF_IMAGES * MAX_IMAGESIZE * MAX_IMAGESIZE * 3);
|
106
109
|
|
107
110
|
int width[MAX_NUM_OF_IMAGES],height[MAX_NUM_OF_IMAGES];
|
108
111
|
|
1
ヘッダファイルの変数定義部分を書き換えました
title
CHANGED
File without changes
|
body
CHANGED
@@ -97,7 +97,13 @@
|
|
97
97
|
//画像枚数
|
98
98
|
#define MAX_NUM_OF_IMAGES 5
|
99
99
|
|
100
|
+
//以下訂正前
|
100
|
-
unsigned char image[MAX_NUM_OF_IMAGES][MAX_IMAGESIZE][MAX_IMAGESIZE][3];
|
101
|
+
//unsigned char image[MAX_NUM_OF_IMAGES][MAX_IMAGESIZE][MAX_IMAGESIZE][3];
|
102
|
+
|
103
|
+
//以下訂正後
|
104
|
+
typedef unsigned char (*pimage_type)[MAX_IMAGEIZE][MAX_IMAGEIZE][3];
|
105
|
+
pimage_type pimage = (pimage_type)malloc(MAX_NUM_OF_IMAGE * MAX_IMAGEIZE * MAX_IMAGEIZE * 3);
|
106
|
+
|
101
107
|
int width[MAX_NUM_OF_IMAGES],height[MAX_NUM_OF_IMAGES];
|
102
108
|
|
103
109
|
void load_color_image( int n, int no, int set );
|