-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathppmb_io_prb.cpp
266 lines (224 loc) · 5.04 KB
/
ppmb_io_prb.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# include <cstdlib>
# include <iostream>
# include <iomanip>
# include <fstream>
# include <ctime>
using namespace std;
# include "ppmb_io.hpp"
int main ( int argc, char *argv[] );
bool test01 ( string file_name );
bool test02 ( string file_name );
void timestamp ( );
//****************************************************************************80
int main ( int argc, char *argv[] )
//****************************************************************************80
//
// Purpose:
//
// MAIN is the main program for PPMB_IO_PRB.
//
// Discussion:
//
// PPMB_IO_PRB tests the PPMB_IO library.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 11 April 2003
//
// Author:
//
// John Burkardt
//
{
bool error;
timestamp ( );
cout << "\n";
cout << "PPMB_IO_PRB:\n";
cout << " C++ version\n";
cout << " Test the PPMB_IO library.\n";
error = test01 ( "ppmb_io_prb.ppm" );
error = test02 ( "ppmb_io_prb.ppm" );
//
// Terminate.
//
cout << "\n";
cout << "PPMB_IO_PRB:\n";
cout << " Normal end of execution.\n";
cout << "\n";
timestamp ( );
return 0;
}
//****************************************************************************80
bool test01 ( string file_name )
//****************************************************************************80
//
// Purpose:
//
// TEST01 tests PPM_EXAMPLE, PPMB_WRITE.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 26 September 2008
//
// Author:
//
// John Burkardt
//
{
unsigned char *b;
bool error;
unsigned char *g;
unsigned char *r;
int result;
int xsize = 300;
int ysize = 300;
cout << "\n";
cout << "TEST01:\n";
cout << " PPM_EXAMPLE sets up PPM data.\n";
cout << " PPMB_WRITE writes a binary PPM file.\n";
r = new unsigned char[ xsize * ysize ];
g = new unsigned char[ xsize * ysize ];
b = new unsigned char[ xsize * ysize ];
error = ppmb_example ( xsize, ysize, r, g, b );
cout << "\n";
cout << " PPM_EXAMPLE has set up the data.\n";
error = ppmb_write ( file_name, xsize, ysize, r, g, b );
if ( error )
{
cout << " PPMB_WRITE failed!\n";
}
else
{
cout << " PPMB_WRITE was successful.\n";
}
delete [] r;
delete [] g;
delete [] b;
return error;
}
//****************************************************************************80
bool test02 ( string file_in_name )
//****************************************************************************80
//
// Purpose:
//
// TEST02 tests PPMB_READ_HEADER, PPMB_READ_DATA.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 22 July 2011
//
// Author:
//
// John Burkardt
//
{
unsigned char *b;
bool error;
ifstream file_in;
unsigned char *g;
int maxrgb;
unsigned char *r;
int xsize;
int ysize;
cout << "\n";
cout << "TEST02\n";
cout << " PPMB_READ_HEADER reads the header of a PPMB file.\n";
cout << " PPMB_READ_DATA reads the data in a PPMB file.\n";
cout << "\n";
cout << " Reading the file " << file_in_name << ".\n";
cout << flush;
file_in.open ( file_in_name.c_str ( ) );
if ( !file_in )
{
cout << "\n";
cout << "TEST02 - Fatal error!\n";
cout << " Could not open the file " << file_in_name << "\n";
return true;
}
cout << "\n";
cout << " The file " << file_in_name << " has been opened.\n";
cout << flush;
error = ppmb_read_header ( file_in, xsize, ysize, maxrgb );
if ( error )
{
cout << "\n";
cout << " PPMB_READ_HEADER failed!\n";
return error;
}
cout << "\n";
cout << " The header was read successfully.\n";
cout << " Number of rows of data = " << xsize << "\n";
cout << " Number of columns of data = " << ysize << "\n";
cout << " Maximum data value = " << maxrgb << "\n";
cout << flush;
r = new unsigned char[ xsize * ysize ];
g = new unsigned char[ xsize * ysize ];
b = new unsigned char[ xsize * ysize ];
error = ppmb_read_data ( file_in, xsize, ysize, r, g, b );
if ( error )
{
cout << "\n";
cout << " PPMB_READ_DATA failed!\n";
return error;
}
cout << "\n";
cout << " The data was read successfully.\n";
delete [] r;
delete [] g;
delete [] b;
return error;
}
//****************************************************************************80
void timestamp ( void )
//****************************************************************************80
//
// Purpose:
//
// TIMESTAMP prints the current YMDHMS date as a time stamp.
//
// Example:
//
// May 31 2001 09:45:54 AM
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 24 September 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// None
//
{
# define TIME_SIZE 40
static char time_buffer[TIME_SIZE];
const struct tm *tm;
size_t len;
time_t now;
now = time ( NULL );
tm = localtime ( &now );
len = strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm );
cout << time_buffer << "\n";
return;
# undef TIME_SIZE
}