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
00066 class SoConversion
00067 {
00068 private:
00070 virtual ~SoConversion();
00071
00072
00074 static void initClass();
00075
00076
00078 static void exitClass();
00079
00080 public:
00082 SoConversion();
00083
00102 virtual int convert(
00103 SoBufferObject* sourceBufferObject, const SbDataType src_type,
00104 SoBufferObject* targetBufferObject, const SbDataType dst_type, const size_t size );
00105
00106
00112 int convert(
00113 SoCpuBufferObject* sourceBufferObject, const SbDataType src_type,
00114 SoCpuBufferObject* targetBufferObject, const SbDataType dst_type, const size_t size );
00115
00132 virtual int convertFloatToRGBA(
00133 SoBufferObject* sourceBufferObject,
00134 SoBufferObject* targetBufferObject,
00135 const size_t size, const float dataMin, const float dataMax );
00136
00137
00143 int convertFloatToRGBA(
00144 SoCpuBufferObject* sourceBufferObject,
00145 SoCpuBufferObject* targetBufferObject,
00146 const size_t size, const float dataMin, const float dataMax );
00147
00148 private:
00163 int convertToFloat(
00164 SoBufferObject* sourceBufferObject, const SbDataType src_type,
00165 SoBufferObject* targetBufferObject, const size_t size );
00166
00167
00173 int convertToFloat(
00174 SoCpuBufferObject* sourceBufferObject, const SbDataType src_type,
00175 SoCpuBufferObject* targetBufferObject, const size_t size );
00176
00177
00189 int convertToUChar(
00190 SoBufferObject* sourceBufferObject, SbDataType src_type,
00191 SoBufferObject* targetBufferObject, const size_t size );
00192
00193
00199 int convertToUChar(
00200 SoCpuBufferObject* sourceBufferObject, SbDataType src_type,
00201 SoCpuBufferObject* targetBufferObject, const size_t size );
00202
00203 private:
00204
00206 enum MappingMethod {
00215 MAP_TO_CENTER,
00216
00225 MAP_TO_BORDER
00226 };
00227
00231 virtual void mapDataRangeToIndex(
00232 SoBufferObject *sourceBufferObject, const SbDataType src_type,
00233 SoBufferObject *targetBufferObject, const SbDataType dst_type,
00234 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00235 const int shift, const int offset );
00236
00237
00241 virtual void mapDataToIndex(
00242 SoBufferObject *sourceBufferObject, const SbDataType src_type,
00243 SoBufferObject *targetBufferObject, const SbDataType dst_type,
00244 const int numSigBits, const int shift, const int offset );
00245
00246
00250 virtual void mapDataRangeToRgba(
00251 SoBufferObject *sourceBufferObject, const SbDataType src_type,
00252 SoBufferObject *targetBufferObject, const SbDataType dst_type,
00253 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00254 const int shift, const int offset,
00255 SoBufferObject *rgbaBufferObject, const int numRgba, MappingMethod rgbaMapping );
00256
00257
00261 virtual void mapDataToRgba(
00262 SoBufferObject *sourceBufferObject, const SbDataType src_type,
00263 SoBufferObject *targetBufferObject, const SbDataType dst_type,
00264 const int numSigBits, const int shift, const int offset,
00265 SoBufferObject *rgbaBufferObject, const int numRgba, MappingMethod mapping );
00266
00274 static void convertByteToBitSet(SoCpuBufferObject* sourceBufferObject,SoCpuBufferObject* targetBufferObject);
00275
00282 static void convertBitSetToByte(SoCpuBufferObject* sourceBufferObject,SoCpuBufferObject* targetBufferObject);
00283
00284 private:
00285
00286
00287 template <typename DataClassIn>
00288 static void cpuMapDataRangeToIndex(const void *srcData, void *dstData,
00289 const size_t bufferSize, const SbDataType::DataType dataTypeDst,
00290 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00291 const int shift, const int offset
00292 );
00293
00294
00295
00296 template <typename DataClassIn, typename DataClassOut>
00297 static void cpuMapDataRangeToIndexTempl(
00298 const void *src, void *dst, const size_t bufferSize,
00299 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00300 const int shift, const int offset
00301 );
00302
00303 #ifdef HAS_SSE
00304
00305 template <typename DataClassIn, typename DataClassOut>
00306 static void cpuMapDataRangeToIndexTemplSSE(
00307 const void *src, void *dst, const size_t bufferSize,
00308 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00309 const int shift, const int offset
00310 );
00311
00312 template <typename DataClassIn>
00313 static void SSE_loadRegister( DataClassIn*& ptr, __m128& reg );
00314
00315 template <typename DataClassOut>
00316 static void SSE_unloadRegister( __m128& regA, __m128& regB, DataClassOut*& ptr );
00317 #endif
00318
00319
00320 template <typename DataClassIn>
00321 static void cpuMapDataRangeToRgba(
00322 const void *src, void *dst, const size_t bufferSize,
00323 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00324 const int shift, const int offset,
00325 const unsigned int *rgba, const int numRgba, MappingMethod mapping
00326 );
00327
00328
00329
00330 template <typename DataClassIn>
00331 static void cpuMapDataToIndex(const void *srcData, void *dstData,
00332 const size_t bufferSize, const SbDataType::DataType dataTypeDst,
00333 const int numSigBits, const int shift, const int offset
00334 );
00335
00336
00337
00338 template <typename DataClassIn, typename DataClassOut>
00339 static void cpuMapDataToIndexTempl(
00340 const void *src, void *dst, const size_t bufferSize,
00341 const int numSigBits, const int shift, const int offset
00342 );
00343
00344
00345
00346 template <typename DataClassIn>
00347 static void cpuMapDataToRgba(
00348 const void *src, void *dst, const size_t bufferSize,
00349 const int numSigBits, const int shift, const int offset,
00350 const unsigned int *rgba, const int numRgba, MappingMethod mapping
00351 );
00352
00353 private:
00354 #if defined(HAS_SSE)
00355 static void convertBitSetToByteSSE(unsigned char* packedTile, unsigned char* unpackedTile, uint64_t size);
00356 #endif
00357 static void convertBitSetToByteStd(unsigned char* packedTile, unsigned char* unpackedTile, uint64_t size);
00358
00359
00360 static bool s_useSSE;
00361
00362 };
00363
00364 #endif //SOCONVERSION_H
00365
00366