Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return success/failure from decode #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/J2KDecoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ class J2KDecoder {
/// HTJ2K encoded bitstream into the encoded buffer before calling this
/// method, see getEncodedBuffer() and getEncodedBytes() above.
/// </summary>
void decode() {
const bool decode() {
decodeLayer_ = 0;
decode_i(0);
return decode_i(0);
}

/// <summary>
Expand All @@ -131,9 +131,9 @@ class J2KDecoder {
/// buffer before calling this method, see getEncodedBuffer() and
/// getEncodedBytes() above.
/// </summary>
void decodeSubResolution(size_t decompositionLevel, size_t decodeLayer) {
const bool decodeSubResolution(size_t decompositionLevel, size_t decodeLayer) {
decodeLayer_ = decodeLayer;
decode_i(decompositionLevel);
return decode_i(decompositionLevel);
}

/// <summary>
Expand Down Expand Up @@ -218,7 +218,7 @@ class J2KDecoder {

private:

void decode_i(size_t decompositionLevel) {
bool decode_i(size_t decompositionLevel) {
opj_dparameters_t parameters;
opj_codec_t* l_codec = NULL;
opj_image_t* image = NULL;
Expand Down Expand Up @@ -255,7 +255,7 @@ class J2KDecoder {
printf("[ERROR] opj_decompress: failed to setup the decoder\n");
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
return;
return false;
}
// disable strict mode so we can partially decode J2K streams
opj_decoder_set_strict_mode(l_codec, OPJ_FALSE);
Expand All @@ -266,7 +266,7 @@ class J2KDecoder {
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
return;
return false;
}

/* decode the image */
Expand All @@ -275,7 +275,7 @@ class J2KDecoder {
opj_destroy_codec(l_codec);
opj_stream_destroy(l_stream);
opj_image_destroy(image);
return;
return false;
}

frameInfo_.width = image->x1;
Expand Down Expand Up @@ -367,6 +367,8 @@ class J2KDecoder {
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);

return true;
}

std::vector<uint8_t> encoded_;
Expand Down