ccrush
Loading...
Searching...
No Matches
ccrush.h
Go to the documentation of this file.
1/*
2
3BSD 2-Clause License
4
5Copyright (c) 2020, Raphael Beck
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
13
142. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29*/
30
37#ifndef CCRUSH_LIBRARY_H
38#define CCRUSH_LIBRARY_H
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44#if defined(_WIN32) && defined(CCRUSH_DLL)
45#ifdef CCRUSH_BUILD_DLL
46#define CCRUSH_API __declspec(dllexport)
47#else
48#define CCRUSH_API __declspec(dllimport)
49#endif
50#else
51#define CCRUSH_API
52#endif
53
54#include <stdio.h>
55#include <stdint.h>
56#include <stddef.h>
57
61#define CCRUSH_VERSION 210
62
66#define CCRUSH_VERSION_STR "2.1.0"
67
68#ifndef CCRUSH_MAX_BUFFER_SIZE_KiB
72#define CCRUSH_MAX_BUFFER_SIZE_KiB (1024 * 256)
73#endif
74
75#ifndef CCRUSH_DEFAULT_CHUNKSIZE
79#define CCRUSH_DEFAULT_CHUNKSIZE (1024 * 256)
80#endif
81
85#define CCRUSH_ERROR_INVALID_ARGS 1000
86
90#define CCRUSH_ERROR_BUFFERSIZE_TOO_LARGE 1001
91
95#define CCRUSH_ERROR_FILE_ACCESS_FAILED 1002
96
100#define CCRUSH_ERROR_OUT_OF_MEMORY 2000
101
105#define CCRUSH_MIN(x, y) (((x) < (y)) ? (x) : (y))
106
110#define CCRUSH_MAX(x, y) (((x) > (y)) ? (x) : (y))
111
112#ifndef CCRUSH_MAX_WIN_FILEPATH_LENGTH
116#define CCRUSH_MAX_WIN_FILEPATH_LENGTH (1024 * 32)
117#endif
118
129CCRUSH_API int ccrush_compress(const uint8_t* data, size_t data_length, uint32_t buffer_size_kib, int level, uint8_t** out, size_t* out_length);
130
139CCRUSH_API int ccrush_compress_file(const char* input_file_path, const char* output_file_path, uint32_t buffer_size_kib, int level);
140
151CCRUSH_API int ccrush_compress_file_raw(FILE* input_file, FILE* output_file, uint32_t buffer_size_kib, int level, int close_input_file, int close_output_file);
152
162CCRUSH_API int ccrush_decompress(const uint8_t* data, size_t data_length, uint32_t buffer_size_kib, uint8_t** out, size_t* out_length);
163
171CCRUSH_API int ccrush_decompress_file(const char* input_file_path, const char* output_file_path, uint32_t buffer_size_kib);
172
182CCRUSH_API int ccrush_decompress_file_raw(FILE* input_file, FILE* output_file, uint32_t buffer_size_kib, int close_input_file, int close_output_file);
183
188CCRUSH_API void ccrush_free(void* mem);
189
194CCRUSH_API uint32_t ccrush_get_version_nr();
195
201
208static inline uint64_t ccrush_nextpow2(uint64_t n)
209{
210 n--;
211 n |= n >> 1;
212 n |= n >> 2;
213 n |= n >> 4;
214 n |= n >> 8;
215 n |= n >> 16;
216 n |= n >> 32;
217 return ++n;
218}
219
220#ifdef __cplusplus
221} // extern "C"
222#endif
223
224#endif // CCRUSH_LIBRARY_H
CCRUSH_API int ccrush_decompress_file_raw(FILE *input_file, FILE *output_file, uint32_t buffer_size_kib, int close_input_file, int close_output_file)
CCRUSH_API int ccrush_compress_file_raw(FILE *input_file, FILE *output_file, uint32_t buffer_size_kib, int level, int close_input_file, int close_output_file)
CCRUSH_API int ccrush_decompress_file(const char *input_file_path, const char *output_file_path, uint32_t buffer_size_kib)
CCRUSH_API int ccrush_compress_file(const char *input_file_path, const char *output_file_path, uint32_t buffer_size_kib, int level)
static uint64_t ccrush_nextpow2(uint64_t n)
Definition ccrush.h:208
CCRUSH_API uint32_t ccrush_get_version_nr()
CCRUSH_API void ccrush_free(void *mem)
CCRUSH_API int ccrush_compress(const uint8_t *data, size_t data_length, uint32_t buffer_size_kib, int level, uint8_t **out, size_t *out_length)
CCRUSH_API char * ccrush_get_version_nr_string()
CCRUSH_API int ccrush_decompress(const uint8_t *data, size_t data_length, uint32_t buffer_size_kib, uint8_t **out, size_t *out_length)