xref: /aosp_15_r20/external/skia/src/codec/SkColorPalette.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 #include "src/codec/SkColorPalette.h"
8 
9 #include "include/private/base/SkMalloc.h"
10 
11 #include <cstring>
12 
SkColorPalette(const SkPMColor colors[],int count)13 SkColorPalette::SkColorPalette(const SkPMColor colors[], int count) {
14     SkASSERT(0 == count || colors);
15     SkASSERT(count >= 0 && count <= 256);
16 
17     fCount = count;
18     fColors = reinterpret_cast<SkPMColor*>(sk_malloc_throw(count * sizeof(SkPMColor)));
19 
20     memcpy(fColors, colors, count * sizeof(SkPMColor));
21 }
22 
~SkColorPalette()23 SkColorPalette::~SkColorPalette() {
24     sk_free(fColors);
25 }
26