AJA NTV2 SDK  18.1.0.2145
NTV2 SDK 18.1.0.2145
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 
278  bool FlipVertically (NTV2Buffer & inFB) const; // New in SDK 18.1
279 
283  NTV2FrameSize GetFullRasterDimensions (void) const;
284 
288  NTV2FrameSize GetVisibleRasterDimensions (void) const;
289 
297  bool GetSMPTELineNumber (const ULWord inLineOffset, ULWord & outSMPTELine, bool & outIsField2) const;
298 
305  bool GetLineOffsetFromSMPTELine (const ULWord inSMPTELine, ULWord & outLineOffset) const;
306 
314  NTV2SegmentedXferInfo & GetSegmentedXferInfo (NTV2SegmentedXferInfo & inSegmentInfo, const bool inIsSource = true) const;
315 
320  bool operator == (const NTV2FormatDescriptor & inRHS) const;
321 
328  std::ostream & Print (std::ostream & inOutStream, const bool inDetailed = true) const;
329 
337  std::ostream & PrintSMPTELineNumber (std::ostream & inOutStream, const ULWord inLineOffset, const bool inForTextMode = false) const;
338 
339  inline NTV2Standard GetVideoStandard (void) const {return mStandard;}
340  inline NTV2VideoFormat GetVideoFormat (void) const {return mVideoFormat;}
341  inline NTV2FrameBufferFormat GetPixelFormat (void) const {return mPixelFormat;}
342  inline NTV2VANCMode GetVANCMode (void) const {return mVancMode;}
343  inline bool IsSD (void) const {return NTV2_IS_SD_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_SD_STANDARD(GetVideoStandard());}
344  inline bool IsHD (void) const {return NTV2_IS_HD_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_HD_STANDARD(GetVideoStandard());}
345  inline bool IsUHD (void) const {return NTV2_IS_UHD_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_UHD_STANDARD(GetVideoStandard());}
346  inline bool Is4K (void) const {return NTV2_IS_4K_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_4K_STANDARD(GetVideoStandard());}
347  inline bool IsUHD2 (void) const {return NTV2_IS_UHD2_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_UHD2_STANDARD(GetVideoStandard());}
348  inline bool Is8K (void) const {return NTV2_IS_8K_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_8K_STANDARD(GetVideoStandard());}
349  inline bool IsQuadRaster (void) const {return NTV2_IS_QUAD_STANDARD(mStandard) || NTV2_IS_4K_VIDEO_FORMAT(mVideoFormat);}
350  inline bool IsTallVanc (void) const {return mVancMode == NTV2_VANCMODE_TALL;}
351  inline bool IsTallerVanc (void) const {return mVancMode == NTV2_VANCMODE_TALLER;}
352  inline NTV2FrameGeometry GetFrameGeometry (void) const {return mFrameGeometry;}
353  inline UByte GetNumBitsLuma (void) const {return mNumBitsLuma;}
354  inline UByte GetNumBitsChroma (void) const {return mNumBitsChroma;}
355  inline UByte GetNumBitsAlpha (void) const {return mNumBitsAlpha;}
356  inline bool HasAlpha (void) const {return IsValid() && GetNumBitsAlpha();}
357  inline bool IsRGB (void) const {return GetNumBitsLuma() ? false : true;}
358  bool Is2KFormat (void) const;
359 #if !defined(NTV2_DEPRECATE_16_3)
361  inline NTV2_DEPRECATED_16_3(bool IsSDFormat(void) const) {return NTV2_IS_SD_VIDEO_FORMAT(GetVideoFormat()) || NTV2_IS_SD_STANDARD(GetVideoStandard());}
362 #endif
363  void MakeInvalid (void);
364 
365  private:
366  friend class CNTV2CaptionRenderer; // The caption renderer needs to call SetPixelFormat
367  inline void SetPixelFormat (const NTV2PixelFormat inPixFmt) {mPixelFormat = inPixFmt;}
368  inline void SetBitsPerComponent (const UByte inLuma, const UByte inChroma, const UByte inAlpha) {mNumBitsLuma = inLuma; mNumBitsChroma = inChroma; mNumBitsAlpha = inAlpha;}
369  void FinalizePlanar (void);
370 
371  // Member Data
372  public:
377  private:
378  NTV2Standard mStandard;
381  NTV2VANCMode mVancMode;
382  ULWord mLinePitch[4];
383  UWord mNumPlanes;
384  NTV2FrameGeometry mFrameGeometry;
385  UByte mNumBitsLuma;
386  UByte mNumBitsChroma;
387  UByte mNumBitsAlpha;
388 
389 }; // NTV2FormatDescriptor
390 
393 
400 AJAExport inline std::ostream & operator << (std::ostream & inOutStream, const NTV2FormatDescriptor & inFormatDesc) {return inFormatDesc.Print (inOutStream);}
401 
402 
412 AJAExport bool UnpackLine_10BitYUVtoUWordSequence (const void * pIn10BitYUVLine, const NTV2FormatDescriptor & inFormatDesc, UWordSequence & out16BitYUVLine);
413 
423 AJAExport bool UnpackLine_10BitARGBtoUWordSequence (const void * pIn10BitARGBLine, const NTV2FormatDescriptor & inFormatDesc, UWordSequence & out16BitARGBLine);
424 
425 #endif // NTV2FORMATDESC_H
#define NTV2_IS_SD_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:746
std::ostream & Print(std::ostream &inOutStream, const bool inDetailed=true) const
Writes a human-readable description of me into the given output stream.
#define NTV2_IS_UHD_STANDARD(__s__)
Definition: ntv2enums.h:204
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:147
NTV2FrameBufferFormat GetPixelFormat(void) const
ULWord GetBytesPerRow(const UWord inPlaneIndex0=0) const
NTV2FrameBufferFormat
Identifies a particular video frame buffer pixel format. See Device Frame Buffer Formats for details...
Definition: ntv2enums.h:221
#define NTV2_DEPRECATED_16_3(__f__)
Definition: ajatypes.h:556
enum _NTV2VideoFormat NTV2VideoFormat
Identifies a particular video format.
#define NTV2_IS_UHD2_STANDARD(__s__)
Definition: ntv2enums.h:212
#define NTV2_IS_FBF_PLANAR(__s__)
Definition: ntv2enums.h:269
ULWord GetFullRasterHeight(void) const
NTV2FrameGeometry GetFrameGeometry(void) const
#define NTV2_IS_4K_STANDARD(__s__)
Definition: ntv2enums.h:207
bool IsTallVanc(void) const
#define NTV2_IS_4K_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:785
#define NTV2_IS_8K_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:895
This identifies the mode in which there are some + extra VANC lines in the frame buffer.
Definition: ntv2enums.h:3804
std::ostream & operator<<(std::ostream &inOutStream, const NTV2FormatDescriptor &inFormatDesc)
Writes the given NTV2FormatDescriptor to the specified output stream.
#define false
ULWord GetVisibleRasterBytes(const UWord inPlaneIndex0=0) const
uint32_t ULWord
Definition: ajatypes.h:236
Describes a segmented data transfer (copy or move) from a source memory location to a destination loc...
mVideoFormat
Definition: ntv2vcam.cpp:801
NTV2RasterLineOffsets::iterator NTV2RasterLineOffsetsIter
A handy non-const iterator into an NTV2RasterLineOffsets.
NTV2FormatDesc NTV2RasterInfo
Shorthand for NTV2FormatDescriptor.
mPixelFormat
Definition: ntv2vcam.cpp:710
#define NTV2_IS_QUAD_STANDARD(__s__)
Definition: ntv2enums.h:210
ULWord numPixels
Width – total number of pixels per line.
NTV2VANCMode GetVANCMode(void) const
ULWord GetFirstActiveLine(void) const
NTV2Standard
Identifies a particular video standard.
Definition: ntv2enums.h:167
Enumerations for controlling NTV2 devices.
bool IsTallerVanc(void) const
ULWord GetRasterHeight(const bool inVisibleOnly=false) const
bool IsQuadRaster(void) const
Defines the import/export macros for producing DLLs or LIBs.
#define NTV2_IS_HD_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:739
Declares the most fundamental data types used by NTV2. Since Windows NT was the first principal devel...
Describes a video frame for a given video standard or format and pixel format, including the total nu...
ULWord firstActiveLine
First active line of video (0 if NTV2_VANCMODE_OFF)
std::vector< uint16_t > UWordSequence
An ordered sequence of UWord (uint16_t) values.
#define NTV2_IS_UHD_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:883
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:2875
uint8_t UByte
Definition: ajatypes.h:231
UByte GetNumBitsChroma(void) const
Describes a user-space buffer on the host computer. I have an address and a length, plus some optional attributes (allocated by SDK?, page-aligned? etc.).
NTV2VideoFormat GetVideoFormat(void) const
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...
bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition: json.hpp:14737
#define AJAExport
Definition: export.h:33
NTV2FrameGeometry
Identifies a particular video frame geometry.
Definition: ntv2enums.h:350
#define NTV2_IS_SD_STANDARD(__s__)
Definition: ntv2enums.h:200
ULWord numLines
Height – total number of lines.
Describes the horizontal and vertical size dimensions of a raster, bitmap, frame or image...
ULWord GetTotalRasterBytes(const UWord inPlaneIndex0=0) const
#define NTV2_IS_8K_STANDARD(__s__)
Definition: ntv2enums.h:213
#define NTV2_IS_HD_STANDARD(__s__)
Definition: ntv2enums.h:201
bool IsSDFormat(void) const
ULWord GetVisibleRasterHeight(void) const
uint16_t UWord
Definition: ajatypes.h:234
ULWord GetRasterWidth(void) const
UWord GetNumPlanes(void) const
NTV2Standard GetVideoStandard(void) const
NTV2VANCMode
These enum values identify the available VANC modes.
Definition: ntv2enums.h:3800
NTV2RasterLineOffsets::const_iterator NTV2RasterLineOffsetsConstIter
A handy const iterator into an NTV2RasterLineOffsets.
std::vector< ULWord > NTV2RasterLineOffsets
An ordered sequence of zero-based line offsets into a frame buffer.
UByte GetNumBitsLuma(void) const
NTV2FormatDescriptor NTV2FormatDesc
Shorthand for NTV2FormatDescriptor.
UByte GetNumBitsAlpha(void) const
ULWord linePitch
Number of 32-bit words per line – shadows mLinePitch[0] / sizeof(ULWord)
Declares enums and structs used by all platform drivers and the SDK.
#define NTV2_IS_UHD2_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:885
bool Is2KFormat(const NTV2VideoFormat format)
Definition: ntv2utils.cpp:5430
This identifies the "tall" mode in which there are some VANC lines in the frame buffer.
Definition: ntv2enums.h:3803
UByte * GetTopVisibleRowAddress(UByte *pInStartAddress) const
This identifies the mode in which there are no VANC lines in the frame buffer.
Definition: ntv2enums.h:3802
bool UnpackLine_10BitARGBtoUWordSequence(const void *pIn10BitARGBLine, const NTV2FormatDescriptor &inFormatDesc, UWordSequence &out16BitARGBLine)
Unpacks a line of NTV2_FBF_10BIT_ARGB video into 16-bit-per-component ARGB data.
Definition: ntv2utils.cpp:172