aboutsummaryrefslogtreecommitdiff
path: root/fxbarcode/common
diff options
context:
space:
mode:
Diffstat (limited to 'fxbarcode/common')
-rw-r--r--fxbarcode/common/BC_CommonBitMatrix.cpp36
-rw-r--r--fxbarcode/common/BC_CommonBitMatrix.h24
-rw-r--r--fxbarcode/common/BC_CommonByteMatrix.cpp33
-rw-r--r--fxbarcode/common/BC_CommonByteMatrix.h26
-rw-r--r--fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp14
-rw-r--r--fxbarcode/common/reedsolomon/BC_ReedSolomon.h2
-rw-r--r--fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp19
-rw-r--r--fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h6
-rw-r--r--fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp23
-rw-r--r--fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h2
10 files changed, 88 insertions, 97 deletions
diff --git a/fxbarcode/common/BC_CommonBitMatrix.cpp b/fxbarcode/common/BC_CommonBitMatrix.cpp
index 4cf07ed7d..92dd9170b 100644
--- a/fxbarcode/common/BC_CommonBitMatrix.cpp
+++ b/fxbarcode/common/BC_CommonBitMatrix.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -22,32 +22,24 @@
#include "fxbarcode/common/BC_CommonBitMatrix.h"
-#include <algorithm>
-#include <iterator>
+#include "core/fxcrt/fixed_zeroed_data_vector.h"
+#include "third_party/base/check_op.h"
-#include "third_party/base/stl_util.h"
-
-CBC_CommonBitMatrix::CBC_CommonBitMatrix() {}
-
-void CBC_CommonBitMatrix::Init(int32_t width, int32_t height) {
- m_width = width;
- m_height = height;
- m_rowSize = (width + 31) >> 5;
- m_bits = pdfium::Vector2D<int32_t>(m_rowSize, m_height);
+CBC_CommonBitMatrix::CBC_CommonBitMatrix(size_t width, size_t height)
+ : m_height(height), m_rowSize((width + 31) >> 5) {
+ static constexpr int32_t kMaxBits = 1024 * 1024 * 1024; // 1 Gb.
+ CHECK_LT(m_rowSize, kMaxBits / m_height);
+ m_bits = FixedZeroedDataVector<uint32_t>(m_rowSize * m_height);
}
CBC_CommonBitMatrix::~CBC_CommonBitMatrix() = default;
-bool CBC_CommonBitMatrix::Get(int32_t x, int32_t y) const {
- int32_t offset = y * m_rowSize + (x >> 5);
- if (offset >= m_rowSize * m_height || offset < 0)
- return false;
- return ((((uint32_t)m_bits[offset]) >> (x & 0x1f)) & 1) != 0;
+bool CBC_CommonBitMatrix::Get(size_t x, size_t y) const {
+ size_t offset = y * m_rowSize + (x >> 5);
+ return ((m_bits.span()[offset] >> (x & 0x1f)) & 1) != 0;
}
-void CBC_CommonBitMatrix::Set(int32_t x, int32_t y) {
- int32_t offset = y * m_rowSize + (x >> 5);
- ASSERT(offset >= 0);
- ASSERT(offset < m_rowSize * m_height);
- m_bits[offset] |= 1 << (x & 0x1f);
+void CBC_CommonBitMatrix::Set(size_t x, size_t y) {
+ size_t offset = y * m_rowSize + (x >> 5);
+ m_bits.writable_span()[offset] |= 1u << (x & 0x1f);
}
diff --git a/fxbarcode/common/BC_CommonBitMatrix.h b/fxbarcode/common/BC_CommonBitMatrix.h
index ce40ade8e..3dabe8ae4 100644
--- a/fxbarcode/common/BC_CommonBitMatrix.h
+++ b/fxbarcode/common/BC_CommonBitMatrix.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,27 +7,23 @@
#ifndef FXBARCODE_COMMON_BC_COMMONBITMATRIX_H_
#define FXBARCODE_COMMON_BC_COMMONBITMATRIX_H_
-#include <vector>
+#include <stddef.h>
+#include <stdint.h>
-#include "core/fxcrt/fx_system.h"
+#include "core/fxcrt/fixed_zeroed_data_vector.h"
class CBC_CommonBitMatrix {
public:
- CBC_CommonBitMatrix();
+ CBC_CommonBitMatrix(size_t width, size_t height);
~CBC_CommonBitMatrix();
- void Init(int32_t width, int32_t height);
-
- bool Get(int32_t x, int32_t y) const;
- void Set(int32_t x, int32_t y);
- int32_t GetWidth() const { return m_width; }
- int32_t GetHeight() const { return m_height; }
+ bool Get(size_t x, size_t y) const;
+ void Set(size_t x, size_t y);
private:
- int32_t m_width = 0;
- int32_t m_height = 0;
- int32_t m_rowSize = 0;
- std::vector<int32_t> m_bits;
+ const size_t m_height;
+ const size_t m_rowSize;
+ FixedZeroedDataVector<uint32_t> m_bits;
};
#endif // FXBARCODE_COMMON_BC_COMMONBITMATRIX_H_
diff --git a/fxbarcode/common/BC_CommonByteMatrix.cpp b/fxbarcode/common/BC_CommonByteMatrix.cpp
index a05fde014..ee02b45e8 100644
--- a/fxbarcode/common/BC_CommonByteMatrix.cpp
+++ b/fxbarcode/common/BC_CommonByteMatrix.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -23,28 +23,37 @@
#include <algorithm>
#include <iterator>
-#include "third_party/base/stl_util.h"
+#include <utility>
-CBC_CommonByteMatrix::CBC_CommonByteMatrix(int32_t width, int32_t height)
+#include "core/fxcrt/data_vector.h"
+#include "third_party/base/check_op.h"
+
+CBC_CommonByteMatrix::CBC_CommonByteMatrix(size_t width, size_t height)
: m_width(width), m_height(height) {
- m_bytes = pdfium::Vector2D<uint8_t>(m_height, m_width);
- clear(0xff);
+ static constexpr size_t kMaxBytes = 256 * 1024 * 1024; // 256 MB.
+ static constexpr uint8_t kDefaultFill = 0xff;
+ CHECK_LT(m_width, kMaxBytes / m_height);
+ m_bytes.resize(m_width * m_height, kDefaultFill);
}
CBC_CommonByteMatrix::~CBC_CommonByteMatrix() = default;
-uint8_t CBC_CommonByteMatrix::Get(int32_t x, int32_t y) const {
- return m_bytes[y * m_width + x];
+DataVector<uint8_t> CBC_CommonByteMatrix::TakeArray() {
+ return std::move(m_bytes);
}
-void CBC_CommonByteMatrix::Set(int32_t x, int32_t y, int32_t value) {
- m_bytes[y * m_width + x] = (uint8_t)value;
+uint8_t CBC_CommonByteMatrix::Get(size_t x, size_t y) const {
+ const size_t offset = y * m_width + x;
+ CHECK_LT(offset, m_bytes.size());
+ return m_bytes[offset];
}
-void CBC_CommonByteMatrix::Set(int32_t x, int32_t y, uint8_t value) {
- m_bytes[y * m_width + x] = value;
+void CBC_CommonByteMatrix::Set(size_t x, size_t y, uint8_t value) {
+ const size_t offset = y * m_width + x;
+ CHECK_LT(offset, m_bytes.size());
+ m_bytes[offset] = value;
}
-void CBC_CommonByteMatrix::clear(uint8_t value) {
+void CBC_CommonByteMatrix::Fill(uint8_t value) {
std::fill(std::begin(m_bytes), std::end(m_bytes), value);
}
diff --git a/fxbarcode/common/BC_CommonByteMatrix.h b/fxbarcode/common/BC_CommonByteMatrix.h
index c5a66a3e8..6ce611998 100644
--- a/fxbarcode/common/BC_CommonByteMatrix.h
+++ b/fxbarcode/common/BC_CommonByteMatrix.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,29 +9,27 @@
#include <stdint.h>
-#include <vector>
-
-#include "core/fxcrt/fx_system.h"
+#include "core/fxcrt/data_vector.h"
#include "third_party/base/span.h"
class CBC_CommonByteMatrix final {
public:
- CBC_CommonByteMatrix(int32_t width, int32_t height);
+ CBC_CommonByteMatrix(size_t width, size_t height);
~CBC_CommonByteMatrix();
- int32_t GetWidth() const { return m_width; }
- int32_t GetHeight() const { return m_height; }
+ size_t GetWidth() const { return m_width; }
+ size_t GetHeight() const { return m_height; }
pdfium::span<const uint8_t> GetArray() const { return m_bytes; }
- uint8_t Get(int32_t x, int32_t y) const;
+ DataVector<uint8_t> TakeArray();
- void Set(int32_t x, int32_t y, int32_t value);
- void Set(int32_t x, int32_t y, uint8_t value);
- void clear(uint8_t value);
+ uint8_t Get(size_t x, size_t y) const;
+ void Set(size_t x, size_t y, uint8_t value);
+ void Fill(uint8_t value);
private:
- int32_t m_width;
- int32_t m_height;
- std::vector<uint8_t> m_bytes;
+ const size_t m_width;
+ const size_t m_height;
+ DataVector<uint8_t> m_bytes;
};
#endif // FXBARCODE_COMMON_BC_COMMONBYTEMATRIX_H_
diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp b/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp
index f19886e6b..c1785f2f2 100644
--- a/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp
+++ b/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -27,23 +27,21 @@
#include "fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h"
#include "fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h"
-#include "third_party/base/ptr_util.h"
CBC_ReedSolomonEncoder::CBC_ReedSolomonEncoder(CBC_ReedSolomonGF256* field)
: m_field(field) {
- m_cachedGenerators.push_back(pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>(
- m_field.Get(), std::vector<int32_t>{1}));
+ m_cachedGenerators.push_back(std::make_unique<CBC_ReedSolomonGF256Poly>(
+ m_field, std::vector<int32_t>{1}));
}
-CBC_ReedSolomonEncoder::~CBC_ReedSolomonEncoder() {}
+CBC_ReedSolomonEncoder::~CBC_ReedSolomonEncoder() = default;
CBC_ReedSolomonGF256Poly* CBC_ReedSolomonEncoder::BuildGenerator(
size_t degree) {
if (degree >= m_cachedGenerators.size()) {
CBC_ReedSolomonGF256Poly* lastGenerator = m_cachedGenerators.back().get();
for (size_t d = m_cachedGenerators.size(); d <= degree; ++d) {
- CBC_ReedSolomonGF256Poly temp_poly(m_field.Get(),
- {1, m_field->Exp(d - 1)});
+ CBC_ReedSolomonGF256Poly temp_poly(m_field, {1, m_field->Exp(d - 1)});
auto nextGenerator = lastGenerator->Multiply(&temp_poly);
if (!nextGenerator)
return nullptr;
@@ -72,7 +70,7 @@ bool CBC_ReedSolomonEncoder::Encode(std::vector<int32_t>* toEncode,
for (size_t x = 0; x < dataBytes; x++)
infoCoefficients[x] = (*toEncode)[x];
- CBC_ReedSolomonGF256Poly info(m_field.Get(), infoCoefficients);
+ CBC_ReedSolomonGF256Poly info(m_field, infoCoefficients);
auto infoTemp = info.MultiplyByMonomial(ecBytes, 1);
if (!infoTemp)
return false;
diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomon.h b/fxbarcode/common/reedsolomon/BC_ReedSolomon.h
index 772ca3c04..fd8954ad2 100644
--- a/fxbarcode/common/reedsolomon/BC_ReedSolomon.h
+++ b/fxbarcode/common/reedsolomon/BC_ReedSolomon.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp
index f2d86b3bb..31e6c89b5 100644
--- a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp
+++ b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -25,7 +25,6 @@
#include <vector>
#include "fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h"
-#include "third_party/base/ptr_util.h"
CBC_ReedSolomonGF256::CBC_ReedSolomonGF256(int32_t primitive) {
int32_t x = 1;
@@ -43,13 +42,13 @@ CBC_ReedSolomonGF256::CBC_ReedSolomonGF256(int32_t primitive) {
}
void CBC_ReedSolomonGF256::Init() {
- m_zero = pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>(
- this, std::vector<int32_t>{0});
- m_one = pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>(this,
- std::vector<int32_t>{1});
+ m_zero =
+ std::make_unique<CBC_ReedSolomonGF256Poly>(this, std::vector<int32_t>{0});
+ m_one =
+ std::make_unique<CBC_ReedSolomonGF256Poly>(this, std::vector<int32_t>{1});
}
-CBC_ReedSolomonGF256::~CBC_ReedSolomonGF256() {}
+CBC_ReedSolomonGF256::~CBC_ReedSolomonGF256() = default;
std::unique_ptr<CBC_ReedSolomonGF256Poly> CBC_ReedSolomonGF256::BuildMonomial(
int32_t degree,
@@ -62,7 +61,7 @@ std::unique_ptr<CBC_ReedSolomonGF256Poly> CBC_ReedSolomonGF256::BuildMonomial(
std::vector<int32_t> coefficients(degree + 1);
coefficients[0] = coefficient;
- return pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>(this, coefficients);
+ return std::make_unique<CBC_ReedSolomonGF256Poly>(this, coefficients);
}
// static
@@ -74,9 +73,9 @@ int32_t CBC_ReedSolomonGF256::Exp(int32_t a) {
return m_expTable[a];
}
-Optional<int32_t> CBC_ReedSolomonGF256::Inverse(int32_t a) {
+absl::optional<int32_t> CBC_ReedSolomonGF256::Inverse(int32_t a) {
if (a == 0)
- return {};
+ return absl::nullopt;
return m_expTable[255 - m_logTable[a]];
}
diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h
index 30f552438..b4b4da81e 100644
--- a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h
+++ b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,7 +9,7 @@
#include <memory>
-#include "third_party/base/optional.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
class CBC_ReedSolomonGF256Poly;
@@ -25,7 +25,7 @@ class CBC_ReedSolomonGF256 {
int32_t coefficient);
static int32_t AddOrSubtract(int32_t a, int32_t b);
int32_t Exp(int32_t a);
- Optional<int32_t> Inverse(int32_t a);
+ absl::optional<int32_t> Inverse(int32_t a);
int32_t Multiply(int32_t a, int32_t b);
void Init();
diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp
index 43395022c..449d0a3ec 100644
--- a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp
+++ b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -26,16 +26,16 @@
#include <utility>
#include "core/fxcrt/fx_system.h"
+#include "core/fxcrt/stl_util.h"
#include "fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h"
-#include "third_party/base/ptr_util.h"
-#include "third_party/base/stl_util.h"
+#include "third_party/base/check.h"
CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly(
CBC_ReedSolomonGF256* field,
const std::vector<int32_t>& coefficients)
: m_field(field) {
- ASSERT(m_field);
- ASSERT(!coefficients.empty());
+ DCHECK(m_field);
+ DCHECK(!coefficients.empty());
if (coefficients.size() == 1 || coefficients.front() != 0) {
m_coefficients = coefficients;
return;
@@ -62,7 +62,7 @@ const std::vector<int32_t>& CBC_ReedSolomonGF256Poly::GetCoefficients() const {
}
int32_t CBC_ReedSolomonGF256Poly::GetDegree() const {
- return pdfium::CollectionSize<int32_t>(m_coefficients) - 1;
+ return fxcrt::CollectionSize<int32_t>(m_coefficients) - 1;
}
bool CBC_ReedSolomonGF256Poly::IsZero() const {
@@ -75,8 +75,7 @@ int32_t CBC_ReedSolomonGF256Poly::GetCoefficients(int32_t degree) const {
std::unique_ptr<CBC_ReedSolomonGF256Poly> CBC_ReedSolomonGF256Poly::Clone()
const {
- return pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>(m_field.Get(),
- m_coefficients);
+ return std::make_unique<CBC_ReedSolomonGF256Poly>(m_field, m_coefficients);
}
std::unique_ptr<CBC_ReedSolomonGF256Poly>
@@ -100,7 +99,7 @@ CBC_ReedSolomonGF256Poly::AddOrSubtract(const CBC_ReedSolomonGF256Poly* other) {
sumDiff[i] = CBC_ReedSolomonGF256::AddOrSubtract(
smallerCoefficients[i - lengthDiff], largerCoefficients[i]);
}
- return pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>(m_field.Get(), sumDiff);
+ return std::make_unique<CBC_ReedSolomonGF256Poly>(m_field, sumDiff);
}
std::unique_ptr<CBC_ReedSolomonGF256Poly> CBC_ReedSolomonGF256Poly::Multiply(
@@ -120,7 +119,7 @@ std::unique_ptr<CBC_ReedSolomonGF256Poly> CBC_ReedSolomonGF256Poly::Multiply(
product[i + j], m_field->Multiply(aCoeff, bCoefficients[j]));
}
}
- return pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>(m_field.Get(), product);
+ return std::make_unique<CBC_ReedSolomonGF256Poly>(m_field, product);
}
std::unique_ptr<CBC_ReedSolomonGF256Poly>
@@ -136,7 +135,7 @@ CBC_ReedSolomonGF256Poly::MultiplyByMonomial(int32_t degree,
for (size_t i = 0; i < size; i++)
product[i] = m_field->Multiply(m_coefficients[i], coefficient);
- return pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>(m_field.Get(), product);
+ return std::make_unique<CBC_ReedSolomonGF256Poly>(m_field, product);
}
std::unique_ptr<CBC_ReedSolomonGF256Poly> CBC_ReedSolomonGF256Poly::Divide(
@@ -152,7 +151,7 @@ std::unique_ptr<CBC_ReedSolomonGF256Poly> CBC_ReedSolomonGF256Poly::Divide(
return nullptr;
int32_t denominatorLeadingTerm = other->GetCoefficients(other->GetDegree());
- Optional<int32_t> inverseDenominatorLeadingTeam =
+ absl::optional<int32_t> inverseDenominatorLeadingTeam =
m_field->Inverse(denominatorLeadingTerm);
if (!inverseDenominatorLeadingTeam.has_value())
return nullptr;
diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h
index 7c3c7fc2f..e274c76d5 100644
--- a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h
+++ b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.