aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkColorTable.cpp
blob: 022b9f8ae31b6933c3ee84e199976d066497e3db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * Copyright 2009 The Android Open Source Project
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkColorTable.h"
#include "SkReadBuffer.h"
#include "SkWriteBuffer.h"

SkColorTable::SkColorTable(const SkPMColor colors[], int count) {
    SkASSERT(0 == count || colors);
    SkASSERT(count >= 0 && count <= 256);

    fCount = count;
    fColors = reinterpret_cast<SkPMColor*>(sk_malloc_throw(count * sizeof(SkPMColor)));

    memcpy(fColors, colors, count * sizeof(SkPMColor));
}

SkColorTable::~SkColorTable() {
    sk_free(fColors);
}

void SkColorTable::Skip(SkReadBuffer& buffer) {
    const int count = buffer.getArrayCount();
    if (buffer.validate(count >= 0 && count <= 256)) {
        buffer.skip(count * sizeof(SkPMColor));
    }
}