PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PColourConverter Class Referenceabstract

This class defines a means to convert an image from one colour format to another. More...

#include <vconvert.h>

Inheritance diagram for PColourConverter:
Collaboration diagram for PColourConverter:

Public Member Functions

virtual void PrintOn (ostream &strm) const
 Print description of converter. More...
 
bool GetVFlipState () const
 Get the video conversion vertical flip state. More...
 
void SetVFlipState (bool vFlipState)
 Set the video conversion vertical flip state. More...
 
virtual PBoolean SetFrameSize (unsigned width, unsigned height)
 Set the frame size to be used. More...
 
virtual PBoolean SetSrcFrameInfo (const PVideoFrameInfo &info)
 Set the source frame info to be used. More...
 
virtual PBoolean SetDstFrameInfo (const PVideoFrameInfo &info)
 Set the destination frame info to be used. More...
 
virtual void GetSrcFrameInfo (PVideoFrameInfo &info)
 Get the source frame info to be used. More...
 
virtual void GetDstFrameInfo (PVideoFrameInfo &info)
 Get the destination frame info to be used. More...
 
virtual PBoolean SetSrcFrameSize (unsigned width, unsigned height)
 Set the source frame size to be used. More...
 
virtual PBoolean SetDstFrameSize (unsigned width, unsigned height)
 Set the destination frame size to be used. More...
 
virtual PBoolean SetDstFrameSize (unsigned width, unsigned height, PBoolean bScale)
 
PINDEX GetMaxSrcFrameBytes () const
 Get the maximum frame size in bytes for source frames. More...
 
void SetSrcFrameBytes (PINDEX frameBytes)
 Set the actual frame size in bytes for source frames. More...
 
PINDEX GetMaxDstFrameBytes () const
 Get the maximum frame size in bytes for destination frames. More...
 
virtual PBoolean Convert (const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, PINDEX *bytesReturned=NULL)=0
 Convert from one colour format to another. More...
 
virtual PBoolean ConvertInPlace (BYTE *frameBuffer, PINDEX *bytesReturned=NULL, PBoolean noIntermediateFrame=false)
 Convert from one colour format to another. More...
 
PBoolean GetDstFrameSize (unsigned &width, unsigned &height) const
 Get the output frame size. More...
 
PBoolean GetSrcFrameSize (unsigned &width, unsigned &height) const
 Get the input frame size. More...
 
unsigned GetSrcFrameWidth () const
 
unsigned GetSrcFrameHeight () const
 
unsigned GetDstFrameWidth () const
 
unsigned GetDstFrameHeight () const
 
void SetResizeMode (PVideoFrameInfo::ResizeMode mode)
 Set the resize mode to be used. More...
 
PVideoFrameInfo::ResizeMode GetResizeMode () const
 Get the resize mode to be used. More...
 
- Public Member Functions inherited from PColourPair
 PColourPair (const PString &src, const PString &dst)
 
Comparison Compare (const PObject &other) const
 Compare the two objects and return their relative rank. More...
 
const PStringGetSrcColourFormat () const
 Get the source colour format. More...
 
const PStringGetDstColourFormat () const
 Get the destination colour format. More...
 
- Public Member Functions inherited from PObject
__inline unsigned GetTraceContextIdentifier () const
 Get PTRACE context identifier. More...
 
__inline void SetTraceContextIdentifier (unsigned id)
 
__inline void SetTraceContextIdentifier (const PObject &obj)
 
__inline void SetTraceContextIdentifier (const PObject *obj)
 
__inline void CopyTraceContextIdentifier (PObject &obj) const
 
__inline void CopyTraceContextIdentifier (PObject *obj) const
 
virtual ~PObject ()
 
__inline const char * GetClass () const
 
__inline bool IsClass (const char *name) const
 
__inline const PObjectPTraceObjectInstance () const
 
virtual PObjectClone () const
 Create a copy of the class on the heap. More...
 
template<class CLS >
CLS * CloneAs () const
 As for Clone() but converts to specified type. More...
 
virtual PINDEX HashFunction () const
 This function yields a hash value required by the PDictionary class. More...
 
virtual Comparison CompareObjectMemoryDirect (const PObject &obj) const
 Determine the byte wise comparison of two objects. More...
 
bool operator== (const PObject &obj) const
 Compare the two objects. More...
 
bool operator!= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator< (const PObject &obj) const
 Compare the two objects. More...
 
bool operator> (const PObject &obj) const
 Compare the two objects. More...
 
bool operator<= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator>= (const PObject &obj) const
 Compare the two objects. More...
 
