Line data Source code
1 :
2 : /* Copyright (c) 2010, Cedric Stalder <cedric.stalder@gmail.com>
3 : * 2010-2014, Stefan Eilemann <eile@eyescale.ch>
4 : *
5 : * This file is part of Lunchbox <https://github.com/Eyescale/Lunchbox>
6 : *
7 : * This library is free software; you can redistribute it and/or modify it under
8 : * the terms of the GNU Lesser General Public License version 2.1 as published
9 : * by the Free Software Foundation.
10 : *
11 : * This library is distributed in the hope that it will be useful, but WITHOUT
12 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 : * details.
15 : *
16 : * You should have received a copy of the GNU Lesser General Public License
17 : * along with this library; if not, write to the Free Software Foundation, Inc.,
18 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 : */
20 :
21 : #ifndef LUNCHBOX_COMPRESSOR_H
22 : #define LUNCHBOX_COMPRESSOR_H
23 :
24 : #include <lunchbox/api.h>
25 : #include <lunchbox/types.h>
26 : #include <lunchbox/thread.h> // thread-safety macros
27 :
28 : namespace lunchbox
29 : {
30 : namespace detail { class Compressor; }
31 :
32 : /**
33 : * A C++ class to handle one compressor plugin instance.
34 : *
35 : * Example: @include tests/compressor.cpp
36 : */
37 : class Compressor : public boost::noncopyable
38 : {
39 : typedef detail::Compressor* const Compressor::*bool_t;
40 :
41 : public:
42 : /** Construct a new, invalid compressor instance. @version 1.7.1 */
43 : LUNCHBOX_API Compressor();
44 :
45 : /**
46 : * Construct a new, named compressor instance.
47 : *
48 : * @param from the plugin registry
49 : * @param name the name of the compressor
50 : * @version 1.7.1
51 : */
52 : LUNCHBOX_API Compressor( PluginRegistry& from, const uint32_t name );
53 :
54 : /** Destruct the compressor. @version 1.7.1 */
55 : LUNCHBOX_API virtual ~Compressor();
56 :
57 : /** @return true if the instance is usable. @version 1.7.1 */
58 : LUNCHBOX_API bool isGood() const;
59 :
60 : /**
61 : * @return true if the instance is usable, false otherwise.
62 : * @version 1.9.1
63 : */
64 : operator bool_t() const { return isGood() ? &Compressor::impl_ : 0; }
65 :
66 : /** @return true if the instance is not usable. @version 1.9.1 */
67 153 : bool operator ! () const { return !isGood(); }
68 :
69 : /**
70 : * @return true if the instance is usable for the given name.
71 : * @version 1.7.1
72 : */
73 : LUNCHBOX_API bool uses( const uint32_t name ) const;
74 :
75 : /** @return the information about the allocated instance. @version 1.7.1 */
76 : LUNCHBOX_API const EqCompressorInfo& getInfo() const;
77 :
78 : /**
79 : * Find the best compressor in all plugins for the given parameters.
80 : *
81 : * This convenience method searches all compressors in all plugins to
82 : * find the compressor which matches best the given parameters.
83 : *
84 : * @param registry the plugin registry to choose from.
85 : * @param tokenType the structure of the data to compress.
86 : * @param minQuality minimal quality of the compressed data, with 0 = no
87 : * quality and 1 = full quality, no loss.
88 : * @param ignoreMSE the most-significant element of a four-element token can
89 : * be ignored, typically the alpha channel of an image.
90 : * @return the name of the chosen compressor.
91 : * @version 1.7.1
92 : */
93 : static LUNCHBOX_API uint32_t choose( const PluginRegistry& registry,
94 : const uint32_t tokenType,
95 : const float minQuality,
96 : const bool ignoreMSE );
97 :
98 : /**
99 : * Set up a new, named compressor instance.
100 : *
101 : * @param from the plugin registry.
102 : * @param name the name of the compressor.
103 : * @return true on success, false otherwise.
104 : * @version 1.7.1
105 : */
106 : LUNCHBOX_API bool setup( PluginRegistry& from, const uint32_t name );
107 :
108 : /**
109 : * Set up a new, auto-selected compressor instance.
110 : * @sa choose() for parameters.
111 : * @version 1.7.1
112 : */
113 : LUNCHBOX_API bool setup( PluginRegistry& registry, const uint32_t tokenType,
114 : const float minQuality, const bool ignoreMSE );
115 :
116 : /** Reallocate the current instance. @version 1.7.1 */
117 : LUNCHBOX_API bool realloc();
118 :
119 : /** Reset to EQ_COMPRESSOR_NONE. @version 1.7.1 */
120 : LUNCHBOX_API void clear();
121 :
122 : /**
123 : * Compress one-dimensional data.
124 : *
125 : * @param in the pointer to the input data.
126 : * @param inDims the dimensions of the input data
127 : * @version 1.7.1
128 : */
129 : LUNCHBOX_API void compress( void* const in, const uint64_t inDims[2] );
130 :
131 : /**
132 : * Compress two-dimensional data.
133 : *
134 : * @param in the pointer to the input data.
135 : * @param pvp the dimensions of the input data
136 : * @param flags capability flags for the compression
137 : * @version 1.7.1
138 : */
139 : LUNCHBOX_API void compress( void* const in, const uint64_t pvp[4],
140 : const uint64_t flags );
141 :
142 : /** @deprecated use new getResult()
143 : * @return the number of compressed chunks of the last compression.
144 : * @version 1.7.1
145 : */
146 : LUNCHBOX_API unsigned getNumResults() const LB_DEPRECATED;
147 :
148 : /**
149 : * @return the result of the last compression.
150 : * @version 1.9.1
151 : */
152 : LUNCHBOX_API CompressorResult getResult() const;
153 :
154 : /** @deprecated use new getResult() */
155 : LUNCHBOX_API void getResult( const unsigned i, void** const out,
156 : uint64_t* const outSize ) const LB_DEPRECATED;
157 :
158 : private:
159 : detail::Compressor* const impl_;
160 306 : LB_TS_VAR( _thread );
161 : };
162 : }
163 : #endif // LUNCHBOX_COMPRESSOR_H
|