blob: aef309cf84d30c8031ab1da79d7cb8a30e0f9b90 [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.
Pierre Ossman6655d962014-01-20 14:50:19 +01003 * Copyright 2009-2014 Pierre Ossman for Cendio AB
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00004 *
5 * This is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This software is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this software; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18 * USA.
19 */
20//
21// PixelFormat - structure to represent a pixel format. Also has useful
22// methods for reading & writing to streams, etc.
23//
24
25#ifndef __RFB_PIXELFORMAT_H__
26#define __RFB_PIXELFORMAT_H__
27
28#include <rfb/Pixel.h>
29#include <rfb/ColourMap.h>
30
31namespace rdr { class InStream; class OutStream; }
32
33namespace rfb {
34
35 class PixelFormat {
36 public:
37 PixelFormat(int b, int d, bool e, bool t,
38 int rm=0, int gm=0, int bm=0, int rs=0, int gs=0, int bs=0);
39 PixelFormat();
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000040
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000041 bool equal(const PixelFormat& other) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000042
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000043 void read(rdr::InStream* is);
44 void write(rdr::OutStream* os) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000045
46 bool is888(void) const;
47 bool isBigEndian(void) const;
48 bool isLittleEndian(void) const;
49
50 inline Pixel pixelFromBuffer(const rdr::U8* buffer) const;
Pierre Ossman19501b82009-03-31 14:06:53 +000051 inline void bufferFromPixel(rdr::U8* buffer, Pixel pixel) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000052
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000053 Pixel pixelFromRGB(rdr::U16 red, rdr::U16 green, rdr::U16 blue, ColourMap* cm=0) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000054 Pixel pixelFromRGB(rdr::U8 red, rdr::U8 green, rdr::U8 blue, ColourMap* cm=0) const;
55
Pierre Ossman19501b82009-03-31 14:06:53 +000056 void bufferFromRGB(rdr::U8 *dst, const rdr::U8* src, int pixels, ColourMap* cm=0) const;
DRC33c15e32011-11-03 18:49:21 +000057 void bufferFromRGB(rdr::U8 *dst, const rdr::U8* src, int w, int pitch,
58 int h, ColourMap* cm=0) const;
Pierre Ossman19501b82009-03-31 14:06:53 +000059
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000060 void rgbFromPixel(Pixel pix, ColourMap* cm, Colour* rgb) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000061 inline void rgbFromPixel(Pixel pix, ColourMap* cm, rdr::U16 *r, rdr::U16 *g, rdr::U16 *b) const;
62 inline void rgbFromPixel(Pixel pix, ColourMap* cm, rdr::U8 *r, rdr::U8 *g, rdr::U8 *b) const;
63
64 void rgbFromBuffer(rdr::U16* dst, const rdr::U8* src, int pixels, ColourMap* cm=0) const;
65 void rgbFromBuffer(rdr::U8* dst, const rdr::U8* src, int pixels, ColourMap* cm=0) const;
DRCffe09d62011-08-17 02:27:59 +000066 void rgbFromBuffer(rdr::U8* dst, const rdr::U8* src, int w, int pitch,
67 int h, ColourMap* cm=0) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000068
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000069 void print(char* str, int len) const;
70 bool parse(const char* str);
71
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000072 protected:
Pierre Ossman19dbca22009-04-21 17:30:45 +000073 void updateState(void);
Pierre Ossman6655d962014-01-20 14:50:19 +010074 bool isSane(void);
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000075
76 public:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000077 int bpp;
78 int depth;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000079 bool trueColour;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000080
81 // FIXME: These should be protected, but we need to fix TransImageGetter first.
82 public:
83 bool bigEndian;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000084 int redMax;
85 int greenMax;
86 int blueMax;
87 int redShift;
88 int greenShift;
89 int blueShift;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000090
91 protected:
92 int redConvShift;
93 int greenConvShift;
94 int blueConvShift;
Pierre Ossman19dbca22009-04-21 17:30:45 +000095 bool endianMismatch;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000096 };
97}
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000098
99#include <rfb/PixelFormat.inl>
100
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000101#endif