mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Migrate guetzli to absl::StatusOr<>
PiperOrigin-RevId: 333731054 Change-Id: I1446b1b58387dbd7c4853b146249bee7deb8c307
This commit is contained in:
parent
88c980218f
commit
cd75f94094
|
@ -24,6 +24,7 @@ cc_library(
|
||||||
srcs = ["guetzli_entry_points.cc"],
|
srcs = ["guetzli_entry_points.cc"],
|
||||||
hdrs = ["guetzli_entry_points.h"],
|
hdrs = ["guetzli_entry_points.h"],
|
||||||
deps = [
|
deps = [
|
||||||
|
"@com_google_absl//absl/status:statusor",
|
||||||
"@com_google_sandboxed_api//sandboxed_api:lenval_core",
|
"@com_google_sandboxed_api//sandboxed_api:lenval_core",
|
||||||
"@com_google_sandboxed_api//sandboxed_api:vars",
|
"@com_google_sandboxed_api//sandboxed_api:vars",
|
||||||
"@guetzli//:guetzli_lib",
|
"@guetzli//:guetzli_lib",
|
||||||
|
@ -53,9 +54,7 @@ sapi_library(
|
||||||
cc_binary(
|
cc_binary(
|
||||||
name = "guetzli_sandboxed",
|
name = "guetzli_sandboxed",
|
||||||
srcs = ["guetzli_sandboxed.cc"],
|
srcs = ["guetzli_sandboxed.cc"],
|
||||||
deps = [
|
deps = [":guetzli_sapi"],
|
||||||
":guetzli_sapi",
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_test(
|
cc_test(
|
||||||
|
|
|
@ -25,8 +25,8 @@
|
||||||
#include "guetzli/jpeg_data_reader.h"
|
#include "guetzli/jpeg_data_reader.h"
|
||||||
#include "guetzli/quality.h"
|
#include "guetzli/quality.h"
|
||||||
#include "png.h" // NOLINT(build/include)
|
#include "png.h" // NOLINT(build/include)
|
||||||
|
#include "absl/status/statusor.h"
|
||||||
#include "sandboxed_api/sandbox2/util/fileops.h"
|
#include "sandboxed_api/sandbox2/util/fileops.h"
|
||||||
#include "sandboxed_api/util/statusor.h"
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ sapi::LenValStruct CreateLenValFromData(const void* data, size_t size) {
|
||||||
return {size, new_data};
|
return {size, new_data};
|
||||||
}
|
}
|
||||||
|
|
||||||
sapi::StatusOr<std::string> ReadFromFd(int fd) {
|
absl::StatusOr<std::string> ReadFromFd(int fd) {
|
||||||
struct stat file_data;
|
struct stat file_data;
|
||||||
int status = fstat(fd, &file_data);
|
int status = fstat(fd, &file_data);
|
||||||
|
|
||||||
|
@ -70,9 +70,9 @@ sapi::StatusOr<std::string> ReadFromFd(int fd) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
sapi::StatusOr<GuetzliInitData> PrepareDataForProcessing(
|
absl::StatusOr<GuetzliInitData> PrepareDataForProcessing(
|
||||||
const ProcessingParams& processing_params) {
|
const ProcessingParams& processing_params) {
|
||||||
sapi::StatusOr<std::string> input = ReadFromFd(processing_params.remote_fd);
|
absl::StatusOr<std::string> input = ReadFromFd(processing_params.remote_fd);
|
||||||
|
|
||||||
if (!input.ok()) {
|
if (!input.ok()) {
|
||||||
return input.status();
|
return input.status();
|
||||||
|
@ -96,7 +96,7 @@ inline uint8_t BlendOnBlack(const uint8_t val, const uint8_t alpha) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modified version of ReadPNG from original guetzli.cc
|
// Modified version of ReadPNG from original guetzli.cc
|
||||||
sapi::StatusOr<ImageData> ReadPNG(const std::string& data) {
|
absl::StatusOr<ImageData> ReadPNG(const std::string& data) {
|
||||||
std::vector<uint8_t> rgb;
|
std::vector<uint8_t> rgb;
|
||||||
int xsize, ysize;
|
int xsize, ysize;
|
||||||
png_structp png_ptr =
|
png_structp png_ptr =
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
#include "guetzli_transaction.h" // NOLINT(build/include)
|
#include "guetzli_transaction.h" // NOLINT(build/include)
|
||||||
#include "sandboxed_api/sandbox2/util/fileops.h"
|
#include "sandboxed_api/sandbox2/util/fileops.h"
|
||||||
#include "sandboxed_api/util/statusor.h"
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ TEST_F(GuetzliSapiTest, ProcessRGB) {
|
||||||
*processing_params.mutable_data() = {
|
*processing_params.mutable_data() = {
|
||||||
in_fd.GetRemoteFd(), 0, kDefaultQualityTarget, kDefaultMemlimitMb};
|
in_fd.GetRemoteFd(), 0, kDefaultQualityTarget, kDefaultMemlimitMb};
|
||||||
sapi::v::LenVal output(0);
|
sapi::v::LenVal output(0);
|
||||||
sapi::StatusOr<bool> processing_result =
|
absl::StatusOr<bool> processing_result =
|
||||||
api_->ProcessRgb(processing_params.PtrBefore(), output.PtrBoth());
|
api_->ProcessRgb(processing_params.PtrBefore(), output.PtrBoth());
|
||||||
ASSERT_TRUE(processing_result.value_or(false)) << "Error processing rgb data";
|
ASSERT_TRUE(processing_result.value_or(false)) << "Error processing rgb data";
|
||||||
std::string reference_data =
|
std::string reference_data =
|
||||||
|
@ -108,7 +108,7 @@ TEST_F(GuetzliSapiTest, ProcessJpeg) {
|
||||||
*processing_params.mutable_data() = {
|
*processing_params.mutable_data() = {
|
||||||
in_fd.GetRemoteFd(), 0, kDefaultQualityTarget, kDefaultMemlimitMb};
|
in_fd.GetRemoteFd(), 0, kDefaultQualityTarget, kDefaultMemlimitMb};
|
||||||
sapi::v::LenVal output(0);
|
sapi::v::LenVal output(0);
|
||||||
sapi::StatusOr<bool> processing_result =
|
absl::StatusOr<bool> processing_result =
|
||||||
api_->ProcessJpeg(processing_params.PtrBefore(), output.PtrBoth());
|
api_->ProcessJpeg(processing_params.PtrBefore(), output.PtrBoth());
|
||||||
ASSERT_TRUE(processing_result.value_or(false)) << "Error processing jpg data";
|
ASSERT_TRUE(processing_result.value_or(false)) << "Error processing jpg data";
|
||||||
std::string reference_data =
|
std::string reference_data =
|
||||||
|
|
|
@ -99,7 +99,7 @@ absl::Status GuetzliTransaction::LinkOutFile(int out_fd) const {
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
sapi::StatusOr<ImageType> GuetzliTransaction::GetImageTypeFromFd(int fd) const {
|
absl::StatusOr<ImageType> GuetzliTransaction::GetImageTypeFromFd(int fd) const {
|
||||||
static const unsigned char kPNGMagicBytes[] = {
|
static const unsigned char kPNGMagicBytes[] = {
|
||||||
0x89, 'P', 'N', 'G', '\r', '\n', 0x1a, '\n',
|
0x89, 'P', 'N', 'G', '\r', '\n', 0x1a, '\n',
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,7 +48,7 @@ class GuetzliTransaction : public sapi::Transaction {
|
||||||
absl::Status Main() final;
|
absl::Status Main() final;
|
||||||
|
|
||||||
absl::Status LinkOutFile(int out_fd) const;
|
absl::Status LinkOutFile(int out_fd) const;
|
||||||
sapi::StatusOr<ImageType> GetImageTypeFromFd(int fd) const;
|
absl::StatusOr<ImageType> GetImageTypeFromFd(int fd) const;
|
||||||
|
|
||||||
const TransactionParams params_;
|
const TransactionParams params_;
|
||||||
ImageType image_type_ = ImageType::kJpeg;
|
ImageType image_type_ = ImageType::kJpeg;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user