-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathgpujpeg_encoder.h
230 lines (206 loc) · 8.05 KB
/
gpujpeg_encoder.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
/**
* @file
* Copyright (c) 2011-2023, CESNET z.s.p.o
* 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_ENCODER_H
#define GPUJPEG_ENCODER_H
#include "gpujpeg_common.h"
#ifdef __cplusplus
extern "C" {
#endif
struct gpujpeg_encoder;
/**
* Encoder input type
*/
enum gpujpeg_encoder_input_type {
/// Encoder will use custom input buffer
GPUJPEG_ENCODER_INPUT_IMAGE,
/// Encoder will use OpenGL Texture PBO Resource as input buffer
GPUJPEG_ENCODER_INPUT_OPENGL_TEXTURE,
/// Encoder will use custom GPU input buffer
GPUJPEG_ENCODER_INPUT_GPU_IMAGE,
};
/**
* Encoder input structure
*/
struct gpujpeg_encoder_input
{
/// Output type
enum gpujpeg_encoder_input_type type;
/// Image data
uint8_t* image;
/// Registered OpenGL Texture
struct gpujpeg_opengl_texture* texture;
};
/**
* Set encoder input to image data
*
* @param encoder_input Encoder input structure
* @param image Input image data
* @return void
* @sa gpujpeg_encoder_input_image
*/
GPUJPEG_API void
gpujpeg_encoder_input_set_image(struct gpujpeg_encoder_input* input, uint8_t* image);
/**
* Set encoder input to GPU image data
*
* @param encoder_input Encoder input structure
* @param image GPU image data
* @return void
* @sa gpujpeg_encoder_input_gpu_image
*/
GPUJPEG_API void
gpujpeg_encoder_input_set_gpu_image(struct gpujpeg_encoder_input* input, uint8_t* image);
/**
* Set encoder input to OpenGL texture
*
* @param encoder_input Encoder input structure
* @param texture_id OpenGL texture id
* @return void
* @sa gpujpeg_encoder_input_set_texture
*/
GPUJPEG_API void
gpujpeg_encoder_input_set_texture(struct gpujpeg_encoder_input* input, struct gpujpeg_opengl_texture* texture);
/// alternative to @ref gpujpeg_encoder_input_set_image returning the struct as a return value
GPUJPEG_API struct gpujpeg_encoder_input
gpujpeg_encoder_input_image(uint8_t* image);
/// alternative to @ref gpujpeg_encoder_input_set_gpu_image returning the struct as a return value
GPUJPEG_API struct gpujpeg_encoder_input
gpujpeg_encoder_input_gpu_image(uint8_t* image);
/// alternative to @ref gpujpeg_encoder_input_set_texture returning the struct as a return value
GPUJPEG_API struct gpujpeg_encoder_input
gpujpeg_encoder_input_texture(struct gpujpeg_opengl_texture* texture);
/**
* Create JPEG encoder
*
* @param stream CUDA stream to be used, may be cudaStreamDefault (0x00)
* @return encoder structure if succeeds, otherwise NULL
*/
GPUJPEG_API struct gpujpeg_encoder*
gpujpeg_encoder_create(cudaStream_t stream);
/**
* Compute maximum number of image pixels (width x height) which can be encoded by given memory size.
*
* @param encoder
* @param param
* @param param_image
* @param image_input_type
* @param memory_size
* @param max_pixels
* @return size of used device memory in bytes if succeeds, otherwise 0
*/
GPUJPEG_API size_t
gpujpeg_encoder_max_pixels(struct gpujpeg_parameters * param, struct gpujpeg_image_parameters * param_image, enum gpujpeg_encoder_input_type image_input_type, size_t memory_size, int * max_pixels);
/**
* Compute maximum size of device memory which will be used for encoding image with given number of pixels.
*
* @param encoder
* @param param
* @param param_image
* @param image_input_type
* @param max_pixels
* @return size of required device memory in bytes if succeeds, otherwise 0
*/
GPUJPEG_API size_t
gpujpeg_encoder_max_memory(struct gpujpeg_parameters * param, struct gpujpeg_image_parameters * param_image, enum gpujpeg_encoder_input_type image_input_type, int max_pixels);
/**
* Pre-allocate all encoding buffers for given image pixels.
*
* @param encoder
* @param param
* @param param_image
* @param image_input_type
* @return 0 if succeeds, otherwise nonzero
*/
GPUJPEG_API int
gpujpeg_encoder_allocate(struct gpujpeg_encoder* encoder, const struct gpujpeg_parameters * param, const struct gpujpeg_image_parameters * param_image, enum gpujpeg_encoder_input_type image_input_type);
/**
* Compress image by encoder
*
* @param encoder Encoder structure
* @param param Parameters for coder
* @param param_image Parameters for image data
* @param image Source image data
* @param image_compressed Pointer to variable where compressed image data buffer will be placed
* @param image_compressed_size Pointer to variable where compressed image size will be placed.
* Buffer is owned by encoder and must not be freed by caller. Buffer
* is valid until next gpujpeg_encoder_encode() call.
* @return 0 if succeeds, otherwise nonzero
*/
GPUJPEG_API int
gpujpeg_encoder_encode(struct gpujpeg_encoder* encoder, const struct gpujpeg_parameters* param,
const struct gpujpeg_image_parameters* param_image, const struct gpujpeg_encoder_input* input,
uint8_t** image_compressed, size_t* image_compressed_size);
/**
* Returns duration statistics for last encoded 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 encoder 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_encoder_get_stats(struct gpujpeg_encoder *encoder, struct gpujpeg_duration_stats *stats);
enum gpujpeg_header_type {
GPUJPEG_HEADER_DEFAULT = 0, ///< for 1 or 3 channel @ref GPUJPEG_YCBCR_JPEG @ref GPUJPEG_HEADER_JFIF, for @ref
///< GPUJPEG_RGB @ref GPUJPEG_HEADER_ADOBE, @ref GPUJPEG_HEADER_SPIFF otherwise
GPUJPEG_HEADER_JFIF = 1<<0,
GPUJPEG_HEADER_SPIFF = 1<<1,
GPUJPEG_HEADER_ADOBE = 1<<2, ///< Adobe APP8 header
};
/**
* Forces JPEG header to be emitted.
*
* Header type should be capable of describing the resulting JPEG, eg. JFIF only for BT.601
* full-scale YCbCr images. If not, resulting JPEG image may be incompatible with decoders.
*/
GPUJPEG_API void
gpujpeg_encoder_set_jpeg_header(struct gpujpeg_encoder *encoder, enum gpujpeg_header_type header_type);
/**
* Suggests optimal restart interval to be used for given param_image balancing both image
* size and performance.
* @param subsampling 444 422 or 420
*/
GPUJPEG_API int
gpujpeg_encoder_suggest_restart_interval(const struct gpujpeg_image_parameters* param_image,
gpujpeg_sampling_factor_t subsampling, bool interleaved, int verbose);
/**
* Destory JPEG encoder
*
* @param encoder Encoder structure
* @return 0 if succeeds, otherwise nonzero
*/
GPUJPEG_API int
gpujpeg_encoder_destroy(struct gpujpeg_encoder* encoder);
#ifdef __cplusplus
}
#endif
#endif // GPUJPEG_ENCODER_H