-
Notifications
You must be signed in to change notification settings - Fork 2
/
QB3.h
160 lines (120 loc) · 5.43 KB
/
QB3.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
Content: Public API for QB3 library
Copyright 2021-2024 Esri
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Contributors: Lucian Plesea
*/
#pragma once
// For size_t
#include <stddef.h>
// For uint64_t
#include <stdint.h>
// CMake will generate LIBQB3_EXPORT linkage as needed
#include "libqb3_export.h"
// Keep this close to plain C so it can have a C API
#if defined(__cplusplus)
extern "C" {
#endif
#define QB3_MAXBANDS 16
typedef struct encs * encsp; // encoder
typedef struct decs * decsp; // decoder
// Types
enum qb3_dtype { QB3_U8 = 0, QB3_I8, QB3_U16, QB3_I16, QB3_U32, QB3_I32, QB3_U64, QB3_I64 };
// To check if the library has QB3M_FTL
#define QB3_HAS_FTL 1
// Encode mode, default is fastest, best is best compression
enum qb3_mode {
// Aliases, values might change
QB3M_DEFAULT = 4,
QB3M_BASE = 4,
QB3M_BEST = 7,
// original z-curve
QB3M_BASE_Z = 0, // Base QB3 with z-curve parsing order
QB3M_CF = 1, // With common factor
QB3M_RLE = 2, // BASE + RLE
QB3M_CF_RLE = 3, // BASE + CF + RLE
// better, with Hilbert curve
QB3M_BASE_H = 4, // Base QB3
QB3M_CF_H = 5, // QB3 Hilbert + CF
QB3M_RLE_H = 6, // QB3 Hilbert + RLE
QB3M_CF_RLE_H = 7, // QB3 Hilbert + CF + RLE
// Faster and only slightly worse than base in many cases
// Hilbert curve but no bit-step, no CF, no RLE
QB3M_FTL = 8,
QB3M_END, // Marks the end of the settable modes
QB3M_STORED = 255, // Raw bypass, can't be requested
QB3M_INVALID = -1 // Invalid mode
}; // Best compression, one of the above
// Errors
enum qb3_error {
QB3E_OK = 0,
QB3E_EINV, // Invalid parameter
QB3E_UNKN, // Unknown
QB3E_ERR, // unspecified error
QB3E_LIBERR = 255 // internal QB3 error, should not happen
};
// In QB3encode.cpp
// Call before anything else
LIBQB3_EXPORT encsp qb3_create_encoder(size_t width, size_t height, size_t bands, qb3_dtype dt);
// Call when done with the encoder
LIBQB3_EXPORT void qb3_destroy_encoder(encsp p);
// Reset state, allowing encoder to be reused
LIBQB3_EXPORT void qb3_reset_encoder(encsp p);
// Change the default core band mapping.
// The default assumes bands are independent, except for 3 or 4 bands
// when RGB(A) is assumed and R-G and B-G is used
// equivalent to cbands = { 1, 1, 1 }
// Returns false if band number differs from the one used to create p
// Only values < bands are acceptable in cband array
// The cband array might be modified if core bands are not valid or iterrative
LIBQB3_EXPORT bool qb3_set_encoder_coreband(encsp p, size_t bands, size_t *cband);
// Sets quantization parameters, returns true on success
// away = true -> round away from zero
LIBQB3_EXPORT bool qb3_set_encoder_quanta(encsp p, uint64_t q, bool away);
// Upper bound of encoded size, without taking the header into consideration
LIBQB3_EXPORT size_t qb3_max_encoded_size(const encsp p);
// Sets and returns the mode which will be used.
// If mode value is out of range, it returns the previous mode value of p
LIBQB3_EXPORT qb3_mode qb3_set_encoder_mode(encsp p, qb3_mode mode);
//// Generate raw qb3 stream, no headers
//LIBQB3_EXPORT void qb3_set_encoder_raw(encsp p);
// Encode the source into destination buffer, which should be at least qb3_max_encoded_size
// Source organization is expected to be y major, then x, then band (interleaved)
// Returns actual size, the encoder can be reused
LIBQB3_EXPORT size_t qb3_encode(encsp p, void *source, void *destination);
// Returns !0 if last encode call failed
LIBQB3_EXPORT int qb3_get_encoder_state(encsp p);
// In QB3decode.cpp
// Starts reading a formatted QB3 source. Reads the main header, which only contains the output size information
// returns nullptr if it fails, usually because the source is not in the correct format
// If successful, size containts 3 values, x size, y size and number of bands
LIBQB3_EXPORT decsp qb3_read_start(void* source, size_t source_size, size_t* image_size);
// Call after qb3_read_start, reads all headers until the raster data, returns false if it fails
LIBQB3_EXPORT bool qb3_read_info(decsp p);
// Call after qb3_read_info, reads all the data, returns bytes read
LIBQB3_EXPORT size_t qb3_read_data(decsp p, void* destination);
LIBQB3_EXPORT void qb3_destroy_decoder(decsp p);
LIBQB3_EXPORT size_t qb3_decoded_size(const decsp p);
LIBQB3_EXPORT qb3_dtype qb3_get_type(const decsp p);
// Set line to line to line stride for decoder, defaults to line size
LIBQB3_EXPORT void qb3_set_decoder_stride(decsp p, size_t stride);
// Query settings, valid after qb3_read_info
// Encoding mode used, returns QB3M_INVALID if failed
LIBQB3_EXPORT qb3_mode qb3_get_mode(const decsp p);
// Returns the number of quantization bits used, returns 0 if failed
LIBQB3_EXPORT uint64_t qb3_get_quanta(const decsp p);
// Return the scanning curve used, returns 0 if failed
LIBQB3_EXPORT uint64_t qb3_get_order(const decsp p);
// Sets the cband array and returns true if successful
LIBQB3_EXPORT bool qb3_get_coreband(const decsp p, size_t *cband);
#if defined(__cplusplus)
}
#endif