Codestyle fix

This commit is contained in:
Bohdan Tyshchenko 2020-08-19 01:21:30 -07:00
parent e99de21e95
commit 465cf9c4bb
4 changed files with 12 additions and 11 deletions

View File

@ -25,5 +25,8 @@ There are two different sets of unit tests which demonstrate how to use differen
* `tests/guetzli_sapi_test.cc` - example usage of Guetzli sandboxed API.
* `tests/guetzli_transaction_test.cc` - example usage of Guetzli transaction.
To run tests use following command:
`bazel test ...`
Also, there is an example of custom security policy for your sandbox in
`guetzli_sandbox.h`

View File

@ -154,7 +154,7 @@ sapi::StatusOr<ImageData> ReadPNG(const std::string& data) {
xsize = png_get_image_width(png_ptr, info_ptr);
ysize = png_get_image_height(png_ptr, info_ptr);
rgb.resize(3 * (xsize) * (ysize));
rgb.resize(3 * xsize * ysize);
const int components = png_get_channels(png_ptr, info_ptr);
switch (components) {
@ -162,7 +162,7 @@ sapi::StatusOr<ImageData> ReadPNG(const std::string& data) {
// GRAYSCALE
for (int y = 0; y < ysize; ++y) {
const uint8_t* row_in = row_pointers[y];
uint8_t* row_out = &(rgb)[3 * y * (xsize)];
uint8_t* row_out = &rgb[3 * y * xsize];
for (int x = 0; x < xsize; ++x) {
const uint8_t gray = row_in[x];
row_out[3 * x + 0] = gray;
@ -176,7 +176,7 @@ sapi::StatusOr<ImageData> ReadPNG(const std::string& data) {
// GRAYSCALE + ALPHA
for (int y = 0; y < ysize; ++y) {
const uint8_t* row_in = row_pointers[y];
uint8_t* row_out = &(rgb)[3 * y * (xsize)];
uint8_t* row_out = &rgb[3 * y * xsize];
for (int x = 0; x < xsize; ++x) {
const uint8_t gray = BlendOnBlack(row_in[2 * x], row_in[2 * x + 1]);
row_out[3 * x + 0] = gray;
@ -190,8 +190,8 @@ sapi::StatusOr<ImageData> ReadPNG(const std::string& data) {
// RGB
for (int y = 0; y < ysize; ++y) {
const uint8_t* row_in = row_pointers[y];
uint8_t* row_out = &(rgb)[3 * y * (xsize)];
memcpy(row_out, row_in, 3 * (xsize));
uint8_t* row_out = &rgb[3 * y * xsize];
memcpy(row_out, row_in, 3 * xsize);
}
break;
}
@ -199,7 +199,7 @@ sapi::StatusOr<ImageData> ReadPNG(const std::string& data) {
// RGBA
for (int y = 0; y < ysize; ++y) {
const uint8_t* row_in = row_pointers[y];
uint8_t* row_out = &(rgb)[3 * y * (xsize)];
uint8_t* row_out = &rgb[3 * y * xsize];
for (int x = 0; x < xsize; ++x) {
const uint8_t alpha = row_in[4 * x + 3];
row_out[3 * x + 0] = BlendOnBlack(row_in[4 * x + 0], alpha);

View File

@ -107,6 +107,7 @@ absl::Status GuetzliTransaction::LinkOutFile(int out_fd) const {
std::stringstream path;
path << "/proc/self/fd/" << out_fd;
if (linkat(AT_FDCWD, path.str().c_str(), AT_FDCWD, params_.out_file,
AT_SYMLINK_FOLLOW) < 0) {
std::stringstream error;

View File

@ -42,12 +42,11 @@ struct TransactionParams {
// Create a new one for each processing operation
class GuetzliTransaction : public sapi::Transaction {
public:
GuetzliTransaction(TransactionParams params)
GuetzliTransaction(TransactionParams params, int retry_count = 0)
: sapi::Transaction(std::make_unique<GuetzliSapiSandbox>())
, params_(std::move(params))
{
//TODO: Add retry count as a parameter
sapi::Transaction::set_retry_count(kDefaultTransactionRetryCount);
sapi::Transaction::set_retry_count(retry_count);
sapi::Transaction::SetTimeLimit(0); // Infinite time limit
}
@ -59,8 +58,6 @@ class GuetzliTransaction : public sapi::Transaction {
const TransactionParams params_;
ImageType image_type_ = ImageType::kJpeg;
static const int kDefaultTransactionRetryCount = 0;
};
} // namespace sandbox