OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The Android Open Source Project | 2 * Copyright 2009 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 #include "SkColorTable.h" | 9 #include "SkColorTable.h" |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 fColors = nullptr; | 75 fColors = nullptr; |
76 } | 76 } |
77 #ifdef SK_DEBUG | 77 #ifdef SK_DEBUG |
78 SkASSERT((unsigned)fCount <= 256); | 78 SkASSERT((unsigned)fCount <= 256); |
79 SkASSERT(success); | 79 SkASSERT(success); |
80 #endif | 80 #endif |
81 } | 81 } |
82 #endif | 82 #endif |
83 | 83 |
84 void SkColorTable::writeToBuffer(SkWriteBuffer& buffer) const { | 84 void SkColorTable::writeToBuffer(SkWriteBuffer& buffer) const { |
85 buffer.writeColorArray(fColors, fCount); | 85 buffer.writeColorArray("fColors", fColors, fCount); |
86 } | 86 } |
87 | 87 |
88 SkColorTable* SkColorTable::Create(SkReadBuffer& buffer) { | 88 SkColorTable* SkColorTable::Create(SkReadBuffer& buffer) { |
89 if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) { | 89 if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) { |
90 /*fAlphaType = */buffer.readUInt(); | 90 /*fAlphaType = */buffer.readUInt(); |
91 } | 91 } |
92 | 92 |
93 const int count = buffer.getArrayCount(); | 93 const int count = buffer.getArrayCount(); |
94 if (0 == count) { | 94 if (0 == count) { |
95 return new SkColorTable(nullptr, 0); | 95 return new SkColorTable(nullptr, 0); |
96 } | 96 } |
97 | 97 |
98 if (count < 0 || count > 256) { | 98 if (count < 0 || count > 256) { |
99 buffer.validate(false); | 99 buffer.validate(false); |
100 return nullptr; | 100 return nullptr; |
101 } | 101 } |
102 | 102 |
103 const size_t allocSize = count * sizeof(SkPMColor); | 103 const size_t allocSize = count * sizeof(SkPMColor); |
104 SkAutoTDelete<SkPMColor> colors((SkPMColor*)sk_malloc_throw(allocSize)); | 104 SkAutoTDelete<SkPMColor> colors((SkPMColor*)sk_malloc_throw(allocSize)); |
105 if (!buffer.readColorArray(colors, count)) { | 105 if (!buffer.readColorArray(colors, count)) { |
106 return nullptr; | 106 return nullptr; |
107 } | 107 } |
108 | 108 |
109 return new SkColorTable(colors.release(), count, kAllocatedWithMalloc); | 109 return new SkColorTable(colors.release(), count, kAllocatedWithMalloc); |
110 } | 110 } |
OLD | NEW |