MWCapture SDK Linux  3.3.1.LAST_SVN_COMMIT_NUM
MWFOURCC.h
1 // CONFIDENTIAL and PROPRIETARY software of Magewell Electronics Co., Ltd.
3 // Copyright (c) 2011-2016 Magewell Electronics Co., Ltd. (Nanjing)
4 // All rights reserved.
5 // This copyright notice MUST be reproduced on all authorized copies.
7 
8 #pragma once
9 
10 #ifndef MWFOURCC
11 #define MWFOURCC(ch0, ch1, ch2, ch3) \
12  ((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \
13  ((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24))
14 #endif
15 
16 #define MWFOURCC_UNK MWFOURCC('U', 'N', 'K', 'N')
17 
18 // 8bits grey
19 #define MWFOURCC_GREY MWFOURCC('G', 'R', 'E', 'Y') // Y0, Y1, Y2, ...
20 #define MWFOURCC_Y800 MWFOURCC('Y', '8', '0', '0') // = GREY
21 #define MWFOURCC_Y8 MWFOURCC('Y', '8', ' ', ' ') // = GREY
22 
23 // 16bits grey
24 #define MWFOURCC_Y16 MWFOURCC('Y', '1', '6', ' ') // Y0, Y1, Y2
25 
26 // RGB 15-32bits
27 #define MWFOURCC_RGB15 MWFOURCC('R', 'G', 'B', '5') // R0, G0, B0, A0, ...
28 #define MWFOURCC_RGB16 MWFOURCC('R', 'G', 'B', '6') // R0, G0, B0, R1, ...
29 #define MWFOURCC_RGB24 MWFOURCC('R', 'G', 'B', ' ') // R0, G0, B0, R1, ...
30 #define MWFOURCC_RGBA MWFOURCC('R', 'G', 'B', 'A') // R0, G0, B0, A0, R1, ...
31 #define MWFOURCC_ARGB MWFOURCC('A', 'R', 'G', 'B') // A0, R0, G0, B0, A1, ...
32 
33 #define MWFOURCC_BGR15 MWFOURCC('B', 'G', 'R', '5') // B0, G0, R0, A0, ...
34 #define MWFOURCC_BGR16 MWFOURCC('B', 'G', 'R', '6') // B0, G0, R0, B1, ...
35 #define MWFOURCC_BGR24 MWFOURCC('B', 'G', 'R', ' ') // B0, G0, R0, B1, ...
36 #define MWFOURCC_BGRA MWFOURCC('B', 'G', 'R', 'A') // B0, G0, R0, A0, B1, ...
37 #define MWFOURCC_ABGR MWFOURCC('A', 'B', 'G', 'R') // A0, B0, G0, R0, A1, ...
38 
39 // Planar YUV 8bits 4:2:2 (16bits)
40 #define MWFOURCC_NV16 MWFOURCC('N', 'V', '1', '6') // Y Plane, UV Plane
41 #define MWFOURCC_NV61 MWFOURCC('N', 'V', '6', '1') // Y Plane, VU Plane
42 #define MWFOURCC_I422 MWFOURCC('I', '4', '2', '2') // Y Plane, U Plane, V Plane
43 #define MWFOURCC_YV16 MWFOURCC('Y', 'V', '1', '6') // Y Plane, V Plane, U Plane
44 
45 // Packed YUV 8bits 4:2:2 (16bits)
46 #define MWFOURCC_YUY2 MWFOURCC('Y', 'U', 'Y', '2') // Y0, U01, Y1, V01, ...
47 #define MWFOURCC_YUYV MWFOURCC('Y', 'U', 'Y', 'V') // = YUY2
48 #define MWFOURCC_UYVY MWFOURCC('U', 'Y', 'V', 'Y') // U01, Y0, V01, Y1, ...
49 
50 #define MWFOURCC_YVYU MWFOURCC('Y', 'V', 'Y', 'U') // Y0, V01, Y1, U01, ...
51 #define MWFOURCC_VYUY MWFOURCC('V', 'Y', 'U', 'Y') // V01, Y0, U01, Y1, ...
52 
53 // Planar YUV 8bits 4:2:0 (12bits)
54 #define MWFOURCC_I420 MWFOURCC('I', '4', '2', '0') // Y Plane, U Plane, V Plane
55 #define MWFOURCC_IYUV MWFOURCC('I', 'Y', 'U', 'V') // = I420
56 #define MWFOURCC_NV12 MWFOURCC('N', 'V', '1', '2') // Y Plane, UV Plane
57 
58 #define MWFOURCC_YV12 MWFOURCC('Y', 'V', '1', '2') // Y Plane, V Plane, U Plane
59 #define MWFOURCC_NV21 MWFOURCC('N', 'V', '2', '1') // Y Plane, VU Plane
60 
61 // Planar YUV 10bits 4:2:0 (24bits)
62 #define MWFOURCC_P010 MWFOURCC('P', '0', '1', '0') // Y Plane, UV Plane
63 
64 // Planar YUV 10bits 4:2:2 (32bits)
65 #define MWFOURCC_P210 MWFOURCC('P', '2', '1', '0') // Y Plane, UV Plane
66 
67 // Packed YUV 8bits 4:4:4 (24bits)
68 #define MWFOURCC_IYU2 MWFOURCC('I', 'Y', 'U', '2') // U0, Y0, V0, U1, Y1, V1, ...
69 #define MWFOURCC_V308 MWFOURCC('v', '3', '0', '8') // V0, Y0, U0, V1, Y1, U1, ...
70 
71 // Packed YUV 8bits 4:4:4 (32bits)
72 #define MWFOURCC_AYUV MWFOURCC('A', 'Y', 'U', 'V') // A0, Y0, U0, V0, ...
73 #define MWFOURCC_UYVA MWFOURCC('U', 'Y', 'V', 'A') // U0, Y0, V0, A0, U1, Y1, ...
74 #define MWFOURCC_V408 MWFOURCC('v', '4', '0', '8') // = MWFOURCC_UYVA
75 #define MWFOURCC_VYUA MWFOURCC('V', 'Y', 'U', 'A') // V0, Y0, U0, A0, V1, Y1, ...
76 
77 // Packed YUV 10bits 4:4:4 (32bits)
78 #define MWFOURCC_Y410 MWFOURCC('Y', '4', '1', '0') // U0, Y0, V0, A0, ...
79 #define MWFOURCC_V410 MWFOURCC('v', '4', '1', '0') // A0, U0, Y0, V0, ...
80 
81 // Packed RGB 10bits 4:4:4 (32bits)
82 #define MWFOURCC_RGB10 MWFOURCC('R', 'G', '1', '0') // R0, G0, B0, A0, ...
83 #define MWFOURCC_BGR10 MWFOURCC('B', 'G', '1', '0') // B0, G0, R0, A0, ...
84 
85 inline bool FOURCC_IsRGB(
86  uint32_t dwFOURCC
87  )
88 {
89  switch (dwFOURCC) {
90  case MWFOURCC_RGB15:
91  case MWFOURCC_BGR15:
92  case MWFOURCC_RGB16:
93  case MWFOURCC_BGR16:
94  case MWFOURCC_RGB24:
95  case MWFOURCC_BGR24:
96  case MWFOURCC_RGBA:
97  case MWFOURCC_BGRA:
98  case MWFOURCC_ARGB:
99  case MWFOURCC_ABGR:
100  case MWFOURCC_RGB10:
101  case MWFOURCC_BGR10:
102  return true;
103  default:
104  return false;
105  }
106 }
107 
108 inline bool FOURCC_IsPacked(
109  uint32_t dwFOURCC
110  )
111 {
112  switch (dwFOURCC) {
113  case MWFOURCC_NV12:
114  case MWFOURCC_NV21:
115  case MWFOURCC_YV12:
116  case MWFOURCC_IYUV:
117  case MWFOURCC_I420:
118  case MWFOURCC_I422:
119  case MWFOURCC_YV16:
120  case MWFOURCC_NV16:
121  case MWFOURCC_NV61:
122  case MWFOURCC_P010:
123  case MWFOURCC_P210:
124  return false;
125  default:
126  return true;
127  }
128 }
129 
130 inline int FOURCC_GetBpp(
131  uint32_t dwFOURCC
132  )
133 {
134  switch (dwFOURCC) {
135  case MWFOURCC_GREY:
136  case MWFOURCC_Y800:
137  case MWFOURCC_Y8:
138  return 8;
139 
140  case MWFOURCC_I420:
141  case MWFOURCC_IYUV:
142  case MWFOURCC_YV12:
143  case MWFOURCC_NV12:
144  case MWFOURCC_NV21:
145  return 12;
146 
147  case MWFOURCC_Y16:
148  case MWFOURCC_RGB15:
149  case MWFOURCC_BGR15:
150  case MWFOURCC_RGB16:
151  case MWFOURCC_BGR16:
152  case MWFOURCC_YUY2:
153  case MWFOURCC_YUYV:
154  case MWFOURCC_UYVY:
155  case MWFOURCC_YVYU:
156  case MWFOURCC_VYUY:
157  case MWFOURCC_I422:
158  case MWFOURCC_YV16:
159  case MWFOURCC_NV16:
160  case MWFOURCC_NV61:
161  return 16;
162 
163  case MWFOURCC_IYU2:
164  case MWFOURCC_V308:
165  case MWFOURCC_RGB24:
166  case MWFOURCC_BGR24:
167  case MWFOURCC_P010:
168  return 24;
169 
170  case MWFOURCC_AYUV:
171  case MWFOURCC_UYVA:
172  case MWFOURCC_V408:
173  case MWFOURCC_VYUA:
174  case MWFOURCC_RGBA:
175  case MWFOURCC_BGRA:
176  case MWFOURCC_ARGB:
177  case MWFOURCC_ABGR:
178  case MWFOURCC_Y410:
179  case MWFOURCC_V410:
180  case MWFOURCC_P210:
181  return 32;
182 
183  default:
184  return 0;
185  }
186 }
187 
188 inline uint32_t FOURCC_CalcMinStride(
189  uint32_t dwFOURCC,
190  int cx,
191  uint32_t dwAlign
192  )
193 {
194  bool bPacked = FOURCC_IsPacked(dwFOURCC);
195 
196  uint32_t cbLine;
197 
198  if (bPacked) {
199  int nBpp = FOURCC_GetBpp(dwFOURCC);
200  cbLine = (cx * nBpp) / 8;
201  }
202  else {
203  switch (dwFOURCC) {
204  case MWFOURCC_P010:
205  case MWFOURCC_P210:
206  cbLine = cx * 2;
207  break;
208  default:
209  cbLine = cx;
210  break;
211  }
212  }
213 
214  return (cbLine + dwAlign - 1) & ~(dwAlign - 1);
215 }
216 
217 inline uint32_t FOURCC_CalcImageSize(
218  uint32_t dwFOURCC,
219  int cx,
220  int cy,
221  uint32_t cbStride
222  )
223 {
224  bool bPacked = FOURCC_IsPacked(dwFOURCC);
225 
226  if (bPacked) {
227  int nBpp = FOURCC_GetBpp(dwFOURCC);
228  uint32_t cbLine = (cx * nBpp) / 8;
229  if (cbStride < cbLine)
230  return 0;
231 
232  return cbStride * cy;
233  }
234  else {
235  if (cbStride < (uint32_t)cx)
236  return 0;
237 
238  switch (dwFOURCC) {
239  case MWFOURCC_NV12:
240  case MWFOURCC_NV21:
241  case MWFOURCC_YV12:
242  case MWFOURCC_IYUV:
243  case MWFOURCC_I420:
244  if ((cbStride & 1) || (cy & 1))
245  return 0;
246  return cbStride * cy * 3 / 2;
247  case MWFOURCC_I422:
248  case MWFOURCC_YV16:
249  case MWFOURCC_NV16:
250  case MWFOURCC_NV61:
251  if (cbStride & 1)
252  return 0;
253  return cbStride * cy * 2;
254  case MWFOURCC_P010:
255  if ((cbStride & 3) || (cy & 1))
256  return 0;
257  return cbStride * cy * 3 / 2;
258  case MWFOURCC_P210:
259  if (cbStride & 3)
260  return 0;
261  return cbStride * cy * 2;
262  default:
263  return 0;
264  }
265  }
266 }
267 
268 inline bool FOURCC_IsMask(const uint32_t * pdwMasks, uint32_t dwRedMask, uint32_t dwGreenMask, uint32_t dwBlueMask)
269 {
270  return ((pdwMasks[0] == dwRedMask) && (pdwMasks[1] == dwGreenMask) && (pdwMasks[2] == dwBlueMask));
271 }
272 
#define MWFOURCC_Y410
Y410.
Definition: MWFOURCC.h:636
#define MWFOURCC_YUY2
YUY2.
Definition: MWFOURCC.h:290
#define MWFOURCC_Y800
8bits Grey
Definition: MWFOURCC.h:45
#define MWFOURCC_BGR15
16bits B5G5R5A1
Definition: MWFOURCC.h:133
#define MWFOURCC_V408
V408.
Definition: MWFOURCC.h:593
#define MWFOURCC_IYUV
IYUV.
Definition: MWFOURCC.h:398
#define MWFOURCC_NV16
NV16.
Definition: MWFOURCC.h:199
#define MWFOURCC_P010
P010.
Definition: MWFOURCC.h:496
#define MWFOURCC_YV12
YV12.
Definition: MWFOURCC.h:448
#define MWFOURCC_GREY
8bits Grey
Definition: MWFOURCC.h:34
#define MWFOURCC_VYUY
VYUY.
Definition: MWFOURCC.h:346
#define MWFOURCC_BGRA
32bits B8G8R8A8
Definition: MWFOURCC.h:166
#define MWFOURCC_ARGB
32bits A8R8G8B8
Definition: MWFOURCC.h:122
#define MWFOURCC_AYUV
AYUV.
Definition: MWFOURCC.h:565
#define MWFOURCC_NV12
NV12.
Definition: MWFOURCC.h:422
BOOLEAN FOURCC_IsPacked(DWORD dwFOURCC)
Determines whether the color format is packed.
Definition: MWFOURCC.h:709
BOOLEAN FOURCC_IsRGB(DWORD dwFOURCC)
Determines whether the color format is RGB.
Definition: MWFOURCC.h:680
#define MWFOURCC_RGB15
16bits R5G5B5A1
Definition: MWFOURCC.h:78
#define MWFOURCC_UYVY
UYVY.
Definition: MWFOURCC.h:318
#define MWFOURCC_IYU2
IYU2.
Definition: MWFOURCC.h:536
#define MWFOURCC_UYVA
UYVA.
Definition: MWFOURCC.h:579
#define MWFOURCC_I420
I420.
Definition: MWFOURCC.h:372
#define MWFOURCC_V308
V308.
Definition: MWFOURCC.h:550
#define MWFOURCC_RGB16
16bits R5G6B5
Definition: MWFOURCC.h:89
#define MWFOURCC_BGR10
BGR10.
Definition: MWFOURCC.h:672
#define MWFOURCC_RGB10
RGB10.
Definition: MWFOURCC.h:661
#define MWFOURCC_BGR24
24bits B8G8R8
Definition: MWFOURCC.h:155
DWORD FOURCC_CalcImageSize(DWORD dwFOURCC, int cx, int cy, DWORD cbStride)
Counts the number of bytes that a frame takes, depending on the color format, resolution and the line...
Definition: MWFOURCC.h:846
#define MWFOURCC_P210
P210.
Definition: MWFOURCC.h:522
#define MWFOURCC_RGB24
24bits R8G8B8
Definition: MWFOURCC.h:100
#define MWFOURCC_ABGR
32bits A8B8G8R8
Definition: MWFOURCC.h:177
#define MWFOURCC_VYUA
VYUA.
Definition: MWFOURCC.h:607
DWORD FOURCC_CalcMinStride(DWORD dwFOURCC, int cx, DWORD dwAlign)
Counts the number of bytes that a line data of image takes, depending on the width of image and the c...
Definition: MWFOURCC.h:804
#define MWFOURCC_I422
I422.
Definition: MWFOURCC.h:248
#define MWFOURCC_Y8
8bits Grey
Definition: MWFOURCC.h:56
#define MWFOURCC_YUYV
YUYV.
Definition: MWFOURCC.h:304
int FOURCC_GetBpp(DWORD dwFOURCC)
Gets the bits that pixel of color format takes.
Definition: MWFOURCC.h:737
#define MWFOURCC_NV61
NV61.
Definition: MWFOURCC.h:221
#define MWFOURCC_YV16
YV16.
Definition: MWFOURCC.h:275
#define MWFOURCC_RGBA
32bits R8G8B8A8
Definition: MWFOURCC.h:111
#define MWFOURCC_BGR16
16bits B5G6R5
Definition: MWFOURCC.h:144
BOOLEAN FOURCC_IsMask(const DWORD *pdwMasks, DWORD dwRedMask, DWORD dwGreenMask, DWORD dwBlueMask)
Determins whether the mask is the same as specified color format.
Definition: MWFOURCC.h:938
#define MWFOURCC_NV21
NV21.
Definition: MWFOURCC.h:472
#define MWFOURCC_V410
V410.
Definition: MWFOURCC.h:650
#define MWFOURCC_YVYU
YVYU.
Definition: MWFOURCC.h:332
#define MWFOURCC_Y16
16bits Grey
Definition: MWFOURCC.h:67