60 for (i = 0; i < 256; i++)
62 if (waveforms[i])
delete waveforms[i];
68 if (ic16)
delete ic16;
76 fprintf(stderr,
"ERROR: file name pointer is zero\n");
80 if (wave_packet_descr == 0)
82 fprintf(stderr,
"ERROR: wave packet descriptor pointer is zero\n");
94 for (i = 0; i < 256; i++) waveforms[i] = 0;
97 for (i = 0; i < 256; i++)
99 if (wave_packet_descr[i])
101 if (waveforms[i] == 0)
108 compressed = compressed || (waveforms[i]->compression > 0);
123 char* file_name_temp = strdup(file_name);
125 int len = strlen(file_name_temp);
126 if (file_name_temp[len-3] ==
'L' || file_name_temp[len-3] ==
'W')
128 file_name_temp[len-3] =
'W';
129 file_name_temp[len-2] =
'D';
130 file_name_temp[len-1] = (compressed ?
'Z' :
'P');
134 file_name_temp[len-3] =
'w';
135 file_name_temp[len-2] =
'd';
136 file_name_temp[len-1] = (compressed ?
'z' :
'p');
138 file = fopen(file_name_temp,
"wb");
142 fprintf(stderr,
"ERROR: cannot open waveform file '%s'\n", file_name_temp);
143 free(file_name_temp);
146 free(file_name_temp);
161 U16 reserved = 0xAABB;
162 if (!stream->put16bitsLE((
U8*)&reserved))
164 fprintf(stderr,
"ERROR: writing EVLR reserved\n");
168 memset(user_id, 0, 16);
169 strcpy(user_id,
"LASF_Spec");
170 if (!stream->putBytes((
U8*)user_id, 16))
172 fprintf(stderr,
"ERROR: writing EVLR user_id\n");
175 U16 record_id = 65535;
176 if (!stream->put16bitsLE((
U8*)&record_id))
178 fprintf(stderr,
"ERROR: writing EVLR record_id\n");
181 I64 record_length_after_header = 0;
182 if (!stream->put64bitsLE((
U8*)&record_length_after_header))
184 fprintf(stderr,
"ERROR: writing EVLR record_length_after_header\n");
188 memset(description, 0, 32);
189 sprintf(description,
"%s by LAStools (%d)", (compressed ?
"compressed" :
"created"),
LAS_TOOLS_VERSION);
190 if (!stream->putBytes((
U8*)description, 32))
192 fprintf(stderr,
"ERROR: writing EVLR description\n");
201 if (!stream->putBytes((
U8*)magic, 24))
203 fprintf(stderr,
"ERROR: writing waveform descriptor cross-check\n");
207 if (!stream->put16bitsLE((
U8*)&number))
209 fprintf(stderr,
"ERROR: writing number of waveform descriptors\n");
213 for (i = 0; i < 256; i++)
217 if (!stream->put16bitsLE((
U8*)&i))
219 fprintf(stderr,
"ERROR: writing index of waveform descriptor %d\n", i);
222 if (!stream->putByte(waveforms[i]->compression))
224 fprintf(stderr,
"ERROR: writing compression of waveform descriptor %d\n", i);
227 if (!stream->putByte(waveforms[i]->nbits))
229 fprintf(stderr,
"ERROR: writing nbits of waveform descriptor %d\n", i);
232 if (!stream->put16bitsLE((
U8*)&(waveforms[i]->nsamples)))
234 fprintf(stderr,
"ERROR: writing nsamples of waveform descriptor %d\n", i);
260 U32 nbits = waveforms[index]->nbits;
261 if ((nbits != 8) && (nbits != 16))
263 fprintf(stderr,
"ERROR: waveform with %d bits per samples not supported yet\n", nbits);
270 fprintf(stderr,
"ERROR: waveform has no samples\n");
276 I64 offset = stream->tell();
283 U32 size = ((nbits/8) * nsamples);
284 if (!stream->putBytes(samples, size))
286 fprintf(stderr,
"ERROR: cannot write %u bytes for waveform with %u samples of %u bits\n", size, nsamples, nbits);
296 stream->putBytes(samples, 1);
298 ic8->initCompressor();
299 for (s_count = 1; s_count <
nsamples; s_count++)
301 ic8->compress(samples[s_count-1], samples[s_count]);
306 stream->putBytes(samples, 2);
308 ic16->initCompressor();
309 for (s_count = 1; s_count <
nsamples; s_count++)
311 ic16->compress(((
U16*)samples)[s_count-1], ((
U16*)samples)[s_count]);
315 U32 size = (
U32)(stream->tell() - offset);
324 if (stream->isSeekable())
326 I64 record_length_after_header = stream->tell();
327 record_length_after_header -= 60;
329 if (!stream->put64bitsLE((
U8*)&record_length_after_header))
331 fprintf(stderr,
"ERROR: updating EVLR record_length_after_header\n");
void setOffset(U64 offset)
U8 getCompressionType() const
U32 getNumberOfSamples() const
#define LAS_TOOLS_VERSION
U8 getBitsPerSample() const