VirtualBox

source: vbox/trunk/src/VBox/Main/include/VideoRecUtils.h@ 75267

Last change on this file since 75267 was 74999, checked in by vboxsync, 6 years ago

VideoRec/Main: SCM fixes.

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