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 int shift, const int offset );
00235
00236
00240 virtual void mapDataToIndex(
00241 SoBufferObject *sourceBufferObject, const SbDataType src_type,
00242 SoBufferObject *targetBufferObject, const SbDataType dst_type,
00243 const int numSigBits, const int shift, const int offset );
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 const int shift, const int offset,
00254 SoBufferObject *rgbaBufferObject, const int numRgba, MappingMethod rgbaMapping );
00255
00256
00260 virtual void mapDataToRgba(
00261 SoBufferObject *sourceBufferObject, const SbDataType src_type,
00262 SoBufferObject *targetBufferObject, const SbDataType dst_type,
00263 const int numSigBits, const int shift, const int offset,
00264 SoBufferObject *rgbaBufferObject, const int numRgba, MappingMethod mapping );
00265
00273 static void convertByteToBitSet(SoCpuBufferObject* sourceBufferObject,SoCpuBufferObject* targetBufferObject);
00274
00281 static void convertBitSetToByte(SoCpuBufferObject* sourceBufferObject,SoCpuBufferObject* targetBufferObject);
00282
00283 private:
00284
00285
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 int shift, const int offset
00291 );
00292
00293
00294
00295 template <typename DataClassIn, typename DataClassOut>
00296 static void cpuMapDataRangeToIndexTempl(
00297 const void *src, void *dst, const size_t bufferSize,
00298 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00299 const int shift, const int offset
00300 );
00301
00302 #ifdef HAS_SSE
00303
00304 template <typename DataClassIn, typename DataClassOut>
00305 static void cpuMapDataRangeToIndexTemplSSE(
00306 const void *src, void *dst, const size_t bufferSize,
00307 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00308 const int shift, const int offset
00309 );
00310
00311 template <typename DataClassIn>
00312 static void SSE_loadRegister( DataClassIn*& ptr, __m128& reg );
00313
00314 template <typename DataClassOut>
00315 static void SSE_unloadRegister( __m128& regA, __m128& regB, DataClassOut*& ptr );
00316 #endif
00317
00318
00319 template <typename DataClassIn>
00320 static void cpuMapDataRangeToRgba(
00321 const void *src, void *dst, const size_t bufferSize,
00322 const double dataRangeMin, const double dataRangeMax, const bool dataRangeMap,
00323 const int shift, const int offset,
00324 const unsigned int *rgba, const int numRgba, MappingMethod mapping
00325 );
00326
00327
00328
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, const int shift, const int offset
00333 );
00334
00335
00336
00337 template <typename DataClassIn, typename DataClassOut>
00338 static void cpuMapDataToIndexTempl(
00339 const void *src, void *dst, const size_t bufferSize,
00340 const int numSigBits, const int shift, const int offset
00341 );
00342
00343
00344
00345 template <typename DataClassIn>
00346 static void cpuMapDataToRgba(
00347 const void *src, void *dst, const size_t bufferSize,
00348 const int numSigBits, const int shift, const int offset,
00349 const unsigned int *rgba, const int numRgba, MappingMethod mapping
00350 );
00351
00352 private:
00353 #if defined(HAS_SSE)
00354 static void convertBitSetToByteSSE(unsigned char* packedTile, unsigned char* unpackedTile, uint64_t size);
00355 #endif
00356 static void convertBitSetToByteStd(unsigned char* packedTile, unsigned char* unpackedTile, uint64_t size);
00357
00358
00359 static bool s_useSSE;
00360
00361 };
00362
00363 #endif //SOCONVERSION_H
00364
00365