Skip to content

Commit

Permalink
BINDINGS/C++: Added finish() to image_input and image_output
Browse files Browse the repository at this point in the history
  • Loading branch information
HappySeaFox committed Jul 17, 2022
1 parent e445625 commit a2a9529
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/c++/qt/advanced-with-c++-api/qtsail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ sail_status_t QtSail::saveImage(const QString &path, const QImage &qimage)
sail::image_output image_output(path.toLocal8Bit().constData());
image_output.with(save_options);
SAIL_TRY(image_output.next_frame(image));
SAIL_TRY(image_output.finish());

return SAIL_OK;
}
Expand Down
13 changes: 12 additions & 1 deletion src/bindings/c++/image_input-c++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ image_input::image_input(sail::abstract_io &abstract_io)
image_input::~image_input()
{
if (d) {
SAIL_TRY_OR_SUPPRESS(sail_stop_loading(d->state));
finish();
}
}

Expand Down Expand Up @@ -179,6 +179,17 @@ image image_input::next_frame()
return image;
}

sail_status_t image_input::finish()
{
sail_status_t saved_status = SAIL_OK;
SAIL_TRY_OR_EXECUTE(sail_stop_loading(d->state),
/* on error */ saved_status = __sail_error_result);

d->state = nullptr;

return saved_status;
}

std::tuple<image, codec_info> image_input::probe()
{
const sail_codec_info *sail_codec_info;
Expand Down
9 changes: 8 additions & 1 deletion src/bindings/c++/image_input-c++.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class SAIL_EXPORT image_input
explicit image_input(sail::abstract_io &abstract_io);

/*
* Stops loading and destroys the image input.
* Finishes loading and destroys the image input.
*/
~image_input();

Expand Down Expand Up @@ -118,6 +118,13 @@ class SAIL_EXPORT image_input
*/
image next_frame();

/*
* Finishes loading and closes the I/O stream. Call to finish() is optional.
*
* Returns SAIL_OK on success.
*/
sail_status_t finish();

/*
* Loads the image and returns its properties without pixels and the corresponding
* codec info.
Expand Down
13 changes: 12 additions & 1 deletion src/bindings/c++/image_output-c++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ image_output::image_output(sail::abstract_io &abstract_io, const sail::codec_inf
image_output::~image_output()
{
if (d) {
SAIL_TRY_OR_SUPPRESS(sail_stop_saving(d->state));
finish();
}
}

Expand Down Expand Up @@ -162,4 +162,15 @@ sail_status_t image_output::next_frame(const sail::image &image)
return SAIL_OK;
}

sail_status_t image_output::finish()
{
sail_status_t saved_status = SAIL_OK;
SAIL_TRY_OR_EXECUTE(sail_stop_saving(d->state),
/* on error */ saved_status = __sail_error_result);

d->state = nullptr;

return saved_status;
}

}
10 changes: 9 additions & 1 deletion src/bindings/c++/image_output-c++.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class SAIL_EXPORT image_output
image_output(sail::abstract_io &abstract_io, const sail::codec_info &codec_info);

/*
* Stops saving and destroys the image output.
* Finishes saving and destroys the image output.
*/
~image_output();

Expand Down Expand Up @@ -112,6 +112,14 @@ class SAIL_EXPORT image_output
*/
sail_status_t next_frame(const sail::image &image);

/*
* Finishes saving and closes the I/O stream. Call to finish() is recommended
* if you want to ensure the I/O stream is flushed and closed successfully.
*
* Returns SAIL_OK on success.
*/
sail_status_t finish();

private:
class pimpl;
std::unique_ptr<pimpl> d;
Expand Down

0 comments on commit a2a9529

Please sign in to comment.