compressorRLE4B.cpp

00001 
00002 /* Copyright (c) 2009, Cedric Stalder <cedric.stalder@gmail.com> 
00003  *               2009, Stefan Eilemann <eile@equalizergraphics.com>
00004  *
00005  * This library is free software; you can redistribute it and/or modify it under
00006  * the terms of the GNU Lesser General Public License version 2.1 as published
00007  * by the Free Software Foundation.
00008  *  
00009  * This library is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00012  * details.
00013  * 
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this library; if not, write to the Free Software Foundation, Inc.,
00016  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00017  */
00018 
00019 #include "compressorRLE4B.h"
00020 
00021 namespace
00022 {
00023 static const uint8_t _rleMarker = 0x42; // just a random number
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 }
Generated on Mon Aug 10 18:58:32 2009 for Equalizer 0.9 by  doxygen 1.5.8