Use _putenv_s for Windows in test helpers
Rename MultiProgressPrinter::GetJob() to GetProgressHook() because it
weirdly gives example_utils.cc(661,37): error C2039: 'GetJobA' is not
a member of 'WP2::MultiProgressPrinter' with MSVC.
Remove unnecessary WP2:: in example_utils.h.
BUG=358743382
Change-Id: Ic5f2faaaea0b3210f1762dd80cde4add1ce9b2f7
Reviewed-on: https://chromium-review.googlesource.com/c/codecs/libwebp2/+/5816810
Tested-by: WebM Builds <builds@webmproject.org>
Reviewed-by: Maryla Ustarroz-Calonge <maryla@google.com>
diff --git a/examples/cwp2.cc b/examples/cwp2.cc
index 59d0986..451ea4d 100644
--- a/examples/cwp2.cc
+++ b/examples/cwp2.cc
@@ -886,7 +886,7 @@
WP2::MultiProgressPrinter progress_printer;
if (report_progress) {
progress_printer.Init(/*num_jobs=*/1);
- params.config.progress_hook = progress_printer.GetJob(0);
+ params.config.progress_hook = progress_printer.GetProgressHook(0);
}
size_t out_size;
@@ -954,7 +954,8 @@
}
if (report_progress) {
- params.config.progress_hook = progress_printer.GetJob(job_index++);
+ params.config.progress_hook =
+ progress_printer.GetProgressHook(job_index++);
}
const bool write_to_memory =
diff --git a/examples/dwp2.cc b/examples/dwp2.cc
index f4ef1c3..196ba79 100644
--- a/examples/dwp2.cc
+++ b/examples/dwp2.cc
@@ -389,8 +389,9 @@
std::string standard_out, standard_err;
const WP2Status status = DecodeAndSaveImage(
in_path, &standard_out, &standard_err,
- settings_.report_progress ? progress_printer_->GetJob(image_index)
- : nullptr);
+ settings_.report_progress
+ ? progress_printer_->GetProgressHook(image_index)
+ : nullptr);
if (!settings_.quiet && !settings_.report_progress) {
// Acquire mutex to be sure to print in order without mixing lines.
diff --git a/examples/example_utils.h b/examples/example_utils.h
index 949a4f2..9d05cf8 100644
--- a/examples/example_utils.h
+++ b/examples/example_utils.h
@@ -111,17 +111,17 @@
static const char* const kMetricNames[] = {"PSNR", "PSNRHVS", "PSNR_YUV",
"SSIM", "SSIM_YUV", "MSSSSIM_orig",
"MSSSIM", "LSIM"};
-STATIC_ASSERT_ARRAY_SIZE(kMetricNames, WP2::NUM_METRIC_TYPES);
+STATIC_ASSERT_ARRAY_SIZE(kMetricNames, NUM_METRIC_TYPES);
// Computes and prints the distortion of the compressed image stored in 'data'
// compared to 'refs' (single image or several frames if it's an animation).
-WP2Status PrintDistortion(const std::vector<WP2::ArgbBuffer>& refs,
+WP2Status PrintDistortion(const std::vector<ArgbBuffer>& refs,
const uint8_t* data, size_t data_size,
- WP2::MetricType metric, bool short_output);
+ MetricType metric, bool short_output);
// One-liner for still images because ArgbBuffer doesn't provide a copy ctor.
-WP2Status PrintDistortion(const WP2::ArgbBuffer& ref, const uint8_t* data,
- size_t data_size, WP2::MetricType metric,
+WP2Status PrintDistortion(const ArgbBuffer& ref, const uint8_t* data,
+ size_t data_size, MetricType metric,
bool short_output);
//------------------------------------------------------------------------------
@@ -186,7 +186,7 @@
for (const auto& p : v.second.histo) counts[p.first] = p.second;
// Display the type and entropy.
const float entropy =
- WP2::ANSCountsCost(counts.data(), counts.size()) / byte_factor;
+ ANSCountsCost(counts.data(), counts.size()) / byte_factor;
constexpr const char* types[] = {"Bit", "ABit", "RValue",
"UValue", "ASymbol", "Symbol"};
fprintf(stderr, "%*s %s, entr: %.1f %s [", 5, "",
@@ -216,8 +216,8 @@
}
}
-static inline void PrintBitTraces(const WP2::DecoderInfo& info,
- size_t data_size, bool sort_values = true,
+static inline void PrintBitTraces(const DecoderInfo& info, size_t data_size,
+ bool sort_values = true,
bool use_bytes = false,
bool show_histograms = false,
bool short_version = false,
@@ -227,7 +227,7 @@
for (const auto& p : info.bit_traces) {
int level = bit_trace_level;
if (p.first.find(ANSDec::kPrefixStr) == 0) {
- const std::string str = p.first.substr(strlen(WP2::ANSDec::kPrefixStr));
+ const std::string str = p.first.substr(strlen(ANSDec::kPrefixStr));
// The number of calls for a cluster is roughly the number of times a
// prefix was added.
acc[str].num_occurrences += p.second.num_occurrences;
@@ -347,16 +347,16 @@
// Read the 'partition' from the file located at 'file_path'. Returns true in
// case of success (or if the file can not be opened and 'read_only' is true).
bool ReadPartition(const char file_path[], bool read_only,
- std::vector<WP2::Rectangle>* partition);
+ std::vector<Rectangle>* partition);
// Adapts the 'partition' by either ignoring blocks that are not part of the
// 'partition_set' or by splitting them until they do.
void ConvertPartition(uint32_t pic_width, uint32_t pic_height,
- WP2::PartitionSet partition_set, bool ignore_invalid,
- std::vector<WP2::Rectangle>* partition);
+ PartitionSet partition_set, bool ignore_invalid,
+ std::vector<Rectangle>* partition);
// Writes the 'partition' to the file located at 'file_path'.
-bool WritePartition(const std::vector<WP2::Rectangle>& partition,
+bool WritePartition(const std::vector<Rectangle>& partition,
const char file_path[]);
static const char* const kPartitionSetString[] = {
@@ -392,7 +392,7 @@
// Parses the "main" argument for a metric option.
// Leaves type untouched if nothing was found. Returns true if one was found.
WP2_NO_DISCARD
- static bool ParseMetricOptions(const char* arg, WP2::MetricType* type);
+ static bool ParseMetricOptions(const char* arg, MetricType* type);
// Parses the 'main' argument for memory-related option.
// Returns true if some memory-related options were parsed, false otherwise.
WP2_NO_DISCARD
@@ -410,10 +410,10 @@
static constexpr double kNumSecondsBetweenPrints = 5.;
void Init(uint32_t num_jobs);
- WP2::ProgressHook* GetJob(uint32_t index) { return &jobs_[index]; }
+ ProgressHook* GetProgressHook(uint32_t index) { return &jobs_[index]; }
private:
- class Job : public WP2::ProgressHook {
+ class Job : public ProgressHook {
public:
Job(MultiProgressPrinter* parent, uint32_t index)
: parent_(parent), index_(index) {}
@@ -429,7 +429,7 @@
void OnUpdate(bool job_just_finished);
std::vector<Job> jobs_;
- WP2::ThreadLock lock_;
+ ThreadLock lock_;
bool started_;
double last_timestamp_;
uint32_t num_finished_jobs_;
diff --git a/tests/include/helpers.cc b/tests/include/helpers.cc
index 8935c17..c436611 100644
--- a/tests/include/helpers.cc
+++ b/tests/include/helpers.cc
@@ -75,7 +75,13 @@
public:
Environment(const char* name, const char* value)
: name_(name), value_(value) {}
- void SetUp() override { setenv(name_, value_, 1); }
+ void SetUp() override {
+#ifdef _WIN32
+ _putenv_s(name_, value_);
+#else
+ setenv(name_, value_, 1);
+#endif
+ }
private:
const char* name_;