Skip to content

Commit 9097c79

Browse files
committed
update README.md
move decoder pre-init to FAQ.md refers to <#103>
1 parent 42b7688 commit 9097c79

File tree

2 files changed

+43
-40
lines changed

2 files changed

+43
-40
lines changed

FAQ.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- [Alpha support in command-line application](#alpha-support-in-command-line-application)
1212
- [API for alpha](#api-for-alpha)
1313
- [What are memory requirements for encoding/decoding](#what-are-memory-requirements-for-encodingdecoding)
14+
- [How to preinitialize the decoder](#how-to-preinitialize-the-decoder)
1415

1516
## Encoding/decoding is slow in first iteration
1617

@@ -185,3 +186,26 @@ image format and parameters according to your needs):
185186
The memory requirements may be excessive if dealing with really huge
186187
images - let us know if there is a problem with this.
187188

189+
# How to preinitialize the decoder
190+
191+
Usually the GPUJPEG decoder full initialization is postponed to decoding
192+
first image where it determines proper image size and all other parameters
193+
(recommended).
194+
195+
If all image parameters (including restart interval and interleaving)
196+
are known, the preinitialization may be performed immediately:
197+
198+
struct gpujpeg_parameters param;
199+
gpujpeg_set_default_parameters(&param);
200+
param.restart_interval = 16;
201+
param.interleaved = 1;
202+
203+
struct gpujpeg_image_parameters param_image;
204+
gpujpeg_image_set_default_parameters(&param_image);
205+
param_image.width = 1920;
206+
param_image.height = 1080;
207+
param_image.color_space = GPUJPEG_RGB;
208+
param_image.pixel_format = GPUJPEG_444_U8_P012;
209+
210+
// Pre initialize decoder before decoding
211+
gpujpeg_decoder_init(decoder, &param, &param_image);

README.md

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -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
205216
For 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(&param, 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`).
242245
Next 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(&param);
309-
param.restart_interval = 16;
310-
param.interleaved = 1;
311-
312-
struct gpujpeg_image_parameters param_image;
313-
gpujpeg_image_set_default_parameters(&param_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, &param, &param_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

322301
If 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
324303
following code:
325304

326305
gpujpeg_decoder_set_output_format(decoder, GPUJPEG_RGB,
@@ -329,8 +308,8 @@ following code:
329308

330309
If 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

Comments
 (0)