AJA NTV2 SDK  17.5.0.1242
NTV2 SDK 17.5.0.1242
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);
91 
95 
100  inline bool IsValid (void) const {return numLines && numPixels && mNumPlanes && mLinePitch[0]
101  && (mNumBitsLuma || mNumBitsChroma);}
102  inline bool IsVANC (void) const {return GetFirstActiveLine() > 0;}
103  inline bool IsPlanar (void) const {return GetNumPlanes() > 1 || NTV2_IS_FBF_PLANAR (mPixelFormat);}
104 
112  ULWord GetVerticalSampleRatio (const UWord inPlaneIndex0 = 0) const; // New in SDK 16.0
113 
120  inline ULWord GetTotalRasterBytes (const UWord inPlaneIndex0 = 0) const
121  { const ULWord vSamp(GetVerticalSampleRatio(inPlaneIndex0));
122  return vSamp ? (GetFullRasterHeight() * GetBytesPerRow(inPlaneIndex0) / vSamp) : 0;
123  }
124 
128  ULWord GetTotalBytes (void) const; // New in SDK 16.0
129 
134  ULWord GetVideoWriteSize (ULWord inPageSize = 4096UL) const; // New in SDK 16.2
135 
140  inline ULWord GetVisibleRasterBytes (const UWord inPlaneIndex0 = 0) const {return GetVisibleRasterHeight() * GetBytesPerRow(inPlaneIndex0);}
141 
146  inline ULWord GetBytesPerRow (const UWord inPlaneIndex0 = 0) const {return inPlaneIndex0 < mNumPlanes ? mLinePitch[inPlaneIndex0] : 0;}
147 
148  inline ULWord GetRasterWidth (void) const {return numPixels;}
149  inline UWord GetNumPlanes (void) const {return mNumPlanes;}
150  std::string PlaneToString (const UWord inPlaneIndex0) const;
151 
157  UWord ByteOffsetToPlane (const ULWord inByteOffset) const;
158 
164  UWord ByteOffsetToRasterLine (const ULWord inByteOffset) const;
165 
170  bool IsAtLineStart (ULWord inByteOffset) const;
171 
176  inline ULWord GetRasterHeight (const bool inVisibleOnly = false) const {return inVisibleOnly ? GetVisibleRasterHeight() : GetFullRasterHeight();}
177 
181  inline ULWord GetFullRasterHeight (void) const {return numLines;}
182 
186  inline ULWord GetFirstActiveLine (void) const {return firstActiveLine;}
187 
191  inline ULWord GetVisibleRasterHeight (void) const {return GetFullRasterHeight() - GetFirstActiveLine();}
192 
202  bool GetRowBuffer (const NTV2Buffer & inFrameBuffer, NTV2Buffer & inOutRowBuffer, const ULWord inRowIndex0, const UWord inPlaneIndex0 = 0) const; // New in SDK 16.0
203 
211  const void * GetRowAddress (const void * pInStartAddress, const ULWord inRowIndex0, const UWord inPlaneIndex0 = 0) const;
212 
220  void * GetWriteableRowAddress (void * pInStartAddress, const ULWord inRowIndex0, const UWord inPlaneIndex0 = 0) const;
221 
229  ULWord RasterLineToByteOffset (const ULWord inRowIndex0, const UWord inPlaneIndex0 = 0) const;
230 
236  inline UByte * GetTopVisibleRowAddress (UByte * pInStartAddress) const {return (UByte *) GetRowAddress (pInStartAddress, firstActiveLine);}
237 
246  bool GetFirstChangedRow (const void * pInStartAddress1, const void * pInStartAddress2, ULWord & outFirstChangedRowNum) const;
247 
259  bool GetChangedLines (NTV2RasterLineOffsets & outDiffs, const void * pInBuffer1, const void * pInBuffer2, const ULWord inMaxLines = 0) const;
260 
264  NTV2FrameDimensions GetFullRasterDimensions (void) const;
265 
269  NTV2FrameDimensions GetVisibleRasterDimensions (void) const;
270 
278  bool GetSMPTELineNumber (const ULWord inLineOffset, ULWord & outSMPTELine, bool & outIsField2) const;
279 
286  bool GetLineOffsetFromSMPTELine (const ULWord inSMPTELine, ULWord & outLineOffset) const;
287 
295  NTV2SegmentedXferInfo & GetSegmentedXferInfo (NTV2SegmentedXferInfo & inSegmentInfo, const bool inIsSource = true) const;
296 
301  bool operator == (const NTV2FormatDescriptor & inRHS) const;
302 
309  std::ostream & Print (std::ostream & inOutStream, const bool inDetailed = true) const;
310 
318  std::ostream & PrintSMPTELineNumber (std::ostream & inOutStream, const ULWord inLineOffset, const bool inForTextMode = false) const;
319 
320  inline NTV2Standard GetVideoStandard (void) const {return mStandard;}
321  inline NTV2VideoFormat GetVideoFormat (void) const {return mVideoFormat;}
322  inline NTV2FrameBufferFormat GetPixelFormat (void) const {return mPixelFormat;}
323  inline NTV2VANCMode GetVANCMode (void) const {return mVancMode;}
324  inline bool IsSD (void) const {return NTV2_IS_SD_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_SD_STANDARD(GetVideoStandard());}
325  inline bool IsHD (void) const {return NTV2_IS_HD_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_HD_STANDARD(GetVideoStandard());}
326  inline bool IsUHD (void) const {return NTV2_IS_UHD_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_UHD_STANDARD(GetVideoStandard());}
327  inline bool Is4K (void) const {return NTV2_IS_4K_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_4K_STANDARD(GetVideoStandard());}
328  inline bool IsUHD2 (void) const {return NTV2_IS_UHD2_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_UHD2_STANDARD(GetVideoStandard());}
329  inline bool Is8K (void) const {return NTV2_IS_8K_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_8K_STANDARD(GetVideoStandard());}
330  inline bool IsQuadRaster (void) const {return NTV2_IS_QUAD_STANDARD(mStandard) || NTV2_IS_4K_VIDEO_FORMAT(mVideoFormat);}
331  inline bool IsTallVanc (void) const {return mVancMode == NTV2_VANCMODE_TALL;}
332  inline bool IsTallerVanc (void) const {return mVancMode == NTV2_VANCMODE_TALLER;}
333  inline NTV2FrameGeometry GetFrameGeometry (void) const {return mFrameGeometry;}
334  inline UByte GetNumBitsLuma (void) const {return mNumBitsLuma;}
335  inline UByte GetNumBitsChroma (void) const {return mNumBitsChroma;}
336  inline UByte GetNumBitsAlpha (void) const {return mNumBitsAlpha;}
337  inline bool HasAlpha (void) const {return IsValid() && GetNumBitsAlpha();}
338  inline bool IsRGB (void) const {return GetNumBitsLuma() ? false : true;}
339  bool Is2KFormat (void) const;
340 #if !defined(NTV2_DEPRECATE_16_3)
342  inline bool IsSDFormat (void) const {return NTV2_IS_SD_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_SD_STANDARD(GetVideoStandard());}
343 #endif
344  void MakeInvalid (void);
345 
346  private:
347  friend class CNTV2CaptionRenderer; // The caption renderer needs to call SetPixelFormat
348  inline void SetPixelFormat (const NTV2PixelFormat inPixFmt) {mPixelFormat = inPixFmt;}
349  inline void SetBitsPerComponent (const UByte inLuma, const UByte inChroma, const UByte inAlpha) {mNumBitsLuma = inLuma; mNumBitsChroma = inChroma; mNumBitsAlpha = inAlpha;}
350  void FinalizePlanar (void);
351 
352  // Member Data
353  public:
358  private:
359  NTV2Standard mStandard;
360  NTV2VideoFormat mVideoFormat;
361  NTV2PixelFormat mPixelFormat;
362  NTV2VANCMode mVancMode;
363  ULWord mLinePitch[4];
364  UWord mNumPlanes;
365  NTV2FrameGeometry mFrameGeometry;
366  UByte mNumBitsLuma;
367  UByte mNumBitsChroma;
368  UByte mNumBitsAlpha;
369 
370 }; // NTV2FormatDescriptor
371 
374 
381 AJAExport inline std::ostream & operator << (std::ostream & inOutStream, const NTV2FormatDescriptor & inFormatDesc) {return inFormatDesc.Print (inOutStream);}
382 
383 
393 AJAExport bool UnpackLine_10BitYUVtoUWordSequence (const void * pIn10BitYUVLine, const NTV2FormatDescriptor & inFormatDesc, UWordSequence & out16BitYUVLine);
394 
395 #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:146
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:730
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:5659
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
A generic user-space buffer object that has an address and a length. Used most often to share an arbi...
Definition: ntv2publicinterface.h:6022
NTV2FormatDescriptor::linePitch
ULWord linePitch
Number of 32-bit words per line – shadows mLinePitch[0] / sizeof(ULWord)
Definition: ntv2formatdescriptor.h:356
NTV2FormatDescriptor::GetTopVisibleRowAddress
UByte * GetTopVisibleRowAddress(UByte *pInStartAddress) const
Definition: ntv2formatdescriptor.h:236
NTV2FormatDescriptor::GetVisibleRasterBytes
ULWord GetVisibleRasterBytes(const UWord inPlaneIndex0=0) const
Definition: ntv2formatdescriptor.h:140
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:176
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:875
NTV2_IS_QUAD_STANDARD
#define NTV2_IS_QUAD_STANDARD(__s__)
Definition: ntv2enums.h:199
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:769
NTV2SegmentedXferInfo
Describes a segmented data transfer (copy or move) from a source memory location to a destination loc...
Definition: ntv2publicinterface.h:5728
NTV2_IS_UHD_VIDEO_FORMAT
#define NTV2_IS_UHD_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:863
NTV2FormatDescriptor::numPixels
ULWord numPixels
Width – total number of pixels per line.
Definition: ntv2formatdescriptor.h:355
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:3753
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:3752
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:354
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:381
NTV2RasterInfo
NTV2FormatDesc NTV2RasterInfo
Shorthand for NTV2FormatDescriptor.
Definition: ntv2formatdescriptor.h:373
NTV2FormatDescriptor::GetFirstActiveLine
ULWord GetFirstActiveLine(void) const
Definition: ntv2formatdescriptor.h:186
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:723
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:372
NTV2VANCMode
NTV2VANCMode
These enum values identify the available VANC modes.
Definition: ntv2enums.h:3750
NTV2FormatDescriptor::GetTotalRasterBytes
ULWord GetTotalRasterBytes(const UWord inPlaneIndex0=0) const
Definition: ntv2formatdescriptor.h:120
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:357
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:3754
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:1112
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:865
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:181
NTV2FormatDescriptor::IsValid
bool IsValid(void) const
Definition: ntv2formatdescriptor.h:100
NTV2FormatDescriptor::GetVisibleRasterHeight
ULWord GetVisibleRasterHeight(void) const
Definition: ntv2formatdescriptor.h:191
Is2KFormat
bool Is2KFormat(const NTV2VideoFormat format)
Definition: ntv2utils.cpp:5488