Add support for new APIs for parsing jpeg streams independently from decoder APIs (#24)
* Add support for new APIs for parsing jpeg streams independently from decoder APIs
* Update document and code clean-up
* code clean-up
[ROCm/rocjpeg commit: e73ec1412c]
This commit is contained in:
committad av
GitHub
förälder
1a61bd56f2
incheckning
93d163fa33
@@ -20,11 +20,64 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "rocjpeg_api_handle.h"
|
||||
#include "rocjpeg_api_stream_handle.h"
|
||||
#include "rocjpeg_api_decoder_handle.h"
|
||||
#include "rocjpeg_commons.h"
|
||||
|
||||
/*****************************************************************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegStreamCreate(RocJpegStreamHandle *jpeg_stream_handle)
|
||||
//! \ingroup group_amd_rocjpeg
|
||||
//! Create the rocJPEG stream parser handle. This handle is used to parse and retrieve the information from the JPEG stream.
|
||||
/*****************************************************************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegStreamCreate(RocJpegStreamHandle *jpeg_stream_handle) {
|
||||
if (jpeg_stream_handle == nullptr) {
|
||||
return ROCJPEG_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
RocJpegStreamHandle rocjpeg_stream_handle = nullptr;
|
||||
try {
|
||||
rocjpeg_stream_handle = new RocJpegStreamParserHandle();
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
ERR(STR("Failed to init the rocJPEG stream handle, ") + STR(e.what()));
|
||||
return ROCJPEG_STATUS_NOT_INITIALIZED;
|
||||
}
|
||||
*jpeg_stream_handle = rocjpeg_stream_handle;
|
||||
return ROCJPEG_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*****************************************************************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegStreamParse(const unsigned char *data, size_t length, RocJpegStreamHandle jpeg_stream_handle)
|
||||
//! \ingroup group_amd_rocjpeg
|
||||
//! Parses a jpeg stream and stores the information from the stream to be used in subsequent API calls for retrieving the image information and decoding it.
|
||||
/*****************************************************************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegStreamParse(const unsigned char *data, size_t length, RocJpegStreamHandle jpeg_stream_handle) {
|
||||
if (data == nullptr || jpeg_stream_handle == nullptr) {
|
||||
return ROCJPEG_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
auto rocjpeg_stream_handle = static_cast<RocJpegStreamParserHandle*>(jpeg_stream_handle);
|
||||
if (!rocjpeg_stream_handle->rocjpeg_stream->ParseJpegStream(data, length)) {
|
||||
return ROCJPEG_STATUS_BAD_JPEG;
|
||||
}
|
||||
return ROCJPEG_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*****************************************************************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegStreamDestroy(RocJpegStreamHandle jpeg_stream_handle)
|
||||
//! \ingroup group_amd_rocjpeg
|
||||
//! Release the jpeg parser object and resources.
|
||||
/*****************************************************************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegStreamDestroy(RocJpegStreamHandle jpeg_stream_handle) {
|
||||
if (jpeg_stream_handle == nullptr) {
|
||||
return ROCJPEG_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
auto rocjpeg_stream_handle = static_cast<RocJpegStreamParserHandle*>(jpeg_stream_handle);
|
||||
delete rocjpeg_stream_handle;
|
||||
return ROCJPEG_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*****************************************************************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegCreate(RocJpegBackend backend, int device_id, RocJpegHandle *handle)
|
||||
//! \ingroup group_amd_rocjpeg
|
||||
//! Create the decoder object based on backend and device_id. A handle to the created decoder is returned
|
||||
/*****************************************************************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegCreate(RocJpegBackend backend, int device_id, RocJpegHandle *handle) {
|
||||
@@ -44,6 +97,7 @@ RocJpegStatus ROCJPEGAPI rocJpegCreate(RocJpegBackend backend, int device_id, Ro
|
||||
|
||||
/*****************************************************************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegDestroy(RocJpegHandle handle)
|
||||
//! \ingroup group_amd_rocjpeg
|
||||
//! Release the decoder object and resources.
|
||||
/*****************************************************************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegDestroy(RocJpegHandle handle) {
|
||||
@@ -56,20 +110,21 @@ RocJpegStatus ROCJPEGAPI rocJpegDestroy(RocJpegHandle handle) {
|
||||
}
|
||||
|
||||
/*****************************************************************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegGetImageInfo(RocJpegHandle handle, const uint8_t *data, size_t length,
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegGetImageInfo(RocJpegHandle handle, RocJpegStreamHandle jpeg_stream_handle,
|
||||
//! int *num_components, RocJpegChromaSubsampling *subsampling, int *widths, int *heights)
|
||||
//! \ingroup group_amd_rocjpeg
|
||||
//! Retrieve the image info, including channel, width and height of each component, and chroma subsampling.
|
||||
/*****************************************************************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegGetImageInfo(RocJpegHandle handle, const uint8_t *data, size_t length, uint8_t *num_components,
|
||||
RocJpegStatus ROCJPEGAPI rocJpegGetImageInfo(RocJpegHandle handle, RocJpegStreamHandle jpeg_stream_handle, uint8_t *num_components,
|
||||
RocJpegChromaSubsampling *subsampling, uint32_t *widths, uint32_t *heights) {
|
||||
if (handle == nullptr || data == nullptr || num_components == nullptr ||
|
||||
if (handle == nullptr || num_components == nullptr ||
|
||||
subsampling == nullptr || widths == nullptr || heights == nullptr) {
|
||||
return ROCJPEG_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
RocJpegStatus rocjpeg_status = ROCJPEG_STATUS_SUCCESS;
|
||||
auto rocjpeg_handle = static_cast<RocJpegDecoderHandle*>(handle);
|
||||
try {
|
||||
rocjpeg_status = rocjpeg_handle->rocjpeg_decoder->GetImageInfo(data, length, num_components, subsampling, widths, heights);
|
||||
rocjpeg_status = rocjpeg_handle->rocjpeg_decoder->GetImageInfo(jpeg_stream_handle, num_components, subsampling, widths, heights);
|
||||
} catch (const std::exception& e) {
|
||||
rocjpeg_handle->CaptureError(e.what());
|
||||
ERR(e.what());
|
||||
@@ -80,24 +135,25 @@ RocJpegStatus ROCJPEGAPI rocJpegGetImageInfo(RocJpegHandle handle, const uint8_t
|
||||
}
|
||||
|
||||
/*****************************************************************************************************/
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegDecode(RocJpegHandle handle, const uint8_t *data, size_t length, const RocJpegDecodeParams *decode_params, RocJpegImage *destination);
|
||||
//! \fn RocJpegStatus ROCJPEGAPI rocJpegDecode(RocJpegHandle handle, RocJpegStreamHandle jpeg_stream_handle, const RocJpegDecodeParams *decode_params, RocJpegImage *destination);
|
||||
//! \ingroup group_amd_rocjpeg
|
||||
//! Decodes single image based on the backend used to create the rocJpeg handle in rocJpegCreate API.
|
||||
//! Destination buffers should be large enough to be able to store output of specified format. These buffers should be pre-allocted by the user in the device memories.
|
||||
//! Destination buffers should be large enough to be able to store output of specified format.
|
||||
//! These buffers should be pre-allocted by the user in the device memories.
|
||||
//! For each color plane (channel) sizes could be retrieved for image using rocJpegGetImageInfo API
|
||||
//! and minimum required memory buffer for each plane is plane_height * plane_pitch where plane_pitch >= plane_width for
|
||||
//! planar output formats and plane_pitch >= plane_width * num_components for interleaved output format.
|
||||
/*****************************************************************************************************/
|
||||
RocJpegStatus ROCJPEGAPI rocJpegDecode(RocJpegHandle handle, const uint8_t *data, size_t length, const RocJpegDecodeParams *decode_params,
|
||||
RocJpegStatus ROCJPEGAPI rocJpegDecode(RocJpegHandle handle, RocJpegStreamHandle jpeg_stream_handle, const RocJpegDecodeParams *decode_params,
|
||||
RocJpegImage *destination) {
|
||||
|
||||
if (handle == nullptr || data == nullptr || decode_params == nullptr || destination == nullptr) {
|
||||
if (handle == nullptr || decode_params == nullptr || destination == nullptr) {
|
||||
return ROCJPEG_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
RocJpegStatus rocjpeg_status = ROCJPEG_STATUS_SUCCESS;
|
||||
auto rocjpeg_handle = static_cast<RocJpegDecoderHandle*>(handle);
|
||||
try {
|
||||
rocjpeg_status = rocjpeg_handle->rocjpeg_decoder->Decode(data, length, decode_params, destination);
|
||||
rocjpeg_status = rocjpeg_handle->rocjpeg_decoder->Decode(jpeg_stream_handle, decode_params, destination);
|
||||
} catch (const std::exception& e) {
|
||||
rocjpeg_handle->CaptureError(e.what());
|
||||
ERR(e.what());
|
||||
|
||||
Referens i nytt ärende
Block a user