virtual void ReadFrom (istream &strm)
 Input the contents of the object from the stream. More...
 

Static Public Member Functions

static PColourConverterCreate (const PVideoFrameInfo &src, const PVideoFrameInfo &dst)
 Create an instance of a colour conversion function. More...
 
static PColourConverterCreate (const PString &srcColourFormat, const PString &destColourFormat, unsigned width, unsigned height)
 
static void RGBtoYUV (unsigned r, unsigned g, unsigned b, BYTE &y, BYTE &u, BYTE &v)
 Convert RGB to YUV. More...
 
static void YUVtoRGB (unsigned y, unsigned u, unsigned v, BYTE &r, BYTE &g, BYTE &b)
 Convert YUV to RGB. More...
 
static bool CopyYUV420P (unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight, unsigned srcFrameWidth, unsigned srcFrameHeight, const BYTE *srcYUV, unsigned dstX, unsigned dstY, unsigned dstWidth, unsigned dstHeight, unsigned dstFrameWidth, unsigned dstFrameHeight, BYTE *dstYUV, PVideoFrameInfo::ResizeMode resizeMode=PVideoFrameInfo::eScale, bool verticalFlip=false, std::ostream *error=NULL)
 Copy a section of the source frame to a section of the destination frame with scaling/cropping as required. More...
 
static bool RotateYUV420P (int angle, unsigned width, unsigned height, BYTE *srcYUV, BYTE *dstYUV=NULL)
 Rotate the video buffer image. More...
 
static bool FillYUV420P (unsigned x, unsigned y, unsigned width, unsigned height, unsigned frameWidth, unsigned frameHeight, BYTE *yuv, unsigned r_or_y, unsigned g_or_u, unsigned b_or_v, bool rgb=true)
 Fill a rectangle of the video buffer with the specified colour. More...
 
- Static Public Member Functions inherited from PObject
static __inline void CopyTraceContextIdentifier (PObject &to, const PObject &from)
 
static __inline void CopyTraceContextIdentifier (PObject &to, const PObject *from)
 
static __inline void CopyTraceContextIdentifier (PObject *to, const PObject &from)
 
static __inline void CopyTraceContextIdentifier (PObject *to, const PObject *from)
 
static __inline const char * Class ()
 
static __inline const PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (const PObject *obj)
 
template<typename T >
static Comparison Compare2 (T v1, T v2)
 Compare two types, returning Comparison type. More...
 
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 

Protected Member Functions

 PColourConverter (const PColourPair &colours)
 Create a new converter. More...
 
 P_REMOVE_VIRTUAL (PBoolean, Convert(const BYTE *, BYTE *, unsigned, PINDEX *), false)
 
- Protected Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own. More...
 

Protected Attributes

unsigned m_srcFrameWidth
 
unsigned m_srcFrameHeight
 
PINDEX m_srcFrameBytes
 
unsigned m_dstFrameWidth
 
unsigned m_dstFrameHeight
 
PINDEX m_dstFrameBytes
 
PVideoFrameInfo::ResizeMode m_resizeMode
 
bool m_verticalFlip
 
PBYTEArray m_intermediateFrameStore
 
- Protected Attributes inherited from PColourPair
const PString m_srcColourFormat
 
const PString m_dstColourFormat
 
- Protected Attributes inherited from PObject
unsigned m_traceContextIdentifier
 

Detailed Description

This class defines a means to convert an image from one colour format to another.

It is an ancestor class for the individual formatting functions.

Constructor & Destructor Documentation

PColourConverter::PColourConverter ( const PColourPair colours)
protected

Create a new converter.

Member Function Documentation

virtual PBoolean PColourConverter::Convert ( const BYTE *  srcFrameBuffer,
BYTE *  dstFrameBuffer,
PINDEX *  bytesReturned = NULL 
)
pure virtual

Convert from one colour format to another.

This version will copy the data from one frame buffer to another. An implementation of this function should allow for the case of where srcFrameBuffer and dstFrameBuffer are the same, if the conversion algorithm allows for that to occur without an intermediate frame store.

The function should return false if srcFrameBuffer and dstFrameBuffer are the same and that form pf conversion is not allowed

Parameters
srcFrameBufferFrame store for source pixels
dstFrameBufferFrame store for destination pixels
bytesReturnedBytes written to dstFrameBuffer
virtual PBoolean PColourConverter::ConvertInPlace ( BYTE *  frameBuffer,
PINDEX *  bytesReturned = NULL,
PBoolean  noIntermediateFrame = false 
)
virtual

Convert from one colour format to another.

