blob: a8408dddbd265b0a472dbdd94233c4117d10fc6c [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
Pierre Ossman823665c2014-01-20 16:55:19 +010022// methods for reading & writing to streams, etc. Conversion to and from
23// other formats are also handled by this class. We have three different
24// representations that we refer to:
25//
26// a) Pixels - Unsigned native integers in the format specified by this
27// PixelFormat object.
28// b) Buffer - Same thing as pixels, but in the appropriate byte stream
29// format. This involves endian conversion and padding.
30// c) RGB - A byte stream of 8 bit red, green and blue elements, in that
31// order.
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000032//
33
34#ifndef __RFB_PIXELFORMAT_H__
35#define __RFB_PIXELFORMAT_H__
36
37#include <rfb/Pixel.h>
38#include <rfb/ColourMap.h>
39
40namespace rdr { class InStream; class OutStream; }
41
42namespace rfb {
43
44 class PixelFormat {
45 public:
46 PixelFormat(int b, int d, bool e, bool t,
47 int rm=0, int gm=0, int bm=0, int rs=0, int gs=0, int bs=0);
48 PixelFormat();
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000049
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000050 bool equal(const PixelFormat& other) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000051
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000052 void read(rdr::InStream* is);
53 void write(rdr::OutStream* os) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000054
55 bool is888(void) const;
56 bool isBigEndian(void) const;
57 bool isLittleEndian(void) const;
58
59 inline Pixel pixelFromBuffer(const rdr::U8* buffer) const;
Pierre Ossman19501b82009-03-31 14:06:53 +000060 inline void bufferFromPixel(rdr::U8* buffer, Pixel pixel) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000061
Pierre Ossman8b874e42014-01-20 17:23:51 +010062 inline Pixel pixelFromRGB(rdr::U16 red, rdr::U16 green, rdr::U16 blue, ColourMap* cm=0) const;
63 inline Pixel pixelFromRGB(rdr::U8 red, rdr::U8 green, rdr::U8 blue, ColourMap* cm=0) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000064
Pierre Ossman19501b82009-03-31 14:06:53 +000065 void bufferFromRGB(rdr::U8 *dst, const rdr::U8* src, int pixels, ColourMap* cm=0) const;
Pierre Ossmana10d8fe2014-01-22 11:28:05 +010066 void bufferFromRGB(rdr::U8 *dst, const rdr::U8* src, int w, int stride,
DRC33c15e32011-11-03 18:49:21 +000067 int h, ColourMap* cm=0) const;
Pierre Ossman19501b82009-03-31 14:06:53 +000068
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000069 void rgbFromPixel(Pixel pix, ColourMap* cm, Colour* rgb) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000070 inline void rgbFromPixel(Pixel pix, ColourMap* cm, rdr::U16 *r, rdr::U16 *g, rdr::U16 *b) const;
71 inline void rgbFromPixel(Pixel pix, ColourMap* cm, rdr::U8 *r, rdr::U8 *g, rdr::U8 *b) const;
72
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000073 void rgbFromBuffer(rdr::U8* dst, const rdr::U8* src, int pixels, ColourMap* cm=0) const;
Pierre Ossmana10d8fe2014-01-22 11:28:05 +010074 void rgbFromBuffer(rdr::U8* dst, const rdr::U8* src, int w, int stride,
DRCffe09d62011-08-17 02:27:59 +000075 int h, ColourMap* cm=0) const;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000076
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000077 void print(char* str, int len) const;
78 bool parse(const char* str);
79
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000080 protected:
Pierre Ossman19dbca22009-04-21 17:30:45 +000081 void updateState(void);
Pierre Ossman6655d962014-01-20 14:50:19 +010082 bool isSane(void);
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000083
84 public:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000085 int bpp;
86 int depth;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000087 bool trueColour;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000088
89 // FIXME: These should be protected, but we need to fix TransImageGetter first.
90 public:
91 bool bigEndian;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000092 int redMax;
93 int greenMax;
94 int blueMax;
95 int redShift;
96 int greenShift;
97 int blueShift;
Pierre Ossman67b2b2f2009-03-06 10:12:55 +000098
99 protected:
Pierre Ossman6e5cd5d2014-02-28 11:54:34 +0100100 /* Pre-computed values to keep algorithms simple */
101 int redBits, greenBits, blueBits;
102 int maxBits, minBits;
Pierre Ossman19dbca22009-04-21 17:30:45 +0000103 bool endianMismatch;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000104 };
105}
Pierre Ossman67b2b2f2009-03-06 10:12:55 +0000106
107#include <rfb/PixelFormat.inl>
108
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000109#endif