blob: fab3c3dc1cdfbddc67051bb190337ae2d848cf1b [file] [log] [blame]
reed@android.coma6260ff2009-05-04 18:52:54 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2009 The Android Open Source Project
reed@android.coma6260ff2009-05-04 18:52:54 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.coma6260ff2009-05-04 18:52:54 +00006 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00007
djsollen@google.com64a0ec32012-06-12 15:17:27 +00008#include "SkColorTable.h"
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +00009#include "SkReadBuffer.h"
10#include "SkWriteBuffer.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000011
Mike Reed323ae0e2017-07-24 22:05:25 -040012SkColorTable::SkColorTable(const SkPMColor colors[], int count) {
13 SkASSERT(0 == count || colors);
14 SkASSERT(count >= 0 && count <= 256);
weita@google.comf9ab99a2009-05-03 18:23:30 +000015
reedc5e15a12014-09-29 12:10:27 -070016 fCount = count;
17 fColors = reinterpret_cast<SkPMColor*>(sk_malloc_throw(count * sizeof(SkPMColor)));
mtklein775b8192014-12-02 09:11:25 -080018
reedc5e15a12014-09-29 12:10:27 -070019 memcpy(fColors, colors, count * sizeof(SkPMColor));
reed@android.com8a1c16f2008-12-17 15:59:43 +000020}
21
reedc5e15a12014-09-29 12:10:27 -070022SkColorTable::~SkColorTable() {
reed@android.com8a1c16f2008-12-17 15:59:43 +000023 sk_free(fColors);
reed@android.com8a1c16f2008-12-17 15:59:43 +000024}
25
Mike Reed323ae0e2017-07-24 22:05:25 -040026void SkColorTable::Skip(SkReadBuffer& buffer) {
reedb236d1a2015-08-28 10:14:18 -070027 const int count = buffer.getArrayCount();
reed264873d2015-08-28 12:38:04 -070028 if (count < 0 || count > 256) {
reedb236d1a2015-08-28 10:14:18 -070029 buffer.validate(false);
Mike Reed323ae0e2017-07-24 22:05:25 -040030 } else {
31 buffer.skip(count * sizeof(SkPMColor));
reedb236d1a2015-08-28 10:14:18 -070032 }
reedb236d1a2015-08-28 10:14:18 -070033}