blob: 6566e38b4b9b3a8d3e7587fbe52924c2f7f654cf [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
DRCffe09d62011-08-17 02:27:59 +00002 * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00003 *
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//
20// PixelFormat - structure to represent a pixel format. Also has useful
21// methods for reading & writing to streams, etc.
22//
23
24#ifndef __RFB_PIXELFORMAT_H__
25#define __RFB_PIXELFORMAT_H__
26
27#include <rfb/Pixel.h>
28#include <rfb/ColourMap.h>
29
30namespace rdr { class InStream; class OutStream; }
31
32namespace rfb {
33
34 class PixelFormat {
35 public:
36 PixelFormat(int b, int d, bool e, bool t,
37 int rm=0, int gm=0, int bm=0, int rs=0, int gs=0, int bs=0);
38 PixelFormat();
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000039
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000040 bool equal(const PixelFormat& other) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000041
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000042 void read(rdr::InStream* is);
43 void write(rdr::OutStream* os) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000044
45 bool is888(void) const;
46 bool isBigEndian(void) const;
47 bool isLittleEndian(void) const;
48
49 inline Pixel pixelFromBuffer(const rdr::U8* buffer) const;
Pierre Ossman19501b82009-03-31 14:06:53 +000050 inline void bufferFromPixel(rdr::U8* buffer, Pixel pixel) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000051
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000052 Pixel pixelFromRGB(rdr::U16 red, rdr::U16 green, rdr::U16 blue, ColourMap* cm=0) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000053 Pixel pixelFromRGB(rdr::U8 red, rdr::U8 green, rdr::U8 blue, ColourMap* cm=0) const;
54
Pierre Ossman19501b82009-03-31 14:06:53 +000055 void bufferFromRGB(rdr::U8 *dst, const rdr::U8* src, int pixels, ColourMap* cm=0) const;
56
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000057 void rgbFromPixel(Pixel pix, ColourMap* cm, Colour* rgb) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000058 inline void rgbFromPixel(Pixel pix, ColourMap* cm, rdr::U16 *r, rdr::U16 *g, rdr::U16 *b) const;
59 inline void rgbFromPixel(Pixel pix, ColourMap* cm, rdr::U8 *r, rdr::U8 *g, rdr::U8 *b) const;
60
61 void rgbFromBuffer(rdr::U16* dst, const rdr::U8* src, int pixels, ColourMap* cm=0) const;
62 void rgbFromBuffer(rdr::U8* dst, const rdr::U8* src, int pixels, ColourMap* cm=0) const;
DRCffe09d62011-08-17 02:27:59 +000063 void rgbFromBuffer(rdr::U8* dst, const rdr::U8* src, int w, int pitch,
64 int h, ColourMap* cm=0) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000065
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000066 void print(char* str, int len) const;
67 bool parse(const char* str);
68
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000069 protected:
Pierre Ossman19dbca22009-04-21 17:30:45 +000070 void updateState(void);
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000071
72 public:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000073 int bpp;
74 int depth;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000075 bool trueColour;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000076
77 // FIXME: These should be protected, but we need to fix TransImageGetter first.
78 public:
79 bool bigEndian;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000080 int redMax;
81 int greenMax;
82 int blueMax;
83 int redShift;
84 int greenShift;
85 int blueShift;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000086
87 protected:
88 int redConvShift;
89 int greenConvShift;
90 int blueConvShift;
Pierre Ossman19dbca22009-04-21 17:30:45 +000091 bool endianMismatch;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000092 };
93}
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000094
95#include <rfb/PixelFormat.inl>
96
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000097#endif