aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkColorTable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/SkColorTable.cpp')
-rw-r--r--src/core/SkColorTable.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/core/SkColorTable.cpp b/src/core/SkColorTable.cpp
index 97103463db..928f5158d4 100644
--- a/src/core/SkColorTable.cpp
+++ b/src/core/SkColorTable.cpp
@@ -23,11 +23,7 @@ void SkColorTable::init(const SkPMColor colors[], int count) {
SkColorTable::SkColorTable(const SkPMColor colors[], int count) {
SkASSERT(0 == count || colors);
- if (count < 0) {
- count = 0;
- } else if (count > 256) {
- count = 256;
- }
+ SkASSERT(count >= 0 && count <= 256);
this->init(colors, count);
}
@@ -56,6 +52,16 @@ const uint16_t* SkColorTable::read16BitCache() const {
return f16BitCache;
}
+sk_sp<SkColorTable> SkColorTable::Make(const SkPMColor colors[], int count) {
+ if (count < 0 || count > 256) {
+ return nullptr;
+ }
+ if (count && !colors) {
+ return nullptr;
+ }
+ return sk_make_sp<SkColorTable>(colors, count);
+}
+
///////////////////////////////////////////////////////////////////////////////
#if 0
@@ -85,14 +91,14 @@ void SkColorTable::writeToBuffer(SkWriteBuffer& buffer) const {
buffer.writeColorArray(fColors, fCount);
}
-SkColorTable* SkColorTable::Create(SkReadBuffer& buffer) {
+sk_sp<SkColorTable> SkColorTable::Create(SkReadBuffer& buffer) {
if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) {
/*fAlphaType = */buffer.readUInt();
}
const int count = buffer.getArrayCount();
if (0 == count) {
- return new SkColorTable(nullptr, 0);
+ return sk_sp<SkColorTable>(new SkColorTable(nullptr, 0));
}
if (count < 0 || count > 256) {
@@ -106,5 +112,5 @@ SkColorTable* SkColorTable::Create(SkReadBuffer& buffer) {
return nullptr;
}
- return new SkColorTable(colors.release(), count, kAllocatedWithMalloc);
+ return sk_sp<SkColorTable>(new SkColorTable(colors.release(), count, kAllocatedWithMalloc));
}