@@ -199,7 +199,18 @@ sources and linked shared library object to your executable:
199199
200200 #include <libgpujpeg/gpujpeg.h>
201201
202- For simple library usage examples you look into subdirectory [ examples] ( examples ) .
202+ For both encoder and decoder, you can first explicitly initialize CUDA
203+ device by calling:
204+
205+ if ( gpujpeg_init_device(device_id, 0) )
206+ return -1;
207+
208+ where the first parameter is the CUDA device number (default ` 0 ` ) and second
209+ parameter is flag if init should be verbose (` 0 ` or ` GPUJPEG_INIT_DEV_VERBOSE ` ).
210+
211+ If not called, default CUDA device will be used.
212+
213+ For simple library code examples you look into subdirectory [ examples] ( examples ) .
203214
204215#### Encoding
205216For encoding by libgpujpeg library you have to declare two structures
@@ -231,14 +242,6 @@ Or define sampling factors by hand:
231242 // User custom sampling factors
232243 gpujpeg_parameters_chroma_subsampling(¶m, MK_SUBSAMPLING(4, 4, 1, 2, 2, 1, 0, 0));
233244
234- Next you can initialize CUDA device by calling (if not called, default CUDA
235- device will be used):
236-
237- if ( gpujpeg_init_device(device_id, 0) )
238- return -1;
239-
240- where first parameters is CUDA device (e.g. ` device_id = 0 ` ) id and second
241- parameter is flag if init should be verbose (` 0 ` or ` GPUJPEG_INIT_DEV_VERBOSE ` ).
242245Next step is to create encoder:
243246
244247 struct gpujpeg_encoder* encoder = gpujpeg_encoder_create(0);
@@ -285,42 +288,18 @@ the encoder.
285288 gpujpeg_encoder_destroy(encoder);
286289
287290#### Decoding
288- For decoding we don't need to initialize two structures of parameters.
289- We only have to initialize CUDA device if we haven't initialized it yet and
290- create decoder:
291-
292- if ( gpujpeg_init_device(device_id, 0) )
293- return -1;
291+ To create the decoder you have to call:
294292
295293 struct gpujpeg_decoder* decoder = gpujpeg_decoder_create(0);
296294 if ( decoder == NULL )
297295 return -1;
298296
299- Now we have ** two options** . The first is to do nothing and decoder will
300- postpone buffer allocations to decoding first image where it determines
301- proper image size and all other parameters (recommended). The second option
302- is to provide input image size and other parameters (reset interval, interleaving)
303- and the decoder will allocate all buffers and it is fully ready when encoding
304- even the first image:
305-
306- // you can skip this code below and let the decoder initialize automatically
307- struct gpujpeg_parameters param;
308- gpujpeg_set_default_parameters(¶m);
309- param.restart_interval = 16;
310- param.interleaved = 1;
311-
312- struct gpujpeg_image_parameters param_image;
313- gpujpeg_image_set_default_parameters(¶m_image);
314- param_image.width = 1920;
315- param_image.height = 1080;
316- param_image.color_space = GPUJPEG_RGB;
317- param_image.pixel_format = GPUJPEG_444_U8_P012;
318-
319- // Pre initialize decoder before decoding
320- gpujpeg_decoder_init(decoder, ¶m, ¶m_image);
297+ Then you can ** optionally** call ` gpujpeg_decoder_init() ` to preinitialize
298+ the decoder (allocate all buffers) to be fully ready when decoding
299+ even the first image (see the [ FAQ] ( FAQ.md#how-to-preinitialize-the-decoder ) ).
321300
322301If you didn't initialize the decoder by ` gpujpeg_decoder_init ` but want
323- to specify output image color space and subsampling factor , you can use
302+ to specify output image color space and pixel format , you can use
324303following code:
325304
326305 gpujpeg_decoder_set_output_format(decoder, GPUJPEG_RGB,
@@ -329,8 +308,8 @@ following code:
329308
330309If not called, RGB or grayscale is output depending on JPEG channel count.
331310
332- Next we have to load JPEG image data from file and decoded it to raw
333- image data :
311+ Then you can decode JPEG to raw image data (optionally loading it from
312+ a file) :
334313
335314 size_t image_size = 0;
336315 uint8_t* image = NULL;
0 commit comments