Skip to content

Commit

Permalink
add gpujpeg_decoder_create_with_params()
Browse files Browse the repository at this point in the history
complementary to gpujpeg_decoder_create() allowing setting some more parameters
  • Loading branch information
MartinPulec committed Oct 8, 2024
1 parent 522c93e commit 7c35c3a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2024-10-08 - 0.25.5
----------
- add gpujpeg_decoder_create_with_params() (+ struct
gpujpeg_decoder_init_parameters, gpujpeg_decoder_default_init_parameters())

2024-10-07 - 0.25.4
----------
- deprecate gpujpeg_decoder_get_stats()/gpujpeg_decoder_get_stats()
Expand Down
31 changes: 31 additions & 0 deletions libgpujpeg/gpujpeg_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef GPUJPEG_DECODER_H
#define GPUJPEG_DECODER_H

#ifndef __cplusplus
#include <stdbool.h>
#endif // __cplusplus

#include "gpujpeg_common.h"
#include "gpujpeg_type.h"

Expand Down Expand Up @@ -77,6 +81,17 @@ struct gpujpeg_decoder_output
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
};

/**
* Set default parameters to decoder output structure
*
Expand Down Expand Up @@ -126,12 +141,28 @@ gpujpeg_decoder_output_set_custom_cuda(struct gpujpeg_decoder_output* output, ui
/**
* 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
*
Expand Down
24 changes: 24 additions & 0 deletions src/gpujpeg_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "gpujpeg_decoder_internal.h"
#include "gpujpeg_huffman_cpu_decoder.h"
#include "gpujpeg_huffman_gpu_decoder.h"
#include "gpujpeg_marker.h"
#include "gpujpeg_postprocessor.h"
#include "gpujpeg_reader.h"
#include "gpujpeg_util.h"
Expand Down Expand Up @@ -153,6 +154,29 @@ gpujpeg_decoder_create(cudaStream_t stream)
return decoder;
}

struct gpujpeg_decoder_init_parameters
gpujpeg_decoder_default_init_parameters()
{
return (struct gpujpeg_decoder_init_parameters){cudaStreamDefault, 0, false};
}
/**
* Create JPEG decoder
*
* @sa gpujpeg_decoder_create
* @return decoder structure if succeeds, otherwise NULL
*/
struct gpujpeg_decoder*
gpujpeg_decoder_create_with_params(const struct gpujpeg_decoder_init_parameters *params)
{
struct gpujpeg_decoder* decoder = gpujpeg_decoder_create(params->stream);
if ( decoder == NULL ) {
return NULL;
}
decoder->coder.param.verbose = params->verbose;
decoder->coder.param.perf_stats = params->perf_stats;
return decoder;
}

/* Documented at declaration */
int
gpujpeg_decoder_init(struct gpujpeg_decoder* decoder, const struct gpujpeg_parameters* param, const struct gpujpeg_image_parameters* param_image)
Expand Down

0 comments on commit 7c35c3a

Please sign in to comment.