VirtualBox

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

Last change on this file since 77863 was 76562, checked in by vboxsync, 6 years ago

Main: Use MAIN_INCLUDED_ and MAIN_INCLUDED_SRC_ as header guard prefixes with scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
1/* $Id: RecordingUtils.h 76562 2019-01-01 03:22:50Z vboxsync $ */
2/** @file
3 * Recording utility header.
4 */
5
6/*
7 * Copyright (C) 2012-2019 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#include <iprt/asm.h>
25#include <iprt/assert.h>
26#include <iprt/critsect.h>
27#include <iprt/path.h>
28#include <iprt/semaphore.h>
29#include <iprt/thread.h>
30#include <iprt/time.h>
31
32
33/**
34 * Iterator class for running through a BGRA32 image buffer and converting
35 * it to RGB.
36 */
37class ColorConvBGRA32Iter
38{
39private:
40 enum { PIX_SIZE = 4 };
41public:
42 ColorConvBGRA32Iter(unsigned aWidth, unsigned aHeight, uint8_t *aBuf)
43 {
44 mPos = 0;
45 mSize = aWidth * aHeight * PIX_SIZE;
46 mBuf = aBuf;
47 }
48
49 /**
50 * Convert the next pixel to RGB.
51 *
52 * @returns true on success, false if we have reached the end of the buffer
53 * @param aRed where to store the red value.
54 * @param aGreen where to store the green value.
55 * @param aBlue where to store the blue value.
56 */
57 bool getRGB(unsigned *aRed, unsigned *aGreen, unsigned *aBlue)
58 {
59 bool rc = false;
60 if (mPos + PIX_SIZE <= mSize)
61 {
62 *aRed = mBuf[mPos + 2];
63 *aGreen = mBuf[mPos + 1];
64 *aBlue = mBuf[mPos ];
65 mPos += PIX_SIZE;
66 rc = true;
67 }
68 return rc;
69 }
70
71 /**
72 * Skip forward by a certain number of pixels.
73 *
74 * @param aPixels How many pixels to skip.
75 */
76 void skip(unsigned aPixels)
77 {
78 mPos += PIX_SIZE * aPixels;
79 }
80private:
81 /** Size of the picture buffer. */
82 unsigned mSize;
83 /** Current position in the picture buffer. */
84 unsigned mPos;
85 /** Address of the picture buffer. */
86 uint8_t *mBuf;
87};
88
89/**
90 * Iterator class for running through an BGR24 image buffer and converting
91 * it to RGB.
92 */
93class ColorConvBGR24Iter
94{
95private:
96 enum { PIX_SIZE = 3 };
97public:
98 ColorConvBGR24Iter(unsigned aWidth, unsigned aHeight, uint8_t *aBuf)
99 {
100 mPos = 0;
101 mSize = aWidth * aHeight * PIX_SIZE;
102 mBuf = aBuf;
103 }
104
105 /**
106 * Convert the next pixel to RGB.
107 *
108 * @returns true on success, false if we have reached the end of the buffer.
109 * @param aRed where to store the red value.
110 * @param aGreen where to store the green value.
111 * @param aBlue where to store the blue value.
112 */
113 bool getRGB(unsigned *aRed, unsigned *aGreen, unsigned *aBlue)
114 {
115 bool rc = false;
116 if (mPos + PIX_SIZE <= mSize)
117 {
118 *aRed = mBuf[mPos + 2];
119 *aGreen = mBuf[mPos + 1];
120 *aBlue = mBuf[mPos ];
121 mPos += PIX_SIZE;
122 rc = true;
123 }
124 return rc;
125 }
126
127 /**
128 * Skip forward by a certain number of pixels.
129 *
130 * @param aPixels How many pixels to skip.
131 */
132 void skip(unsigned aPixels)
133 {
134 mPos += PIX_SIZE * aPixels;
135 }
136private:
137 /** Size of the picture buffer. */
138 unsigned mSize;
139 /** Current position in the picture buffer. */
140 unsigned mPos;
141 /** Address of the picture buffer. */
142 uint8_t *mBuf;
143};
144
145/**
146 * Iterator class for running through an BGR565 image buffer and converting
147 * it to RGB.
148 */
149class ColorConvBGR565Iter
150{
151private:
152 enum { PIX_SIZE = 2 };
153public:
154 ColorConvBGR565Iter(unsigned aWidth, unsigned aHeight, uint8_t *aBuf)
155 {
156 mPos = 0;
157 mSize = aWidth * aHeight * PIX_SIZE;
158 mBuf = aBuf;
159 }
160
161 /**
162 * Convert the next pixel to RGB.
163 *
164 * @returns true on success, false if we have reached the end of the buffer.
165 * @param aRed Where to store the red value.
166 * @param aGreen where to store the green value.
167 * @param aBlue where to store the blue value.
168 */
169 bool getRGB(unsigned *aRed, unsigned *aGreen, unsigned *aBlue)
170 {
171 bool rc = false;
172 if (mPos + PIX_SIZE <= mSize)
173 {
174 unsigned uFull = (((unsigned) mBuf[mPos + 1]) << 8)
175 | ((unsigned) mBuf[mPos]);
176 *aRed = (uFull >> 8) & ~7;
177 *aGreen = (uFull >> 3) & ~3 & 0xff;
178 *aBlue = (uFull << 3) & ~7 & 0xff;
179 mPos += PIX_SIZE;
180 rc = true;
181 }
182 return rc;
183 }
184
185 /**
186 * Skip forward by a certain number of pixels.
187 *
188 * @param aPixels How many pixels to skip.
189 */
190 void skip(unsigned aPixels)
191 {
192 mPos += PIX_SIZE * aPixels;
193 }
194private:
195 /** Size of the picture buffer. */
196 unsigned mSize;
197 /** Current position in the picture buffer. */
198 unsigned mPos;
199 /** Address of the picture buffer. */
200 uint8_t *mBuf;
201};
202
203int RecordingUtilsRGBToYUV(uint32_t uPixelFormat,
204 uint8_t *paDst, uint32_t uDstWidth, uint32_t uDstHeight,
205 uint8_t *paSrc, uint32_t uSrcWidth, uint32_t uSrcHeight);
206
207#endif /* !MAIN_INCLUDED_RecordingUtils_h */
208
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