ISA: Make the decode function part of the ISA's decoder.
[gem5.git] / src / base / vnc / convert.hh
1 /*
2 * Copyright (c) 2011 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * Authors: Ali Saidi
38 */
39
40 /** @file
41 * This file provides conversion functions for a variety of video modes
42 */
43
44 #ifndef __BASE_VNC_CONVERT_HH__
45 #define __BASE_VNC_CONVERT_HH__
46
47 #include <zlib.h>
48 #include "base/bitunion.hh"
49
50 class VideoConvert
51 {
52 public:
53 enum Mode {
54 UnknownMode,
55 bgr565,
56 rgb565,
57 bgr8888,
58 rgb8888,
59 rgb888,
60 bgr888,
61 bgr444,
62 bgr4444,
63 rgb444,
64 rgb4444
65 };
66
67 // supports bpp32 RGB (bmp) and bpp16 5:6:5 mode BGR (linux)
68 BitUnion32(Rgb8888)
69 Bitfield<7,0> blue;
70 Bitfield<15,8> green;
71 Bitfield<23,16> red;
72 Bitfield<31,24> alpha;
73 EndBitUnion(Rgb8888)
74
75 BitUnion32(Bgr8888)
76 Bitfield<7,0> red;
77 Bitfield<15,8> green;
78 Bitfield<23,16> blue;
79 Bitfield<31,24> alpha;
80 EndBitUnion(Bgr8888)
81
82 BitUnion16(Bgr565)
83 Bitfield<4,0> red;
84 Bitfield<10,5> green;
85 Bitfield<15,11> blue;
86 EndBitUnion(Bgr565)
87
88 BitUnion16(Rgb565)
89 Bitfield<4,0> red;
90 Bitfield<10,5> green;
91 Bitfield<15,11> blue;
92 EndBitUnion(Rgb565)
93
94 /** Setup the converter with the given parameters
95 * @param input_mode type of data that will be provided
96 * @param output_mode type of data that should be output
97 * @param _width width of the frame buffer
98 * @param _height height of the frame buffer
99 */
100 VideoConvert(Mode input_mode, Mode output_mode, int _width, int _height);
101
102 /** Destructor
103 */
104 ~VideoConvert();
105
106 /** Convert the provided frame buffer data into the format specified in the
107 * constructor.
108 * @param fb the frame buffer to convert
109 * @return the converted data (user must free)
110 */
111 uint8_t* convert(const uint8_t *fb) const;
112
113 /** Return the number of pixels that this buffer specifies
114 * @return number of pixels
115 */
116 int area() const { return width * height; }
117
118 /**
119 * Returns a hash on the raw data.
120 *
121 * @return hash of the buffer
122 */
123 inline uint64_t getHash(const uint8_t *fb) const {
124 return adler32(0UL, fb, width * height);
125 }
126
127 private:
128
129 /**
130 * Convert a bgr8888 input to rgb8888.
131 * @param fb the data to convert
132 * @return converted data
133 */
134 uint8_t* bgr8888rgb8888(const uint8_t *fb) const;
135
136 /**
137 * Convert a bgr565 or rgb565 input to rgb8888.
138 * @param fb the data to convert
139 * @param bgr true if the input data is bgr565
140 * @return converted data
141 */
142 uint8_t* m565rgb8888(const uint8_t *fb, bool bgr) const;
143
144 Mode inputMode;
145 Mode outputMode;
146 int width;
147 int height;
148 };
149
150 #endif // __BASE_VNC_CONVERT_HH__
151