VirtualBox

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

Last change on this file since 99739 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/* $Id: RecordingUtils.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * Recording utility header.
4 */
5
6/*
7 * Copyright (C) 2012-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
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#include "RecordingInternals.h"
35
36
37/**
38 * Iterator class for running through a BGRA32 image buffer and converting
39 * it to RGB.
40 */
41class ColorConvBGRA32Iter
42{
43private:
44 enum { PIX_SIZE = 4 };
45public:
46 ColorConvBGRA32Iter(unsigned aWidth, unsigned aHeight, uint8_t *aBuf)
47 {
48 mPos = 0;
49 mSize = aWidth * aHeight * PIX_SIZE;
50 mBuf = aBuf;
51 }
52
53 /**
54 * Convert the next pixel to RGB.
55 *
56 * @returns true on success, false if we have reached the end of the buffer
57 * @param aRed where to store the red value.
58 * @param aGreen where to store the green value.
59 * @param aBlue where to store the blue value.
60 */
61 bool getRGB(unsigned *aRed, unsigned *aGreen, unsigned *aBlue)
62 {
63 bool rc = false;
64 if (mPos + PIX_SIZE <= mSize)
65 {
66 *aRed = mBuf[mPos + 2];
67 *aGreen = mBuf[mPos + 1];
68 *aBlue = mBuf[mPos ];
69 mPos += PIX_SIZE;
70 rc = true;
71 }
72 return rc;
73 }
74
75 /**
76 * Skip forward by a certain number of pixels.
77 *
78 * @param aPixels How many pixels to skip.
79 */
80 void skip(unsigned aPixels)
81 {
82 mPos += PIX_SIZE * aPixels;
83 }
84private:
85 /** Size of the picture buffer. */
86 unsigned mSize;
87 /** Current position in the picture buffer. */
88 unsigned mPos;
89 /** Address of the picture buffer. */
90 uint8_t *mBuf;
91};
92
93/**
94 * Iterator class for running through an BGR24 image buffer and converting
95 * it to RGB.
96 */
97class ColorConvBGR24Iter
98{
99private:
100 enum { PIX_SIZE = 3 };
101public:
102 ColorConvBGR24Iter(unsigned aWidth, unsigned aHeight, uint8_t *aBuf)
103 {
104 mPos = 0;
105 mSize = aWidth * aHeight * PIX_SIZE;
106 mBuf = aBuf;
107 }
108
109 /**
110 * Convert the next pixel to RGB.
111 *
112 * @returns true on success, false if we have reached the end of the buffer.
113 * @param aRed where to store the red value.
114 * @param aGreen where to store the green value.
115 * @param aBlue where to store the blue value.
116 */
117 bool getRGB(unsigned *aRed, unsigned *aGreen, unsigned *aBlue)
118 {
119 bool rc = false;
120 if (mPos + PIX_SIZE <= mSize)
121 {
122 *aRed = mBuf[mPos + 2];
123 *aGreen = mBuf[mPos + 1];
124 *aBlue = mBuf[mPos ];
125 mPos += PIX_SIZE;
126 rc = true;
127 }
128 return rc;
129 }
130
131 /**
132 * Skip forward by a certain number of pixels.
133 *
134 * @param aPixels How many pixels to skip.
135 */
136 void skip(unsigned aPixels)
137 {
138 mPos += PIX_SIZE * aPixels;
139 }
140private:
141 /** Size of the picture buffer. */
142 unsigned mSize;
143 /** Current position in the picture buffer. */
144 unsigned mPos;
145 /** Address of the picture buffer. */
146 uint8_t *mBuf;
147};
148
149/**
150 * Iterator class for running through an BGR565 image buffer and converting
151 * it to RGB.
152 */
153class ColorConvBGR565Iter
154{
155private:
156 enum { PIX_SIZE = 2 };
157public:
158 ColorConvBGR565Iter(unsigned aWidth, unsigned aHeight, uint8_t *aBuf)
159 {
160 mPos = 0;
161 mSize = aWidth * aHeight * PIX_SIZE;
162 mBuf = aBuf;
163 }
164
165 /**
166 * Convert the next pixel to RGB.
167 *
168 * @returns true on success, false if we have reached the end of the buffer.
169 * @param aRed Where to store the red value.
170 * @param aGreen where to store the green value.
171 * @param aBlue where to store the blue value.
172 */
173 bool getRGB(unsigned *aRed, unsigned *aGreen, unsigned *aBlue)
174 {
175 bool rc = false;
176 if (mPos + PIX_SIZE <= mSize)
177 {
178 unsigned uFull = (((unsigned) mBuf[mPos + 1]) << 8)
179 | ((unsigned) mBuf[mPos]);
180 *aRed = (uFull >> 8) & ~7;
181 *aGreen = (uFull >> 3) & ~3 & 0xff;
182 *aBlue = (uFull << 3) & ~7 & 0xff;
183 mPos += PIX_SIZE;
184 rc = true;
185 }
186 return rc;
187 }
188
189 /**
190 * Skip forward by a certain number of pixels.
191 *
192 * @param aPixels How many pixels to skip.
193 */
194 void skip(unsigned aPixels)
195 {
196 mPos += PIX_SIZE * aPixels;
197 }
198private:
199 /** Size of the picture buffer. */
200 unsigned mSize;
201 /** Current position in the picture buffer. */
202 unsigned mPos;
203 /** Address of the picture buffer. */
204 uint8_t *mBuf;
205};
206
207int RecordingUtilsRGBToYUV(RECORDINGPIXELFMT enmPixelFormat,
208 uint8_t *paDst, uint32_t uDstWidth, uint32_t uDstHeight,
209 uint8_t *paSrc, uint32_t uSrcWidth, uint32_t uSrcHeight);
210
211#ifdef DEBUG
212int RecordingUtilsDbgDumpFrameEx(const uint8_t *pu8RGBBuf, size_t cbRGBBuf, const char *pszPath, const char *pszPrefx, uint16_t uWidth, uint32_t uHeight, uint8_t uBPP);
213int RecordingUtilsDbgDumpFrame(const PRECORDINGFRAME pFrame);
214#endif
215
216#endif /* !MAIN_INCLUDED_RecordingUtils_h */
217
Note: See TracBrowser for help on using the repository browser.

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