00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined SOCONVERSION_H
00024 #define SOCONVERSION_H
00025
00026 #include <Inventor/SbString.h>
00027 #include <Inventor/SbDataType.h>
00028
00029 #include <Inventor/STL/vector>
00030
00031 #include <Inventor/algorithms/SoAlgorithmsDefs.h>
00032
00033 #if defined(__i386__) || defined(__amd64__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_AMD64)
00034 # define HAS_SSE
00035 #endif
00036
00037 #if ( __GNUC__ == 3 && __GNUC_MINOR__ == 2 )
00038 #undef HAS_SSE
00039 #endif
00040
00041 #ifdef HAS_SSE
00042 # include <mmintrin.h>
00043 # include <xmmintrin.h>
00044 # include <emmintrin.h>
00045 #endif
00046
00047 class SoBufferObject;
00048 class SoCpuBufferObject;
00049
00065 class SoConversion
00066 {
00067 private:
00069 virtual ~SoConversion();
00070
00071
00073 static void initClass();
00074
00075
00077 static void exitClass();
00078
00079 public:
00081 SoConversion();
00082
00101 virtual int convert(
00102 SoBufferObject* sourceBufferObject, const SbDataType src_type,
00103 SoBufferObject* targetBufferObject, const SbDataType dst_type, const size_t size );
00104
00105
00111 int convert(
00112 SoCpuBufferObject* sourceBufferObject, const SbDataType src_type,
00113 SoCpuBufferObject* targetBufferObject, const SbDataType dst_type, const size_t size );
00114
00131 virtual int convertFloatToRGBA(
00132 SoBufferObject* sourceBufferObject,
00133 SoBufferObject* targetBufferObject,
00134 const size_t size, const float dataMin, const float dataMax );
00135
00136
00142 int convertFloatToRGBA(
00143 SoCpuBufferObject* sourceBufferObject,
00144 SoCpuBufferObject* targetBufferObject,
00145 const size_t size, const float dataMin, const float dataMax );
00146
00147 private:
00162 int convertToFloat(
00163 SoBufferObject* sourceBufferObject, const SbDataType src_type,
00164 SoBufferObject* targetBufferObject, const size_t size );
00165
00166
00172 int convertToFloat(
00173 SoCpuBufferObject* sourceBufferObject, const SbDataType src_type,
00174 SoCpuBufferObject* targetBufferObject, const size_t size );
00175
00176
00188 int convertToUChar(
00189 SoBufferObject* sourceBufferObject, SbDataType src_type,
00190 SoBufferObject* targetBufferObject, const size_t size );
00191
00192
00198 int convertToUChar(
00199 SoCpuBufferObject* sourceBufferObject, SbDataType src_type,
00200 SoCpuBufferObject* targetBufferObject, const size_t size );
00201
00202 private:
00203
00205 enum MappingMethod {
00214 MAP_TO_CENTER,
00215
00224 MAP_TO_BORDER
00225 };
00226
00230 virtual void mapDataRangeToIndex(
00231 SoBufferObject *sourceBufferObject, const SbDataType src_type,
00232 SoBufferObject *targetBufferObject, const SbDataType dst_type,
00233 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00234 const double undefinedValue = std::numeric_limits<double>::quiet_NaN() );
00235
00236
00240 virtual void mapDataToIndex(
00241 SoBufferObject *sourceBufferObject, const SbDataType src_type,
00242 SoBufferObject *targetBufferObject, const SbDataType dst_type,
00243 const int numSigBits );
00244
00245
00249 virtual void mapDataRangeToRgba(
00250 SoBufferObject *sourceBufferObject, const SbDataType src_type,
00251 SoBufferObject *targetBufferObject, const SbDataType dst_type,
00252 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00253 SoBufferObject *rgbaBufferObject, const int numRgba, MappingMethod rgbaMapping );
00254
00255
00259 virtual void mapDataToRgba(
00260 SoBufferObject *sourceBufferObject, const SbDataType src_type,
00261 SoBufferObject *targetBufferObject, const SbDataType dst_type,
00262 const int numSigBits,
00263 SoBufferObject *rgbaBufferObject, const int numRgba, MappingMethod mapping );
00264
00272 static void convertByteToBitSet(SoCpuBufferObject* sourceBufferObject,SoCpuBufferObject* targetBufferObject);
00273
00280 static void convertBitSetToByte(SoCpuBufferObject* sourceBufferObject,SoCpuBufferObject* targetBufferObject);
00281
00286 template <typename DataClassIn>
00287 static void cpuMapDataRangeToIndex(const void *srcData, void *dstData,
00288 const size_t bufferSize, const SbDataType::DataType dataTypeDst,
00289 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00290 const double undefinedValue = std::numeric_limits<double>::quiet_NaN()
00291 );
00292
00297 template <typename DataClassIn, typename DataClassOut>
00298 static void cpuMapDataRangeToIndexTempl(
00299 const void *src, void *dst, const size_t bufferSize,
00300 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00301 const double undefinedValue = std::numeric_limits<double>::quiet_NaN()
00302 );
00303
00308 template <typename DataClassIn, typename DataClassOut>
00309 static void cpuMapDataRangeToIndexTemplSSE(
00310 const void *src, void *dst, const size_t bufferSize,
00311 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap
00312 );
00313
00318 template <typename DataClassIn>
00319 static void cpuMapDataRangeToRgba(
00320 const void *src, void *dst, const size_t bufferSize,
00321 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00322 const unsigned int *rgba, const int numRgba, MappingMethod mapping
00323 );
00324
00329 template <typename DataClassIn>
00330 static void cpuMapDataToIndex(const void *srcData, void *dstData,
00331 const size_t bufferSize, const SbDataType::DataType dataTypeDst,
00332 const int numSigBits
00333 );
00334
00339 template <typename DataClassIn, typename DataClassOut>
00340 static void cpuMapDataToIndexTempl(
00341 const void *src, void *dst, const size_t bufferSize,
00342 const int numSigBits
00343 );
00344
00349 template <typename DataClassIn>
00350 static void cpuMapDataToRgba(
00351 const void *src, void *dst, const size_t bufferSize,
00352 const int numSigBits,
00353 const unsigned int *rgba, const int numRgba, MappingMethod mapping
00354 );
00355
00356 private:
00357
00358
00359 template <typename DataClassIn>
00360 static void cpuMapDataRangeToIndex(const void *srcData, void *dstData,
00361 const size_t bufferSize, const SbDataType::DataType dataTypeDst,
00362 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00363 const int shift, const int offset
00364 );
00365
00366
00367
00368 template <typename DataClassIn, typename DataClassOut>
00369 static void cpuMapDataRangeToIndexTempl(
00370 const void *src, void *dst, const size_t bufferSize,
00371 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00372 const int shift, const int offset
00373 );
00374
00375 #ifdef HAS_SSE
00376
00377 template <typename DataClassIn, typename DataClassOut>
00378 static void cpuMapDataRangeToIndexTemplSSE(
00379 const void *src, void *dst, const size_t bufferSize,
00380 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00381 const int shift, const int offset
00382 );
00383
00384 template <typename DataClassIn>
00385 static void SSE_loadRegister( DataClassIn*& ptr, __m128& reg );
00386
00387 template <typename DataClassOut>
00388 static void SSE_unloadRegister( __m128& regA, __m128& regB, DataClassOut*& ptr );
00389 #endif
00390
00391
00392 template <typename DataClassIn>
00393 static void cpuMapDataRangeToRgba(
00394 const void *src, void *dst, const size_t bufferSize,
00395 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00396 const int shift, const int offset,
00397 const unsigned int *rgba, const int numRgba, MappingMethod mapping
00398 );
00399
00400
00401
00402 template <typename DataClassIn>
00403 static void cpuMapDataToIndex(const void *srcData, void *dstData,
00404 const size_t bufferSize, const SbDataType::DataType dataTypeDst,
00405 const int numSigBits, const int shift, const int offset
00406 );
00407
00408
00409
00410 template <typename DataClassIn, typename DataClassOut>
00411 static void cpuMapDataToIndexTempl(
00412 const void *src, void *dst, const size_t bufferSize,
00413 const int numSigBits, const int shift, const int offset
00414 );
00415
00416
00417
00418 template <typename DataClassIn>
00419 static void cpuMapDataToRgba(
00420 const void *src, void *dst, const size_t bufferSize,
00421 const int numSigBits, const int shift, const int offset,
00422 const unsigned int *rgba, const int numRgba, MappingMethod mapping
00423 );
00424
00425 private:
00426 #if defined(HAS_SSE)
00427 static void convertBitSetToByteSSE(unsigned char* packedTile, unsigned char* unpackedTile, uint64_t size);
00428 #endif
00429 static void convertBitSetToByteStd(unsigned char* packedTile, unsigned char* unpackedTile, uint64_t size);
00430
00431
00432 static bool s_useSSE;
00433
00434 };
00435
00436 #endif //SOCONVERSION_H
00437
00438