1 | /* $Id: RecordingUtils.h 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Recording utility header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef MAIN_INCLUDED_RecordingUtils_h
|
---|
19 | #define MAIN_INCLUDED_RecordingUtils_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Iterator class for running through a BGRA32 image buffer and converting
|
---|
27 | * it to RGB.
|
---|
28 | */
|
---|
29 | class ColorConvBGRA32Iter
|
---|
30 | {
|
---|
31 | private:
|
---|
32 | enum { PIX_SIZE = 4 };
|
---|
33 | public:
|
---|
34 | ColorConvBGRA32Iter(unsigned aWidth, unsigned aHeight, uint8_t *aBuf)
|
---|
35 | {
|
---|
36 | mPos = 0;
|
---|
37 | mSize = aWidth * aHeight * PIX_SIZE;
|
---|
38 | mBuf = aBuf;
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Convert the next pixel to RGB.
|
---|
43 | *
|
---|
44 | * @returns true on success, false if we have reached the end of the buffer
|
---|
45 | * @param aRed where to store the red value.
|
---|
46 | * @param aGreen where to store the green value.
|
---|
47 | * @param aBlue where to store the blue value.
|
---|
48 | */
|
---|
49 | bool getRGB(unsigned *aRed, unsigned *aGreen, unsigned *aBlue)
|
---|
50 | {
|
---|
51 | bool rc = false;
|
---|
52 | if (mPos + PIX_SIZE <= mSize)
|
---|
53 | {
|
---|
54 | *aRed = mBuf[mPos + 2];
|
---|
55 | *aGreen = mBuf[mPos + 1];
|
---|
56 | *aBlue = mBuf[mPos ];
|
---|
57 | mPos += PIX_SIZE;
|
---|
58 | rc = true;
|
---|
59 | }
|
---|
60 | return rc;
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Skip forward by a certain number of pixels.
|
---|
65 | *
|
---|
66 | * @param aPixels How many pixels to skip.
|
---|
67 | */
|
---|
68 | void skip(unsigned aPixels)
|
---|
69 | {
|
---|
70 | mPos += PIX_SIZE * aPixels;
|
---|
71 | }
|
---|
72 | private:
|
---|
73 | /** Size of the picture buffer. */
|
---|
74 | unsigned mSize;
|
---|
75 | /** Current position in the picture buffer. */
|
---|
76 | unsigned mPos;
|
---|
77 | /** Address of the picture buffer. */
|
---|
78 | uint8_t *mBuf;
|
---|
79 | };
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Iterator class for running through an BGR24 image buffer and converting
|
---|
83 | * it to RGB.
|
---|
84 | */
|
---|
85 | class ColorConvBGR24Iter
|
---|
86 | {
|
---|
87 | private:
|
---|
88 | enum { PIX_SIZE = 3 };
|
---|
89 | public:
|
---|
90 | ColorConvBGR24Iter(unsigned aWidth, unsigned aHeight, uint8_t *aBuf)
|
---|
91 | {
|
---|
92 | mPos = 0;
|
---|
93 | mSize = aWidth * aHeight * PIX_SIZE;
|
---|
94 | mBuf = aBuf;
|
---|
95 | }
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * Convert the next pixel to RGB.
|
---|
99 | *
|
---|
100 | * @returns true on success, false if we have reached the end of the buffer.
|
---|
101 | * @param aRed where to store the red value.
|
---|
102 | * @param aGreen where to store the green value.
|
---|
103 | * @param aBlue where to store the blue value.
|
---|
104 | */
|
---|
105 | bool getRGB(unsigned *aRed, unsigned *aGreen, unsigned *aBlue)
|
---|
106 | {
|
---|
107 | bool rc = false;
|
---|
108 | if (mPos + PIX_SIZE <= mSize)
|
---|
109 | {
|
---|
110 | *aRed = mBuf[mPos + 2];
|
---|
111 | *aGreen = mBuf[mPos + 1];
|
---|
112 | *aBlue = mBuf[mPos ];
|
---|
113 | mPos += PIX_SIZE;
|
---|
114 | rc = true;
|
---|
115 | }
|
---|
116 | return rc;
|
---|
117 | }
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Skip forward by a certain number of pixels.
|
---|
121 | *
|
---|
122 | * @param aPixels How many pixels to skip.
|
---|
123 | */
|
---|
124 | void skip(unsigned aPixels)
|
---|
125 | {
|
---|
126 | mPos += PIX_SIZE * aPixels;
|
---|
127 | }
|
---|
128 | private:
|
---|
129 | /** Size of the picture buffer. */
|
---|
130 | unsigned mSize;
|
---|
131 | /** Current position in the picture buffer. */
|
---|
132 | unsigned mPos;
|
---|
133 | /** Address of the picture buffer. */
|
---|
134 | uint8_t *mBuf;
|
---|
135 | };
|
---|
136 |
|
---|
137 | /**
|
---|
138 | * Iterator class for running through an BGR565 image buffer and converting
|
---|
139 | * it to RGB.
|
---|
140 | */
|
---|
141 | class ColorConvBGR565Iter
|
---|
142 | {
|
---|
143 | private:
|
---|
144 | enum { PIX_SIZE = 2 };
|
---|
145 | public:
|
---|
146 | ColorConvBGR565Iter(unsigned aWidth, unsigned aHeight, uint8_t *aBuf)
|
---|
147 | {
|
---|
148 | mPos = 0;
|
---|
149 | mSize = aWidth * aHeight * PIX_SIZE;
|
---|
150 | mBuf = aBuf;
|
---|
151 | }
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Convert the next pixel to RGB.
|
---|
155 | *
|
---|
156 | * @returns true on success, false if we have reached the end of the buffer.
|
---|
157 | * @param aRed Where to store the red value.
|
---|
158 | * @param aGreen where to store the green value.
|
---|
159 | * @param aBlue where to store the blue value.
|
---|
160 | */
|
---|
161 | bool getRGB(unsigned *aRed, unsigned *aGreen, unsigned *aBlue)
|
---|
162 | {
|
---|
163 | bool rc = false;
|
---|
164 | if (mPos + PIX_SIZE <= mSize)
|
---|
165 | {
|
---|
166 | unsigned uFull = (((unsigned) mBuf[mPos + 1]) << 8)
|
---|
167 | | ((unsigned) mBuf[mPos]);
|
---|
168 | *aRed = (uFull >> 8) & ~7;
|
---|
169 | *aGreen = (uFull >> 3) & ~3 & 0xff;
|
---|
170 | *aBlue = (uFull << 3) & ~7 & 0xff;
|
---|
171 | mPos += PIX_SIZE;
|
---|
172 | rc = true;
|
---|
173 | }
|
---|
174 | return rc;
|
---|
175 | }
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * Skip forward by a certain number of pixels.
|
---|
179 | *
|
---|
180 | * @param aPixels How many pixels to skip.
|
---|
181 | */
|
---|
182 | void skip(unsigned aPixels)
|
---|
183 | {
|
---|
184 | mPos += PIX_SIZE * aPixels;
|
---|
185 | }
|
---|
186 | private:
|
---|
187 | /** Size of the picture buffer. */
|
---|
188 | unsigned mSize;
|
---|
189 | /** Current position in the picture buffer. */
|
---|
190 | unsigned mPos;
|
---|
191 | /** Address of the picture buffer. */
|
---|
192 | uint8_t *mBuf;
|
---|
193 | };
|
---|
194 |
|
---|
195 | int RecordingUtilsRGBToYUV(uint32_t uPixelFormat,
|
---|
196 | uint8_t *paDst, uint32_t uDstWidth, uint32_t uDstHeight,
|
---|
197 | uint8_t *paSrc, uint32_t uSrcWidth, uint32_t uSrcHeight);
|
---|
198 |
|
---|
199 | #endif /* !MAIN_INCLUDED_RecordingUtils_h */
|
---|
200 |
|
---|