127 template<
typename T,
typename MappingType>
128 static void map( T* src, MappingType* dst,
size_t sampleCount,
const SbVec2d& range );
141 template <
typename T,
typename MappingType>
142 static void unmap( MappingType* src, T* dst,
size_t sampleCount,
const SbVec2d& range );
149 size_t uncompressRaw(
void* dst,
size_t dstLen,
const TileInfo& tileInfo );
156 template <
typename T>
157 size_t uncompressAndUnmap(
void* dst,
size_t dstLen,
const TileInfo& tileInfo );
161template<
typename T,
typename MappingType>
163SoJp3dDataCompressor::map( T* src, MappingType* dst,
size_t sampleCount,
const SbVec2d& range )
165 double rangeOffset = range[0];
166 double rangeMax = range[1] - range[0];
169 for (
size_t i = 0; i < sampleCount; ++i )
171 ratio = (
static_cast<double>( src[i] ) - rangeOffset ) / rangeMax;
172 dst[i] =
static_cast<MappingType
>( ratio * std::numeric_limits<uint16_t>::max() );
177template <
typename T,
typename MappingType>
179SoJp3dDataCompressor::unmap( MappingType* src, T* dst,
size_t sampleCount,
const SbVec2d& range )
186 for (
size_t i = 0; i < sampleCount; ++i )
188 ratio =
static_cast<double>( src[i] ) / std::numeric_limits<MappingType>::max();
189 dst[i] =
static_cast<T
>(
rangeMin + ratio*mappingRange );
196SoJp3dDataCompressor::uncompressAndUnmap(
void* dst,
size_t dstLen,
const TileInfo& tileInfo )
198 T* dstBuffer =
reinterpret_cast<T*
>( dst );
200 size_t sampleCount = tileInfo.dims[0];
201 sampleCount *= tileInfo.dims[1];
202 sampleCount *= tileInfo.dims[2];
204 size_t dstSampleCount = dstLen /
sizeof( T );
206 if ( sampleCount > dstSampleCount )
209 "SoJp3dDataCompressor::uncompressAndUnmap",
210 "%ld samples to uncompress, only space for %ld samples in destination.", sampleCount, dstSampleCount
216 std::vector<uint16_t> mapBuffer( sampleCount );
217 size_t uncompressedBytes = uncompressRaw( &mapBuffer[0], mapBuffer.size() *
sizeof( uint16_t ), tileInfo );
218 size_t uncompressedSamples = uncompressedBytes /
sizeof( uint16_t );
220 if ( uncompressedSamples != sampleCount )
223 "SoJp3dDataCompressor::uncompressAndUnmap",
224 "incorrect sample count, %ld sampled decoded on %ld.", uncompressedSamples, sampleCount
230 unmap( &mapBuffer[0], dstBuffer, mapBuffer.size(), tileInfo.range );
232 return mapBuffer.size() *
sizeof( T );
#define SO_TYPED_CLASS_HEADER()
Class for smart character strings.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> 2D vector class ...
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Data com...
static void post(const char *methodName, const char *formatString ...)
Posts an error.
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> JP3D dat...
virtual size_t uncompress(void *dst, size_t dstLen, const TileInfo &tileInfo)
Uncompresses data from the internal buffer to the given buffer.
SoJp3dDataCompressor()
Constructor.
virtual ~SoJp3dDataCompressor()
Destructor.
virtual SbString getCompressionFormatName() const
Returns the name of the compression algorithm used by this class.
virtual size_t compress(void *src, size_t srcLen, const TileInfo &tileInfo)
Compresses the given buffer into the internal buffer.
virtual bool isLossless()
Checks if the compression is lossless.
T rangeMax()
Returns the maximum finite value representable by the numeric type T.
T rangeMin()
Returns the lowest finite value representable by the numeric type T, that is, a finite value x such t...
This structure contains the dimension and the type of the tile being processed.