reed@android.com | a6260ff | 2009-05-04 18:52:54 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2009 The Android Open Source Project |
reed@android.com | a6260ff | 2009-05-04 18:52:54 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
5 | * found in the LICENSE file. | ||||
reed@android.com | a6260ff | 2009-05-04 18:52:54 +0000 | [diff] [blame] | 6 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | |
djsollen@google.com | 64a0ec3 | 2012-06-12 15:17:27 +0000 | [diff] [blame] | 8 | #include "SkColorTable.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 9 | #include "SkReadBuffer.h" |
10 | #include "SkWriteBuffer.h" | ||||
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 11 | |
Mike Reed | 323ae0e | 2017-07-24 22:05:25 -0400 | [diff] [blame] | 12 | SkColorTable::SkColorTable(const SkPMColor colors[], int count) { |
13 | SkASSERT(0 == count || colors); | ||||
14 | SkASSERT(count >= 0 && count <= 256); | ||||
weita@google.com | f9ab99a | 2009-05-03 18:23:30 +0000 | [diff] [blame] | 15 | |
reed | c5e15a1 | 2014-09-29 12:10:27 -0700 | [diff] [blame] | 16 | fCount = count; |
17 | fColors = reinterpret_cast<SkPMColor*>(sk_malloc_throw(count * sizeof(SkPMColor))); | ||||
mtklein | 775b819 | 2014-12-02 09:11:25 -0800 | [diff] [blame] | 18 | |
reed | c5e15a1 | 2014-09-29 12:10:27 -0700 | [diff] [blame] | 19 | memcpy(fColors, colors, count * sizeof(SkPMColor)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 20 | } |
21 | |||||
reed | c5e15a1 | 2014-09-29 12:10:27 -0700 | [diff] [blame] | 22 | SkColorTable::~SkColorTable() { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | sk_free(fColors); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 24 | } |
25 | |||||
Mike Reed | 323ae0e | 2017-07-24 22:05:25 -0400 | [diff] [blame] | 26 | void SkColorTable::Skip(SkReadBuffer& buffer) { |
reed | b236d1a | 2015-08-28 10:14:18 -0700 | [diff] [blame] | 27 | const int count = buffer.getArrayCount(); |
reed | 264873d | 2015-08-28 12:38:04 -0700 | [diff] [blame] | 28 | if (count < 0 || count > 256) { |
reed | b236d1a | 2015-08-28 10:14:18 -0700 | [diff] [blame] | 29 | buffer.validate(false); |
Mike Reed | 323ae0e | 2017-07-24 22:05:25 -0400 | [diff] [blame] | 30 | } else { |
31 | buffer.skip(count * sizeof(SkPMColor)); | ||||
reed | b236d1a | 2015-08-28 10:14:18 -0700 | [diff] [blame] | 32 | } |
reed | b236d1a | 2015-08-28 10:14:18 -0700 | [diff] [blame] | 33 | } |