Line data Source code
1 :
2 : /* Copyright (c) 2016, Stefan Eilemann <eile@eyescale.ch>
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : #include "compressorZSTD.h"
19 :
20 : #include "zstd/lib/zstd.h"
21 :
22 : namespace pression
23 : {
24 : namespace plugin
25 : {
26 : namespace
27 : {
28 1 : static void _getInfo( EqCompressorInfo* const info )
29 : {
30 1 : info->version = EQ_COMPRESSOR_VERSION;
31 1 : info->capabilities = EQ_COMPRESSOR_DATA_1D | EQ_COMPRESSOR_DATA_2D;
32 1 : info->quality = 1.f;
33 1 : info->ratio = .47f;
34 1 : info->speed = .25f;
35 1 : info->name = EQ_COMPRESSOR_ZSTD_BYTE;
36 1 : info->tokenType = EQ_COMPRESSOR_DATATYPE_BYTE;
37 1 : }
38 :
39 1 : static bool _register()
40 : {
41 : Compressor::registerEngine(
42 2 : Compressor::Functions( EQ_COMPRESSOR_ZSTD_BYTE,
43 : _getInfo,
44 : CompressorZSTD::getNewCompressor,
45 : CompressorZSTD::getNewDecompressor,
46 1 : CompressorZSTD::decompress, 0 ));
47 1 : return true;
48 : }
49 :
50 1 : static const bool LB_UNUSED _initialized = _register();
51 : }
52 :
53 74 : void CompressorZSTD::compress( const void* const inData,
54 : const eq_uint64_t nPixels,
55 : const bool /*alpha*/ )
56 : {
57 74 : _nResults = 1;
58 74 : if( _results.size() < _nResults )
59 37 : _results.push_back( new pression::plugin::Compressor::Result );
60 74 : size_t size = ZSTD_compressBound( nPixels );
61 74 : _results[0]->reserve( size );
62 :
63 74 : size = ZSTD_compress( _results[0]->getData(), size, inData, nPixels, 2 );
64 74 : _results[0]->setSize( size );
65 74 : }
66 :
67 74 : void CompressorZSTD::decompress( const void* const* inData,
68 : const eq_uint64_t* const inSizes,
69 : const unsigned nInputs,
70 : void* const outData,
71 : eq_uint64_t* const outDims,
72 : const eq_uint64_t flags, void* const )
73 : {
74 74 : if( nInputs == 0 )
75 0 : return;
76 :
77 74 : const eq_uint64_t nPixels = ( flags & EQ_COMPRESSOR_DATA_1D) ?
78 74 : outDims[1] : outDims[1] * outDims[3];
79 74 : ZSTD_decompress( outData, nPixels, inData[0], inSizes[0] );
80 : }
81 :
82 : }
83 3 : }
|