AJA NTV2 SDK  17.5.0.1492
NTV2 SDK 17.5.0.1492
ntv2formatdescriptor.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 #ifndef NTV2FORMATDESC_H
9 #define NTV2FORMATDESC_H
10 
11 #include "ajaexport.h"
12 #include "ajatypes.h"
13 #include "ntv2enums.h"
14 #include "ntv2publicinterface.h"
15 #include <string>
16 #include <iostream>
17 #include <vector>
18 #if defined (AJALinux)
19  #include <stdint.h>
20 #endif
21 
22 
23 typedef std::vector <ULWord> NTV2RasterLineOffsets;
24 typedef NTV2RasterLineOffsets::const_iterator NTV2RasterLineOffsetsConstIter;
25 typedef NTV2RasterLineOffsets::iterator NTV2RasterLineOffsetsIter;
26 
33 AJAExport std::ostream & NTV2PrintRasterLineOffsets (const NTV2RasterLineOffsets & inObj, std::ostream & inOutStream = std::cout);
34 
42 {
43 public:
47 
51  explicit NTV2FormatDescriptor ();
52 
63  explicit NTV2FormatDescriptor ( const ULWord inNumLines,
64  const ULWord inNumPixels,
65  const ULWord inLinePitch,
66  const ULWord in1stActiveLine = 0,
67  const UByte inNumLumaBits = 0,
68  const UByte inNumChromaBits = 0,
69  const UByte inNumAlphaBits = 0);
70 
77  explicit NTV2FormatDescriptor ( const NTV2Standard inStandard,
78  const NTV2FrameBufferFormat inFrameBufferFormat,
79  const NTV2VANCMode inVancMode = NTV2_VANCMODE_OFF);
80 
87  explicit NTV2FormatDescriptor ( const NTV2VideoFormat inVideoFormat,
88  const NTV2FrameBufferFormat inFrameBufferFormat,
89  const NTV2VANCMode inVancMode = NTV2_VANCMODE_OFF);
90 
99  explicit NTV2FormatDescriptor ( const NTV2FrameSize & inRasterSize,
100  const NTV2PixelFormat inPixelFormat,
101  const NTV2VANCMode inVancMode = NTV2_VANCMODE_OFF);
103 
107 
112  inline bool IsValid (void) const {return numLines && numPixels && mNumPlanes && mLinePitch[0]
113  && (mNumBitsLuma || mNumBitsChroma);}
114  inline bool IsVANC (void) const {return GetFirstActiveLine() > 0;}
115  inline bool IsPlanar (void) const {return GetNumPlanes() > 1 || NTV2_IS_FBF_PLANAR (mPixelFormat);}
116 
124  ULWord GetVerticalSampleRatio (const UWord inPlaneIndex0 = 0) const; // New in SDK 16.0
125 
132  inline ULWord GetTotalRasterBytes (const UWord inPlaneIndex0 = 0) const
133  { const ULWord vSamp(GetVerticalSampleRatio(inPlaneIndex0));
134  return vSamp ? (GetFullRasterHeight() * GetBytesPerRow(inPlaneIndex0) / vSamp) : 0;
135  }
136 
140  ULWord GetTotalBytes (void) const; // New in SDK 16.0
141 
146  ULWord GetVideoWriteSize (ULWord inPageSize = 4096UL) const; // New in SDK 16.2
147 
152  inline ULWord GetVisibleRasterBytes (const UWord inPlaneIndex0 = 0) const {return GetVisibleRasterHeight() * GetBytesPerRow(inPlaneIndex0);}
153 
158  inline ULWord GetBytesPerRow (const UWord inPlaneIndex0 = 0) const {return inPlaneIndex0 < mNumPlanes ? mLinePitch[inPlaneIndex0] : 0;}
159 
160  inline ULWord GetRasterWidth (void) const {return numPixels;}
161  inline UWord GetNumPlanes (void) const {return mNumPlanes;}
162  std::string PlaneToString (const UWord inPlaneIndex0) const;
163 
169  UWord ByteOffsetToPlane (const ULWord inByteOffset) const;
170 
176  UWord ByteOffsetToRasterLine (const ULWord inByteOffset) const;
177 
182  bool IsAtLineStart (ULWord inByteOffset) const;
183 
188  inline ULWord GetRasterHeight (const bool inVisibleOnly = false) const {return inVisibleOnly ? GetVisibleRasterHeight() : GetFullRasterHeight();}
189 
193  inline ULWord GetFullRasterHeight (void) const {return numLines;}
194 
198  inline ULWord GetFirstActiveLine (void) const {return firstActiveLine;}
199 
203  inline ULWord GetVisibleRasterHeight (void) const {return GetFullRasterHeight() - GetFirstActiveLine();}
204 
214  bool GetRowBuffer (const NTV2Buffer & inFrameBuffer, NTV2Buffer & inOutRowBuffer, const ULWord inRowIndex0, const UWord inPlaneIndex0 = 0) const; // New in SDK 16.0
215 
223  const void * GetRowAddress (const void * pInStartAddress, const ULWord inRowIndex0, const UWord inPlaneIndex0 = 0) const;
224 
232  void * GetWriteableRowAddress (void * pInStartAddress, const ULWord inRowIndex0, const UWord inPlaneIndex0 = 0) const;
233 
241  ULWord RasterLineToByteOffset (const ULWord inRowIndex0, const UWord inPlaneIndex0 = 0) const;
242 
248  inline UByte * GetTopVisibleRowAddress (UByte * pInStartAddress) const {return (UByte *) GetRowAddress (pInStartAddress, firstActiveLine);}
249 
258  bool GetFirstChangedRow (const void * pInStartAddress1, const void * pInStartAddress2, ULWord & outFirstChangedRowNum) const;
259 
271  bool GetChangedLines (NTV2RasterLineOffsets & outDiffs, const void * pInBuffer1, const void * pInBuffer2, const ULWord inMaxLines = 0) const;
272 
276  NTV2FrameDimensions GetFullRasterDimensions (void) const;
277 
281  NTV2FrameDimensions GetVisibleRasterDimensions (void) const;
282 
290  bool GetSMPTELineNumber (const ULWord inLineOffset, ULWord & outSMPTELine, bool & outIsField2) const;
291 
298  bool GetLineOffsetFromSMPTELine (const ULWord inSMPTELine, ULWord & outLineOffset) const;
299 
307  NTV2SegmentedXferInfo & GetSegmentedXferInfo (NTV2SegmentedXferInfo & inSegmentInfo, const bool inIsSource = true) const;
308 
313  bool operator == (const NTV2FormatDescriptor & inRHS) const;
314 
321  std::ostream & Print (std::ostream & inOutStream, const bool inDetailed = true) const;
322 
330  std::ostream & PrintSMPTELineNumber (std::ostream & inOutStream, const ULWord inLineOffset, const bool inForTextMode = false) const;
331 
332  inline NTV2Standard GetVideoStandard (void) const {return mStandard;}
333  inline NTV2VideoFormat GetVideoFormat (void) const {return mVideoFormat;}
334  inline NTV2FrameBufferFormat GetPixelFormat (void) const {return mPixelFormat;}
335  inline NTV2VANCMode GetVANCMode (void) const {return mVancMode;}
336  inline bool IsSD (void) const {return NTV2_IS_SD_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_SD_STANDARD(GetVideoStandard());}
337  inline bool IsHD (void) const {return NTV2_IS_HD_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_HD_STANDARD(GetVideoStandard());}
338  inline bool IsUHD (void) const {return NTV2_IS_UHD_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_UHD_STANDARD(GetVideoStandard());}
339  inline bool Is4K (void) const {return NTV2_IS_4K_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_4K_STANDARD(GetVideoStandard());}
340  inline bool IsUHD2 (void) const {return NTV2_IS_UHD2_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_UHD2_STANDARD(GetVideoStandard());}
341  inline bool Is8K (void) const {return NTV2_IS_8K_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_8K_STANDARD(GetVideoStandard());}
342  inline bool IsQuadRaster (void) const {return NTV2_IS_QUAD_STANDARD(mStandard) || NTV2_IS_4K_VIDEO_FORMAT(mVideoFormat);}
343  inline bool IsTallVanc (void) const {return mVancMode == NTV2_VANCMODE_TALL;}
344  inline bool IsTallerVanc (void) const {return mVancMode == NTV2_VANCMODE_TALLER;}
345  inline NTV2FrameGeometry GetFrameGeometry (void) const {return mFrameGeometry;}
346  inline UByte GetNumBitsLuma (void) const {return mNumBitsLuma;}
347  inline UByte GetNumBitsChroma (void) const {return mNumBitsChroma;}
348  inline UByte GetNumBitsAlpha (void) const {return mNumBitsAlpha;}
349  inline bool HasAlpha (void) const {return IsValid() && GetNumBitsAlpha();}
350  inline bool IsRGB (void) const {return GetNumBitsLuma() ? false : true;}
351  bool Is2KFormat (void) const;
352 #if !defined(NTV2_DEPRECATE_16_3)
354  inline bool IsSDFormat (void) const {return NTV2_IS_SD_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_SD_STANDARD(GetVideoStandard());}
355 #endif
356  void MakeInvalid (void);
357 
358  private:
359  friend class CNTV2CaptionRenderer; // The caption renderer needs to call SetPixelFormat
360  inline void SetPixelFormat (const NTV2PixelFormat inPixFmt) {mPixelFormat = inPixFmt;}
361  inline void SetBitsPerComponent (const UByte inLuma, const UByte inChroma, const UByte inAlpha) {mNumBitsLuma = inLuma; mNumBitsChroma = inChroma; mNumBitsAlpha = inAlpha;}
362  void FinalizePlanar (void);
363 
364  // Member Data
365  public:
370  private:
371  NTV2Standard mStandard;
372  NTV2VideoFormat mVideoFormat;
373  NTV2PixelFormat mPixelFormat;
374  NTV2VANCMode mVancMode;
375  ULWord mLinePitch[4];
376  UWord mNumPlanes;
377  NTV2FrameGeometry mFrameGeometry;
378  UByte mNumBitsLuma;
379  UByte mNumBitsChroma;
380  UByte mNumBitsAlpha;
381 
382 }; // NTV2FormatDescriptor
383 
386 
393 AJAExport inline std::ostream & operator << (std::ostream & inOutStream, const NTV2FormatDescriptor & inFormatDesc) {return inFormatDesc.Print (inOutStream);}
394 
395 
405 AJAExport bool UnpackLine_10BitYUVtoUWordSequence (const void * pIn10BitYUVLine, const NTV2FormatDescriptor & inFormatDesc, UWordSequence & out16BitYUVLine);
406 
407 #endif // NTV2FORMATDESC_H
NTV2_IS_UHD2_STANDARD
#define NTV2_IS_UHD2_STANDARD(__s__)
Definition: ntv2enums.h:201
NTV2_IS_UHD_STANDARD
#define NTV2_IS_UHD_STANDARD(__s__)
Definition: ntv2enums.h:193
NTV2FormatDescriptor::GetBytesPerRow
ULWord GetBytesPerRow(const UWord inPlaneIndex0=0) const
Definition: ntv2formatdescriptor.h:158
NTV2_IS_4K_STANDARD
#define NTV2_IS_4K_STANDARD(__s__)
Definition: ntv2enums.h:196
NTV2_IS_SD_VIDEO_FORMAT
#define NTV2_IS_SD_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:735
ajaexport.h
Defines the import/export macros for producing DLLs or LIBs.
NTV2FormatDescriptor
Describes a video frame for a given video standard or format and pixel format, including the total nu...
Definition: ntv2formatdescriptor.h:41
NTV2_IS_FBF_PLANAR
#define NTV2_IS_FBF_PLANAR(__s__)
Definition: ntv2enums.h:258
NTV2Buffer
Describes a user-space buffer on the host computer. I have an address and a length,...
Definition: ntv2publicinterface.h:6094
NTV2FormatDescriptor::linePitch
ULWord linePitch
Number of 32-bit words per line – shadows mLinePitch[0] / sizeof(ULWord)
Definition: ntv2formatdescriptor.h:368
NTV2FormatDescriptor::GetTopVisibleRowAddress
UByte * GetTopVisibleRowAddress(UByte *pInStartAddress) const
Definition: ntv2formatdescriptor.h:248
NTV2FormatDescriptor::GetVisibleRasterBytes
ULWord GetVisibleRasterBytes(const UWord inPlaneIndex0=0) const
Definition: ntv2formatdescriptor.h:152
UnpackLine_10BitYUVtoUWordSequence
bool UnpackLine_10BitYUVtoUWordSequence(const void *pIn10BitYUVLine, const NTV2FormatDescriptor &inFormatDesc, UWordSequence &out16BitYUVLine)
Unpacks a line of NTV2_FBF_10BIT_YCBCR video into 16-bit-per-component YUV data.
Definition: ntv2utils.cpp:143
NTV2FormatDescriptor::GetRasterHeight
ULWord GetRasterHeight(const bool inVisibleOnly=false) const
Definition: ntv2formatdescriptor.h:188
NTV2FrameBufferFormat
NTV2FrameBufferFormat
Identifies a particular video frame buffer format. See Device Frame Buffer Formats for details.
Definition: ntv2enums.h:210
nlohmann::json_abiNLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON_v3_11_NLOHMANN_JSON_VERSION_PATCH::operator==
bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition: json.hpp:14737
NTV2_IS_8K_VIDEO_FORMAT
#define NTV2_IS_8K_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:884
NTV2_IS_QUAD_STANDARD
#define NTV2_IS_QUAD_STANDARD(__s__)
Definition: ntv2enums.h:199
NTV2FrameSize
Describes the horizontal and vertical size dimensions of a raster, bitmap, frame or image.
Definition: ntv2publicinterface.h:5694
ajatypes.h
Declares the most fundamental data types used by NTV2. Since Windows NT was the first principal devel...
NTV2_IS_4K_VIDEO_FORMAT
#define NTV2_IS_4K_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:774
NTV2SegmentedXferInfo
Describes a segmented data transfer (copy or move) from a source memory location to a destination loc...
Definition: ntv2publicinterface.h:5802
NTV2_IS_UHD_VIDEO_FORMAT
#define NTV2_IS_UHD_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:872
NTV2FormatDescriptor::numPixels
ULWord numPixels
Width – total number of pixels per line.
Definition: ntv2formatdescriptor.h:367
NTV2_VANCMODE_TALL
@ NTV2_VANCMODE_TALL
This identifies the "tall" mode in which there are some VANC lines in the frame buffer.
Definition: ntv2enums.h:3770
NTV2Standard
NTV2Standard
Identifies a particular video standard.
Definition: ntv2enums.h:156
NTV2_VANCMODE_OFF
@ NTV2_VANCMODE_OFF
This identifies the mode in which there are no VANC lines in the frame buffer.
Definition: ntv2enums.h:3769
ULWord
uint32_t ULWord
Definition: ajatypes.h:255
NTV2PrintRasterLineOffsets
std::ostream & NTV2PrintRasterLineOffsets(const NTV2RasterLineOffsets &inObj, std::ostream &inOutStream=std::cout)
Streams a human-readable dump of the given NTV2RasterLineOffsets sequence into the specified output s...
NTV2RasterLineOffsetsIter
NTV2RasterLineOffsets::iterator NTV2RasterLineOffsetsIter
A handy non-const iterator into an NTV2RasterLineOffsets.
Definition: ntv2formatdescriptor.h:25
NTV2FormatDescriptor::numLines
ULWord numLines
Height – total number of lines.
Definition: ntv2formatdescriptor.h:366
UWordSequence
std::vector< uint16_t > UWordSequence
An ordered sequence of UWord (uint16_t) values.
Definition: ntv2publicinterface.h:42
operator<<
std::ostream & operator<<(std::ostream &inOutStream, const NTV2FormatDescriptor &inFormatDesc)
Writes the given NTV2FormatDescriptor to the specified output stream.
Definition: ntv2formatdescriptor.h:393
NTV2RasterInfo
NTV2FormatDesc NTV2RasterInfo
Shorthand for NTV2FormatDescriptor.
Definition: ntv2formatdescriptor.h:385
NTV2FormatDescriptor::GetFirstActiveLine
ULWord GetFirstActiveLine(void) const
Definition: ntv2formatdescriptor.h:198
UWord
uint16_t UWord
Definition: ajatypes.h:253
ntv2enums.h
Enumerations for controlling NTV2 devices.
NTV2_IS_HD_VIDEO_FORMAT
#define NTV2_IS_HD_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:728
GetVideoWriteSize
ULWord GetVideoWriteSize(const NTV2VideoFormat inVideoFormat, const NTV2FrameBufferFormat inFBFormat, const NTV2VANCMode inVancMode=NTV2_VANCMODE_OFF)
Identical to the GetVideoActiveSize function, except rounds the result up to the nearest 4K page size...
Definition: ntv2utils.cpp:2779
NTV2FormatDesc
NTV2FormatDescriptor NTV2FormatDesc
Shorthand for NTV2FormatDescriptor.
Definition: ntv2formatdescriptor.h:384
NTV2VANCMode
NTV2VANCMode
These enum values identify the available VANC modes.
Definition: ntv2enums.h:3767
NTV2FormatDescriptor::GetTotalRasterBytes
ULWord GetTotalRasterBytes(const UWord inPlaneIndex0=0) const
Definition: ntv2formatdescriptor.h:132
NTV2RasterLineOffsets
std::vector< ULWord > NTV2RasterLineOffsets
An ordered sequence of zero-based line offsets into a frame buffer.
Definition: ntv2formatdescriptor.h:23
NTV2FormatDescriptor::firstActiveLine
ULWord firstActiveLine
First active line of video (0 if NTV2_VANCMODE_OFF)
Definition: ntv2formatdescriptor.h:369
NTV2_IS_8K_STANDARD
#define NTV2_IS_8K_STANDARD(__s__)
Definition: ntv2enums.h:202
NTV2_IS_HD_STANDARD
#define NTV2_IS_HD_STANDARD(__s__)
Definition: ntv2enums.h:190
NTV2_VANCMODE_TALLER
@ NTV2_VANCMODE_TALLER
This identifies the mode in which there are some + extra VANC lines in the frame buffer.
Definition: ntv2enums.h:3771
CNTV2CaptionRenderer
Definition: ntv2captionrenderer.h:31
false
#define false
Definition: ntv2devicefeatures.h:25
UByte
uint8_t UByte
Definition: ajatypes.h:250
NTV2_IS_SD_STANDARD
#define NTV2_IS_SD_STANDARD(__s__)
Definition: ntv2enums.h:189
NTV2FormatDescriptor::Print
std::ostream & Print(std::ostream &inOutStream, const bool inDetailed=true) const
Writes a human-readable description of me into the given output stream.
Definition: ntv2formatdescriptor.cpp:1203
AJAExport
#define AJAExport
Definition: export.h:33
NTV2VideoFormat
enum _NTV2VideoFormat NTV2VideoFormat
Identifies a particular video format.
NTV2FrameGeometry
NTV2FrameGeometry
Identifies a particular video frame geometry.
Definition: ntv2enums.h:339
ntv2publicinterface.h
Declares enums and structs used by all platform drivers and the SDK.
NTV2_IS_UHD2_VIDEO_FORMAT
#define NTV2_IS_UHD2_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:874
NTV2RasterLineOffsetsConstIter
NTV2RasterLineOffsets::const_iterator NTV2RasterLineOffsetsConstIter
A handy const iterator into an NTV2RasterLineOffsets.
Definition: ntv2formatdescriptor.h:24
NTV2FormatDescriptor::GetFullRasterHeight
ULWord GetFullRasterHeight(void) const
Definition: ntv2formatdescriptor.h:193
NTV2FormatDescriptor::IsValid
bool IsValid(void) const
Definition: ntv2formatdescriptor.h:112
NTV2FormatDescriptor::GetVisibleRasterHeight
ULWord GetVisibleRasterHeight(void) const
Definition: ntv2formatdescriptor.h:203
Is2KFormat
bool Is2KFormat(const NTV2VideoFormat format)
Definition: ntv2utils.cpp:5493