From 8b36b3e5affa748884abf42116c6d4df4a1797e9 Mon Sep 17 00:00:00 2001 From: Alexandra Latysheva Date: Sat, 26 Sep 2020 11:27:13 +0000 Subject: [PATCH] clang-format again --- .../libtiff/example/main_sandboxed.cc | 114 +++---- oss-internship-2020/libtiff/formated.cc | 305 ++++++++++++++++++ .../libtiff/short_test.tif9veSQm | Bin 0 -> 306 bytes oss-internship-2020/libtiff/test/check_tag.h | 2 +- .../libtiff/test/defer_strile_writing.cc | 6 +- oss-internship-2020/libtiff/test/helper.cc | 6 +- oss-internship-2020/libtiff/test/long_tag.cc | 8 +- .../libtiff/test/raw_decode.cc | 12 +- oss-internship-2020/libtiff/test/short_tag.cc | 35 +- oss-internship-2020/libtiff/wrapper/func.h | 2 +- 10 files changed, 387 insertions(+), 103 deletions(-) create mode 100644 oss-internship-2020/libtiff/formated.cc create mode 100644 oss-internship-2020/libtiff/short_test.tif9veSQm diff --git a/oss-internship-2020/libtiff/example/main_sandboxed.cc b/oss-internship-2020/libtiff/example/main_sandboxed.cc index fe59e8b..08a0cc1 100644 --- a/oss-internship-2020/libtiff/example/main_sandboxed.cc +++ b/oss-internship-2020/libtiff/example/main_sandboxed.cc @@ -12,11 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include -#include #include #include +#include +#include #include "../sandboxed.h" #include "sandboxed_api/sandbox2/util/fileops.h" @@ -47,21 +46,11 @@ absl::Status CheckCluster(int cluster, const sapi::v::Array& buffer, return absl::OkStatus(); } - std::cerr << "Cluster " << cluster << " did not match expected results.\n" - << "Expect: " << expected_cluster[0] << "\t" << expected_cluster[1] - << "\t" << expected_cluster[4] << "\t" << expected_cluster[5] - << "\t" << expected_cluster[2] << "\t" << expected_cluster[3] - << "\n" - << "Got: " << target[0] << "\t" << target[1] << "\t" << target[4] - << "\t" << target[5] << "\t" << target[2] << "\t" << target[3] - << '\n'; - - return absl::InternalError(absl::StrCat( - "Cluster ", cluster, " did not match expected results.\n", "Expect: ", - expected_cluster[0], "\t", expected_cluster[1], "\t", expected_cluster[4], - "\t", expected_cluster[5], "\t", expected_cluster[2], "\t", - expected_cluster[3], "\n" - )); + return absl::InternalError( + absl::StrCat("Cluster ", cluster, " did not match expected results.\n", + "Expect: ", expected_cluster[0], "\t", expected_cluster[1], + "\t", expected_cluster[4], "\t", expected_cluster[5], "\t", + expected_cluster[2], "\t", expected_cluster[3], "\n")); } absl::Status CheckRgbPixel(int pixel, int min_red, int max_red, int min_green, @@ -75,11 +64,10 @@ absl::Status CheckRgbPixel(int pixel, int min_red, int max_red, int min_green, } return absl::InternalError(absl::StrCat( - "Pixel ", pixel, " did not match expected results.\n", "Got R=", rgb[0], - " (expected ", min_red, "..", max_red, "), G=", rgb[1], " (expected ", - min_green, "..", max_green, "), B=", rgb[2], " (expected ", min_blue, "..", - max_blue, ")\n" - )); + "Pixel ", pixel, " did not match expected results.\n", "Got R=", rgb[0], + " (expected ", min_red, "..", max_red, "), G=", rgb[1], " (expected ", + min_green, "..", max_green, "), B=", rgb[2], " (expected ", min_blue, + "..", max_blue, ")\n")); } absl::Status CheckRgbaPixel(int pixel, int min_red, int max_red, int min_green, @@ -101,15 +89,14 @@ absl::Status CheckRgbaPixel(int pixel, int min_red, int max_red, int min_green, } return absl::InternalError(absl::StrCat( - "Pixel ", pixel, " did not match expected results.\n", "Got R=", - TIFFGetR(rgba), " (expected ", min_red, "..", max_red, "), G=", - TIFFGetG(rgba), " (expected ", min_green, "..", max_green, "), B=", - TIFFGetB(rgba), " (expected ", min_blue, "..", max_blue, "), A=", - TIFFGetA(rgba), " (expected ", min_alpha, "..", max_alpha, ")\n" - )); + "Pixel ", pixel, " did not match expected results.\n", + "Got R=", TIFFGetR(rgba), " (expected ", min_red, "..", max_red, + "), G=", TIFFGetG(rgba), " (expected ", min_green, "..", max_green, + "), B=", TIFFGetB(rgba), " (expected ", min_blue, "..", max_blue, "), A=", + TIFFGetA(rgba), " (expected ", min_alpha, "..", max_alpha, ")\n")); } -} // namespace +} // namespace std::string GetFilePath(const std::string& dir, const std::string& filename) { return sandbox2::file::JoinPath(dir, "test", "images", filename); @@ -155,7 +142,7 @@ absl::Status LibTIFFMain(const std::string& srcfile) { sapi::v::ConstCStr r_var("r"); SAPI_ASSIGN_OR_RETURN( - status_or_tif, api.TIFFOpen(srcfile_var.PtrBefore(), r_var.PtrBefore())); + status_or_tif, api.TIFFOpen(srcfile_var.PtrBefore(), r_var.PtrBefore())); sapi::v::RemotePtr tif(status_or_tif.value()); if (!tif.GetValue()) { @@ -163,30 +150,27 @@ absl::Status LibTIFFMain(const std::string& srcfile) { return absl::InternalError(absl::StrCat("Could not open ", srcfile)); } - SAPI_ASSIGN_OR_RETURN( - status_or_int, api.TIFFGetField2(&tif, TIFFTAG_YCBCRSUBSAMPLING, - h.PtrBoth(), v.PtrBoth())); + SAPI_ASSIGN_OR_RETURN(status_or_int, + api.TIFFGetField2(&tif, TIFFTAG_YCBCRSUBSAMPLING, + h.PtrBoth(), v.PtrBoth())); if (status_or_int.value() == 0 || h.GetValue() != 2 || v.GetValue() != 2) { return absl::InternalError("Could not retrieve subsampling tag"); } - SAPI_ASSIGN_OR_RETURN( - status_or_long, api.TIFFTileSize(&tif)); + SAPI_ASSIGN_OR_RETURN(status_or_long, api.TIFFTileSize(&tif)); if (status_or_long.value() != 24576) { - return absl::InternalError(absl::StrCat("tiles are ", - status_or_long.value(), - " bytes\n")); + return absl::InternalError( + absl::StrCat("tiles are ", status_or_long.value(), " bytes\n")); } tsize_t sz = status_or_long.value(); sapi::v::Array buffer_(sz); SAPI_ASSIGN_OR_RETURN( - status_or_long, api.TIFFReadEncodedTile(&tif, 9, buffer_.PtrBoth(), sz)); + status_or_long, api.TIFFReadEncodedTile(&tif, 9, buffer_.PtrBoth(), sz)); if (status_or_long.value() != sz) { return absl::InternalError(absl::StrCat( - "Did not get expected result code from TIFFReadEncodedTile(): ", - status_or_long.value(), " instead of ", sz - )); + "Did not get expected result code from TIFFReadEncodedTile(): ", + status_or_long.value(), " instead of ", sz)); } unsigned pixel_status = 1; @@ -199,7 +183,7 @@ absl::Status LibTIFFMain(const std::string& srcfile) { LOG(ERROR) << "CheckCluster failed:\n" << status.ToString(); } pixel_status &= status.ok(); - + if (status = CheckCluster(128, buffer_, kCluster128); !status.ok()) { LOG(ERROR) << "CheckCluster failed:\n" << status.ToString(); } @@ -210,35 +194,31 @@ absl::Status LibTIFFMain(const std::string& srcfile) { } SAPI_ASSIGN_OR_RETURN( - status_or_int, api.TIFFSetFieldU1(&tif, TIFFTAG_JPEGCOLORMODE, - JPEGCOLORMODE_RGB)); + status_or_int, + api.TIFFSetFieldU1(&tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB)); if (!status_or_int.value()) { return absl::InternalError("TIFFSetFieldU1 not available"); } - SAPI_ASSIGN_OR_RETURN( - status_or_long, api.TIFFTileSize(&tif)); + SAPI_ASSIGN_OR_RETURN(status_or_long, api.TIFFTileSize(&tif)); if (status_or_long.value() != 128 * 128 * 3) { - return absl::InternalError(absl::StrCat("tiles are ", - status_or_long.value(), - " bytes")); + return absl::InternalError( + absl::StrCat("tiles are ", status_or_long.value(), " bytes")); } sz = status_or_long.value(); sapi::v::Array buffer2_(sz); SAPI_ASSIGN_OR_RETURN( - status_or_long, api.TIFFReadEncodedTile(&tif, 9, buffer2_.PtrBoth(), sz)); + status_or_long, api.TIFFReadEncodedTile(&tif, 9, buffer2_.PtrBoth(), sz)); if (status_or_long.value() != sz) { return absl::InternalError(absl::StrCat( - "Did not get expected result code from TIFFReadEncodedTile(): ", - status_or_long.value(), " instead of ", sz - )); + "Did not get expected result code from TIFFReadEncodedTile(): ", + status_or_long.value(), " instead of ", sz)); } pixel_status = 1; - if (status = CheckRgbPixel(0, 15, 18, 0, 0, 18, 41, buffer2_); - !status.ok()) { + if (status = CheckRgbPixel(0, 15, 18, 0, 0, 18, 41, buffer2_); !status.ok()) { LOG(ERROR) << "CheckRgbPixel failed:\n" << status.ToString(); } pixel_status &= status.ok(); @@ -247,7 +227,7 @@ absl::Status LibTIFFMain(const std::string& srcfile) { LOG(ERROR) << "CheckRgbPixel failed:\n" << status.ToString(); } pixel_status &= status.ok(); - + if (status = CheckRgbPixel(512, 5, 6, 34, 36, 182, 196, buffer2_); !status.ok()) { LOG(ERROR) << "CheckRgbPixel failed:\n" << status.ToString(); @@ -257,7 +237,7 @@ absl::Status LibTIFFMain(const std::string& srcfile) { SAPI_RETURN_IF_ERROR(api.TIFFClose(&tif)); SAPI_ASSIGN_OR_RETURN( - status_or_tif, api.TIFFOpen(srcfile_var.PtrBefore(), r_var.PtrBefore())); + status_or_tif, api.TIFFOpen(srcfile_var.PtrBefore(), r_var.PtrBefore())); sapi::v::RemotePtr tif2(status_or_tif.value()); if (!tif2.GetValue()) { // tif is NULL @@ -266,8 +246,9 @@ absl::Status LibTIFFMain(const std::string& srcfile) { sapi::v::Array rgba_buffer_(128 * 128); - SAPI_ASSIGN_OR_RETURN(status_or_int, - api.TIFFReadRGBATile(&tif2, 1 * 128, 2 * 128, rgba_buffer_.PtrBoth())); + SAPI_ASSIGN_OR_RETURN( + status_or_int, + api.TIFFReadRGBATile(&tif2, 1 * 128, 2 * 128, rgba_buffer_.PtrBoth())); if (!status_or_int.value()) { return absl::InternalError("TIFFReadRGBATile() returned failure code"); } @@ -283,9 +264,10 @@ absl::Status LibTIFFMain(const std::string& srcfile) { LOG(ERROR) << "CheckRgbaPixel failed:\n" << status.ToString(); } pixel_status &= status.ok(); - - if (status = CheckRgbaPixel(512, 5, 6, 34, 36, 182, 196, 255, 255, - rgba_buffer_); !status.ok()) { + + if (status = + CheckRgbaPixel(512, 5, 6, 34, 36, 182, 196, 255, 255, rgba_buffer_); + !status.ok()) { LOG(ERROR) << "CheckRgbaPixel failed:\n" << status.ToString(); } pixel_status &= status.ok(); @@ -314,8 +296,8 @@ int main(int argc, char** argv) { auto status = LibTIFFMain(srcfile); if (!status.ok()) { - LOG(ERROR) - << "LibTIFFMain failed with error:\n" << status.ToString() << '\n'; + LOG(ERROR) << "LibTIFFMain failed with error:\n" + << status.ToString() << '\n'; return EXIT_FAILURE; } diff --git a/oss-internship-2020/libtiff/formated.cc b/oss-internship-2020/libtiff/formated.cc new file mode 100644 index 0000000..08a0cc1 --- /dev/null +++ b/oss-internship-2020/libtiff/formated.cc @@ -0,0 +1,305 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include +#include + +#include "../sandboxed.h" +#include "sandboxed_api/sandbox2/util/fileops.h" +#include "sandboxed_api/sandbox2/util/path.h" +#include "sandboxed_api/vars.h" +#include "tiffio.h" // NOLINT(build/include) + +// sapi functions: +// TIFFTileSize +// TIFFOpen +// TIFFReadEncodedTile +// TIFFSetField +// TIFFClose +// TIFFReadRGBATile +// TIFFGetField + +constexpr std::array kCluster0 = {0, 0, 2, 0, 138, 139}; +constexpr std::array kCluster64 = {0, 0, 9, 6, 134, 119}; +constexpr std::array kCluster128 = {44, 40, 63, 59, 230, 95}; + +namespace { + +absl::Status CheckCluster(int cluster, const sapi::v::Array& buffer, + const std::array& expected_cluster) { + uint8_t* target = buffer.GetData() + cluster * 6; + + if (!std::memcmp(target, expected_cluster.data(), 6)) { + return absl::OkStatus(); + } + + return absl::InternalError( + absl::StrCat("Cluster ", cluster, " did not match expected results.\n", + "Expect: ", expected_cluster[0], "\t", expected_cluster[1], + "\t", expected_cluster[4], "\t", expected_cluster[5], "\t", + expected_cluster[2], "\t", expected_cluster[3], "\n")); +} + +absl::Status CheckRgbPixel(int pixel, int min_red, int max_red, int min_green, + int max_green, int min_blue, int max_blue, + const sapi::v::Array& buffer) { + uint8_t* rgb = buffer.GetData() + 3 * pixel; + + if (rgb[0] >= min_red && rgb[0] <= max_red && rgb[1] >= min_green && + rgb[1] <= max_green && rgb[2] >= min_blue && rgb[2] <= max_blue) { + return absl::OkStatus(); + } + + return absl::InternalError(absl::StrCat( + "Pixel ", pixel, " did not match expected results.\n", "Got R=", rgb[0], + " (expected ", min_red, "..", max_red, "), G=", rgb[1], " (expected ", + min_green, "..", max_green, "), B=", rgb[2], " (expected ", min_blue, + "..", max_blue, ")\n")); +} + +absl::Status CheckRgbaPixel(int pixel, int min_red, int max_red, int min_green, + int max_green, int min_blue, int max_blue, + int min_alpha, int max_alpha, + const sapi::v::Array& buffer) { + // RGBA images are upside down - adjust for normal ordering + int adjusted_pixel = pixel % 128 + (127 - (pixel / 128)) * 128; + uint32 rgba = buffer[adjusted_pixel]; + + if (TIFFGetR(rgba) >= (uint32)min_red && TIFFGetR(rgba) <= (uint32)max_red && + TIFFGetG(rgba) >= (uint32)min_green && + TIFFGetG(rgba) <= (uint32)max_green && + TIFFGetB(rgba) >= (uint32)min_blue && + TIFFGetB(rgba) <= (uint32)max_blue && + TIFFGetA(rgba) >= (uint32)min_alpha && + TIFFGetA(rgba) <= (uint32)max_alpha) { + return absl::OkStatus(); + } + + return absl::InternalError(absl::StrCat( + "Pixel ", pixel, " did not match expected results.\n", + "Got R=", TIFFGetR(rgba), " (expected ", min_red, "..", max_red, + "), G=", TIFFGetG(rgba), " (expected ", min_green, "..", max_green, + "), B=", TIFFGetB(rgba), " (expected ", min_blue, "..", max_blue, "), A=", + TIFFGetA(rgba), " (expected ", min_alpha, "..", max_alpha, ")\n")); +} + +} // namespace + +std::string GetFilePath(const std::string& dir, const std::string& filename) { + return sandbox2::file::JoinPath(dir, "test", "images", filename); +} + +std::string GetFilePath(const std::string filename) { + std::string cwd = sandbox2::file_util::fileops::GetCWD(); + auto find = cwd.rfind("build"); + + std::string project_path; + if (find == std::string::npos) { + LOG(ERROR) << "Something went wrong: CWD don't contain build dir. " + << "Please run tests from build dir or send project dir as a " + << "parameter: ./sandboxed /absolute/path/to/project/dir \n"; + project_path = cwd; + } else { + project_path = cwd.substr(0, find); + } + + return sandbox2::file::JoinPath(project_path, "test", "images", filename); +} + +absl::Status LibTIFFMain(const std::string& srcfile) { + // without addDir to sandbox. to add dir use + // sandbox(absolute_path_to_dir, srcfile) or + // sandbox(absolute_path_to_dir). file and dir should be exists. + // srcfile must also be absolute_path_to_file + TiffSapiSandbox sandbox("", srcfile); + + // initialize sapi vars after constructing TiffSapiSandbox + sapi::v::UShort h, v; + sapi::StatusOr status_or_tif; + sapi::StatusOr status_or_int; + sapi::StatusOr status_or_long; + absl::Status status; + + status = sandbox.Init(); + + SAPI_RETURN_IF_ERROR(sandbox.Init()); + + TiffApi api(&sandbox); + sapi::v::ConstCStr srcfile_var(srcfile.c_str()); + sapi::v::ConstCStr r_var("r"); + + SAPI_ASSIGN_OR_RETURN( + status_or_tif, api.TIFFOpen(srcfile_var.PtrBefore(), r_var.PtrBefore())); + + sapi::v::RemotePtr tif(status_or_tif.value()); + if (!tif.GetValue()) { + // tif is NULL + return absl::InternalError(absl::StrCat("Could not open ", srcfile)); + } + + SAPI_ASSIGN_OR_RETURN(status_or_int, + api.TIFFGetField2(&tif, TIFFTAG_YCBCRSUBSAMPLING, + h.PtrBoth(), v.PtrBoth())); + if (status_or_int.value() == 0 || h.GetValue() != 2 || v.GetValue() != 2) { + return absl::InternalError("Could not retrieve subsampling tag"); + } + + SAPI_ASSIGN_OR_RETURN(status_or_long, api.TIFFTileSize(&tif)); + if (status_or_long.value() != 24576) { + return absl::InternalError( + absl::StrCat("tiles are ", status_or_long.value(), " bytes\n")); + } + tsize_t sz = status_or_long.value(); + + sapi::v::Array buffer_(sz); + SAPI_ASSIGN_OR_RETURN( + status_or_long, api.TIFFReadEncodedTile(&tif, 9, buffer_.PtrBoth(), sz)); + if (status_or_long.value() != sz) { + return absl::InternalError(absl::StrCat( + "Did not get expected result code from TIFFReadEncodedTile(): ", + status_or_long.value(), " instead of ", sz)); + } + + unsigned pixel_status = 1; + if (status = CheckCluster(0, buffer_, kCluster0); !status.ok()) { + LOG(ERROR) << "CheckCluster failed:\n" << status.ToString(); + } + pixel_status &= status.ok(); + + if (status = CheckCluster(64, buffer_, kCluster64); !status.ok()) { + LOG(ERROR) << "CheckCluster failed:\n" << status.ToString(); + } + pixel_status &= status.ok(); + + if (status = CheckCluster(128, buffer_, kCluster128); !status.ok()) { + LOG(ERROR) << "CheckCluster failed:\n" << status.ToString(); + } + pixel_status &= status.ok(); + + if (!pixel_status) { + return absl::InternalError("unexpected pixel_status value"); + } + + SAPI_ASSIGN_OR_RETURN( + status_or_int, + api.TIFFSetFieldU1(&tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB)); + if (!status_or_int.value()) { + return absl::InternalError("TIFFSetFieldU1 not available"); + } + + SAPI_ASSIGN_OR_RETURN(status_or_long, api.TIFFTileSize(&tif)); + if (status_or_long.value() != 128 * 128 * 3) { + return absl::InternalError( + absl::StrCat("tiles are ", status_or_long.value(), " bytes")); + } + sz = status_or_long.value(); + + sapi::v::Array buffer2_(sz); + + SAPI_ASSIGN_OR_RETURN( + status_or_long, api.TIFFReadEncodedTile(&tif, 9, buffer2_.PtrBoth(), sz)); + if (status_or_long.value() != sz) { + return absl::InternalError(absl::StrCat( + "Did not get expected result code from TIFFReadEncodedTile(): ", + status_or_long.value(), " instead of ", sz)); + } + + pixel_status = 1; + if (status = CheckRgbPixel(0, 15, 18, 0, 0, 18, 41, buffer2_); !status.ok()) { + LOG(ERROR) << "CheckRgbPixel failed:\n" << status.ToString(); + } + pixel_status &= status.ok(); + + if (status = CheckRgbPixel(64, 0, 0, 0, 0, 0, 2, buffer2_); !status.ok()) { + LOG(ERROR) << "CheckRgbPixel failed:\n" << status.ToString(); + } + pixel_status &= status.ok(); + + if (status = CheckRgbPixel(512, 5, 6, 34, 36, 182, 196, buffer2_); + !status.ok()) { + LOG(ERROR) << "CheckRgbPixel failed:\n" << status.ToString(); + } + pixel_status &= status.ok(); + + SAPI_RETURN_IF_ERROR(api.TIFFClose(&tif)); + + SAPI_ASSIGN_OR_RETURN( + status_or_tif, api.TIFFOpen(srcfile_var.PtrBefore(), r_var.PtrBefore())); + + sapi::v::RemotePtr tif2(status_or_tif.value()); + if (!tif2.GetValue()) { // tif is NULL + return absl::InternalError(absl::StrCat("Could not reopen ", srcfile)); + } + + sapi::v::Array rgba_buffer_(128 * 128); + + SAPI_ASSIGN_OR_RETURN( + status_or_int, + api.TIFFReadRGBATile(&tif2, 1 * 128, 2 * 128, rgba_buffer_.PtrBoth())); + if (!status_or_int.value()) { + return absl::InternalError("TIFFReadRGBATile() returned failure code"); + } + + if (status = CheckRgbaPixel(0, 15, 18, 0, 0, 18, 41, 255, 255, rgba_buffer_); + !status.ok()) { + LOG(ERROR) << "CheckRgbaPixel failed:\n" << status.ToString(); + } + pixel_status &= status.ok(); + + if (status = CheckRgbaPixel(64, 0, 0, 0, 0, 0, 2, 255, 255, rgba_buffer_); + !status.ok()) { + LOG(ERROR) << "CheckRgbaPixel failed:\n" << status.ToString(); + } + pixel_status &= status.ok(); + + if (status = + CheckRgbaPixel(512, 5, 6, 34, 36, 182, 196, 255, 255, rgba_buffer_); + !status.ok()) { + LOG(ERROR) << "CheckRgbaPixel failed:\n" << status.ToString(); + } + pixel_status &= status.ok(); + + SAPI_RETURN_IF_ERROR(api.TIFFClose(&tif2)); + + if (!pixel_status) { + return absl::InternalError("unexpected pixel_status value"); + } + + return absl::OkStatus(); +} + +int main(int argc, char** argv) { + gflags::ParseCommandLineFlags(&argc, &argv, true); + + std::string srcfile; + // "test/images/quad-tile.jpg.tiff" + std::string srcfilerel = "quad-tile.jpg.tiff"; + + if (argc < 2) { + srcfile = GetFilePath(srcfilerel); + } else { + srcfile = GetFilePath(argv[1], srcfilerel); + } + + auto status = LibTIFFMain(srcfile); + if (!status.ok()) { + LOG(ERROR) << "LibTIFFMain failed with error:\n" + << status.ToString() << '\n'; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/oss-internship-2020/libtiff/short_test.tif9veSQm b/oss-internship-2020/libtiff/short_test.tif9veSQm new file mode 100644 index 0000000000000000000000000000000000000000..a4236085fa93b3de51eb546ea2e6d495a2b0d85a GIT binary patch literal 306 zcmYj~!3x4K5JYDaksv+Pf~|@NPesL_@K_KL{GfibUr=Y_9yUwZm)XheG~LjEXI{_) zmSKF<8#s|O^&ngvcY*uhAKWj`p1S&(yAIAH`4s#YXYIX` o)s6LV1{OSn=jE*2w|fd&e8|%7% #include "helper.h" -#include "tiffio.h" +#include "tiffio.h" // NOLINT(build/include) void CheckShortField(TiffApi&, sapi::v::RemotePtr& tif, const ttag_t field, const uint16_t value); diff --git a/oss-internship-2020/libtiff/test/defer_strile_writing.cc b/oss-internship-2020/libtiff/test/defer_strile_writing.cc index 67ff3c3..f7da76f 100644 --- a/oss-internship-2020/libtiff/test/defer_strile_writing.cc +++ b/oss-internship-2020/libtiff/test/defer_strile_writing.cc @@ -15,7 +15,7 @@ #include #include "helper.h" -#include "tiffio.h" +#include "tiffio.h" // NOLINT(build/include) // sapi functions: // TIFFOpen @@ -35,7 +35,7 @@ // TIFFDeferStrileArrayWriting // TIFFForceStrileArrayWriting -namespace { +namespace { #define TBS 256 // kTileBufferSize constexpr uint16_t kWidth = 1; @@ -324,4 +324,4 @@ TEST(SandboxTest, DeferStrileWriting) { } } -} // namespace +} // namespace diff --git a/oss-internship-2020/libtiff/test/helper.cc b/oss-internship-2020/libtiff/test/helper.cc index b50fc1d..19d3c22 100644 --- a/oss-internship-2020/libtiff/test/helper.cc +++ b/oss-internship-2020/libtiff/test/helper.cc @@ -14,16 +14,14 @@ #include "helper.h" -#include - static auto* g_in_dir = new std::string(); std::string GetImagesDir() { std::string cwd = sandbox2::file_util::fileops::GetCWD(); auto find = cwd.rfind("/build"); if (find == std::string::npos) { - std::cerr << "Something went wrong: CWD don't contain build dir. " - << "Please run tests from build dir, path might be incorrect\n"; + LOG(ERROR) << "Something went wrong: CWD don't contain build dir. " + << "Please run tests from build dir, path might be incorrect\n"; return cwd + "/test/images"; } diff --git a/oss-internship-2020/libtiff/test/long_tag.cc b/oss-internship-2020/libtiff/test/long_tag.cc index e575ded..bc1b62a 100644 --- a/oss-internship-2020/libtiff/test/long_tag.cc +++ b/oss-internship-2020/libtiff/test/long_tag.cc @@ -13,10 +13,9 @@ // limitations under the License. #include -#include #include "check_tag.h" -#include "tiffio.h" +#include "tiffio.h" // NOLINT(build/include) // sapi functions: // TIFFWriteScanline @@ -34,7 +33,8 @@ struct LongTag { }; constexpr std::array kLongTags = { - {TIFFTAG_SUBFILETYPE, 1, FILETYPE_REDUCEDIMAGE | FILETYPE_PAGE | FILETYPE_MASK}}; + {TIFFTAG_SUBFILETYPE, 1, + FILETYPE_REDUCEDIMAGE | FILETYPE_PAGE | FILETYPE_MASK}}; #define SPP 3 // kSamplePerPixel constexpr unsigned kWidth = 1; constexpr unsigned kLength = 1; @@ -134,4 +134,4 @@ TEST(SandboxTest, LongTag) { unlink(srcfile.c_str()); } -} // namespace +} // namespace diff --git a/oss-internship-2020/libtiff/test/raw_decode.cc b/oss-internship-2020/libtiff/test/raw_decode.cc index d359316..9d9b311 100644 --- a/oss-internship-2020/libtiff/test/raw_decode.cc +++ b/oss-internship-2020/libtiff/test/raw_decode.cc @@ -17,7 +17,7 @@ #include "gtest/gtest.h" #include "helper.h" -#include "tiffio.h" +#include "tiffio.h" // NOLINT(build/include) // sapi functions: // TIFFOpen @@ -34,8 +34,8 @@ constexpr std::array kCluster0 = {0, 0, 2, 0, 138, 139}; constexpr std::array kCluster64 = {0, 0, 9, 6, 134, 119}; constexpr std::array kCluster128 = {44, 40, 63, 59, 230, 95}; -int CheckCluster(int cluster, const sapi::v::Array &buffer, - const std::array &expected_cluster) { +int CheckCluster(int cluster, const sapi::v::Array& buffer, + const std::array& expected_cluster) { uint8_t* target = buffer.GetData() + cluster * 6; bool comp = !(std::memcmp(target, expected_cluster.data(), 6) == 0); @@ -53,7 +53,7 @@ int CheckCluster(int cluster, const sapi::v::Array &buffer, int CheckRgbPixel(int pixel, int min_red, int max_red, int min_green, int max_green, int min_blue, int max_blue, - const sapi::v::Array &buffer) { + const sapi::v::Array& buffer) { uint8_t* rgb = buffer.GetData() + 3 * pixel; bool comp = @@ -71,7 +71,7 @@ int CheckRgbPixel(int pixel, int min_red, int max_red, int min_green, int CheckRgbaPixel(int pixel, int min_red, int max_red, int min_green, int max_green, int min_blue, int max_blue, int min_alpha, - int max_alpha, const sapi::v::Array &buffer) { + int max_alpha, const sapi::v::Array& buffer) { // RGBA images are upside down - adjust for normal ordering int adjusted_pixel = pixel % 128 + (127 - (pixel / 128)) * 128; unsigned rgba = buffer[adjusted_pixel]; @@ -196,4 +196,4 @@ TEST(SandboxTest, RawDecode) { EXPECT_THAT(pixel_status, IsFalse()) << "wrong encoding"; } -} // namespace +} // namespace diff --git a/oss-internship-2020/libtiff/test/short_tag.cc b/oss-internship-2020/libtiff/test/short_tag.cc index 5913d51..8d0d011 100644 --- a/oss-internship-2020/libtiff/test/short_tag.cc +++ b/oss-internship-2020/libtiff/test/short_tag.cc @@ -14,10 +14,9 @@ #include #include -#include #include "check_tag.h" -#include "tiffio.h" +#include "tiffio.h" // NOLINT(build/include) // sapi functions: // TIFFWriteScanline @@ -46,22 +45,22 @@ struct PairedTag { const std::array values; }; -constexpr std::array kShortSingleTags = {{ - {TIFFTAG_COMPRESSION, COMPRESSION_NONE}, - {TIFFTAG_FILLORDER, FILLORDER_MSB2LSB}, - {TIFFTAG_ORIENTATION, ORIENTATION_BOTRIGHT}, - {TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH}, - {TIFFTAG_MINSAMPLEVALUE, 23}, - {TIFFTAG_MAXSAMPLEVALUE, 241}, - {TIFFTAG_INKSET, INKSET_MULTIINK}, - {TIFFTAG_NUMBEROFINKS, SPP}, - {TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT}}}; +constexpr std::array kShortSingleTags = { + {{TIFFTAG_COMPRESSION, COMPRESSION_NONE}, + {TIFFTAG_FILLORDER, FILLORDER_MSB2LSB}, + {TIFFTAG_ORIENTATION, ORIENTATION_BOTRIGHT}, + {TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH}, + {TIFFTAG_MINSAMPLEVALUE, 23}, + {TIFFTAG_MAXSAMPLEVALUE, 241}, + {TIFFTAG_INKSET, INKSET_MULTIINK}, + {TIFFTAG_NUMBEROFINKS, SPP}, + {TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT}}}; -constexpr std::array kShortPairedTags = {{ - {TIFFTAG_PAGENUMBER, {1, 1}}, - {TIFFTAG_HALFTONEHINTS, {0, 255}}, - {TIFFTAG_DOTRANGE, {8, 16}}, - {TIFFTAG_YCBCRSUBSAMPLING, {2, 1}}}}; +constexpr std::array kShortPairedTags = { + {{TIFFTAG_PAGENUMBER, {1, 1}}, + {TIFFTAG_HALFTONEHINTS, {0, 255}}, + {TIFFTAG_DOTRANGE, {8, 16}}, + {TIFFTAG_YCBCRSUBSAMPLING, {2, 1}}}}; TEST(SandboxTest, ShortTag) { sapi::StatusOr status_or_path = @@ -171,4 +170,4 @@ TEST(SandboxTest, ShortTag) { ASSERT_THAT(api.TIFFClose(&tif2), IsOk()) << "TIFFClose fatal error"; } -} // namespace +} // namespace diff --git a/oss-internship-2020/libtiff/wrapper/func.h b/oss-internship-2020/libtiff/wrapper/func.h index 3115ddb..b056327 100644 --- a/oss-internship-2020/libtiff/wrapper/func.h +++ b/oss-internship-2020/libtiff/wrapper/func.h @@ -15,7 +15,7 @@ #ifndef LIBTIFF_WRAPPER_FUNC_H #define LIBTIFF_WRAPPER_FUNC_H -#include "tiffio.h" +#include "tiffio.h" // NOLINT(build/include) // wrapper for variadic functions TIFFGetField and TIFFSetField // s - signed