blob: 8adbf911052b179542666c822a34352c52c6f0ee [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* 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
29namespace rdr { class InStream; class OutStream; }
30
31namespace 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 Ossman67b2b2f2009-03-06 10:12:55 +000038
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000039 bool equal(const PixelFormat& other) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000040
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000041 void read(rdr::InStream* is);
42 void write(rdr::OutStream* os) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000043
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 Ossman19501b82009-03-31 14:06:53 +000049 inline void bufferFromPixel(rdr::U8* buffer, Pixel pixel) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000050
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000051 Pixel pixelFromRGB(rdr::U16 red, rdr::U16 green, rdr::U16 blue, ColourMap* cm=0) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000052 Pixel pixelFromRGB(rdr::U8 red, rdr::U8 green, rdr::U8 blue, ColourMap* cm=0) const;
53
Pierre Ossman19501b82009-03-31 14:06:53 +000054 void bufferFromRGB(rdr::U8 *dst, const rdr::U8* src, int pixels, ColourMap* cm=0) const;
55
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000056 void rgbFromPixel(Pixel pix, ColourMap* cm, Colour* rgb) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000057 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 Kaplinskya2adc8d2006-05-25 05:01:55 +000063 void print(char* str, int len) const;
64 bool parse(const char* str);
65
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000066 protected:
67 void updateShifts(void);
68
69 public:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000070 int bpp;
71 int depth;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000072 bool trueColour;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000073
74 // FIXME: These should be protected, but we need to fix TransImageGetter first.
75 public:
76 bool bigEndian;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000077 int redMax;
78 int greenMax;
79 int blueMax;
80 int redShift;
81 int greenShift;
82 int blueShift;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000083
84 protected:
85 int redConvShift;
86 int greenConvShift;
87 int blueConvShift;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000088 };
89}
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000090
91#include <rfb/PixelFormat.inl>
92
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000093#endif