summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_basic_util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt/fx_basic_util.cpp')
-rw-r--r--core/fxcrt/fx_basic_util.cpp35
1 files changed, 33 insertions, 2 deletions
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;
+}