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 "compressorRLE4HF.h"
20 :
21 : namespace
22 : {
23 : // NaN
24 : static const uint16_t _rleMarker = 0xffff;
25 : }
26 :
27 : #include "compressorRLE.ipp"
28 :
29 : namespace lunchbox
30 : {
31 : namespace plugin
32 : {
33 : namespace
34 : {
35 59 : REGISTER_ENGINE( CompressorRLE4HF, RGBA16F, RGBA16F, 1., 0.7, 1., true );
36 59 : REGISTER_ENGINE( CompressorRLE4HF, BGRA16F, BGRA16F, 1., 0.7, 1., true );
37 59 : REGISTER_ENGINE( CompressorDiffRLE4HF, DIFF_RGBA16F, \
38 : RGBA16F, 1., 0.9, 1., true );
39 59 : REGISTER_ENGINE( CompressorDiffRLE4HF, DIFF_BGRA16F, \
40 : BGRA16F, 1., 0.9, 1., true );
41 :
42 : class NoSwizzle
43 : {
44 : public:
45 0 : static inline void swizzle( const uint64_t input, uint16_t& one,
46 : uint16_t& two, uint16_t& three, uint16_t& four )
47 : {
48 0 : one = input & 0xffffull;
49 0 : two = (input & 0xffff0000ull) >> 16;
50 0 : three = (input & 0xffff00000000ull) >> 32;
51 0 : four = (input & 0xffff000000000000ull) >> 48;
52 0 : }
53 :
54 0 : static inline void swizzle( const uint64_t input, uint16_t& one,
55 : uint16_t& two, uint16_t& three )
56 : {
57 0 : one = input & 0xffffull;
58 0 : two = (input & 0xffff0000ull) >> 16;
59 0 : three = (input & 0xffff00000000ull) >> 32;
60 0 : }
61 :
62 0 : static inline uint64_t deswizzle( const uint16_t one, const uint16_t two,
63 : const uint16_t three, const uint16_t four)
64 : {
65 : return
66 0 : one +
67 0 : ( static_cast< uint64_t >( two ) << 16 ) +
68 0 : ( static_cast< uint64_t > ( three ) << 32) +
69 0 : ( static_cast< uint64_t > ( four ) << 48 );
70 : }
71 :
72 0 : static inline uint64_t deswizzle( const uint16_t one, const uint16_t two,
73 : const uint16_t three )
74 : {
75 : return
76 0 : one +
77 0 : ( static_cast< uint64_t >( two ) << 16 ) +
78 0 : ( static_cast< uint64_t > ( three ) << 32);
79 : }
80 : };
81 :
82 : class Swizzle
83 : {
84 : public:
85 0 : static inline void swizzle( const uint64_t input, uint16_t& one,
86 : uint16_t& two, uint16_t& three, uint16_t& four )
87 : {
88 : NoSwizzle::swizzle(
89 0 : ( input & 0xffc0000007c0001full ) |
90 0 : (( input & 0x3f0000ull) >> 11 ) |
91 0 : (( input & 0x7ff00000000ull) >> 21 ) |
92 0 : (( input & 0xc0003fe0ull) << 22 ) |
93 0 : (( input & 0x38000000ull) << 9 ) |
94 0 : (( input & 0x3f000000000000ull) >> 9 ) |
95 0 : (( input & 0xf80000000000ull) << 2 ) |
96 0 : (( input & 0xc000ull) << 36 ) ,one, two, three, four );
97 0 : }
98 :
99 0 : static inline void swizzle( const uint64_t input, uint16_t& one,
100 : uint16_t& two, uint16_t& three )
101 : {
102 : NoSwizzle::swizzle(
103 0 : ( input & 0xc073070c380ull )|
104 0 : (( input & 0x3c000000000ull ) >> 38 ) | // one
105 0 : (( input & 0x3800000ull ) >> 19 ) |
106 0 : (( input & 0xc00000000000ull ) >> 36 ) |
107 0 : (( input & 0x3000c0000000ull ) >> 18 )|
108 :
109 0 : (( input & 0x78ull ) << 13 )| //two
110 0 : (( input & 0x3800000000ull ) >> 12 )|
111 :
112 0 : (( input & 0xc00ull ) << 36 )| //three
113 0 : (( input & 0x7ull ) << 39 )|
114 0 : (( input & 0xc003000ull ) << 18 )|
115 0 : (( input & 0xf0000ull ) << 19 ),one, two, three);
116 0 : }
117 :
118 0 : static inline uint64_t deswizzle( const uint16_t one, const uint16_t two,
119 : const uint16_t three, const uint16_t four)
120 : {
121 0 : uint64_t output = NoSwizzle::deswizzle( one, two, three, four );
122 :
123 0 : return (( output & 0xffc0000007c0001full ) |
124 0 : (( output & 0x7e0ull ) << 11 ) |
125 0 : (( output & 0x3ff800ull ) << 21 ) |
126 0 : (( output & 0x30000ff8000000ull ) >> 22 ) |
127 0 : (( output & 0x7000000000ull) >> 9 ) |
128 0 : (( output & 0x1f8000000000ull ) << 9 ) |
129 0 : (( output & 0x3e00000000000ull ) >> 2 ) |
130 0 : (( output & 0xc000000000000ull ) >> 36 ) );
131 :
132 :
133 : }
134 :
135 0 : static inline uint64_t deswizzle( const uint16_t one, const uint16_t two,
136 : const uint16_t three )
137 : {
138 0 : uint64_t output = NoSwizzle::deswizzle( one, two, three );
139 0 : return ( output & 0xc073070c380ull ) |
140 0 : (( output & 0xfull ) << 38 ) | // one
141 0 : (( output & 0x70ull ) << 19 ) |
142 0 : (( output & 0xc00ull ) << 36 ) |
143 0 : (( output & 0xc003000ull ) << 18 )|
144 :
145 0 : (( output & 0xf0000ull ) >> 13 )| //two
146 0 : (( output & 0x3800000ull ) << 12 )|
147 :
148 0 : (( output & 0xc00000000000ull ) >> 36 )| //three
149 0 : (( output & 0x38000000000ull ) >> 39 )|
150 0 : (( output & 0x3000c0000000ull ) >> 18 )|
151 0 : (( output & 0x7800000000ull ) >> 19 );
152 : }
153 : };
154 : }
155 :
156 0 : void CompressorRLE4HF::compress( const void* const inData,
157 : const eq_uint64_t nPixels,
158 : const bool useAlpha )
159 : {
160 0 : if( useAlpha )
161 : _nResults = _compress< uint64_t, uint16_t, NoSwizzle,
162 0 : UseAlpha >( inData, nPixels, _results );
163 : else
164 : _nResults = _compress< uint64_t, uint16_t, NoSwizzle,
165 0 : NoAlpha >( inData, nPixels, _results );
166 0 : }
167 :
168 0 : void CompressorRLE4HF::decompress( const void* const* inData,
169 : const eq_uint64_t* const inSizes,
170 : const unsigned nInputs, 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< uint64_t, uint16_t, NoSwizzle,
178 0 : NoAlpha >( inData, inSizes, nInputs, outData, nPixels );
179 : else
180 : _decompress< uint64_t, uint16_t, NoSwizzle,
181 0 : UseAlpha >( inData, inSizes, nInputs, outData, nPixels );
182 0 : }
183 :
184 :
185 0 : void CompressorDiffRLE4HF::compress( const void* const inData,
186 : const eq_uint64_t nPixels,
187 : const bool useAlpha )
188 : {
189 0 : if( useAlpha )
190 : _nResults = _compress< uint64_t, uint16_t, Swizzle,
191 0 : UseAlpha >( inData, nPixels, _results );
192 : else
193 : _nResults = _compress< uint64_t, uint16_t, Swizzle,
194 0 : NoAlpha >( inData, nPixels, _results );
195 0 : }
196 :
197 0 : void CompressorDiffRLE4HF::decompress( const void* const* inData,
198 : const eq_uint64_t* const inSizes,
199 : const unsigned nInputs,
200 : void* const outData,
201 : eq_uint64_t* const outDims,
202 : const eq_uint64_t flags, void* const )
203 : {
204 0 : const eq_uint64_t nPixels = ( flags & EQ_COMPRESSOR_DATA_1D) ?
205 0 : outDims[1] : outDims[1] * outDims[3];
206 0 : if( flags & EQ_COMPRESSOR_IGNORE_ALPHA )
207 : _decompress< uint64_t, uint16_t, Swizzle,
208 0 : NoAlpha >( inData, inSizes, nInputs, outData, nPixels );
209 : else
210 : _decompress< uint64_t, uint16_t, Swizzle,
211 0 : UseAlpha >( inData, inSizes, nInputs, outData, nPixels );
212 0 : }
213 :
214 : }
215 87 : }
|