Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | // |
| 19 | // PixelFormat - structure to represent a pixel format. Also has useful |
| 20 | // methods for reading & writing to streams, etc. |
| 21 | // |
| 22 | |
| 23 | #ifndef __RFB_PIXELFORMAT_H__ |
| 24 | #define __RFB_PIXELFORMAT_H__ |
| 25 | |
| 26 | #include <rfb/Pixel.h> |
| 27 | #include <rfb/ColourMap.h> |
| 28 | |
| 29 | namespace rdr { class InStream; class OutStream; } |
| 30 | |
| 31 | namespace rfb { |
| 32 | |
| 33 | class PixelFormat { |
| 34 | public: |
| 35 | PixelFormat(int b, int d, bool e, bool t, |
| 36 | int rm=0, int gm=0, int bm=0, int rs=0, int gs=0, int bs=0); |
| 37 | PixelFormat(); |
Pierre Ossman | 67b2b2f | 2009-03-06 10:12:55 +0000 | [diff] [blame] | 38 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 39 | bool equal(const PixelFormat& other) const; |
Pierre Ossman | 67b2b2f | 2009-03-06 10:12:55 +0000 | [diff] [blame] | 40 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 41 | void read(rdr::InStream* is); |
| 42 | void write(rdr::OutStream* os) const; |
Pierre Ossman | 67b2b2f | 2009-03-06 10:12:55 +0000 | [diff] [blame] | 43 | |
| 44 | bool is888(void) const; |
| 45 | bool isBigEndian(void) const; |
| 46 | bool isLittleEndian(void) const; |
| 47 | |
| 48 | inline Pixel pixelFromBuffer(const rdr::U8* buffer) const; |
Pierre Ossman | 19501b8 | 2009-03-31 14:06:53 +0000 | [diff] [blame] | 49 | inline void bufferFromPixel(rdr::U8* buffer, Pixel pixel) const; |
Pierre Ossman | 67b2b2f | 2009-03-06 10:12:55 +0000 | [diff] [blame] | 50 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 51 | Pixel pixelFromRGB(rdr::U16 red, rdr::U16 green, rdr::U16 blue, ColourMap* cm=0) const; |
Pierre Ossman | 67b2b2f | 2009-03-06 10:12:55 +0000 | [diff] [blame] | 52 | Pixel pixelFromRGB(rdr::U8 red, rdr::U8 green, rdr::U8 blue, ColourMap* cm=0) const; |
| 53 | |
Pierre Ossman | 19501b8 | 2009-03-31 14:06:53 +0000 | [diff] [blame] | 54 | void bufferFromRGB(rdr::U8 *dst, const rdr::U8* src, int pixels, ColourMap* cm=0) const; |
| 55 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 56 | void rgbFromPixel(Pixel pix, ColourMap* cm, Colour* rgb) const; |
Pierre Ossman | 67b2b2f | 2009-03-06 10:12:55 +0000 | [diff] [blame] | 57 | inline void rgbFromPixel(Pixel pix, ColourMap* cm, rdr::U16 *r, rdr::U16 *g, rdr::U16 *b) const; |
| 58 | inline void rgbFromPixel(Pixel pix, ColourMap* cm, rdr::U8 *r, rdr::U8 *g, rdr::U8 *b) const; |
| 59 | |
| 60 | void rgbFromBuffer(rdr::U16* dst, const rdr::U8* src, int pixels, ColourMap* cm=0) const; |
| 61 | void rgbFromBuffer(rdr::U8* dst, const rdr::U8* src, int pixels, ColourMap* cm=0) const; |
| 62 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 63 | void print(char* str, int len) const; |
| 64 | bool parse(const char* str); |
| 65 | |
Pierre Ossman | 67b2b2f | 2009-03-06 10:12:55 +0000 | [diff] [blame] | 66 | protected: |
| 67 | void updateShifts(void); |
| 68 | |
| 69 | public: |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 70 | int bpp; |
| 71 | int depth; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 72 | bool trueColour; |
Pierre Ossman | 67b2b2f | 2009-03-06 10:12:55 +0000 | [diff] [blame] | 73 | |
| 74 | // FIXME: These should be protected, but we need to fix TransImageGetter first. |
| 75 | public: |
| 76 | bool bigEndian; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 77 | int redMax; |
| 78 | int greenMax; |
| 79 | int blueMax; |
| 80 | int redShift; |
| 81 | int greenShift; |
| 82 | int blueShift; |
Pierre Ossman | 67b2b2f | 2009-03-06 10:12:55 +0000 | [diff] [blame] | 83 | |
| 84 | protected: |
| 85 | int redConvShift; |
| 86 | int greenConvShift; |
| 87 | int blueConvShift; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 88 | }; |
| 89 | } |
Pierre Ossman | 67b2b2f | 2009-03-06 10:12:55 +0000 | [diff] [blame] | 90 | |
| 91 | #include <rfb/PixelFormat.inl> |
| 92 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 93 | #endif |