MCPcopy Create free account
hub / github.com/FreeFem/FreeFem-sources / Load

Method Load

plugin/seq/pcm.cpp:156–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154}
155
156void PCM::Load(const char *filename) {
157 char token[TOKEN_SIZE];
158 ifstream input_stream(filename, BINARY_IN);
159
160 if (!input_stream) {
161 fatal_error("PCM::Load -> file not found.");
162 }
163
164 // check magic number
165 extract_token(input_stream, token, TOKEN_SIZE);
166 if (strcmp(token, "PC") != 0) {
167 fprintf(stderr, "Magic number \"%s\" != PC\n", token);
168 fatal_error("PCM::Load -> bad magic number");
169 }
170
171 // get dimensions
172 extract_token(input_stream, token, TOKEN_SIZE);
173 width = atoi(token);
174 extract_token(input_stream, token, TOKEN_SIZE);
175 height = atoi(token);
176 extract_token(input_stream, token, TOKEN_SIZE);
177 max = atof(token);
178 cout << " pcm : " << width << "x" << height << " max :" << max << endl;
179 // Reallocate memory, if necessary.
180 unsigned long p = (long)(width * height);
181 if (p != pixels) {
182 pixels = p;
183 if (image) {
184 delete[] image;
185 image = NULL;
186 }
187 }
188
189 if (!image) {
190 image = new pcm_complex[pixels];
191 }
192
193 // skip max cols
194 extract_token(input_stream, token, TOKEN_SIZE);
195 char ch;
196 input_stream.read((char *)&ch, sizeof(char));
197
198 // if machine is big endian then we need to convert floats from little endian
199 void (*endian_filter)(float *);
200 int i4 = 1;
201 char zero_is_little_endian = *((static_cast< const char * >((void *)&i4)) + 3);
202
203 if (zero_is_little_endian == 0) {
204 endian_filter = (void (*)(float *))do_nothing;
205 } else {
206 endian_filter = (void (*)(float *))swap_float_endian;
207 }
208
209 // read data
210 for (int y = 0; y < height; y++) {
211 for (int x = 0; x < width; x++) {
212 pcm_complex c;
213 input_stream.read((char *)(void *)&c.r, sizeof(c.r));

Callers

nothing calls this directly

Calls 6

fatal_errorFunction · 0.85
extract_tokenFunction · 0.85
atoiFunction · 0.85
atofFunction · 0.85
readMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected