Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
Pierre Ossman | 8c46619 | 2011-03-02 12:45:57 +0000 | [diff] [blame] | 2 | * Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 3 | * |
| 4 | * This is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This software is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this software; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 17 | * USA. |
| 18 | */ |
| 19 | #ifndef __RFB_COLOURMAP_H__ |
| 20 | #define __RFB_COLOURMAP_H__ |
| 21 | namespace rfb { |
| 22 | struct Colour { |
| 23 | Colour() : r(0), g(0), b(0) {} |
| 24 | Colour(int r_, int g_, int b_) : r(r_), g(g_), b(b_) {} |
| 25 | int r, g, b; |
| 26 | bool operator==(const Colour& c) const {return c.r == r && c.g == g && c.b == b;} |
| 27 | bool operator!=(const Colour& c) const {return !(c == *this);} |
| 28 | }; |
| 29 | |
| 30 | class ColourMap { |
| 31 | public: |
| 32 | virtual void lookup(int index, int* r, int* g, int* b)=0; |
| 33 | }; |
Pierre Ossman | 8c46619 | 2011-03-02 12:45:57 +0000 | [diff] [blame] | 34 | |
| 35 | class SimpleColourMap : public ColourMap { |
| 36 | public: |
| 37 | SimpleColourMap(int size = 256) { table = new Colour[size]; }; |
| 38 | ~SimpleColourMap() { delete [] table; }; |
| 39 | |
| 40 | void lookup(int index, int* r, int* g, int* b) |
| 41 | { *r = table[index].r; *g = table[index].g; *b = table[index].b; }; |
| 42 | |
| 43 | void set(int index, int r, int g, int b) |
| 44 | { table[index].r = r; table[index].g = g; table[index].b = b; }; |
| 45 | |
| 46 | protected: |
| 47 | Colour *table; |
| 48 | }; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 49 | } |
| 50 | #endif |