AJA NTV2 SDK  18.0.0.2122
NTV2 SDK 18.0.0.2122
pixelformat.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 //---------------------------------------------------------------------------------------------------------------------
9 // Includes
10 //---------------------------------------------------------------------------------------------------------------------
11 #include "ajabase/common/types.h"
12 #include "ajabase/common/public.h" // Needed to pull in definition of size_t
14 
15 //---------------------------------------------------------------------------------------------------------------------
16 // Defines and structures
17 //---------------------------------------------------------------------------------------------------------------------
18 
20 {
22  uint32_t fourcc;
23  uint32_t bitDepth;
26  uint32_t planeCount;
27  bool isRGB;
28  const char* pName;
29 };
30 
31 //---------------------------------------------------------------------------------------------------------------------
32 // Format table (the fourcc's aren't right in this yet...change as needed)
33 //---------------------------------------------------------------------------------------------------------------------
35 {
36  {AJA_PixelFormat_Unknown, AJA_FOURCC(' ',' ',' ',' '), 0, AJAScaleTypeNone, AJASubSampleNone, 0, false, "Unknown"},
37  {AJA_PixelFormat_YCbCr10, AJA_FOURCC('v','2','1','0'), 10, AJAScaleTypeNone, AJASubSample422, 1, false, "10 Bit YCbCr"},
38  {AJA_PixelFormat_YCbCr8, AJA_FOURCC('2','v','u','y'), 8, AJAScaleTypeNone, AJASubSample422, 1, false, "8 Bit YCbCr"},
39  {AJA_PixelFormat_ARGB8, AJA_FOURCC('b','g','r','A'), 8, AJAScaleTypeNone, AJASubSample4444, 1, true, "8 Bit ARGB"},
40  {AJA_PixelFormat_RGBA8, AJA_FOURCC('r','g','b','a'), 8, AJAScaleTypeNone, AJASubSample4444, 1, true, "8 Bit RGBA"},
41  {AJA_PixelFormat_RGB10, AJA_FOURCC('1','0','r','b'), 10, AJAScaleTypeNone, AJASubSample444, 1, true, "10 Bit RGB"},
42  {AJA_PixelFormat_YUY28, AJA_FOURCC('Y','U','Y','2'), 8, AJAScaleTypeNone, AJASubSample422, 1, false, "8 Bit YCbCr Alternate"},
43  {AJA_PixelFormat_ABGR8, AJA_FOURCC('a','r','g','B'), 8, AJAScaleTypeNone, AJASubSample4444, 1, true, "8 Bit RGBA OpenGL"},
44  {AJA_PixelFormat_RGB_DPX, AJA_FOURCC('R','1','0','k'), 10, AJAScaleTypeNone, AJASubSample444, 1, true, "10 Bit RGB DPX"},
45  {AJA_PixelFormat_YCbCr_DPX, AJA_FOURCC('d','p','x','2'), 10, AJAScaleTypeNone, AJASubSample422, 1, false, "10 Bit YCbCr DPX"},
46  {AJA_PixelFormat_DVCPRO, AJA_FOURCC('2','v','u','y'), 8, AJAScaleTypeDVCPro, AJASubSample422, 1, false, "DVC Pro"},
47  {AJA_PixelFormat_QREZ, AJA_FOURCC('2','v','u','y'), 8, AJAScaleTypeQRez, AJASubSample422, 1, false, "QRez"},
48  {AJA_PixelFormat_HDV, AJA_FOURCC('2','v','u','y'), 8, AJAScaleTypeHDV, AJASubSample422, 1, false, "HDV"},
49  {AJA_PixelFormat_RGB8_PACK, AJA_FOURCC('r','g','b',' '), 8, AJAScaleTypeNone, AJASubSample444, 1, true, "8 Bit RGB"},
50  {AJA_PixelFormat_BGR8_PACK, AJA_FOURCC('b','g','r',' '), 8, AJAScaleTypeNone, AJASubSample444, 1, true, "8 Bit BGR"},
51  {AJA_PixelFormat_YCbCrA10, AJA_FOURCC(' ',' ',' ',' '), 10, AJAScaleTypeNone, AJASubSample422, 1, false, "10 Bit YCbCrA"},
52  {AJA_PixelFormat_RGB_DPX_LE, AJA_FOURCC('r','1','0','k'), 10, AJAScaleTypeNone, AJASubSample444, 1, true, "10 Bit RGB DPX LE"},
53  {AJA_PixelFormat_RGB12, AJA_FOURCC(' ',' ',' ',' '), 12, AJAScaleTypeNone, AJASubSample444, 1, true, "RGB12"}, //tmp name, may need to change
54  {AJA_PixelFormat_RGB12P, AJA_FOURCC(' ',' ',' ',' '), 12, AJAScaleTypeNone, AJASubSample444, 1, true, "RGB12P"},
55  {AJA_PixelFormat_PRORES_DVPRO, AJA_FOURCC('a','c','p','n'), 8, AJAScaleTypeDVCPro, AJASubSample422, 1, false, "ProRes DVC Pro"},
56  {AJA_PixelFormat_PRORES_HDV, AJA_FOURCC('a','c','p','n'), 8, AJAScaleTypeHDV, AJASubSample422, 1, false, "ProRes HDV"},
57  {AJA_PixelFormat_RGB10_PACK, AJA_FOURCC(' ',' ',' ',' '), 10, AJAScaleTypeNone, AJASubSample444, 1, true, "RGB10Pack"}, //tmp name, may need to change
58  {AJA_PixelFormat_YCbCr12_444, AJA_FOURCC(' ',' ',' ',' '), 12, AJAScaleTypeNone, AJASubSample444, 1, false, "12 Bit YCbCr444"}, //tmp name, may need to change
59  {AJA_PixelFormat_YCbCr12_422, AJA_FOURCC(' ',' ',' ',' '), 12, AJAScaleTypeNone, AJASubSample422, 1, false, "12 Bit YCbCr422"}, //tmp name, may need to change
60  {AJA_PixelFormat_RGB16, AJA_FOURCC('b','4','8','r'), 16, AJAScaleTypeNone, AJASubSample444, 1, true, "16 Bit RGB"},
61  {AJA_PixelFormat_YCbCr10_4K_RQ, AJA_FOURCC(' ',' ',' ',' '), 10, AJAScaleTypeNone, AJASubSample422, 1, false, "10 Bit YCbCr 4K RQ"},
62  {AJA_PixelFormat_BAYER10_DPX_LJ, AJA_FOURCC(' ',' ',' ',' '), 10, AJAScaleTypeNone, AJASubSampleBayer, 1, true, "Bayer 10 Bit DPX LJ"},
63  {AJA_PixelFormat_BAYER10_DPX_LJ, AJA_FOURCC(' ',' ',' ',' '), 10, AJAScaleTypeNone, AJASubSampleBayer, 1, true, "Bayer 12 Bit DPX LJ"},
64  {AJA_PixelFormat_BAYER10_HS, AJA_FOURCC(' ',' ',' ',' '), 10, AJAScaleTypeNone, AJASubSampleBayer, 1, true, "Bayer 10 Bit HS"},
65  {AJA_PixelFormat_BAYER12_HS, AJA_FOURCC(' ',' ',' ',' '), 12, AJAScaleTypeNone, AJASubSampleBayer, 1, true, "Bayer 12 Bit HS"},
66  {AJA_PixelFormat_BAYER12_PACK_HS, AJA_FOURCC('C','1','2','s'), 12, AJAScaleTypeNone, AJASubSampleBayer, 1, true, "Bayer 12 Bit Packed HS"},
67  {AJA_PixelFormat_RAW10, AJA_FOURCC('C','1','0','s'), 10, AJAScaleTypeNone, AJASubSampleBayer, 1, true, "RAW 10 Bit"}, // CION Raw 10 bit
68  {AJA_PixelFormat_RAW10_HS, AJA_FOURCC('C','1','0','h'), 10, AJAScaleTypeNone, AJASubSampleBayer, 1, true, "RAW 10 Bit HS"}, // CION Raw 10 bit HS
69  {AJA_PixelFormat_YCBCR10_420PL, AJA_FOURCC(' ',' ',' ',' '), 10, AJAScaleTypeNone, AJASubSample420, 3, false, "10 Bit YCbCr 420 Packed 3-Plane"},
70  {AJA_PixelFormat_YCBCR10_422PL, AJA_FOURCC(' ',' ',' ',' '), 10, AJAScaleTypeNone, AJASubSample422, 3, false, "10 Bit YCbCr 422 Packed 3-Plane"},
71  {AJA_PixelFormat_YCBCR8_420PL, AJA_FOURCC(' ',' ',' ',' '), 8, AJAScaleTypeNone, AJASubSample420, 3, false, "8 Bit YCbCr 420 3-Plane"},
72  {AJA_PixelFormat_YCBCR8_422PL, AJA_FOURCC(' ',' ',' ',' '), 8, AJAScaleTypeNone, AJASubSample422, 3, false, "8 Bit YCbCr 422 3-Plane"},
73  {AJA_PixelFormat_YCBCR8_420PL3, AJA_FOURCC('I','4','2','0'), 8, AJAScaleTypeNone, AJASubSample420, 3, false, "8 Bit YCbCr 420 3-Plane"},
74  {AJA_PixelFormat_YCBCR8_422PL3, AJA_FOURCC('Y','4','2','B'), 8, AJAScaleTypeNone, AJASubSample422, 3, false, "8 Bit YCbCr 422 3-Plane"},
75  {AJA_PixelFormat_YCBCR10_420PL3LE, AJA_FOURCC('Y','3',0xb,0xa), 10, AJAScaleTypeNone, AJASubSample420, 3, false, "10 Bit YCbCr 420 Unpacked 3-Plane LE"}, // from FFmpeg
76  {AJA_PixelFormat_YCBCR10_422PL3LE, AJA_FOURCC('Y','3',0xa,0xa), 10, AJAScaleTypeNone, AJASubSample422, 3, false, "10 Bit YCbCr 422 Unpacked 3-Plane LE"}, // from FFmpeg
77  {AJA_PixelFormat_YCBCR10_420PL2, AJA_FOURCC('2','Y','2','0'), 10, AJAScaleTypeNone, AJASubSample420, 2, false, "10 Bit YCbCr 420 Packed 2-Plane LE"}, // AJA ad hoc 4cc
78  {AJA_PixelFormat_YCBCR10_422PL2, AJA_FOURCC('2','Y','2','2'), 10, AJAScaleTypeNone, AJASubSample422, 2, false, "10 Bit YCbCr 422 Packed 2-Plane LE"}, // AJA ad hoc 4cc
79  {AJA_PixelFormat_YCBCR8_420PL2, AJA_FOURCC('N','V','1','2'), 8, AJAScaleTypeNone, AJASubSample420, 2, false, "8 Bit YCbCr 420 2-Plane"}, // from FFmpeg
80  {AJA_PixelFormat_YCBCR8_422PL2, AJA_FOURCC('N','V','1','6'), 8, AJAScaleTypeNone, AJASubSample422, 2, false, "8 Bit YCbCr 422 2-Plane"}, // from FFmpeg
81  {AJA_PixelFormat_YCBCR10_420PL2LE, AJA_FOURCC('P','0','1','0'), 10, AJAScaleTypeNone, AJASubSample420, 3, false, "10 Bit YCbCr 420 Unpacked 2-Plane LE"}, // from FFmpeg
82  {AJA_PixelFormat_YCBCR10_422PL2LE, AJA_FOURCC('N','V','2','0'), 10, AJAScaleTypeNone, AJASubSample422, 3, false, "10 Bit YCbCr 422 Unpacked 2-Plane LE"} // from FFmpeg
83 };
85 
86 
87 
89 {
91 }
92 
94 {
95  if (!QueryIsValid(format))
96  format = AJA_PixelFormat_Unknown;
97  m_format = format;
98 }
99 
101 {
102 }
103 
105 {
106  if (!QueryIsValid(format))
107  format = AJA_PixelFormat_Unknown;
108  m_format = format;
109 }
110 
112 {
113  return m_format;
114 }
115 
117 {
119 }
120 
122 {
124 }
125 
127 {
129 }
130 
132 {
134 }
135 
137 {
138  if (!QueryIsValid(format))
139  format = AJA_PixelFormat_Unknown;
140  return AJAPixelFormatTable[format].bitDepth;
141 }
142 
144 {
146 }
147 
149 {
150  if (!QueryIsValid(format))
151  format = AJA_PixelFormat_Unknown;
152  return AJAPixelFormatTable[format].subSampleType;
153 }
154 
156 {
158 }
159 
161 {
162  if (!QueryIsValid(format))
163  format = AJA_PixelFormat_Unknown;
164  return AJAPixelFormatTable[format].planeCount;
165 }
166 
168 {
170 }
171 
173 {
174  return format > AJA_PixelFormat_Unknown && format < AJA_PixelFormat_Size;
175 }
176 
178 {
180 }
181 
183 {
184  return AJAPixelFormatTableSize-1; //don't count AJA_PixelFormat_Unknown
185 }
186 
188 {
189  if(index >=0 && (size_t)index < AJAPixelFormatTableSize-1)
190  {
191  //+1 skip AJA_PixelFormat_Unknown
192  fmt.Set(AJAPixelFormatTable[index+1].pixelFormat);
193  return true;
194  }
195  else
196  {
197  return false;
198  }
199 }
200 
201 bool AJAPixelFormat::QueryIsScalable(uint32_t bitmapWidth,uint32_t wireWidth,uint32_t xAspect,uint32_t yAspect,
202  AJA_PixelFormat *pMatchingFormat,AJA_PixelFormat *pScalingFormat)
203 {
204  bool bIsScalable = false;
206 
207  if (yAspect)
208  {
209  if (xAspect == yAspect)
210  return bIsScalable;
211 
212  uint32_t correctedBitmapWidth = (bitmapWidth * xAspect) / yAspect;
213  if (wireWidth == correctedBitmapWidth)
214  {
215  switch (bitmapWidth)
216  {
217  case 1440:
218  bIsScalable = true;
219  scalingFormat = AJA_PixelFormat_HDV;
220  break;
221  case 1280:
222  bIsScalable = true;
223  scalingFormat = AJA_PixelFormat_DVCPRO;
224  break;
225  case 960:
226  bIsScalable = true;
227  scalingFormat = AJA_PixelFormat_HDV;
228  break;
229  default:
230  bIsScalable = false;
231  break;
232  }
233  }
234  }
235 
236  if (pMatchingFormat)
237  {
238  if (bIsScalable)
239  *pMatchingFormat = AJA_PixelFormat_YCbCr8;
240  else
241  *pMatchingFormat = AJA_PixelFormat_Unknown;
242  }
243 
244  if (pScalingFormat)
245  {
246  *pScalingFormat = scalingFormat;
247  }
248 
249  return bIsScalable;
250 }
251 
252 bool AJAPixelFormat::ConvertWidth(AJAScaleType scaleType,int xIn,int &xOut)
253 {
254  bool bOk = false;
255  xOut = xIn;
256  switch (scaleType)
257  {
259  if (xIn == 1280)
260  {
261  xOut = 1920;
262  bOk = true;
263  }
264  else if (xIn == 1920)
265  {
266  xOut = 1280;
267  bOk = true;
268  }
269  break;
271  if (xIn == 1280)
272  {
273  xOut = 960;
274  bOk = true;
275  }
276  else if (xIn == 960)
277  {
278  xOut = 1280;
279  bOk = true;
280  }
281  break;
283  if (xIn == 1440)
284  {
285  xOut = 1920;
286  bOk = true;
287  }
288  else if (xIn == 1920)
289  {
290  xOut = 1440;
291  bOk = true;
292  }
293  break;
294  default:
295  {
296  xOut = xIn;
297  bOk = false;
298  }
299  break;
300  }
301  return bOk;
302 }
303 
304 bool AJAPixelFormat::ConvertAspect(AJAScaleType scaleType,int hSpacingIn, int vSpacingIn, int &hSpacingOut,int &vSpacingOut)
305 {
306  bool bOk = false;
307  hSpacingOut = hSpacingIn;
308  vSpacingOut = vSpacingIn;
309  switch (scaleType)
310  {
312  if (hSpacingIn == vSpacingIn)
313  {
314  hSpacingOut = 3; vSpacingOut = 2; bOk = true;
315  }
316  break;
319  if (hSpacingIn == vSpacingIn)
320  {
321  hSpacingOut = 4; vSpacingOut = 3; bOk = true;
322  }
323  break;
324  default:
325  break;
326  }
327  return bOk;
328 }
329 
330 bool AJAPixelFormat::QueryScaleType(int xWire,int xBitmap,AJA_PixelFormat &primaryFormat,AJAScaleType &scaleType)
331 {
332  bool bOk = true;
333  if ((xWire == 1920) && (xBitmap == 1440))
334  {
335  scaleType = AJAScaleType1440To1920;
336  primaryFormat = AJA_PixelFormat_YCbCr8;
337  }
338  else if ((xWire == 1920) && (xBitmap == 1280))
339  {
340  scaleType = AJAScaleType1280To1920;
341  primaryFormat = AJA_PixelFormat_YCbCr8;
342  }
343  else if ((xWire == 1280) && (xBitmap == 960))
344  {
345  scaleType = AJAScaleType960To1280;
346  primaryFormat = AJA_PixelFormat_YCbCr8;
347  }
348  else
349  {
350  bOk = false;
351  }
352 
353  return bOk;
354 }
355 
356 
357 int AJAPixelFormat::QueryFullScaleWidth(int scaledWidth, int height)
358 {
359  int fullScaleWidth = scaledWidth;
360 
361  if (height == 1080 && scaledWidth == 1280)
362  fullScaleWidth = 1920;
363 
364  else if (height == 1080 && scaledWidth == 1440)
365  fullScaleWidth = 1920;
366 
367  else if (height == 720 && scaledWidth == 960)
368  fullScaleWidth = 1280;
369 
370  return fullScaleWidth;
371 }
372 
373 
375 {
377 
378  if (height == 1080 && scaledWidth == 1280)
379  pixelFormat = AJA_PixelFormat_DVCPRO;
380 
381  else if (height == 1080 && scaledWidth == 1440)
382  pixelFormat = AJA_PixelFormat_HDV;
383 
384  else if (height == 720 && scaledWidth == 960)
385  pixelFormat = AJA_PixelFormat_HDV;
386 
387  return pixelFormat;
388 }
AJAScaleType
Definition: pixelformat.h:15
AJASubSampleType subSampleType
Definition: pixelformat.cpp:25
const char * pName
Definition: pixelformat.cpp:28
Declares common types used in the ajabase library.
static int QueryFullScaleWidth(int scaledWidth, int height)
AJA_PixelFormat
Definition: videotypes.h:121
uint32_t QueryBitDepth()
static bool QueryFormatAtIndex(int index, AJAPixelFormat &fmt)
Definition: pixelformat.cpp:19
Storage and utility class for AJA_PixelFormat defines. This class provides a means of storing and que...
Definition: pixelformat.h:43
#define AJA_FOURCC(a, b, c, d)
Definition: types.h:359
AJAPixelFormatEntry AJAPixelFormatTable[AJA_PixelFormat_Size]
Definition: pixelformat.cpp:34
uint32_t fourcc
Definition: pixelformat.cpp:22
static int QueryNumberPossibleFormats()
Contains the declaration of the AJAPixelFormat class.
void Set(AJA_PixelFormat format)
uint32_t bitDepth
Definition: pixelformat.cpp:23
const size_t AJAPixelFormatTableSize
Definition: pixelformat.cpp:84
bool isRGB
Definition: pixelformat.cpp:27
bool QueryRgb(void)
Master header for the ajabase library.
uint32_t QueryPlaneCount()
const char * QueryDisplayName(void)
FFmpeg related (see AVPixelFormat in libavutil/pixfmt.h, libavutil/pixdesc.c) - unpacked 16bpp...
Definition: videotypes.h:171
AJA_PixelFormat Query(void)
AJAScaleType QueryScaleType(void)
AJAScaleType scaleType
Definition: pixelformat.cpp:24
static bool QueryIsScalable(uint32_t bitmapWidth, uint32_t wireWidth, uint32_t xAspect, uint32_t yAspect, AJA_PixelFormat *pMatchingFormat, AJA_PixelFormat *pScalingFormat)
static bool ConvertAspect(AJAScaleType scaleType, int hIn, int vIn, int &hOut, int &vOut)
virtual ~AJAPixelFormat()
uint32_t QueryFourCC(void)
AJA_PixelFormat m_format
Definition: pixelformat.h:214
static bool ConvertWidth(AJAScaleType scaleType, int xIn, int &xOut)
static AJA_PixelFormat QueryScaledPixelFormat(int scaledWidth, int height)
AJA_PixelFormat pixelFormat
Definition: pixelformat.cpp:21
uint32_t planeCount
Definition: pixelformat.cpp:26
AJASubSampleType
Definition: pixelformat.h:27
AJASubSampleType QuerySubSampleType()