This version will copy the data from one frame buffer to the same frame buffer. Not all conversions can do this so an intermediate store and copy may be required. If the noIntermediateFrame parameter is true and the conversion cannot be done in place then the function returns false. If the in place conversion can be done then that parameter is ignored.

Note that the frame should be large enough to take the destination pixels.

Default behaviour calls Convert() from the frameBuffer to itself, and if that returns false then calls it again (provided noIntermediateFrame is false) using an intermediate store, copying the intermediate store back to the original frame store.

Parameters
frameBufferFrame buffer to translate data
bytesReturnedBytes written to frameBuffer
noIntermediateFrameFlag to use intermediate store
static bool PColourConverter::CopyYUV420P ( unsigned  srcX,
unsigned  srcY,
unsigned  srcWidth,
unsigned  srcHeight,
unsigned  srcFrameWidth,
unsigned  srcFrameHeight,
const BYTE *  srcYUV,
unsigned  dstX,
unsigned  dstY,
unsigned  dstWidth,
unsigned  dstHeight,
unsigned  dstFrameWidth,
unsigned  dstFrameHeight,
BYTE *  dstYUV,
PVideoFrameInfo::ResizeMode  resizeMode = PVideoFrameInfo::eScale,
bool  verticalFlip = false,
std::ostream *  error = NULL 
)
static

Copy a section of the source frame to a section of the destination frame with scaling/cropping as required.

static PColourConverter* PColourConverter::Create ( const PVideoFrameInfo src,
const PVideoFrameInfo dst 
)
static

Create an instance of a colour conversion function.

Returns NULL if there is no registered colour converter between the two named formats.

Parameters
srcSource frame info (colour formet, size etc)
dstDestination frame info
static PColourConverter* PColourConverter::Create ( const PString srcColourFormat,
const PString destColourFormat,
unsigned  width,
unsigned  height 
)
static
static bool PColourConverter::FillYUV420P ( unsigned  x,
unsigned  y,
unsigned  width,
unsigned  height,
unsigned  frameWidth,
unsigned  frameHeight,
BYTE *  yuv,
unsigned  r_or_y,
unsigned  g_or_u,
unsigned  b_or_v,
bool  rgb = true 
)
static

Fill a rectangle of the video buffer with the specified colour.

unsigned PColourConverter::GetDstFrameHeight ( ) const
inline

References m_dstFrameHeight.

virtual void PColourConverter::GetDstFrameInfo ( PVideoFrameInfo info)
virtual

Get the destination frame info to be used.

Parameters
infoNew info for frame
PBoolean PColourConverter::GetDstFrameSize ( unsigned &  width,
unsigned &  height 
) const

Get the output frame size.

Parameters
widthWidth of destination frame
heightHeight of destination frame
unsigned PColourConverter::GetDstFrameWidth ( ) const
inline

References m_dstFrameWidth.

PINDEX PColourConverter::GetMaxDstFrameBytes ( ) const
inline

Get the maximum frame size in bytes for destination frames.

Note a particular device may be able to provide variable length frames (eg motion JPEG) so will be the maximum size of all frames.

References m_dstFrameBytes.

PINDEX PColourConverter::GetMaxSrcFrameBytes ( ) const
inline

Get the maximum frame size in bytes for source frames.

Note a particular device may be able to provide variable length frames (eg motion JPEG) so will be the maximum size of all frames.

References m_srcFrameBytes.

PVideoFrameInfo::ResizeMode PColourConverter::GetResizeMode ( ) const
inline

Get the resize mode to be used.

References m_resizeMode.

unsigned PColourConverter::GetSrcFrameHeight ( ) const
inline

References m_srcFrameHeight.

virtual void PColourConverter::GetSrcFrameInfo ( PVideoFrameInfo info)
virtual

Get the source frame info to be used.

Parameters
infoNew info for frame
PBoolean PColourConverter::GetSrcFrameSize ( unsigned &  width,
unsigned &  height 
) const

Get the input frame size.

Parameters
widthWidth of source frame
heightHeight of source frame
unsigned PColourConverter::GetSrcFrameWidth ( ) const
inline

References m_srcFrameWidth.

bool PColourConverter::GetVFlipState ( ) const
inline

Get the video conversion vertical flip state.

References m_verticalFlip.

PColourConverter::P_REMOVE_VIRTUAL ( PBoolean  ,
Convert(const BYTE *, BYTE *, unsigned, PINDEX *)  ,
false   
)
protected
virtual void PColourConverter::PrintOn ( ostream &  strm) const
virtual

Print description of converter.

