more style changes

This commit is contained in:
Katarzyna Miernikiewicz 2020-08-27 08:46:12 +00:00
parent 1b0fbc89bb
commit 2c50bea22c

View File

@ -58,66 +58,65 @@ int main(int argc, char* argv[]) {
google::InitGoogleLogging(argv[0]);
if (argc != 3) {
std::cerr << "usage: " << basename(argv[0]) << " absolute/path/to/INPUT.jp2"
std::cerr << "Usage: " << basename(argv[0]) << " absolute/path/to/INPUT.jp2"
<< " absolute/path/to/OUTPUT.pnm\n";
return EXIT_FAILURE;
}
std::string in_file(argv[1]);
// initialize sandbox
// Initialize sandbox.
Openjp2SapiSandbox sandbox(in_file);
absl::Status status = sandbox.Init();
CHECK(status.ok()) << "sandbox initialization failed" << status;
CHECK(status.ok()) << "Sandbox initialization failed " << status;
Openjp2Api api(&sandbox);
sapi::v::ConstCStr in_file_v(in_file.c_str());
// initialize library's main data-holders
// Initialize library's main data-holders.
sapi::StatusOr<opj_stream_t*> stream =
api.opj_stream_create_default_file_stream(in_file_v.PtrBefore(), 1);
CHECK(stream.ok()) << "opj_stream initialization failed: " << stream.status();
CHECK(stream.ok()) << "Stream initialization failed: " << stream.status();
sapi::v::RemotePtr stream_pointer(stream.value());
sapi::StatusOr<opj_codec_t*> codec = api.opj_create_decompress(OPJ_CODEC_JP2);
CHECK(codec.ok()) << "opj_codec initialization failed: " << stream.status();
CHECK(codec.ok()) << "Codec initialization failed: " << stream.status();
sapi::v::RemotePtr codec_pointer(codec.value());
sapi::v::Struct<opj_dparameters_t> parameters;
status = api.opj_set_default_decoder_parameters(parameters.PtrBoth());
CHECK(status.ok()) << "parameters initialization failed" << status;
CHECK(status.ok()) << "Parameters initialization failed " << status;
sapi::StatusOr<OPJ_BOOL> bool_status =
api.opj_setup_decoder(&codec_pointer, parameters.PtrBefore());
CHECK(bool_status.ok() && bool_status.value()) << "decoder setup failed";
CHECK(bool_status.ok() && bool_status.value()) << "Decoder setup failed";
// start reading image from the input file
// Start reading image from the input file.
sapi::v::GenericPtr image_pointer;
bool_status = api.opj_read_header(&stream_pointer, &codec_pointer,
image_pointer.PtrAfter());
CHECK(bool_status.ok() && bool_status.value())
<< "reading image header failed";
<< "Reading image header failed";
sapi::v::Struct<opj_image_t> image;
image.SetRemote(reinterpret_cast<void*>(image_pointer.GetValue()));
CHECK(sandbox.TransferFromSandboxee(&image).ok())
<< "transfer from sandboxee failed";
<< "Transfer from sandboxee failed";
bool_status =
api.opj_decode(&codec_pointer, &stream_pointer, image.PtrAfter());
CHECK(bool_status.ok() && bool_status.value()) << "decoding failed";
CHECK(bool_status.ok() && bool_status.value()) << "Decoding failed";
bool_status = api.opj_end_decompress(&codec_pointer, &stream_pointer);
CHECK(bool_status.ok() && bool_status.value()) << "ending decompress failed";
CHECK(bool_status.ok() && bool_status.value()) << "Ending decompress failed";
int components = image.data().numcomps;
// transfer the read data to the main process
// Transfer the read data to the main process.
sapi::v::Array<opj_image_comp_t> image_components(components);
image_components.SetRemote(image.data().comps);
CHECK(sandbox.TransferFromSandboxee(&image_components).ok())
<< "transfer from sandboxee failed";
<< "Transfer from sandboxee failed";
image.mutable_data()->comps = (opj_image_comp_t*)image_components.GetLocal();
@ -130,7 +129,7 @@ int main(int argc, char* argv[]) {
for (int i = 0; i < components; ++i) {
image_components_data.SetRemote(image.data().comps[i].data);
CHECK(sandbox.TransferFromSandboxee(&image_components_data).ok())
<< "transfer from sandboxee failed";
<< "Transfer from sandboxee failed";
std::vector<OPJ_INT32> component_data(
image_components_data.GetData(),
@ -139,20 +138,20 @@ int main(int argc, char* argv[]) {
image_components[i].data = &data[i][0];
}
// convert the image to the desired format and save it to the file
// Convert the image to the desired format and save it to the file.
int error =
imagetopnm(reinterpret_cast<opj_image_t*>(image.GetLocal()), argv[2], 0);
CHECK(!error) << "image convert failed";
CHECK(!error) << "Image convert failed";
// cleanup
// Clean up.
status = api.opj_image_destroy(image.PtrNone());
CHECK(status.ok()) << "image destroy failed" << status;
CHECK(status.ok()) << "Image destroy failed " << status;
status = api.opj_stream_destroy(&stream_pointer);
CHECK(status.ok()) << "stream destroy failed" << status;
CHECK(status.ok()) << "Stream destroy failed " << status;
status = api.opj_destroy_codec(&codec_pointer);
CHECK(status.ok()) << "codec destroy failed" << status;
CHECK(status.ok()) << "Codec destroy failed " << status;
return EXIT_SUCCESS;
}