VirtualBox

source: vbox/trunk/src/VBox/Main/include/RecordingUtils.h@ 96407

Last change on this file since 96407 was 96407, checked in by vboxsync, 3 years ago

scm copyright and license note update

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette