1 /* 2 * Copyright 2009 The Android Open Source Project 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "SkColorTable.h" 9 #include "SkReadBuffer.h" 10 #include "SkWriteBuffer.h" 11 12 SkColorTable::SkColorTable(const SkPMColor colors[], int count) { 13 SkASSERT(0 == count || colors); 14 SkASSERT(count >= 0 && count <= 256); 15 16 fCount = count; 17 fColors = reinterpret_cast<SkPMColor*>(sk_malloc_throw(count * sizeof(SkPMColor))); 18 19 memcpy(fColors, colors, count * sizeof(SkPMColor)); 20 } 21 22 SkColorTable::~SkColorTable() { 23 sk_free(fColors); 24 } 25 26 void SkColorTable::Skip(SkReadBuffer& buffer) { 27 const int count = buffer.getArrayCount(); 28 if (count < 0 || count > 256) { 29 buffer.validate(false); 30 } else { 31 buffer.skip(count * sizeof(SkPMColor)); 32 } 33 } 34