LCOV - code coverage report
Current view: top level - pression/compressor - compressorRLE4B.cpp (source / functions) Hit Total Coverage
Test: Pression Lines: 12 103 11.7 %
Date: 2016-12-06 05:44:58 Functions: 24 40 60.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2009, Cedric Stalder <cedric.stalder@gmail.com>
       3             :  *               2009-2013, Stefan Eilemann <eile@equalizergraphics.com>
       4             :  *
       5             :  * This library is free software; you can redistribute it and/or modify it under
       6             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       7             :  * by the Free Software Foundation.
       8             :  *
       9             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      10             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      11             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      12             :  * details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public License
      15             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      16             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      17             :  */
      18             : 
      19             : #include "compressorRLE4B.h"
      20             : 
      21             : namespace
      22             : {
      23             : static const uint8_t _rleMarker = 0x42; // just a random number
      24             : }
      25             : 
      26             : #include "compressorRLE.ipp"
      27             : 
      28             : namespace pression
      29             : {
      30             : namespace plugin
      31             : {
      32             : 
      33             : namespace
      34             : {
      35           3 : REGISTER_ENGINE( CompressorRLE4B, RGBA, RGBA, 1., 0.59, 1., true );
      36           3 : REGISTER_ENGINE( CompressorRLE4B, BGRA, BGRA, 1., 0.59, 1., true );
      37           3 : REGISTER_ENGINE( CompressorRLE4B, RGBA_UINT_8_8_8_8_REV,    \
      38             :                  RGBA_UINT_8_8_8_8_REV, 1., 0.59, 1., true );
      39           3 : REGISTER_ENGINE( CompressorRLE4B, BGRA_UINT_8_8_8_8_REV,    \
      40             :                  BGRA_UINT_8_8_8_8_REV, 1., 0.59, 1., true );
      41           3 : REGISTER_ENGINE( CompressorRLE4B, RGB10_A2, RGB10_A2, 1., 0.59, 1., true );
      42           3 : REGISTER_ENGINE( CompressorRLE4B, BGR10_A2, BGR10_A2, 1., 0.59, 1., true );
      43           3 : REGISTER_ENGINE( CompressorRLE4B, DEPTH_UNSIGNED_INT, \
      44             :                  DEPTH_UNSIGNED_INT, 1., 0.59, 1., false );
      45             : 
      46           3 : REGISTER_ENGINE( CompressorDiffRLE4B, DIFF_RGBA, RGBA, 1., .5, 1.1, true );
      47           3 : REGISTER_ENGINE( CompressorDiffRLE4B, DIFF_BGRA, BGRA, 1., .5, 1.1, true );
      48           3 : REGISTER_ENGINE( CompressorDiffRLE4B, DIFF_RGBA_UINT_8_8_8_8_REV,   \
      49             :                  RGBA_UINT_8_8_8_8_REV, 1., .5, 1.1, true );
      50           3 : REGISTER_ENGINE( CompressorDiffRLE4B, DIFF_BGRA_UINT_8_8_8_8_REV, \
      51             :                  BGRA_UINT_8_8_8_8_REV, 1., .5, 1.1, true );
      52             : 
      53             : class NoSwizzle
      54             : {
      55             : public:
      56           0 :     static inline void swizzle( const uint32_t input, uint8_t& one,
      57             :                                 uint8_t& two, uint8_t& three, uint8_t& four )
      58             :         {
      59           0 :             one = input & 0xff;
      60           0 :             two = (input & 0xff00) >> 8;
      61           0 :             three = (input & 0xff0000) >> 16;
      62           0 :             four = (input & 0xff000000) >> 24;
      63           0 :         }
      64             : 
      65           0 :     static inline void swizzle( const uint32_t input, uint8_t& one,
      66             :                                 uint8_t& two, uint8_t& three )
      67             :         {
      68           0 :             one = input & 0xff;
      69           0 :             two = (input & 0xff00) >> 8;
      70           0 :             three = (input & 0xff0000) >> 16;
      71           0 :         }
      72             : 
      73           0 :     static inline uint32_t deswizzle( const uint8_t one, const uint8_t two,
      74             :                                       const uint8_t three, const uint8_t four )
      75             :     {
      76           0 :         return one + (two<<8) + (three<<16) + (four<<24);
      77             :     }
      78             : 
      79           0 :     static inline uint32_t deswizzle( const uint8_t one, const uint8_t two,
      80             :                                       const uint8_t three )
      81             :     {
      82           0 :         return one + (two<<8) + (three<<16);
      83             :     }
      84             : };
      85             : 
      86             : class SwizzleUInt32
      87             : {
      88             : public:
      89           0 :     static inline void swizzle( const uint32_t input, uint8_t& one,
      90             :                                 uint8_t& two, uint8_t& three, uint8_t& four )
      91             :     {
      92           0 :         NoSwizzle::swizzle(
      93           0 :             (( input &  ( LB_BIT32 | LB_BIT31 | LB_BIT22 | LB_BIT21 |
      94           0 :                           LB_BIT12 | LB_BIT11 | LB_BIT2 | LB_BIT1 ))        |
      95           0 :              (( input & ( LB_BIT8  | LB_BIT7 ))<<18 )                       |
      96           0 :              (( input & ( LB_BIT24 | LB_BIT23 | LB_BIT14 | LB_BIT13 ))<<6 ) |
      97             :              (( input & ( LB_BIT16 | LB_BIT15 | LB_BIT6  |
      98           0 :                           LB_BIT5  | LB_BIT4  | LB_BIT3 )) <<12 )           |
      99           0 :              (( input & ( LB_BIT28 | LB_BIT27 | LB_BIT26 | LB_BIT25 ))>>18) |
     100           0 :              (( input & ( LB_BIT18 | LB_BIT17 ))>>12)                       |
     101             :              (( input & ( LB_BIT30 | LB_BIT29 | LB_BIT20 | LB_BIT19 |
     102           0 :                           LB_BIT10 | LB_BIT9 ))>>6 )),
     103           0 :                                   one, two, three, four );
     104           0 :     }
     105           0 :     static inline void swizzle( const uint32_t, uint8_t&, uint8_t&, uint8_t& )
     106           0 :         { assert( 0 ); }
     107             : 
     108           0 :     static inline uint32_t deswizzle( const uint8_t one, const uint8_t two,
     109             :                                       const uint8_t three, const uint8_t four )
     110             :     {
     111           0 :         const uint32_t input = one + (two<<8) + (three<<16) + (four<<24);
     112           0 :         return ((  input & ( LB_BIT32 | LB_BIT31 | LB_BIT22 | LB_BIT21 |
     113           0 :                              LB_BIT11 | LB_BIT12 | LB_BIT2 | LB_BIT1 ))        |
     114           0 :                 (( input & ( LB_BIT26 | LB_BIT25 )) >>18 )                     |
     115           0 :                 (( input & ( LB_BIT30 | LB_BIT29 | LB_BIT20 | LB_BIT19 ))>>6 ) |
     116             :                 (( input & ( LB_BIT28 | LB_BIT27 | LB_BIT18 |
     117           0 :                              LB_BIT17 | LB_BIT16 |LB_BIT15 ))>>12 )            |
     118           0 :                 (( input & ( LB_BIT10 | LB_BIT9  | LB_BIT8  | LB_BIT7 ))<<18 ) |
     119           0 :                 (( input & ( LB_BIT6  | LB_BIT5 ))<<12 )                       |
     120             :                 (( input & ( LB_BIT24 | LB_BIT23 | LB_BIT14 |
     121           0 :                              LB_BIT13 | LB_BIT4  | LB_BIT3 ))<<6 ));
     122             :     }
     123             : 
     124           0 :     static inline uint32_t deswizzle( const uint8_t, const uint8_t,
     125             :                                       const uint8_t )
     126           0 :         { assert( 0 ); return 0; }
     127             : };
     128             : 
     129             : class SwizzleUInt24
     130             : {
     131             : public:
     132           0 :     static inline void swizzle( const uint32_t, uint8_t&, uint8_t&, uint8_t&,
     133           0 :                                 uint8_t& ) { assert( 0 ); }
     134             : 
     135           0 :     static inline void swizzle( const uint32_t input, uint8_t& one,
     136             :                                 uint8_t& two, uint8_t& three )
     137             :     {
     138           0 :         NoSwizzle::swizzle(
     139           0 :             (( input &  ( LB_BIT24 | LB_BIT23 | LB_BIT22 | LB_BIT13 |
     140           0 :                           LB_BIT12 | LB_BIT3  | LB_BIT2  | LB_BIT1 )) |
     141           0 :              (( input & ( LB_BIT16 | LB_BIT15 | LB_BIT14 )) << 5 )    |
     142           0 :              (( input & ( LB_BIT11 | LB_BIT10 | LB_BIT9  )) >> 5 )    |
     143             :              (( input & ( LB_BIT8  | LB_BIT7  | LB_BIT6  | LB_BIT5  |
     144           0 :                           LB_BIT4  )) << 10 )                         |
     145             :              (( input & ( LB_BIT21 | LB_BIT20 | LB_BIT19 | LB_BIT18 |
     146           0 :                           LB_BIT17 )) >> 10 )),
     147           0 :                                   one, two, three );
     148           0 :     }
     149           0 :     static inline uint32_t deswizzle( const uint8_t, const uint8_t,
     150             :                                       const uint8_t, const uint8_t )
     151           0 :         { assert( 0 ); return 0; }
     152             : 
     153           0 :     static inline uint32_t deswizzle( const uint8_t one, const uint8_t two,
     154             :                                       const uint8_t three )
     155             :     {
     156           0 :         const uint32_t input = one + (two<<8) + (three<<16);
     157           0 :         return ((  input & ( LB_BIT24 | LB_BIT23 | LB_BIT22 | LB_BIT13 |
     158           0 :                              LB_BIT12 | LB_BIT3  | LB_BIT2  | LB_BIT1 )) |
     159           0 :                 (( input & ( LB_BIT21 | LB_BIT20 | LB_BIT19 ))>>5 )      |
     160           0 :                 (( input & ( LB_BIT6  | LB_BIT5  | LB_BIT4 ))<<5 )       |
     161             :                 (( input & ( LB_BIT18 | LB_BIT17 | LB_BIT16 |
     162           0 :                              LB_BIT15 | LB_BIT14 ))>>10 )                |
     163             :                 (( input & ( LB_BIT11 | LB_BIT10 | LB_BIT9  |
     164           0 :                              LB_BIT8  | LB_BIT7 ))<<10 ));
     165             :     }
     166             : };
     167             : 
     168             : }
     169             : 
     170           0 : void CompressorRLE4B::compress( const void* const inData,
     171             :                                 const eq_uint64_t nPixels,
     172             :                                 const bool useAlpha )
     173             : {
     174           0 :     if( useAlpha )
     175           0 :         _nResults = _compress< uint32_t, uint8_t, NoSwizzle,
     176           0 :                                UseAlpha >( inData, nPixels, _results );
     177             :     else
     178           0 :         _nResults = _compress< uint32_t, uint8_t, NoSwizzle,
     179           0 :                                NoAlpha >( inData, nPixels, _results );
     180           0 : }
     181             : 
     182           0 : void CompressorRLE4B::decompress( const void* const* inData,
     183             :                                   const eq_uint64_t* const inSizes,
     184             :                                   const unsigned numInputs,
     185             :                                   void* const outData,
     186             :                                   eq_uint64_t* const outDims,
     187             :                                   const eq_uint64_t flags, void* const )
     188             : {
     189           0 :     const eq_uint64_t nPixels = ( flags & EQ_COMPRESSOR_DATA_1D) ?
     190           0 :                                     outDims[1] : outDims[1] * outDims[3];
     191           0 :     if( flags & EQ_COMPRESSOR_IGNORE_ALPHA )
     192             :         _decompress< uint32_t, uint8_t, NoSwizzle,
     193           0 :                      NoAlpha >( inData, inSizes, numInputs, outData, nPixels );
     194             :     else
     195             :         _decompress< uint32_t, uint8_t, NoSwizzle,
     196           0 :                      UseAlpha >( inData, inSizes, numInputs, outData, nPixels );
     197           0 : }
     198             : 
     199           0 : void CompressorDiffRLE4B::compress( const void* const inData,
     200             :                                     const eq_uint64_t nPixels,
     201             :                                     const bool useAlpha )
     202             : {
     203           0 :     if( useAlpha )
     204           0 :         _nResults = _compress< uint32_t, uint8_t, SwizzleUInt32,
     205           0 :                                UseAlpha >( inData, nPixels, _results );
     206             :     else
     207           0 :         _nResults = _compress< uint32_t, uint8_t, SwizzleUInt24,
     208           0 :                                NoAlpha >( inData, nPixels, _results );
     209           0 : }
     210             : 
     211           0 : void CompressorDiffRLE4B::decompress( const void* const* inData,
     212             :                                       const eq_uint64_t* const inSizes,
     213             :                                       const unsigned numInputs,
     214             :                                       void* const outData,
     215             :                                       eq_uint64_t* const outDims,
     216             :                                       const eq_uint64_t flags, void* const )
     217             : {
     218           0 :     const eq_uint64_t nPixels = ( flags & EQ_COMPRESSOR_DATA_1D) ?
     219           0 :                                     outDims[1] : outDims[1] * outDims[3];
     220           0 :     if( flags & EQ_COMPRESSOR_IGNORE_ALPHA )
     221             :         _decompress< uint32_t, uint8_t, SwizzleUInt24,
     222           0 :                      NoAlpha >( inData, inSizes, numInputs, outData, nPixels );
     223             :     else
     224             :         _decompress< uint32_t, uint8_t, SwizzleUInt32,
     225           0 :                      UseAlpha >( inData, inSizes, numInputs, outData, nPixels );
     226           0 : }
     227             : 
     228             : }
     229           3 : }

Generated by: LCOV version 1.11