-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathgpujpeg_decoder.h
274 lines (246 loc) · 9.45 KB
/
gpujpeg_decoder.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/**
* @file
* Copyright (c) 2011-2024, CESNET
* Copyright (c) 2011, Silicon Genome, LLC.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GPUJPEG_DECODER_H
#define GPUJPEG_DECODER_H
#ifndef __cplusplus
#include <stdbool.h>
#endif // __cplusplus
#include "gpujpeg_common.h"
#include "gpujpeg_type.h"
#ifdef __cplusplus
extern "C" {
#endif
struct gpujpeg_decoder;
/**
* Decoder output type
*/
enum gpujpeg_decoder_output_type {
/// Decoder will use it's internal output buffer
GPUJPEG_DECODER_OUTPUT_INTERNAL_BUFFER,
/// Decoder will use custom output buffer
GPUJPEG_DECODER_OUTPUT_CUSTOM_BUFFER,
/// Decoder will use OpenGL Texture PBO Resource as output buffer
GPUJPEG_DECODER_OUTPUT_OPENGL_TEXTURE,
/// Decoder will use internal CUDA buffer as output buffer
GPUJPEG_DECODER_OUTPUT_CUDA_BUFFER,
/// Decoder will use custom CUDA buffer as output buffer
GPUJPEG_DECODER_OUTPUT_CUSTOM_CUDA_BUFFER,
};
/**
* Decoder output structure
*/
struct gpujpeg_decoder_output
{
/// Output type
enum gpujpeg_decoder_output_type type;
/// Decompressed data
uint8_t* data;
/// Decompressed data size
size_t data_size;
/// Decoded image parameters
struct gpujpeg_image_parameters param_image;
/// OpenGL texture
struct gpujpeg_opengl_texture* texture;
};
/**
* @sa gpujpeg_parametes
* call gpujpeg_decoder_default_init_parameters() to initialize
*/
struct gpujpeg_decoder_init_parameters
{
cudaStream_t stream; ///< stream CUDA stream to be used, cudaStreamDefault (0x00) is default
int verbose; ///< verbosity level (-1 - quiet, 0 - normal, 1 - verbose)
bool perf_stats; ///< print performance statistics on output
bool ff_cs_itu601_is_709; ///< if FFmpeg specific COM marker "CS=ITU601" present, interpret the data as
///< limited-range BT.709 not BT.601
};
/**
* Set default parameters to decoder output structure
*
* @param output Decoder output structure
* @return void
*/
GPUJPEG_API void
gpujpeg_decoder_output_set_default(struct gpujpeg_decoder_output* output);
/**
* Setup decoder output to custom buffer
*
* @param output Decoder output structure
* @param custom_buffer Custom buffer
* @return void
*/
GPUJPEG_API void
gpujpeg_decoder_output_set_custom(struct gpujpeg_decoder_output* output, uint8_t* custom_buffer);
/**
* Set decoder output to OpenGL texture
*
* @param output Decoder output structure
* @return void
*/
GPUJPEG_API void
gpujpeg_decoder_output_set_texture(struct gpujpeg_decoder_output* output, struct gpujpeg_opengl_texture* texture);
/**
* Sets output to CUDA buffer
*
* @param output Decoder output structure
*/
GPUJPEG_API void
gpujpeg_decoder_output_set_cuda_buffer(struct gpujpeg_decoder_output* output);
/**
* Setup decoder output to custom CUDA buffer
*
* @param output Decoder output structure
* @param d_custom_buffer Custom buffer in CUDA device memory
* @return void
*/
GPUJPEG_API void
gpujpeg_decoder_output_set_custom_cuda(struct gpujpeg_decoder_output* output, uint8_t* d_custom_buffer);
/**
* Create JPEG decoder
*
* @sa gpujpeg_decoder_create_with_params
* @param stream CUDA stream to be used, may be cudaStreamDefault (0x00)
* @return decoder structure if succeeds, otherwise NULL
*/
GPUJPEG_API struct gpujpeg_decoder*
gpujpeg_decoder_create(cudaStream_t stream);
GPUJPEG_API struct gpujpeg_decoder_init_parameters
gpujpeg_decoder_default_init_parameters(void);
/**
* @brief Create JPEG decoder - extended versison
*
* This version is an alternative to gpujpeg_decoder_create() allowing setting more parameters during initialization
* (verbose, perf_stats). Previously, if those needed to be set, it the decoder must have been configured with
* gpujpeg_decoder_init().
*
* @sa gpujpeg_decoder_create
* @return decoder structure if succeeds, otherwise NULL
*/
GPUJPEG_API struct gpujpeg_decoder*
gpujpeg_decoder_create_with_params(const struct gpujpeg_decoder_init_parameters *params);
/**
* Init JPEG decoder for specific image properties
*
* Following properties are relevant:
* - image dimensions, commonent count
* - output pixel format that will be requested
* - interleaving, restart interval, color_space_internal (usually GPUJPEG_YCBCR_BT601_256LVLS)
* - correct subsampling setting
*
* @note
* Doesn't need to be called from user code, buffers will be initialized automatically according to
* image properties during decompression.
*
* @param decoder Decoder structure
* @param[in] param Parameters for coder, pointed structure is copied
* @param[in] param_image Parameters for image data, pointed structure is copied
* @return 0 if succeeds, otherwise nonzero
*/
GPUJPEG_API int
gpujpeg_decoder_init(struct gpujpeg_decoder* decoder, const struct gpujpeg_parameters* param, const struct gpujpeg_image_parameters* param_image);
/**
* Decompress image by decoder
*
* @param decoder Decoder structure
* @param image Source image data
* @param image_size Source image data size
* @param image_decompressed Pointer to variable where decompressed image data buffer will be placed
* @param image_decompressed_size Pointer to variable where decompressed image size will be placed
* @return @ref Errors
*/
GPUJPEG_API int
gpujpeg_decoder_decode(struct gpujpeg_decoder* decoder, uint8_t* image, size_t image_size, struct gpujpeg_decoder_output* output);
/**
* Returns duration statistics for last decoded image
* @return 0 if succeeds, otherwise nonzero
* @note
* The values are only informative and for debugging only and thus this is
* not considered as a part of a public API.
* @deprecated
* The decoder now prints the statistics to stdout if gpujpeg_parameters.perf_stats is set.
* May be removed in future versions - please report if using this function.
*/
GPUJPEG_DEPRECATED GPUJPEG_API int
gpujpeg_decoder_get_stats(struct gpujpeg_decoder *decoder, struct gpujpeg_duration_stats *stats);
/**
* Destory JPEG decoder
*
* @param decoder Decoder structure
* @return 0 if succeeds, otherwise nonzero
*/
GPUJPEG_API int
gpujpeg_decoder_destroy(struct gpujpeg_decoder* decoder);
/**
* @defgroup decoder_pixfmt_placeholders
* @{
* following format placeholders are special values that may be passed
* to the decoeer in order to detect the format with optional constraints.
* Defined outside the enums to avoid -Wswitch warns.
*/
/// decoder default pixfmt - usually @ref GPUJPEG_444_U8_P012;
/// @ref GPUJPEG_U8 for grayscale and @ref GPUJPEG_444_U8_P0123 if alpha present
///
#define GPUJPEG_PIXFMT_AUTODETECT ((enum gpujpeg_pixel_format)(GPUJPEG_PIXFMT_NONE - 1))
/// as @ref GPUJPEG_PIXFMT_AUTODETECT, but alpha stripped if present
#define GPUJPEG_PIXFMT_NO_ALPHA ((enum gpujpeg_pixel_format)(GPUJPEG_PIXFMT_AUTODETECT - 1))
/// pixel format that may be stored in a PAM or Y4M file - a planar pixel
/// format that is either 444, 422 or 420 for YUV, P012(3) otherwise
#define GPUJPEG_PIXFMT_STD ((enum gpujpeg_pixel_format)(GPUJPEG_PIXFMT_NO_ALPHA - 1))
/// @}
/// Decode RGB for 3 or 4 channels, GPUJPEG_YCBCR for grayscale.
/// decoder only, valid only if passed to gpujpeg_decoder_set_output_format()
#define GPUJPEG_CS_DEFAULT ((enum gpujpeg_color_space)(GPUJPEG_NONE - 1))
/**
* Sets output format
*
* If not called, @ref GPUJPEG_CS_DEFAULT and @ref GPUJPEG_PIXFMT_AUTODETECT
* are used.
*
* @param decoder Decoder structure
* @param color_space Requested output color space,
* use @ref GPUJPEG_NONE to keep JPEG internal color space;
* special value @ref GPUJPEG_CS_DEFAULT to decode RGB
* (or luma for grayscale)
* @param sampling_factor Requestd color sampling factor; special values
* @ref decoder_pixfmt_placeholders can be used
*/
GPUJPEG_API void
gpujpeg_decoder_set_output_format(struct gpujpeg_decoder* decoder,
enum gpujpeg_color_space color_space,
enum gpujpeg_pixel_format pixel_format);
/**
* @copydoc gpujpeg_reader_get_image_info
*/
GPUJPEG_API int
gpujpeg_decoder_get_image_info(uint8_t *image, size_t image_size, struct gpujpeg_image_parameters *param_image, struct gpujpeg_parameters *param, int *segment_count);
#ifdef __cplusplus
}
#endif
#endif // GPUJPEG_DECODER_H