MCPcopy Create free account
hub / github.com/LAStools/LAStools / writeCorrector

Method writeCorrector

LASzip/src/integercompressor.cpp:364–465  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

362*/
363
364void IntegerCompressor::writeCorrector(I32 c, ArithmeticModel* mBits)
365{
366 U32 c1;
367
368 // find the tighest interval [ - (2^k - 1) ... + (2^k) ] that contains c
369
370 k = 0;
371
372 // do this by checking the absolute value of c (adjusted for the case that c is 2^k)
373
374 c1 = (c <= 0 ? -c : c-1);
375
376 // this loop could be replaced with more efficient code
377
378 while (c1)
379 {
380 c1 = c1 >> 1;
381 k = k + 1;
382 }
383
384 // the number k is between 0 and corr_bits and describes the interval the corrector falls into
385 // we can compress the exact location of c within this interval using k bits
386
387 enc->encodeSymbol(mBits, k);
388
389#ifdef COMPRESS_ONLY_K
390 if (k) // then c is either smaller than 0 or bigger than 1
391 {
392 assert((c != 0) && (c != 1));
393 if (k < 32)
394 {
395 // translate the corrector c into the k-bit interval [ 0 ... 2^k - 1 ]
396 if (c < 0) // then c is in the interval [ - (2^k - 1) ... - (2^(k-1)) ]
397 {
398 // so we translate c into the interval [ 0 ... + 2^(k-1) - 1 ] by adding (2^k - 1)
399 enc->writeBits(k, c + ((1<<k) - 1));
400#ifdef CREATE_HISTOGRAMS
401 corr_histogram[k][c + ((1<<k) - 1)]++;
402#endif
403 }
404 else // then c is in the interval [ 2^(k-1) + 1 ... 2^k ]
405 {
406 // so we translate c into the interval [ 2^(k-1) ... + 2^k - 1 ] by subtracting 1
407 enc->writeBits(k, c - 1);
408#ifdef CREATE_HISTOGRAMS
409 corr_histogram[k][c - 1]++;
410#endif
411 }
412 }
413 }
414 else // then c is 0 or 1
415 {
416 assert((c == 0) || (c == 1));
417 enc->writeBit(c);
418#ifdef CREATE_HISTOGRAMS
419 corr_histogram[0][c]++;
420#endif
421 }

Callers

nothing calls this directly

Calls 4

encodeSymbolMethod · 0.45
writeBitsMethod · 0.45
writeBitMethod · 0.45
encodeBitMethod · 0.45

Tested by

no test coverage detected