| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2009 The Android Open Source Project | 3 * Copyright 2009 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkColorTable.h" | 10 #include "SkColorTable.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 } else if (count > 256) { | 29 } else if (count > 256) { |
| 30 count = 256; | 30 count = 256; |
| 31 } | 31 } |
| 32 this->init(colors, count); | 32 this->init(colors, count); |
| 33 } | 33 } |
| 34 | 34 |
| 35 SkColorTable::SkColorTable(SkPMColor* colors, int count, AllocatedWithMalloc) | 35 SkColorTable::SkColorTable(SkPMColor* colors, int count, AllocatedWithMalloc) |
| 36 : fColors(colors) | 36 : fColors(colors) |
| 37 , fCount(count) | 37 , fCount(count) |
| 38 { | 38 { |
| 39 SkASSERT(count > 0 && count <= 255); | 39 SkASSERT(count > 0 && count <= 256); |
| 40 SkASSERT(colors); | 40 SkASSERT(colors); |
| 41 } | 41 } |
| 42 | 42 |
| 43 SkColorTable::~SkColorTable() { | 43 SkColorTable::~SkColorTable() { |
| 44 sk_free(fColors); | 44 sk_free(fColors); |
| 45 // f16BitCache frees itself | 45 // f16BitCache frees itself |
| 46 } | 46 } |
| 47 | 47 |
| 48 #include "SkColorPriv.h" | 48 #include "SkColorPriv.h" |
| 49 | 49 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 SkColorTable* SkColorTable::Create(SkReadBuffer& buffer) { | 101 SkColorTable* SkColorTable::Create(SkReadBuffer& buffer) { |
| 102 if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) { | 102 if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) { |
| 103 /*fAlphaType = */buffer.readUInt(); | 103 /*fAlphaType = */buffer.readUInt(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 const int count = buffer.getArrayCount(); | 106 const int count = buffer.getArrayCount(); |
| 107 if (0 == count) { | 107 if (0 == count) { |
| 108 return new SkColorTable(nullptr, 0); | 108 return new SkColorTable(nullptr, 0); |
| 109 } | 109 } |
| 110 | 110 |
| 111 if (count < 0 || count > 255) { | 111 if (count < 0 || count > 256) { |
| 112 buffer.validate(false); | 112 buffer.validate(false); |
| 113 return nullptr; | 113 return nullptr; |
| 114 } | 114 } |
| 115 | 115 |
| 116 const size_t allocSize = count * sizeof(SkPMColor); | 116 const size_t allocSize = count * sizeof(SkPMColor); |
| 117 SkAutoTDelete<SkPMColor> colors((SkPMColor*)sk_malloc_throw(allocSize)); | 117 SkAutoTDelete<SkPMColor> colors((SkPMColor*)sk_malloc_throw(allocSize)); |
| 118 if (!buffer.readColorArray(colors, count)) { | 118 if (!buffer.readColorArray(colors, count)) { |
| 119 return nullptr; | 119 return nullptr; |
| 120 } | 120 } |
| 121 | 121 |
| 122 return new SkColorTable(colors.detach(), count, kAllocatedWithMalloc); | 122 return new SkColorTable(colors.detach(), count, kAllocatedWithMalloc); |
| 123 } | 123 } |
| 124 | 124 |
| OLD | NEW |