aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2016-02-23 12:55:20 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-23 12:55:20 -0800
commitccb74b824a16d0009f7f9ebcf2a03fb53451af9a (patch)
tree26e46706bb4f9ea577970995f39602b38e32d562 /src
parentd936f63c35fb7dfb2b6c20802206adbfc3cc48d0 (diff)
Move SkPackBits to src/effects.
Prior to this change SkPackBits.h was in include/core and SkPackBits.cpp in src/core. However, SkPackBits appears to have been written specifically as an implementation detail of the SkTableColorFilter effect. This change moves SkPackBits out of core and into effects, which is the only current user. Review URL: https://codereview.chromium.org/1722173003
Diffstat (limited to 'src')
-rw-r--r--src/effects/SkPackBits.cpp (renamed from src/core/SkPackBits.cpp)10
-rw-r--r--src/effects/SkPackBits.h46
2 files changed, 50 insertions, 6 deletions
diff --git a/src/core/SkPackBits.cpp b/src/effects/SkPackBits.cpp
index a3424e2bdc..286d9d140c 100644
--- a/src/core/SkPackBits.cpp
+++ b/src/effects/SkPackBits.cpp
@@ -6,14 +6,14 @@
*/
#include "SkPackBits.h"
-size_t SkPackBits::ComputeMaxSize8(int count) {
+size_t SkPackBits::ComputeMaxSize8(size_t srcSize) {
// worst case is the number of 8bit values + 1 byte per (up to) 128 entries.
- return ((count + 127) >> 7) + count;
+ return ((srcSize + 127) >> 7) + srcSize;
}
static uint8_t* flush_same8(uint8_t dst[], uint8_t value, size_t count) {
while (count > 0) {
- int n = count > 128 ? 128 : count;
+ size_t n = count > 128 ? 128 : count;
*dst++ = (uint8_t)(n - 1);
*dst++ = (uint8_t)value;
count -= n;
@@ -24,7 +24,7 @@ static uint8_t* flush_same8(uint8_t dst[], uint8_t value, size_t count) {
static uint8_t* flush_diff8(uint8_t* SK_RESTRICT dst,
const uint8_t* SK_RESTRICT src, size_t count) {
while (count > 0) {
- int n = count > 128 ? 128 : count;
+ size_t n = count > 128 ? 128 : count;
*dst++ = (uint8_t)(n + 127);
memcpy(dst, src, n);
src += n;
@@ -78,8 +78,6 @@ size_t SkPackBits::Pack8(const uint8_t* SK_RESTRICT src, size_t srcSize,
return dst - origDst;
}
-#include "SkUtils.h"
-
int SkPackBits::Unpack8(const uint8_t* SK_RESTRICT src, size_t srcSize,
uint8_t* SK_RESTRICT dst, size_t dstSize) {
uint8_t* const origDst = dst;
diff --git a/src/effects/SkPackBits.h b/src/effects/SkPackBits.h
new file mode 100644
index 0000000000..f6430faadd
--- /dev/null
+++ b/src/effects/SkPackBits.h
@@ -0,0 +1,46 @@
+
+/*
+ * Copyright 2008 The Android Open Source Project
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#ifndef SkPackBits_DEFINED
+#define SkPackBits_DEFINED
+
+#include "SkTypes.h"
+
+class SkPackBits {
+public:
+ /** Given the number of 8bit values that will be passed to Pack8,
+ returns the worst-case size needed for the dst[] buffer.
+ */
+ static size_t ComputeMaxSize8(size_t srcSize);
+
+ /** Write the src array into a packed format. The packing process may end
+ up writing more bytes than it read, so dst[] must be large enough.
+ @param src Input array of 8bit values
+ @param srcSize Number of entries in src[]
+ @param dst Buffer (allocated by caller) to write the packed data
+ into
+ @param dstSize Number of bytes in the output buffer.
+ @return the number of bytes written to dst[]
+ */
+ static size_t Pack8(const uint8_t src[], size_t srcSize, uint8_t dst[],
+ size_t dstSize);
+
+ /** Unpack the data in src[], and expand it into dst[]. The src[] data was
+ written by a previous call to Pack8.
+ @param src Input data to unpack, previously created by Pack8.
+ @param srcSize Number of bytes of src to unpack
+ @param dst Buffer (allocated by caller) to expand the src[] into.
+ @param dstSize Number of bytes in the output buffer.
+ @return the number of bytes written into dst.
+ */
+ static int Unpack8(const uint8_t src[], size_t srcSize, uint8_t dst[],
+ size_t dstSize);
+};
+
+#endif