LCOV - code coverage report
Current view: top level - lunchbox/compressor - compressorRLEYUV.cpp (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 3 96 3.1 %
Date: 2014-08-05 Functions: 6 22 27.3 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2010, Cedric Stalder <cedric.stalder@gmail.com>
       3             :  *               2010-2013, Stefan Eilemann <eile@eyescale.ch>
       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 "compressorRLEYUV.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 lunchbox
      29             : {
      30             : namespace plugin
      31             : {
      32             : namespace
      33             : {
      34          59 : REGISTER_ENGINE( CompressorRLEYUV, YUVA_50P, YUVA_50P, 1., 0.59, 1., true );
      35          59 : REGISTER_ENGINE( CompressorDiffRLEYUV, DIFF_YUVA_50P,   \
      36             :                  YUVA_50P, 1., 0.5, 1.1, true );
      37             : 
      38             : class NoSwizzle
      39             : {
      40             : public:
      41           0 :     static inline void swizzle( const uint32_t input, uint8_t& one,
      42             :                                 uint8_t& two, uint8_t& three, uint8_t& four )
      43             :         {
      44           0 :             one = input & 0xff;
      45           0 :             two = (input & 0xff00) >> 8;
      46           0 :             three = (input & 0xff0000) >> 16;
      47           0 :             four = (input & 0xff000000) >> 24;
      48           0 :         }
      49             : 
      50           0 :     static inline void swizzle( const uint32_t input, uint8_t& one,
      51             :                                 uint8_t& two, uint8_t& three )
      52             :         {
      53           0 :             one = input & 0xff;
      54           0 :             two = (input & 0xff00) >> 8;
      55           0 :             three = (input & 0xff0000) >> 16;
      56           0 :         }
      57             : 
      58           0 :     static inline uint32_t deswizzle( const uint8_t one, const uint8_t two,
      59             :                                       const uint8_t three, const uint8_t four )
      60             :     {
      61           0 :         return one + (two<<8) + (three<<16) + (four<<24);
      62             :     }
      63             : 
      64           0 :     static inline uint32_t deswizzle( const uint8_t one, const uint8_t two,
      65             :                                       const uint8_t three )
      66             :     {
      67           0 :         return one + (two<<8) + (three<<16);
      68             :     }
      69             : };
      70             : 
      71             : class SwizzleUInt32
      72             : {
      73             : public:
      74           0 :     static inline void swizzle( const uint32_t input, uint8_t& one,
      75             :                                 uint8_t& two, uint8_t& three, uint8_t& four )
      76             :     {
      77             :         NoSwizzle::swizzle(
      78           0 :             (( input &  ( LB_BIT32 | LB_BIT31 | LB_BIT22 | LB_BIT21 |
      79           0 :                           LB_BIT12 | LB_BIT11 | LB_BIT2 | LB_BIT1 ))        |
      80           0 :              (( input & ( LB_BIT8  | LB_BIT7 ))<<18 )                       |
      81           0 :              (( input & ( LB_BIT24 | LB_BIT23 | LB_BIT14 | LB_BIT13 ))<<6 ) |
      82           0 :              (( input & ( LB_BIT16 | LB_BIT15 | LB_BIT6  |
      83           0 :                           LB_BIT5  | LB_BIT4  | LB_BIT3 )) <<12 )           |
      84           0 :              (( input & ( LB_BIT28 | LB_BIT27 | LB_BIT26 | LB_BIT25 ))>>18) |
      85           0 :              (( input & ( LB_BIT18 | LB_BIT17 ))>>12)                       |
      86           0 :              (( input & ( LB_BIT30 | LB_BIT29 | LB_BIT20 | LB_BIT19 |
      87           0 :                           LB_BIT10 | LB_BIT9 ))>>6 )),
      88           0 :                                   one, two, three, four );
      89           0 :     }
      90           0 :     static inline void swizzle( const uint32_t, uint8_t&, uint8_t&, uint8_t& )
      91           0 :         { assert( 0 ); }
      92             : 
      93           0 :     static inline uint32_t deswizzle( const uint8_t one, const uint8_t two,
      94             :                                       const uint8_t three, const uint8_t four )
      95             :     {
      96           0 :         const uint32_t input = one + (two<<8) + (three<<16) + (four<<24);
      97           0 :         return ((  input & ( LB_BIT32 | LB_BIT31 | LB_BIT22 | LB_BIT21 |
      98           0 :                              LB_BIT11 | LB_BIT12 | LB_BIT2 | LB_BIT1 ))        |
      99           0 :                 (( input & ( LB_BIT26 | LB_BIT25 )) >>18 )                     |
     100           0 :                 (( input & ( LB_BIT30 | LB_BIT29 | LB_BIT20 | LB_BIT19 ))>>6 ) |
     101           0 :                 (( input & ( LB_BIT28 | LB_BIT27 | LB_BIT18 |
     102           0 :                              LB_BIT17 | LB_BIT16 |LB_BIT15 ))>>12 )            |
     103           0 :                 (( input & ( LB_BIT10 | LB_BIT9  | LB_BIT8  | LB_BIT7 ))<<18 ) |
     104           0 :                 (( input & ( LB_BIT6  | LB_BIT5 ))<<12 )                       |
     105           0 :                 (( input & ( LB_BIT24 | LB_BIT23 | LB_BIT14 |
     106           0 :                              LB_BIT13 | LB_BIT4  | LB_BIT3 ))<<6 ));
     107             :     }
     108             : 
     109           0 :     static inline uint32_t deswizzle( const uint8_t, const uint8_t,
     110             :                                       const uint8_t )
     111           0 :         { assert( 0 ); return 0; }
     112             : };
     113             : 
     114             : class SwizzleUInt24
     115             : {
     116             : public:
     117           0 :     static inline void swizzle( const uint32_t, uint8_t&, uint8_t&, uint8_t&,
     118           0 :                                 uint8_t& ) { assert( 0 ); }
     119             : 
     120           0 :     static inline void swizzle( const uint32_t input, uint8_t& one,
     121             :                                 uint8_t& two, uint8_t& three )
     122             :     {
     123             :         NoSwizzle::swizzle(
     124           0 :             (( input &  ( LB_BIT24 | LB_BIT23 | LB_BIT22 | LB_BIT13 |
     125           0 :                           LB_BIT12 | LB_BIT3  | LB_BIT2  | LB_BIT1 )) |
     126           0 :              (( input & ( LB_BIT16 | LB_BIT15 | LB_BIT14 )) << 5 )    |
     127           0 :              (( input & ( LB_BIT11 | LB_BIT10 | LB_BIT9  )) >> 5 )    |
     128           0 :              (( input & ( LB_BIT8  | LB_BIT7  | LB_BIT6  | LB_BIT5  |
     129           0 :                           LB_BIT4  )) << 10 )                         |
     130           0 :              (( input & ( LB_BIT21 | LB_BIT20 | LB_BIT19 | LB_BIT18 |
     131           0 :                           LB_BIT17 )) >> 10 )),
     132           0 :                                   one, two, three );
     133           0 :     }
     134           0 :     static inline uint32_t deswizzle( const uint8_t, const uint8_t,
     135             :                                       const uint8_t, const uint8_t )
     136           0 :         { assert( 0 ); return 0; }
     137             : 
     138           0 :     static inline uint32_t deswizzle( const uint8_t one, const uint8_t two,
     139             :                                       const uint8_t three )
     140             :     {
     141           0 :         const uint32_t input = one + (two<<8) + (three<<16);
     142           0 :         return ((  input & ( LB_BIT24 | LB_BIT23 | LB_BIT22 | LB_BIT13 |
     143           0 :                              LB_BIT12 | LB_BIT3  | LB_BIT2  | LB_BIT1 )) |
     144           0 :                 (( input & ( LB_BIT21 | LB_BIT20 | LB_BIT19 ))>>5 )      |
     145           0 :                 (( input & ( LB_BIT6  | LB_BIT5  | LB_BIT4 ))<<5 )       |
     146           0 :                 (( input & ( LB_BIT18 | LB_BIT17 | LB_BIT16 |
     147           0 :                              LB_BIT15 | LB_BIT14 ))>>10 )                |
     148           0 :                 (( input & ( LB_BIT11 | LB_BIT10 | LB_BIT9  |
     149           0 :                              LB_BIT8  | LB_BIT7 ))<<10 ));
     150             :     }
     151             : };
     152             : 
     153             : }
     154             : 
     155           0 : void CompressorRLEYUV::compress( const void* const inData,
     156             :                                  const eq_uint64_t nPixels,
     157             :                                  const bool useAlpha )
     158             : {
     159           0 :     if( useAlpha )
     160             :         _nResults = _compress< uint32_t, uint8_t, NoSwizzle,
     161           0 :                                UseAlpha >( inData, nPixels, _results );
     162             :     else
     163             :         _nResults = _compress< uint32_t, uint8_t, NoSwizzle,
     164           0 :                                NoAlpha >( inData, nPixels, _results );
     165           0 : }
     166             : 
     167           0 : void CompressorRLEYUV::decompress( const void* const* inData,
     168             :                                    const eq_uint64_t* const inSizes,
     169             :                                    const unsigned numInputs,
     170             :                                    void* const outData,
     171             :                                    eq_uint64_t* const outDims,
     172             :                                    const eq_uint64_t flags, void* const )
     173             : {
     174           0 :     const eq_uint64_t nPixels = ( flags & EQ_COMPRESSOR_DATA_1D) ?
     175           0 :                                     outDims[1] : outDims[1] * outDims[3];
     176           0 :     if( flags & EQ_COMPRESSOR_IGNORE_ALPHA )
     177             :         _decompress< uint32_t, uint8_t, NoSwizzle, NoAlpha >(
     178           0 :             inData, inSizes, numInputs, outData, nPixels );
     179             :     else
     180             :         _decompress< uint32_t, uint8_t, NoSwizzle, UseAlpha >(
     181           0 :             inData, inSizes, numInputs, outData, nPixels );
     182           0 : }
     183             : 
     184           0 : void CompressorDiffRLEYUV::compress( const void* const inData,
     185             :                                      const eq_uint64_t nPixels,
     186             :                                      const bool useAlpha )
     187             : {
     188           0 :     if( useAlpha )
     189             :         _nResults = _compress< uint32_t, uint8_t, SwizzleUInt32,
     190           0 :                                UseAlpha >( inData, nPixels, _results );
     191             :     else
     192             :         _nResults = _compress< uint32_t, uint8_t, SwizzleUInt24,
     193           0 :                                NoAlpha >( inData, nPixels, _results );
     194           0 : }
     195             : 
     196           0 : void CompressorDiffRLEYUV::decompress( const void* const* inData,
     197             :                                        const eq_uint64_t* const inSizes,
     198             :                                        const unsigned numInputs,
     199             :                                        void* const outData,
     200             :                                        eq_uint64_t* const outDims,
     201             :                                        const eq_uint64_t flags, void* const )
     202             : {
     203           0 :     const eq_uint64_t nPixels = ( flags & EQ_COMPRESSOR_DATA_1D) ?
     204           0 :                                     outDims[1] : outDims[1] * outDims[3];
     205           0 :     if( flags & EQ_COMPRESSOR_IGNORE_ALPHA )
     206             :         _decompress< uint32_t, uint8_t, SwizzleUInt24,
     207           0 :                      NoAlpha >( inData, inSizes, numInputs, outData, nPixels );
     208             :     else
     209             :         _decompress< uint32_t, uint8_t, SwizzleUInt32,
     210           0 :                      UseAlpha >( inData, inSizes, numInputs, outData, nPixels );
     211           0 : }
     212             : 
     213             : }
     214          87 : }

Generated by: LCOV version 1.10