| 1 | // Aseprite Document Library |
| 2 | // Copyright (c) 2020-2022 Igara Studio S.A. |
| 3 | // |
| 4 | // This file is released under the terms of the MIT license. |
| 5 | // Read LICENSE.txt for more information. |
| 6 | |
| 7 | #ifndef DOC_RGBMAP_H_INCLUDED |
| 8 | #define DOC_RGBMAP_H_INCLUDED |
| 9 | #pragma once |
| 10 | |
| 11 | #include "base/debug.h" |
| 12 | #include "doc/color.h" |
| 13 | |
| 14 | namespace doc { |
| 15 | |
| 16 | class Palette; |
| 17 | |
| 18 | // Matches a RGBA value with an index in a color palette (doc::Palette). |
| 19 | class RgbMap { |
| 20 | public: |
| 21 | virtual ~RgbMap() { } |
| 22 | |
| 23 | virtual void regenerateMap(const Palette* palette, const int maskIndex) = 0; |
| 24 | |
| 25 | // Should return the best index in a palette that matches the given RGBA values. |
| 26 | virtual int mapColor(const color_t rgba) const = 0; |
| 27 | |
| 28 | virtual int maskIndex() const = 0; |
| 29 | |
| 30 | int mapColor(const int r, |
| 31 | const int g, |
| 32 | const int b, |
| 33 | const int a) const { |
| 34 | ASSERT(r >= 0 && r < 256); |
| 35 | ASSERT(g >= 0 && g < 256); |
| 36 | ASSERT(b >= 0 && b < 256); |
| 37 | ASSERT(a >= 0 && a < 256); |
| 38 | return mapColor(rgba(r, g, b, a)); |
| 39 | } |
| 40 | |
| 41 | }; |
| 42 | |
| 43 | } // namespace doc |
| 44 | |
| 45 | #endif |
| 46 | |