00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "compressorRLE4B.h"
00020
00021 namespace
00022 {
00023 static const uint8_t _rleMarker = 0x42;
00024 }
00025
00026 #include "compressorRLE.ipp"
00027
00028 namespace eq
00029 {
00030 namespace plugin
00031 {
00032
00033 namespace
00034 {
00035 class NoSwizzle
00036 {
00037 public:
00038 static inline void swizzle( const uint32_t input, uint8_t& one,
00039 uint8_t& two, uint8_t& three, uint8_t& four )
00040 {
00041 one = input & 0xff;
00042 two = (input & 0xff00) >> 8;
00043 three = (input & 0xff0000) >> 16;
00044 four = (input & 0xff000000) >> 24;
00045 }
00046
00047 static inline void swizzle( const uint32_t input, uint8_t& one,
00048 uint8_t& two, uint8_t& three )
00049 {
00050 one = input & 0xff;
00051 two = (input & 0xff00) >> 8;
00052 three = (input & 0xff0000) >> 16;
00053 }
00054
00055 static inline uint32_t deswizzle( const uint8_t one, const uint8_t two,
00056 const uint8_t three, const uint8_t four )
00057 {
00058 return one + (two<<8) + (three<<16) + (four<<24);
00059 }
00060
00061 static inline uint32_t deswizzle( const uint8_t one, const uint8_t two,
00062 const uint8_t three )
00063 {
00064 return one + (two<<8) + (three<<16);
00065 }
00066 };
00067
00068 class SwizzleUInt32
00069 {
00070 public:
00071 static inline void swizzle( const uint32_t input, uint8_t& one,
00072 uint8_t& two, uint8_t& three, uint8_t& four )
00073 {
00074 return NoSwizzle::swizzle(
00075 (( input & ( EQ_BIT32 | EQ_BIT31 | EQ_BIT22 | EQ_BIT21 |
00076 EQ_BIT12 | EQ_BIT11 | EQ_BIT2 | EQ_BIT1 )) |
00077 (( input & ( EQ_BIT8 | EQ_BIT7 ))<<18 ) |
00078 (( input & ( EQ_BIT24 | EQ_BIT23 | EQ_BIT14 | EQ_BIT13 ))<<6 ) |
00079 (( input & ( EQ_BIT16 | EQ_BIT15 | EQ_BIT6 |
00080 EQ_BIT5 | EQ_BIT4 | EQ_BIT3 )) <<12 ) |
00081 (( input & ( EQ_BIT28 | EQ_BIT27 | EQ_BIT26 | EQ_BIT25 ))>>18) |
00082 (( input & ( EQ_BIT18 | EQ_BIT17 ))>>12) |
00083 (( input & ( EQ_BIT30 | EQ_BIT29 | EQ_BIT20 | EQ_BIT19 |
00084 EQ_BIT10 | EQ_BIT9 ))>>6 )),
00085 one, two, three, four );
00086 }
00087 static inline void swizzle( const uint32_t input, uint8_t& one,
00088 uint8_t& two, uint8_t& three )
00089 { assert( 0 ); }
00090
00091 static inline uint32_t deswizzle( const uint8_t one, const uint8_t two,
00092 const uint8_t three, const uint8_t four )
00093 {
00094 const uint32_t input = one + (two<<8) + (three<<16) + (four<<24);
00095 return (( input & ( EQ_BIT32 | EQ_BIT31 | EQ_BIT22 | EQ_BIT21 |
00096 EQ_BIT11 | EQ_BIT12 | EQ_BIT2 | EQ_BIT1 )) |
00097 (( input & ( EQ_BIT26 | EQ_BIT25 )) >>18 ) |
00098 (( input & ( EQ_BIT30 | EQ_BIT29 | EQ_BIT20 | EQ_BIT19 ))>>6 ) |
00099 (( input & ( EQ_BIT28 | EQ_BIT27 | EQ_BIT18 |
00100 EQ_BIT17 | EQ_BIT16 |EQ_BIT15 ))>>12 ) |
00101 (( input & ( EQ_BIT10 | EQ_BIT9 | EQ_BIT8 | EQ_BIT7 ))<<18 ) |
00102 (( input & ( EQ_BIT6 | EQ_BIT5 ))<<12 ) |
00103 (( input & ( EQ_BIT24 | EQ_BIT23 | EQ_BIT14 |
00104 EQ_BIT13 | EQ_BIT4 | EQ_BIT3 ))<<6 ));
00105 }
00106
00107 static inline uint32_t deswizzle( const uint8_t one, const uint8_t two,
00108 const uint8_t three )
00109 { assert( 0 ); return 0; }
00110 };
00111
00112 class SwizzleUInt24
00113 {
00114 public:
00115 static inline void swizzle( const uint32_t input, uint8_t& one,
00116 uint8_t& two, uint8_t& three, uint8_t& four )
00117 { assert( 0 ); }
00118
00119 static inline void swizzle( const uint32_t input, uint8_t& one,
00120 uint8_t& two, uint8_t& three )
00121 {
00122 return NoSwizzle::swizzle(
00123 (( input & ( EQ_BIT24 | EQ_BIT23 | EQ_BIT22 | EQ_BIT13 |
00124 EQ_BIT12 | EQ_BIT3 | EQ_BIT2 | EQ_BIT1 )) |
00125 (( input & ( EQ_BIT16 | EQ_BIT15 | EQ_BIT14 )) << 5 ) |
00126 (( input & ( EQ_BIT11 | EQ_BIT10 | EQ_BIT9 )) >> 5 ) |
00127 (( input & ( EQ_BIT8 | EQ_BIT7 | EQ_BIT6 | EQ_BIT5 |
00128 EQ_BIT4 )) << 10 ) |
00129 (( input & ( EQ_BIT21 | EQ_BIT20 | EQ_BIT19 | EQ_BIT18 |
00130 EQ_BIT17 )) >> 10 )),
00131 one, two, three );
00132 }
00133 static inline uint32_t deswizzle( const uint8_t one, const uint8_t two,
00134 const uint8_t three, const uint8_t four )
00135 { assert( 0 ); return 0; }
00136
00137 static inline uint32_t deswizzle( const uint8_t one, const uint8_t two,
00138 const uint8_t three )
00139 {
00140 const uint32_t input = one + (two<<8) + (three<<16);
00141 return (( input & ( EQ_BIT24 | EQ_BIT23 | EQ_BIT22 | EQ_BIT13 |
00142 EQ_BIT12 | EQ_BIT3 | EQ_BIT2 | EQ_BIT1 )) |
00143 (( input & ( EQ_BIT21 | EQ_BIT20 | EQ_BIT19 ))>>5 ) |
00144 (( input & ( EQ_BIT6 | EQ_BIT5 | EQ_BIT4 ))<<5 ) |
00145 (( input & ( EQ_BIT18 | EQ_BIT17 | EQ_BIT16 |
00146 EQ_BIT15 | EQ_BIT14 ))>>10 ) |
00147 (( input & ( EQ_BIT11 | EQ_BIT10 | EQ_BIT9 |
00148 EQ_BIT8 | EQ_BIT7 ))<<10 ));
00149 }
00150 };
00151
00152 }
00153
00154 void CompressorRLE4B::compress( const void* const inData,
00155 const eq_uint64_t nPixels, const bool useAlpha,
00156 const bool swizzle )
00157 {
00158 if( useAlpha )
00159 if( swizzle )
00160 _compress< uint32_t, uint8_t, SwizzleUInt32, UseAlpha >(
00161 inData, nPixels, useAlpha, swizzle, _results );
00162 else
00163 _compress< uint32_t, uint8_t, NoSwizzle, UseAlpha >(
00164 inData, nPixels, useAlpha, swizzle, _results );
00165 else
00166 if( swizzle )
00167 _compress< uint32_t, uint8_t, SwizzleUInt24, NoAlpha >(
00168 inData, nPixels, useAlpha, swizzle, _results );
00169 else
00170 _compress< uint32_t, uint8_t, NoSwizzle, NoAlpha >(
00171 inData, nPixels, useAlpha, swizzle, _results );
00172 }
00173
00174 void CompressorRLE4B::decompress( const void* const* inData,
00175 const eq_uint64_t* const inSizes,
00176 const unsigned numInputs,
00177 void* const outData,
00178 const eq_uint64_t nPixels,
00179 const bool useAlpha )
00180 {
00181 if( useAlpha )
00182 _decompress< uint32_t, uint8_t, NoSwizzle, UseAlpha >(
00183 inData, inSizes, numInputs, outData, nPixels );
00184 else
00185 _decompress< uint32_t, uint8_t, NoSwizzle, NoAlpha >(
00186 inData, inSizes, numInputs, outData, nPixels );
00187 }
00188
00189 void CompressorDiffRLE4B::decompress( const void* const* inData,
00190 const eq_uint64_t* const inSizes,
00191 const unsigned numInputs,
00192 void* const outData,
00193 const eq_uint64_t nPixels,
00194 const bool useAlpha )
00195 {
00196 if( useAlpha )
00197 _decompress< uint32_t, uint8_t, SwizzleUInt32, UseAlpha >(
00198 inData, inSizes, numInputs, outData, nPixels );
00199 else
00200 _decompress< uint32_t, uint8_t, SwizzleUInt24, NoAlpha >(
00201 inData, inSizes, numInputs, outData, nPixels );
00202 }
00203
00204 }
00205 }