MCPcopy Create free account
hub / github.com/PDAL/PDAL / bitsNeeded

Method bitsNeeded

plugins/e57/libE57Format/src/ImageFileImpl.cpp:809–862  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

807 }
808
809 unsigned ImageFileImpl::bitsNeeded( int64_t minimum, int64_t maximum )
810 {
811 // Relatively quick way to compute ceil(log2(maximum - minimum + 1)));
812 // Uses only integer operations and is machine independent (no assembly code). Find the bit
813 // position of the first 1 (from left) in the binary form of stateCountMinus1.
814 //??? move to E57Utility?
815
816 uint64_t stateCountMinus1 = maximum - minimum;
817
818 unsigned log2 = 0;
819
820 if ( stateCountMinus1 & 0xFFFFFFFF00000000LL )
821 {
822 stateCountMinus1 >>= 32;
823 log2 += 32;
824 }
825
826 if ( stateCountMinus1 & 0xFFFF0000LL )
827 {
828 stateCountMinus1 >>= 16;
829 log2 += 16;
830 }
831
832 if ( stateCountMinus1 & 0xFF00LL )
833 {
834 stateCountMinus1 >>= 8;
835 log2 += 8;
836 }
837
838 if ( stateCountMinus1 & 0xF0LL )
839 {
840 stateCountMinus1 >>= 4;
841 log2 += 4;
842 }
843
844 if ( stateCountMinus1 & 0xCLL )
845 {
846 stateCountMinus1 >>= 2;
847 log2 += 2;
848 }
849
850 if ( stateCountMinus1 & 0x2LL )
851 {
852 stateCountMinus1 >>= 1;
853 log2 += 1;
854 }
855
856 if ( stateCountMinus1 & 1LL )
857 {
858 log2++;
859 }
860
861 return log2;
862 }
863
864#ifdef E57_ENABLE_DIAGNOSTIC_OUTPUT
865 void ImageFileImpl::dump( int indent, std::ostream &os ) const

Callers 4

DecoderFactoryMethod · 0.80
BitpackIntegerDecoderMethod · 0.80
EncoderFactoryMethod · 0.80
BitpackIntegerEncoderMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected