Line data Source code
1 :
2 : /* Copyright (c) 2009-2010, Sarah Amsellem <sarah.amsellem@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 "compressorRLE565.h"
20 :
21 : namespace
22 : {
23 : static const uint8_t _rleMarker = 0x17; // just a random number
24 : }
25 :
26 : #include "compressorRLE.ipp"
27 :
28 : namespace pression
29 : {
30 : namespace plugin
31 : {
32 : namespace
33 : {
34 3 : REGISTER_ENGINE( CompressorRLE565, DIFF_565_RGBA, RGBA, .7, .1, 1.1, true );
35 3 : REGISTER_ENGINE( CompressorRLE565, DIFF_565_BGRA, BGRA, .7, .1, 1.1, true );
36 3 : REGISTER_ENGINE( CompressorRLE565, DIFF_565_RGBA_UINT_8_8_8_8_REV, \
37 : RGBA_UINT_8_8_8_8_REV, .7, .1, 1.1, true );
38 3 : REGISTER_ENGINE( CompressorRLE565, DIFF_565_BGRA_UINT_8_8_8_8_REV, \
39 : BGRA_UINT_8_8_8_8_REV, .7, .1, 1.1, true );
40 :
41 : class NoSwizzle
42 : {
43 : public:
44 0 : static inline void swizzle( const uint32_t input, uint8_t& one,
45 : uint8_t& two, uint8_t& three, uint8_t& four )
46 : {
47 0 : one = input & 0xff;
48 0 : two = ( input & 0xff00 ) >> 8;
49 0 : three = ( input & 0xff0000 ) >> 16;
50 0 : four = ( input & 0xff000000 ) >> 24;
51 0 : }
52 :
53 0 : static inline void swizzle( const uint32_t input, uint8_t& one,
54 : uint8_t& two, uint8_t& three )
55 : {
56 0 : one = input & 0xff;
57 0 : two = ( input & 0xff00 ) >> 8;
58 0 : three = ( input & 0xff0000 ) >> 16;
59 0 : }
60 : };
61 :
62 : class SwizzleUInt32
63 : {
64 : public:
65 0 : static inline void swizzle( const uint32_t input, uint8_t& one,
66 : uint8_t& two, uint8_t& three, uint8_t& four )
67 : {
68 0 : NoSwizzle::swizzle(
69 0 : ((( input & ( LB_BIT6 | LB_BIT5 | LB_BIT4 )) >> 3 ) |
70 0 : (( input & ( LB_BIT14 | LB_BIT13 | LB_BIT12 )) >> 8 ) |
71 0 : (( input & ( LB_BIT8 | LB_BIT7 )) << 5 ) |
72 : (( input & ( LB_BIT24 | LB_BIT23 | LB_BIT22 |
73 0 : LB_BIT21 | LB_BIT20 )) >> 13 ) |
74 0 : (( input & ( LB_BIT16 | LB_BIT15 )) >> 1 ) |
75 0 : (( input & LB_BIT32 ) >> 16 )),
76 0 : one, two, three, four );
77 0 : }
78 :
79 0 : static inline void swizzle( const uint32_t, uint8_t&, uint8_t&, uint8_t& )
80 0 : { assert( 0 ); }
81 :
82 0 : static inline uint32_t deswizzle( const uint8_t one, const uint8_t two,
83 : const uint8_t three, const uint8_t four )
84 : {
85 0 : const uint32_t input = one + ( two << 8 ) + ( three << 16 ) +
86 0 : ( four << 24 );
87 0 : return (((( input & ( LB_BIT3 | LB_BIT2 | LB_BIT1 )) << 3 ) |
88 0 : (( input & ( LB_BIT6 | LB_BIT5 | LB_BIT4 )) << 8 ) |
89 0 : (( input & ( LB_BIT13 | LB_BIT12 )) >> 5 ) |
90 : (( input & ( LB_BIT11 | LB_BIT10 | LB_BIT9 |
91 0 : LB_BIT8 | LB_BIT7 )) << 13 ) |
92 0 : (( input & ( LB_BIT15 | LB_BIT14 )) << 1 ) |
93 0 : (( input & LB_BIT16 ) << 16 )))
94 0 : | 0x3f040404;
95 : }
96 :
97 0 : static inline uint32_t deswizzle( const uint8_t, const uint8_t,
98 0 : const uint8_t ) { assert( 0 ); return 0; }
99 : };
100 :
101 : class SwizzleUInt24
102 : {
103 : public:
104 0 : static inline void swizzle( const uint32_t, uint8_t&, uint8_t&, uint8_t&,
105 0 : uint8_t& ) { assert( 0 ); }
106 :
107 0 : static inline void swizzle( const uint32_t input, uint8_t& one,
108 : uint8_t& two, uint8_t& three )
109 : {
110 0 : NoSwizzle::swizzle(
111 0 : ((( input & ( LB_BIT6 | LB_BIT5 | LB_BIT4 )) >> 3 ) |
112 0 : (( input & ( LB_BIT13 | LB_BIT12 | LB_BIT11 )) >> 7 ) |
113 0 : (( input & ( LB_BIT8 | LB_BIT7 )) << 5 ) |
114 : (( input & ( LB_BIT24 | LB_BIT23 | LB_BIT22 |
115 0 : LB_BIT21 | LB_BIT20 )) >> 13 ) |
116 0 : ( input & ( LB_BIT16 | LB_BIT15 | LB_BIT14 ))),
117 0 : one, two, three );
118 0 : }
119 :
120 0 : static inline uint32_t deswizzle( const uint8_t, const uint8_t,
121 : const uint8_t, const uint8_t )
122 0 : { assert( 0 ); return 0; }
123 :
124 0 : static inline uint32_t deswizzle( const uint8_t one, const uint8_t two,
125 : const uint8_t three )
126 : {
127 0 : const uint32_t input = one + ( two << 8 ) + ( three << 16 );
128 0 : return (((( input & ( LB_BIT3 | LB_BIT2 | LB_BIT1 )) << 3 ) |
129 0 : (( input & ( LB_BIT6 | LB_BIT5 | LB_BIT4 )) << 7 ) |
130 0 : (( input & ( LB_BIT13 | LB_BIT12 )) >> 5 ) |
131 : (( input & ( LB_BIT11 | LB_BIT10 | LB_BIT9 |
132 0 : LB_BIT8 | LB_BIT7 )) << 13 ) |
133 0 : ( input & ( LB_BIT16 | LB_BIT15 | LB_BIT14 )))
134 0 : & 0xf8fcf8 )
135 0 : | 0x020202;
136 : }
137 : };
138 :
139 : }
140 :
141 0 : void CompressorRLE565::compress( const void* const inData,
142 : const eq_uint64_t nPixels,
143 : const bool useAlpha )
144 : {
145 0 : if( useAlpha )
146 0 : _nResults = _compress< uint32_t, uint8_t, SwizzleUInt32, UseAlpha >(
147 : inData, nPixels, _results );
148 : else
149 0 : _nResults = _compress< uint32_t, uint8_t, SwizzleUInt24, NoAlpha >(
150 : inData, nPixels, _results );
151 0 : }
152 :
153 0 : void CompressorRLE565::decompress( const void* const* inData,
154 : const eq_uint64_t* const inSizes,
155 : const unsigned numInputs,
156 : void* const outData,
157 : eq_uint64_t* const outDims,
158 : const eq_uint64_t flags, void* const )
159 : {
160 0 : const eq_uint64_t nPixels = ( flags & EQ_COMPRESSOR_DATA_1D) ?
161 0 : outDims[1] : outDims[1] * outDims[3];
162 0 : if( flags & EQ_COMPRESSOR_IGNORE_ALPHA )
163 : _decompress< uint32_t, uint8_t, SwizzleUInt24,
164 0 : NoAlpha >( inData, inSizes, numInputs, outData, nPixels );
165 : else
166 : _decompress< uint32_t, uint8_t, SwizzleUInt32,
167 0 : UseAlpha >( inData, inSizes, numInputs, outData, nPixels );
168 0 : }
169 :
170 : }
171 3 : }
|