| 261 | } |
| 262 | |
| 263 | BOOL LASwaveform13writer::write_waveform(LASpoint* point, U8* samples) |
| 264 | { |
| 265 | U32 index = point->wavepacket.getIndex(); |
| 266 | if (index == 0) |
| 267 | { |
| 268 | return FALSE; |
| 269 | } |
| 270 | |
| 271 | U32 nbits = waveforms[index]->nbits; |
| 272 | if ((nbits != 8) && (nbits != 16)) |
| 273 | { |
| 274 | laserror("waveform with %d bits per samples not supported yet", nbits); |
| 275 | return FALSE; |
| 276 | } |
| 277 | |
| 278 | U32 nsamples = waveforms[index]->nsamples; |
| 279 | if (nsamples == 0) |
| 280 | { |
| 281 | laserror("waveform has no samples"); |
| 282 | return FALSE; |
| 283 | } |
| 284 | |
| 285 | // set offset to waveform data |
| 286 | |
| 287 | I64 offset = stream->tell(); |
| 288 | point->wavepacket.setOffset(offset); |
| 289 | |
| 290 | // write waveform |
| 291 | |
| 292 | if (waveforms[index]->compression == 0) |
| 293 | { |
| 294 | U32 size = ((nbits/8) * nsamples); |
| 295 | if (!stream->putBytes(samples, size)) |
| 296 | { |
| 297 | laserror("cannot write %u bytes for waveform with %u samples of %u bits", size, nsamples, nbits); |
| 298 | return FALSE; |
| 299 | } |
| 300 | point->wavepacket.setSize(size); |
| 301 | } |
| 302 | else |
| 303 | { |
| 304 | U32 s_count; |
| 305 | if (nbits == 8) |
| 306 | { |
| 307 | stream->putBytes(samples, 1); |
| 308 | enc->init(stream); |
| 309 | ic8->initCompressor(); |
| 310 | for (s_count = 1; s_count < nsamples; s_count++) |
| 311 | { |
| 312 | ic8->compress(samples[s_count-1], samples[s_count]); |
| 313 | } |
| 314 | } |
| 315 | else |
| 316 | { |
| 317 | stream->putBytes(samples, 2); |
| 318 | enc->init(stream); |
| 319 | ic16->initCompressor(); |
| 320 | for (s_count = 1; s_count < nsamples; s_count++) |