AJA NTV2 SDK  17.1.3.1410
NTV2 SDK 17.1.3.1410
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 
60  explicit NTV2FormatDescriptor ( const ULWord inNumLines,
61  const ULWord inNumPixels,
62  const ULWord inLinePitch,
63  const ULWord inFirstActiveLine = 0);
64 
71  explicit NTV2FormatDescriptor ( const NTV2Standard inStandard,
72  const NTV2FrameBufferFormat inFrameBufferFormat,
73  const NTV2VANCMode inVancMode = NTV2_VANCMODE_OFF);
74 
81  explicit NTV2FormatDescriptor ( const NTV2VideoFormat inVideoFormat,
82  const NTV2FrameBufferFormat inFrameBufferFormat,
83  const NTV2VANCMode inVancMode = NTV2_VANCMODE_OFF);
85 
89 
94  inline bool IsValid (void) const {return numLines && numPixels && mNumPlanes && mLinePitch[0]
95  && (mNumBitsLuma || mNumBitsChroma);}
96  inline bool IsVANC (void) const {return GetFirstActiveLine() > 0;}
97  inline bool IsPlanar (void) const {return GetNumPlanes() > 1 || NTV2_IS_FBF_PLANAR (mPixelFormat);}
98 
106  ULWord GetVerticalSampleRatio (const UWord inPlaneIndex0 = 0) const; // New in SDK 16.0
107 
114  inline ULWord GetTotalRasterBytes (const UWord inPlaneIndex0 = 0) const
115  { const ULWord vSamp(GetVerticalSampleRatio(inPlaneIndex0));
116  return vSamp ? (GetFullRasterHeight() * GetBytesPerRow(inPlaneIndex0) / vSamp) : 0;
117  }
118 
122  ULWord GetTotalBytes (void) const; // New in SDK 16.0
123 
128  ULWord GetVideoWriteSize (ULWord inPageSize = 4096UL) const; // New in SDK 16.2
129 
134  inline ULWord GetVisibleRasterBytes (const UWord inPlaneIndex0 = 0) const {return GetVisibleRasterHeight() * GetBytesPerRow(inPlaneIndex0);}
135 
140  inline ULWord GetBytesPerRow (const UWord inPlaneIndex0 = 0) const {return inPlaneIndex0 < mNumPlanes ? mLinePitch[inPlaneIndex0] : 0;}
141 
142  inline ULWord GetRasterWidth (void) const {return numPixels;}
143  inline UWord GetNumPlanes (void) const {return mNumPlanes;}
144  std::string PlaneToString (const UWord inPlaneIndex0) const;
145 
151  UWord ByteOffsetToPlane (const ULWord inByteOffset) const;
152 
158  UWord ByteOffsetToRasterLine (const ULWord inByteOffset) const;
159 
164  bool IsAtLineStart (ULWord inByteOffset) const;
165 
170  inline ULWord GetRasterHeight (const bool inVisibleOnly = false) const {return inVisibleOnly ? GetVisibleRasterHeight() : GetFullRasterHeight();}
171 
175  inline ULWord GetFullRasterHeight (void) const {return numLines;}
176 
180  inline ULWord GetFirstActiveLine (void) const {return firstActiveLine;}
181 
185  inline ULWord GetVisibleRasterHeight (void) const {return GetFullRasterHeight() - GetFirstActiveLine();}
186 
196  bool GetRowBuffer (const NTV2Buffer & inFrameBuffer, NTV2Buffer & inOutRowBuffer, const ULWord inRowIndex0, const UWord inPlaneIndex0 = 0) const; // New in SDK 16.0
197 
205  const void * GetRowAddress (const void * pInStartAddress, const ULWord inRowIndex0, const UWord inPlaneIndex0 = 0) const;
206 
214  void * GetWriteableRowAddress (void * pInStartAddress, const ULWord inRowIndex0, const UWord inPlaneIndex0 = 0) const;
215 
223  ULWord RasterLineToByteOffset (const ULWord inRowIndex0, const UWord inPlaneIndex0 = 0) const;
224 
230  inline UByte * GetTopVisibleRowAddress (UByte * pInStartAddress) const {return (UByte *) GetRowAddress (pInStartAddress, firstActiveLine);}
231 
240  bool GetFirstChangedRow (const void * pInStartAddress1, const void * pInStartAddress2, ULWord & outFirstChangedRowNum) const;
241 
253  bool GetChangedLines (NTV2RasterLineOffsets & outDiffs, const void * pInBuffer1, const void * pInBuffer2, const ULWord inMaxLines = 0) const;
254 
258  NTV2FrameDimensions GetFullRasterDimensions (void) const;
259 
263  NTV2FrameDimensions GetVisibleRasterDimensions (void) const;
264 
272  bool GetSMPTELineNumber (const ULWord inLineOffset, ULWord & outSMPTELine, bool & outIsField2) const;
273 
280  bool GetLineOffsetFromSMPTELine (const ULWord inSMPTELine, ULWord & outLineOffset) const;
281 
289  NTV2SegmentedXferInfo & GetSegmentedXferInfo (NTV2SegmentedXferInfo & inSegmentInfo, const bool inIsSource = true) const;
290 
295  bool operator == (const NTV2FormatDescriptor & inRHS) const;
296 
303  std::ostream & Print (std::ostream & inOutStream, const bool inDetailed = true) const;
304 
312  std::ostream & PrintSMPTELineNumber (std::ostream & inOutStream, const ULWord inLineOffset, const bool inForTextMode = false) const;
313 
314  inline NTV2Standard GetVideoStandard (void) const {return mStandard;}
315  inline NTV2VideoFormat GetVideoFormat (void) const {return mVideoFormat;}
316  inline NTV2FrameBufferFormat GetPixelFormat (void) const {return mPixelFormat;}
317  inline NTV2VANCMode GetVANCMode (void) const {return mVancMode;}
318  inline bool IsSD (void) const {return NTV2_IS_SD_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_SD_STANDARD(GetVideoStandard());}
319  inline bool IsHD (void) const {return NTV2_IS_HD_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_HD_STANDARD(GetVideoStandard());}
320  inline bool IsUHD (void) const {return NTV2_IS_UHD_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_UHD_STANDARD(GetVideoStandard());}
321  inline bool Is4K (void) const {return NTV2_IS_4K_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_4K_STANDARD(GetVideoStandard());}
322  inline bool IsUHD2 (void) const {return NTV2_IS_UHD2_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_UHD2_STANDARD(GetVideoStandard());}
323  inline bool Is8K (void) const {return NTV2_IS_8K_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_8K_STANDARD(GetVideoStandard());}
324  inline bool IsQuadRaster (void) const {return NTV2_IS_QUAD_STANDARD(mStandard) || NTV2_IS_4K_VIDEO_FORMAT(mVideoFormat);}
325  inline bool IsTallVanc (void) const {return mVancMode == NTV2_VANCMODE_TALL;}
326  inline bool IsTallerVanc (void) const {return mVancMode == NTV2_VANCMODE_TALLER;}
327  inline NTV2FrameGeometry GetFrameGeometry (void) const {return mFrameGeometry;}
328  inline UByte GetNumBitsLuma (void) const {return mNumBitsLuma;}
329  inline UByte GetNumBitsChroma (void) const {return mNumBitsChroma;}
330  inline UByte GetNumBitsAlpha (void) const {return mNumBitsAlpha;}
331  inline bool HasAlpha (void) const {return IsValid() && GetNumBitsAlpha();}
332  inline bool IsRGB (void) const {return GetNumBitsLuma() ? false : true;}
333  bool Is2KFormat (void) const;
334 #if !defined(NTV2_DEPRECATE_16_3)
336  inline bool IsSDFormat (void) const {return NTV2_IS_SD_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_SD_STANDARD(GetVideoStandard());}
337 #endif
338  void MakeInvalid (void);
339 
340  private:
341  friend class CNTV2CaptionRenderer; // The caption renderer needs to call SetPixelFormat
342  inline void SetPixelFormat (const NTV2PixelFormat inPixFmt) {mPixelFormat = inPixFmt;}
343  inline void SetBitsPerComponent (const UByte inLuma, const UByte inChroma, const UByte inAlpha) {mNumBitsLuma = inLuma; mNumBitsChroma = inChroma; mNumBitsAlpha = inAlpha;}
344  void FinalizePlanar (void);
345 
346  // Member Data
347  public:
352  private:
353  NTV2Standard mStandard;
354  NTV2VideoFormat mVideoFormat;
355  NTV2FrameBufferFormat mPixelFormat;
356  NTV2VANCMode mVancMode;
357  ULWord mLinePitch[4];
358  UWord mNumPlanes;
359  NTV2FrameGeometry mFrameGeometry;
360  UByte mNumBitsLuma;
361  UByte mNumBitsChroma;
362  UByte mNumBitsAlpha;
363 
364 }; // NTV2FormatDescriptor
365 
367 
374 AJAExport inline std::ostream & operator << (std::ostream & inOutStream, const NTV2FormatDescriptor & inFormatDesc) {return inFormatDesc.Print (inOutStream);}
375 
376 
386 AJAExport bool UnpackLine_10BitYUVtoUWordSequence (const void * pIn10BitYUVLine, const NTV2FormatDescriptor & inFormatDesc, UWordSequence & out16BitYUVLine);
387 
388 #endif // NTV2FORMATDESC_H
NTV2_IS_UHD2_STANDARD
#define NTV2_IS_UHD2_STANDARD(__s__)
Definition: ntv2enums.h:198
NTV2_IS_UHD_STANDARD
#define NTV2_IS_UHD_STANDARD(__s__)
Definition: ntv2enums.h:190
NTV2FormatDescriptor::GetBytesPerRow
ULWord GetBytesPerRow(const UWord inPlaneIndex0=0) const
Definition: ntv2formatdescriptor.h:140
NTV2_IS_4K_STANDARD
#define NTV2_IS_4K_STANDARD(__s__)
Definition: ntv2enums.h:193
NTV2_IS_SD_VIDEO_FORMAT
#define NTV2_IS_SD_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:707
ajaexport.h
Defines the import/export macros for producing DLLs or LIBs.
NTV2FrameDimensions
Describes the horizontal and vertical size dimensions of a raster, bitmap, frame or image.
Definition: ntv2publicinterface.h:5658
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:255
NTV2Buffer
A generic user-space buffer object that has an address and a length. Used most often to share an arbi...
Definition: ntv2publicinterface.h:5993
NTV2FormatDescriptor::linePitch
ULWord linePitch
Number of 32-bit words per line. Shadows mLinePitch[0] * sizeof(ULWord).
Definition: ntv2formatdescriptor.h:350
NTV2FormatDescriptor::GetTopVisibleRowAddress
UByte * GetTopVisibleRowAddress(UByte *pInStartAddress) const
Definition: ntv2formatdescriptor.h:230
NTV2FormatDescriptor::GetVisibleRasterBytes
ULWord GetVisibleRasterBytes(const UWord inPlaneIndex0=0) const
Definition: ntv2formatdescriptor.h:134
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:170
NTV2FrameBufferFormat
NTV2FrameBufferFormat
Identifies a particular video frame buffer format. See Device Frame Buffer Formats for details.
Definition: ntv2enums.h:207
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:852
NTV2_IS_QUAD_STANDARD
#define NTV2_IS_QUAD_STANDARD(__s__)
Definition: ntv2enums.h:196
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:746
NTV2SegmentedXferInfo
Describes a segmented data transfer (copy or move) from a source memory location to a destination loc...
Definition: ntv2publicinterface.h:5732
NTV2_IS_UHD_VIDEO_FORMAT
#define NTV2_IS_UHD_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:840
NTV2FormatDescriptor::numPixels
ULWord numPixels
Width – total number of pixels per line.
Definition: ntv2formatdescriptor.h:349
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:3719
NTV2Standard
NTV2Standard
Identifies a particular video standard.
Definition: ntv2enums.h:153
NTV2_VANCMODE_OFF
@ NTV2_VANCMODE_OFF
This identifies the mode in which there are no VANC lines in the frame buffer.
Definition: ntv2enums.h:3718
ULWord
uint32_t ULWord
Definition: ajatypes.h:253
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:348
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:374
NTV2FormatDescriptor::GetFirstActiveLine
ULWord GetFirstActiveLine(void) const
Definition: ntv2formatdescriptor.h:180
UWord
uint16_t UWord
Definition: ajatypes.h:251
ntv2enums.h
Enumerations for controlling NTV2 devices.
NTV2_IS_HD_VIDEO_FORMAT
#define NTV2_IS_HD_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:700
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:2775
NTV2FormatDesc
NTV2FormatDescriptor NTV2FormatDesc
Shorthand for NTV2FormatDescriptor.
Definition: ntv2formatdescriptor.h:366
NTV2VANCMode
NTV2VANCMode
These enum values identify the available VANC modes.
Definition: ntv2enums.h:3716
NTV2FormatDescriptor::GetTotalRasterBytes
ULWord GetTotalRasterBytes(const UWord inPlaneIndex0=0) const
Definition: ntv2formatdescriptor.h:114
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:351
NTV2_IS_8K_STANDARD
#define NTV2_IS_8K_STANDARD(__s__)
Definition: ntv2enums.h:199
NTV2_IS_HD_STANDARD
#define NTV2_IS_HD_STANDARD(__s__)
Definition: ntv2enums.h:187
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:3720
CNTV2CaptionRenderer
Definition: ntv2captionrenderer.h:31
false
#define false
Definition: ntv2devicefeatures.h:25
UByte
uint8_t UByte
Definition: ajatypes.h:248
NTV2_IS_SD_STANDARD
#define NTV2_IS_SD_STANDARD(__s__)
Definition: ntv2enums.h:186
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:1108
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:336
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:842
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:175
NTV2FormatDescriptor::IsValid
bool IsValid(void) const
Definition: ntv2formatdescriptor.h:94
NTV2FormatDescriptor::GetVisibleRasterHeight
ULWord GetVisibleRasterHeight(void) const
Definition: ntv2formatdescriptor.h:185
Is2KFormat
bool Is2KFormat(const NTV2VideoFormat format)
Definition: ntv2utils.cpp:5460