Fix some VS compilation errors in the encoder.

- Use std::numeric_limits<double>::infinity() instead of 1.0 / 0.0
  - Use FastLog2() instead of log2() in cost model
This commit is contained in:
Zoltan Szabadka 2015-06-29 14:20:25 +02:00
parent 9fa3016e66
commit 95ddb48a11

View File

@ -17,13 +17,15 @@
#include "./backward_references.h"
#include <algorithm>
#include <limits>
#include <vector>
#include "./command.h"
#include "./fast_log.h"
namespace brotli {
static const double kInfinity = 1.0 / 0.0;
static const double kInfinity = std::numeric_limits<double>::infinity();
// Histogram based cost model for zopflification.
class ZopfliCostModel {
@ -130,18 +132,19 @@ class ZopfliCostModel {
private:
void Set(const std::vector<int>& histogram, std::vector<double>* cost) {
cost->resize(histogram.size());
double sum = 0;
int sum = 0;
for (size_t i = 0; i < histogram.size(); i++) {
sum += histogram[i];
}
double log2sum = FastLog2(sum);
for (size_t i = 0; i < histogram.size(); i++) {
if (histogram[i] == 0) {
(*cost)[i] = -log2(0.25 / sum);
(*cost)[i] = log2sum + 2;
continue;
}
// Shannon bits for this symbol.
(*cost)[i] = -log2(histogram[i] / sum);
(*cost)[i] = log2sum - FastLog2(histogram[i]);
// Cannot be coded with less than 1 bit
if ((*cost)[i] < 1) (*cost)[i] = 1;