Squash  0.7.0
codec.h
1 /* Copyright (c) 2013-2015 The Squash Authors
2  *
3  * Permission is hereby granted, free of charge, to any person
4  * obtaining a copy of this software and associated documentation
5  * files (the "Software"), to deal in the Software without
6  * restriction, including without limitation the rights to use, copy,
7  * modify, merge, publish, distribute, sublicense, and/or sell copies
8  * of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be
12  * included in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  *
23  * Authors:
24  * Evan Nemerson <evan@nemerson.com>
25  */
26 
27 #ifndef SQUASH_CODEC_H
28 #define SQUASH_CODEC_H
29 
30 #if !defined (SQUASH_H_INSIDE) && !defined (SQUASH_COMPILATION)
31 #error "Only <squash/squash.h> can be included directly."
32 #endif
33 
34 SQUASH_BEGIN_DECLS
35 
36 typedef enum {
40 
45 
46  SQUASH_CODEC_INFO_MASK = 0xffffffff
48 
49 #define SQUASH_CODEC_INFO_INVALID ((SquashCodecInfo) 0)
50 
53 
54  const SquashOptionInfo* options;
55 
56  /* Streams */
57  SquashStream* (* create_stream) (SquashCodec* codec, SquashStreamType stream_type, SquashOptions* options);
58  SquashStatus (* process_stream) (SquashStream* stream, SquashOperation operation);
59 
60  /* Buffers */
61  SquashStatus (* decompress_buffer) (SquashCodec* codec,
62  size_t* decompressed_length,
63  uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)],
64  size_t compressed_length,
65  const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)],
66  SquashOptions* options);
67  SquashStatus (* compress_buffer) (SquashCodec* codec,
68  size_t* compressed_length,
69  uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)],
70  size_t uncompressed_length,
71  const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)],
72  SquashOptions* options);
73  SquashStatus (* compress_buffer_unsafe) (SquashCodec* codec,
74  size_t* compressed_length,
75  uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)],
76  size_t uncompressed_length,
77  const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)],
78  SquashOptions* options);
79 
80  /* Codecs */
81  size_t (* get_uncompressed_size) (SquashCodec* codec,
82  size_t compressed_length,
83  const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)]);
84  size_t (* get_max_compressed_size) (SquashCodec* codec, size_t uncompressed_length);
85 
86  /* Reserved */
87  void (* _reserved1) (void);
88  void (* _reserved2) (void);
89  void (* _reserved3) (void);
90  void (* _reserved4) (void);
91  void (* _reserved5) (void);
92  void (* _reserved6) (void);
93  void (* _reserved7) (void);
94  void (* _reserved8) (void);
95 };
96 
97 typedef void (*SquashCodecForeachFunc) (SquashCodec* codec, void* data);
98 
99 SQUASH_API SquashStatus squash_codec_init (SquashCodec* codec);
100 SQUASH_API const char* squash_codec_get_name (SquashCodec* codec);
101 SQUASH_API unsigned int squash_codec_get_priority (SquashCodec* codec);
102 SQUASH_API SquashPlugin* squash_codec_get_plugin (SquashCodec* codec);
103 SQUASH_API const char* squash_codec_get_extension (SquashCodec* codec);
104 
105 SQUASH_API size_t squash_codec_get_uncompressed_size (SquashCodec* codec,
106  size_t compressed_length,
107  const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)]);
108 SQUASH_API size_t squash_codec_get_max_compressed_size (SquashCodec* codec, size_t uncompressed_length);
109 
110 SQUASH_API SquashStream* squash_codec_create_stream (SquashCodec* codec, SquashStreamType stream_type, ...);
111 SQUASH_API SquashStream* squash_codec_create_stream_with_options (SquashCodec* codec, SquashStreamType stream_type, SquashOptions* options);
112 
113 SQUASH_API SquashStatus squash_codec_compress (SquashCodec* codec,
114  size_t* compressed_length,
115  uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)],
116  size_t uncompressed_length,
117  const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)],
118  ...);
119 SQUASH_API SquashStatus squash_codec_compress_with_options (SquashCodec* codec,
120  size_t* compressed_length,
121  uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)],
122  size_t uncompressed_length,
123  const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)],
124  SquashOptions* options);
125 SQUASH_API SquashStatus squash_codec_decompress (SquashCodec* codec,
126  size_t* decompressed_length,
127  uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)],
128  size_t compressed_length,
129  const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)], ...);
130 SQUASH_API SquashStatus squash_codec_decompress_with_options (SquashCodec* codec,
131  size_t* decompressed_length,
132  uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)],
133  size_t compressed_length,
134  const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)],
135  SquashOptions* options);
136 SQUASH_API SquashCodecInfo squash_codec_get_info (SquashCodec* codec);
137 SQUASH_API const SquashOptionInfo* squash_codec_get_option_info (SquashCodec* codec);
138 
139 SQUASH_API const char* squash_codec_get_option_string (SquashCodec* codec,
140  SquashOptions* options,
141  const char* key);
142 SQUASH_API bool squash_codec_get_option_bool (SquashCodec* codec,
143  SquashOptions* options,
144  const char* key);
145 SQUASH_API int squash_codec_get_option_int (SquashCodec* codec,
146  SquashOptions* options,
147  const char* key);
148 SQUASH_API size_t squash_codec_get_option_size (SquashCodec* codec,
149  SquashOptions* options,
150  const char* key);
151 SQUASH_API const char* squash_codec_get_option_string_index (SquashCodec* codec,
152  SquashOptions* options,
153  size_t index);
154 SQUASH_API bool squash_codec_get_option_bool_index (SquashCodec* codec,
155  SquashOptions* options,
156  size_t index);
157 SQUASH_API int squash_codec_get_option_int_index (SquashCodec* codec,
158  SquashOptions* options,
159  size_t index);
160 SQUASH_API size_t squash_codec_get_option_size_index (SquashCodec* codec,
161  SquashOptions* options,
162  size_t index);
163 
164 
165 SQUASH_API size_t squash_get_max_compressed_size (const char* codec, size_t uncompressed_length);
166 SQUASH_API size_t squash_get_uncompressed_size (const char* codec,
167  size_t compressed_length,
168  const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)]);
169 
170 SQUASH_API SquashStatus squash_compress (const char* codec,
171  size_t* compressed_length,
172  uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)],
173  size_t uncompressed_length,
174  const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)],
175  ...);
176 SQUASH_API SquashStatus squash_compress_with_options (const char* codec,
177  size_t* compressed_length,
178  uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)],
179  size_t uncompressed_length,
180  const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)],
181  SquashOptions* options);
182 SQUASH_API SquashStatus squash_decompress (const char* codec,
183  size_t* decompressed_length,
184  uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)],
185  size_t compressed_length,
186  const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)],
187  ...);
188 SQUASH_API SquashStatus squash_decompress_with_options (const char* codec,
189  size_t* decompressed_length,
190  uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)],
191  size_t compressed_length,
192  const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)],
193  SquashOptions* options);
194 SQUASH_API SquashCodecInfo squash_get_info (const char* codec);
195 SQUASH_API const SquashOptionInfo* squash_get_option_info (const char* codec);
196 
197 SQUASH_END_DECLS
198 
199 #endif /* SQUASH_CODEC_H */
Mask of flags which are automatically set based on which callbacks are provided.
Definition: codec.h:41
SQUASH_API SquashStream * squash_codec_create_stream_with_options(SquashCodec *codec, SquashStreamType stream_type, SquashOptions *options)
Create a new stream with existing SquashOptions.
Definition: codec.c:485
void(* _reserved1)(void)
Reserved for future use.
Definition: codec.h:87
SQUASH_API size_t squash_codec_get_option_size(SquashCodec *codec, SquashOptions *options, const char *key)
Get the size value for an option.
Definition: codec.c:1239
void(* _reserved3)(void)
Reserved for future use.
Definition: codec.h:89
Function table for plugins.
Definition: codec.h:51
SQUASH_API size_t squash_get_max_compressed_size(const char *codec, size_t uncompressed_length)
Get the maximum buffer size necessary to store compressed data.
Definition: codec.c:465
SQUASH_API bool squash_codec_get_option_bool(SquashCodec *codec, SquashOptions *options, const char *key)
Get the boolean value for an option.
Definition: codec.c:1141
const SquashOptionInfo * options
options which may bo passed to the codec to modify its operation
Definition: codec.h:54
SQUASH_API const char * squash_codec_get_option_string_index(SquashCodec *codec, SquashOptions *options, size_t index)
Get the string value for an option by index.
Definition: codec.c:1119
void(* _reserved2)(void)
Reserved for future use.
Definition: codec.h:88
SquashStatus(* process_stream)(SquashStream *stream, SquashOperation operation)
Process a SquashStream.
Definition: codec.h:58
SQUASH_API const SquashOptionInfo * squash_get_option_info(const char *codec)
Get a list of options applicable to the codec.
Definition: codec.c:1044
void(* _reserved4)(void)
Reserved for future use.
Definition: codec.h:90
SQUASH_API SquashCodecInfo squash_get_info(const char *codec)
Get a bitmask of information about the codec.
Definition: codec.c:1014
SQUASH_API bool squash_codec_get_option_bool_index(SquashCodec *codec, SquashOptions *options, size_t index)
Get the boolean value for an option by index.
Definition: codec.c:1167
SquashCodecInfo
Information about the codec.
Definition: codec.h:36
void(* _reserved5)(void)
Reserved for future use.
Definition: codec.h:91
SQUASH_API SquashStatus squash_decompress(const char *codec, size_t *decompressed_length, uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)], size_t compressed_length, const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)],...)
Decompress a buffer with an existing SquashOptions.
Definition: codec.c:880
SQUASH_API SquashStatus squash_codec_compress(SquashCodec *codec, size_t *compressed_length, uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)], size_t uncompressed_length, const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)],...)
Compress a buffer.
Definition: codec.c:663
The data is processed in a background thread.
Definition: codec.h:38
SQUASH_API const char * squash_codec_get_extension(SquashCodec *codec)
Get the codec's extension.
Definition: codec.c:979
SQUASH_API SquashPlugin * squash_codec_get_plugin(SquashCodec *codec)
Get the plugin associated with a codec.
Definition: codec.c:324
The codec is valid.
Definition: codec.h:42
SQUASH_API size_t squash_codec_get_uncompressed_size(SquashCodec *codec, size_t compressed_length, const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)])
Get the uncompressed size of the compressed buffer.
Definition: codec.c:383
SQUASH_API SquashStream * squash_codec_create_stream(SquashCodec *codec, SquashStreamType stream_type,...)
Create a new stream with existing SquashOptions.
Definition: codec.c:517
SQUASH_API size_t squash_codec_get_option_size_index(SquashCodec *codec, SquashOptions *options, size_t index)
Get the size value for an option by index.
Definition: codec.c:1266
SQUASH_API SquashStatus squash_compress_with_options(const char *codec, size_t *compressed_length, uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)], size_t uncompressed_length, const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)], SquashOptions *options)
Compress a buffer with an existing SquashOptions.
Definition: codec.c:848
SQUASH_API SquashStatus squash_codec_init(SquashCodec *codec)
Initialize a codec.
Definition: codec.c:347
SQUASH_API SquashStatus squash_compress(const char *codec, size_t *compressed_length, uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)], size_t uncompressed_length, const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)],...)
Compress a buffer.
Definition: codec.c:811
SquashCodecInfo info
Capability information about the codec.
Definition: codec.h:52
The codec will not write outside of the buffer supplied to it during decompression.
Definition: codec.h:39
SQUASH_API int squash_codec_get_option_int(SquashCodec *codec, SquashOptions *options, const char *key)
Get the integer value for an option.
Definition: codec.c:1189
SQUASH_API size_t squash_codec_get_max_compressed_size(SquashCodec *codec, size_t uncompressed_length)
Get the maximum buffer size necessary to store compressed data.
Definition: codec.c:433
SQUASH_API const char * squash_codec_get_name(SquashCodec *codec)
Get the name of a SquashCodec.
Definition: codec.c:298
SQUASH_API SquashStatus squash_codec_compress_with_options(SquashCodec *codec, size_t *compressed_length, uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)], size_t uncompressed_length, const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)], SquashOptions *options)
Compress a buffer with an existing SquashOptions.
Definition: codec.c:545
SQUASH_API SquashStatus squash_decompress_with_options(const char *codec, size_t *decompressed_length, uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)], size_t compressed_length, const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)], SquashOptions *options)
Decompress a buffer.
Definition: codec.c:916
SQUASH_API const char * squash_codec_get_option_string(SquashCodec *codec, SquashOptions *options, const char *key)
Get the string value for an option.
Definition: codec.c:1093
SQUASH_API SquashStatus squash_codec_decompress_with_options(SquashCodec *codec, size_t *decompressed_length, uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)], size_t compressed_length, const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)], SquashOptions *options)
Decompress a buffer with an existing SquashOptions.
Definition: codec.c:698
SquashStatus(* decompress_buffer)(SquashCodec *codec, size_t *decompressed_length, uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)], size_t compressed_length, const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)], SquashOptions *options)
Decompress a buffer.
Definition: codec.h:61
Flushing is supported.
Definition: codec.h:37
void(* _reserved6)(void)
Reserved for future use.
Definition: codec.h:92
SQUASH_API const SquashOptionInfo * squash_codec_get_option_info(SquashCodec *codec)
Get a list of options applicable to the codec.
Definition: codec.c:1032
SquashStatus
Status codes.
Definition: status.h:36
void(* _reserved7)(void)
Reserved for future use.
Definition: codec.h:93
SquashOperation
Operations to perform on a stream.
Definition: stream.h:51
void(* SquashCodecForeachFunc)(SquashCodec *codec, void *data)
Squashlback to be invoked on each SquashCodec in a set.
Definition: codec.h:97
SQUASH_API SquashStatus squash_codec_decompress(SquashCodec *codec, size_t *decompressed_length, uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)], size_t compressed_length, const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)],...)
Decompress a buffer.
Definition: codec.c:772
size_t(* get_max_compressed_size)(SquashCodec *codec, size_t uncompressed_length)
Get the maximum compressed size.
Definition: codec.h:84
SquashStatus(* compress_buffer_unsafe)(SquashCodec *codec, size_t *compressed_length, uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)], size_t uncompressed_length, const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)], SquashOptions *options)
Compress a buffer.
Definition: codec.h:73
SQUASH_API unsigned int squash_codec_get_priority(SquashCodec *codec)
Get the priority of a SquashCodec.
Definition: codec.c:311
SquashStatus(* compress_buffer)(SquashCodec *codec, size_t *compressed_length, uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)], size_t uncompressed_length, const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)], SquashOptions *options)
Compress a buffer.
Definition: codec.h:67
SQUASH_API SquashCodecInfo squash_codec_get_info(SquashCodec *codec)
Get a bitmask of information about the codec.
Definition: codec.c:1002
The compressed data encodes the length of the uncompressed data without having to decompress it...
Definition: codec.h:43
The codec natively supports a streaming interface.
Definition: codec.h:44
void(* _reserved8)(void)
Reserved for future use.
Definition: codec.h:94
SQUASH_API int squash_codec_get_option_int_index(SquashCodec *codec, SquashOptions *options, size_t index)
Get the integer value for an option by index.
Definition: codec.c:1217
SquashStreamType
Stream type.
Definition: stream.h:38
size_t(* get_uncompressed_size)(SquashCodec *codec, size_t compressed_length, const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)])
Get the buffer's uncompressed size.
Definition: codec.h:81