Skip to content

Commit

Permalink
Fix image encoder status (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
skyline75489 authored Dec 10, 2024
1 parent db33bc3 commit c3674f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 11 additions & 5 deletions operators/vision/encode_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ struct EncodeImage: public internal::EncodeImage {
std::unique_ptr<uint8_t[]> conversion_buf;
auto encoding_data = input_data_ptr;
bool conversion_needed = false;
auto fx_supported_bgr =
auto fx_supported_bgr =
extension_ == ".png"? &internal::EncodeImage::pngSupportsBgr : &internal::EncodeImage::JpgSupportsBgr;

bool bgr_source = is_bgr_;
bool bgr_source = is_bgr_;
if ((this->*fx_supported_bgr)() != is_bgr_) {
conversion_needed = true;
bgr_source = !is_bgr_;
Expand All @@ -128,12 +128,18 @@ struct EncodeImage: public internal::EncodeImage {
encoding_data = cvt_data;
}

OrtxStatus status{};

if (extension_ == ".jpg") {
EncodeJpg(encoding_data, bgr_source, width, height, &outbuffer, &outsize);
status = EncodeJpg(encoding_data, bgr_source, width, height, &outbuffer, &outsize);
} else if (extension_ == ".png") {
EncodePng(encoding_data, bgr_source, width, height, &outbuffer, &outsize);
status = EncodePng(encoding_data, bgr_source, width, height, &outbuffer, &outsize);
} else {
return {kOrtxErrorInvalidArgument, "[EncodeImage] Unsupported image format."};
status = {kOrtxErrorInvalidArgument, "[EncodeImage] Unsupported image format."};
}

if (!status.IsOk()) {
return status;
}

std::vector<int64_t> output_dimensions{static_cast<int64_t>(outsize)};
Expand Down
1 change: 1 addition & 0 deletions operators/vision/image_encoder_darwin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct EncodeImage {
CFDataGetBytes(result, CFRangeMake(0, size), *outbuffer);
CFRelease(result);
*outsize = size;
return {};
}

CFDictionaryRef imageDestinationOptions_{NULL};
Expand Down

0 comments on commit c3674f5

Please sign in to comment.