compressorRLE4HF.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 "compressorRLE4HF.h"
00020 
00021 namespace
00022 {
00023 // NaN
00024 static const uint16_t _rleMarker = 0xffff; 
00025 }
00026 
00027 #include "compressorRLE.ipp"
00028 
00029 namespace eq
00030 {
00031 namespace plugin
00032 {
00033 
00034 namespace
00035 {
00036 class NoSwizzle
00037 {
00038 public:
00039     static inline void swizzle( const uint64_t input, uint16_t& one,
00040                                 uint16_t& two, uint16_t& three, uint16_t& four )
00041         {
00042             one   = input & 0xffffull;
00043             two   = (input & 0xffff0000ull) >> 16;
00044             three = (input & 0xffff00000000ull) >> 32;
00045             four  = (input & 0xffff000000000000ull) >> 48;
00046         }
00047 
00048     static inline void swizzle( const uint64_t input, uint16_t& one,
00049                                 uint16_t& two, uint16_t& three )
00050         {
00051             one   = input & 0xffffull;
00052             two   = (input & 0xffff0000ull) >> 16;
00053             three = (input & 0xffff00000000ull) >> 32;
00054         }
00055 
00056     static inline uint64_t deswizzle( const uint16_t one, const uint16_t two,
00057                                       const uint16_t three, const uint16_t four)
00058     {
00059         return 
00060             one +
00061             ( static_cast< uint64_t >( two ) << 16 ) +
00062             ( static_cast< uint64_t > ( three ) << 32) +
00063             ( static_cast< uint64_t > ( four ) << 48 );
00064     }
00065 
00066     static inline uint64_t deswizzle( const uint16_t one, const uint16_t two,
00067                                       const uint16_t three )
00068     {
00069         return 
00070             one +
00071             ( static_cast< uint64_t >( two ) << 16 ) +
00072             ( static_cast< uint64_t > ( three ) << 32);
00073     }
00074 };
00075 }
00076 
00077 void CompressorRLE4HF::compress( const void* const inData, 
00078                                  const eq_uint64_t nPixels, const bool useAlpha,
00079                                  const bool swizzle )
00080 {
00081     assert( !swizzle );
00082     if( useAlpha )
00083         _compress< uint64_t, uint16_t, NoSwizzle, UseAlpha >(
00084             inData, nPixels, useAlpha, swizzle, _results );
00085     else
00086         _compress< uint64_t, uint16_t, NoSwizzle, NoAlpha >(
00087             inData, nPixels, useAlpha, swizzle, _results );
00088 }
00089 
00090 void CompressorRLE4HF::decompress( const void* const* inData, 
00091                                    const eq_uint64_t* const inSizes,
00092                                    const unsigned nInputs, void* const outData, 
00093                                    const eq_uint64_t nPixels, 
00094                                    const bool useAlpha )
00095 {
00096     if( useAlpha )
00097         _decompress< uint64_t, uint16_t, NoSwizzle, UseAlpha >( 
00098             inData, inSizes, nInputs, outData, nPixels );
00099     else
00100         _decompress< uint64_t, uint16_t, NoSwizzle, NoAlpha >(
00101             inData, inSizes, nInputs, outData, nPixels );
00102 }
00103 
00104 }
00105 }
Generated on Mon Aug 10 18:58:32 2009 for Equalizer 0.9 by  doxygen 1.5.8