Reimplemented from PObject.

static void PColourConverter::RGBtoYUV ( unsigned  r,
unsigned  g,
unsigned  b,
BYTE &  y,
BYTE &  u,
BYTE &  v 
)
static

Convert RGB to YUV.

static bool PColourConverter::RotateYUV420P ( int  angle,
unsigned  width,
unsigned  height,
BYTE *  srcYUV,
BYTE *  dstYUV = NULL 
)
static

Rotate the video buffer image.

At this time, the angle may be 90, -90 or 180. Note: if dstYUV is NULL for an in-place rotation, then there may be a performance hit due to allocating an internal buffer and copying back to the source memory.

virtual PBoolean PColourConverter::SetDstFrameInfo ( const PVideoFrameInfo info)
virtual

Set the destination frame info to be used.

Default behaviour sets the dstFrameWidth and dstFrameHeight variables, and the scale / crop preference. It then recalculates the frame buffer size in bytes then returns true if the size was calculated correctly.

Returns false if the colour formats do not agree.

Parameters
infoNew info for frame
virtual PBoolean PColourConverter::SetDstFrameSize ( unsigned  width,
unsigned  height 
)
virtual

Set the destination frame size to be used.

Default behaviour sets the dstFrameWidth and dstFrameHeight variables, and the scale / crop preference. It then recalculates the frame buffer size in bytes then returns true if the size was calculated correctly.

Parameters
widthNew width of target frame
heightNew height of target frame
virtual PBoolean PColourConverter::SetDstFrameSize ( unsigned  width,
unsigned  height,
PBoolean  bScale 
)
virtual
Parameters
widthNew width of target frame
heightNew height of target frame
bScaleIndicate if scaling or cropping is to be used
virtual PBoolean PColourConverter::SetFrameSize ( unsigned  width,
unsigned  height 
)
virtual

Set the frame size to be used.

Default behaviour calls SetSrcFrameSize() and SetDstFrameSize().

Parameters
widthNew width of frame
heightNew height of frame
void PColourConverter::SetResizeMode ( PVideoFrameInfo::ResizeMode  mode)
inline

Set the resize mode to be used.

References m_resizeMode.

void PColourConverter::SetSrcFrameBytes ( PINDEX  frameBytes)
inline

Set the actual frame size in bytes for source frames.

Note a particular device may be able to provide variable length frames (eg motion JPEG) so will be the maximum size of all frames.

References m_srcFrameBytes.

virtual PBoolean PColourConverter::SetSrcFrameInfo ( const PVideoFrameInfo info)
virtual

Set the source frame info to be used.

Default behaviour sets the srcFrameWidth and srcFrameHeight variables and recalculates the frame buffer size in bytes then returns true if the size was calculated correctly.

Returns false if the colour formats do not agree.

Parameters
infoNew info for frame
virtual PBoolean PColourConverter::SetSrcFrameSize ( unsigned  width,
unsigned  height 
)
virtual

Set the source frame size to be used.

Default behaviour sets the srcFrameWidth and srcFrameHeight variables and recalculates the frame buffer size in bytes then returns true if the size was calculated correctly.

Parameters
widthNew width of frame
heightNew height of frame
void PColourConverter::SetVFlipState ( bool  vFlipState)
inline

Set the video conversion vertical flip state.

Parameters
vFlipStateNew state for flipping images

References m_verticalFlip.

static void PColourConverter::YUVtoRGB ( unsigned  y,
unsigned  u,
unsigned  v,
BYTE &  r,
BYTE &  g,
BYTE &  b 
)
static

Convert YUV to RGB.

Member Data Documentation

PINDEX PColourConverter::m_dstFrameBytes
protected

Referenced by GetMaxDstFrameBytes().

unsigned PColourConverter::m_dstFrameHeight
protected

Referenced by GetDstFrameHeight().

unsigned PColourConverter::m_dstFrameWidth
protected

Referenced by GetDstFrameWidth().

PBYTEArray PColourConverter::m_intermediateFrameStore
protected
PVideoFrameInfo::ResizeMode PColourConverter::m_resizeMode
protected

Referenced by GetResizeMode(), and SetResizeMode().

PINDEX PColourConverter::m_srcFrameBytes
protected
unsigned PColourConverter::m_srcFrameHeight
protected

Referenced by GetSrcFrameHeight().

unsigned PColourConverter::m_srcFrameWidth
protected

Referenced by GetSrcFrameWidth().

bool PColourConverter::m_verticalFlip
protected

Referenced by GetVFlipState(), and SetVFlipState().


The documentation for this class was generated from the following file: