summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_func.cpp10
-rw-r--r--core/fxcrt/fx_basic_util.cpp35
-rw-r--r--core/fxcrt/fx_basic_util_unittest.cpp (renamed from core/fxge/skia/fx_skia_device_unittest.cpp)15
-rw-r--r--core/fxcrt/include/fx_basic.h4
-rw-r--r--core/fxge/skia/fx_skia_device.cpp30
5 files changed, 44 insertions, 50 deletions
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_func.cpp b/core/fpdfapi/fpdf_page/fpdf_page_func.cpp
index c9b0ea236e..bb1d631576 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_func.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_func.cpp
@@ -8,6 +8,7 @@
#include <limits.h>
+#include <algorithm>
#include <memory>
#include <utility>
#include <vector>
@@ -504,15 +505,6 @@ FX_FLOAT PDF_Interpolate(FX_FLOAT x,
return ymin + (divisor ? (x - xmin) * (ymax - ymin) / divisor : 0);
}
-uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits) {
- int result = 0;
- for (int i = 0; i < nbits; i++) {
- if (pData[(bitpos + i) / 8] & (1 << (7 - (bitpos + i) % 8)))
- result |= 1 << (nbits - i - 1);
- }
- return result;
-}
-
class CPDF_PSFunc : public CPDF_Function {
public:
CPDF_PSFunc() : CPDF_Function(Type::kType4PostScript) {}
diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp
index aa36d56f38..2d3483e9b3 100644
--- a/core/fxcrt/fx_basic_util.cpp
+++ b/core/fxcrt/fx_basic_util.cpp
@@ -7,8 +7,6 @@
#include "core/fxcrt/include/fx_basic.h"
#include "core/fxcrt/include/fx_ext.h"
-#include <cctype>
-
#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
#include <dirent.h>
#include <sys/types.h>
@@ -16,6 +14,9 @@
#include <direct.h>
#endif
+#include <algorithm>
+#include <cctype>
+
CFX_PrivateData::CFX_PrivateData() {}
CFX_PrivateData::~CFX_PrivateData() {
@@ -364,3 +365,33 @@ CFX_Vector_3by1 CFX_Matrix_3by3::TransformVector(const CFX_Vector_3by1& v) {
d * v.a + e * v.b + f * v.c,
g * v.a + h * v.b + i * v.c);
}
+
+uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits) {
+ ASSERT(0 < nbits && nbits <= 32);
+ const uint8_t* dataPtr = &pData[bitpos / 8];
+ int bitShift;
+ int bitMask;
+ int dstShift;
+ int bitCount = bitpos & 0x07;
+ if (nbits < 8 && nbits + bitCount <= 8) {
+ bitShift = 8 - nbits - bitCount;
+ bitMask = (1 << nbits) - 1;
+ dstShift = 0;
+ } else {
+ bitShift = 0;
+ int bitOffset = 8 - bitCount;
+ bitMask = (1 << std::min(bitOffset, nbits)) - 1;
+ dstShift = nbits - bitOffset;
+ }
+ uint32_t result = (uint32_t)(*dataPtr++ >> bitShift & bitMask) << dstShift;
+ while (dstShift >= 8) {
+ dstShift -= 8;
+ result |= *dataPtr++ << dstShift;
+ }
+ if (dstShift > 0) {
+ bitShift = 8 - dstShift;
+ bitMask = (1 << dstShift) - 1;
+ result |= *dataPtr++ >> bitShift & bitMask;
+ }
+ return result;
+}
diff --git a/core/fxge/skia/fx_skia_device_unittest.cpp b/core/fxcrt/fx_basic_util_unittest.cpp
index 57a4ec140b..3272eab70c 100644
--- a/core/fxge/skia/fx_skia_device_unittest.cpp
+++ b/core/fxcrt/fx_basic_util_unittest.cpp
@@ -2,18 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "core/fxge/skia/fx_skia_device.cpp"
+#include "core/fxcrt/include/fx_basic.h"
#include "testing/fx_string_testhelpers.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
-uint32_t _GetBits32(const uint8_t* pData, int bitpos, int nbits) {
+uint32_t ReferenceGetBits32(const uint8_t* pData, int bitpos, int nbits) {
int result = 0;
- for (int i = 0; i < nbits; i++)
- if (pData[(bitpos + i) / 8] & (1 << (7 - (bitpos + i) % 8))) {
+ for (int i = 0; i < nbits; i++) {
+ if (pData[(bitpos + i) / 8] & (1 << (7 - (bitpos + i) % 8)))
result |= 1 << (nbits - i - 1);
- }
+ }
return result;
}
@@ -23,9 +23,8 @@ TEST(fxge, GetBits32) {
unsigned char data[] = {0xDE, 0x3F, 0xB1, 0x7C, 0x12, 0x9A, 0x04, 0x56};
for (int nbits = 1; nbits <= 32; ++nbits) {
for (int bitpos = 0; bitpos < (int)sizeof(data) * 8 - nbits; ++bitpos) {
- uint32_t ref = _GetBits32(data, bitpos, nbits);
- uint32_t test = GetBits32(data, bitpos, nbits);
- EXPECT_TRUE(ref == test);
+ EXPECT_EQ(ReferenceGetBits32(data, bitpos, nbits),
+ GetBits32(data, bitpos, nbits));
}
}
}
diff --git a/core/fxcrt/include/fx_basic.h b/core/fxcrt/include/fx_basic.h
index 7fdfbf699d..d3dce8c749 100644
--- a/core/fxcrt/include/fx_basic.h
+++ b/core/fxcrt/include/fx_basic.h
@@ -178,7 +178,7 @@ class CFX_UTF8Encoder {
class CFX_BasicArray {
protected:
- CFX_BasicArray(int unit_size);
+ explicit CFX_BasicArray(int unit_size);
CFX_BasicArray(const CFX_BasicArray&) = delete;
~CFX_BasicArray();
@@ -972,4 +972,6 @@ class CFX_Matrix_3by3 {
FX_FLOAT i;
};
+uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits);
+
#endif // CORE_FXCRT_INCLUDE_FX_BASIC_H_
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index 3168e2251b..177f10c5b9 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -174,36 +174,6 @@ bool AddColors(const CPDF_ExpIntFunc* pFunc, SkTDArray<SkColor>* skColors) {
return true;
}
-uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits) {
- ASSERT(0 < nbits && nbits <= 32);
- const uint8_t* dataPtr = &pData[bitpos / 8];
- int bitShift;
- int bitMask;
- int dstShift;
- int bitCount = bitpos & 0x07;
- if (nbits < 8 && nbits + bitCount <= 8) {
- bitShift = 8 - nbits - bitCount;
- bitMask = (1 << nbits) - 1;
- dstShift = 0;
- } else {
- bitShift = 0;
- int bitOffset = 8 - bitCount;
- bitMask = (1 << SkTMin(bitOffset, nbits)) - 1;
- dstShift = nbits - bitOffset;
- }
- uint32_t result = (uint32_t)(*dataPtr++ >> bitShift & bitMask) << dstShift;
- while (dstShift >= 8) {
- dstShift -= 8;
- result |= *dataPtr++ << dstShift;
- }
- if (dstShift > 0) {
- bitShift = 8 - dstShift;
- bitMask = (1 << dstShift) - 1;
- result |= *dataPtr++ >> bitShift & bitMask;
- }
- return result;
-}
-
uint8_t FloatToByte(FX_FLOAT f) {
ASSERT(0 <= f && f <= 1);
return (uint8_t)(f * 255.99f);