PTLib  Version 2.10.4
PColourConverter Class Reference

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

#include <vconvert.h>

Inheritance diagram for PColourConverter:
PObject PSynonymColour

List of all members.

Public Member Functions

 PColourConverter (const PString &srcColourFormat, const PString &dstColourFormat, unsigned width, unsigned height)
 Create a new converter.
 PColourConverter (const PVideoFrameInfo &src, const PVideoFrameInfo &dst)
virtual void PrintOn (ostream &strm) const
 Print description of converter.
PBoolean GetVFlipState ()
 Get the video conversion vertical flip state.
void SetVFlipState (PBoolean vFlipState)
 Set the video conversion vertical flip state.
virtual PBoolean SetFrameSize (unsigned width, unsigned height)
 Set the frame size to be used.
virtual PBoolean SetSrcFrameInfo (const PVideoFrameInfo &info)
 Set the source frame info to be used.
virtual PBoolean SetDstFrameInfo (const PVideoFrameInfo &info)
 Set the destination frame info to be used.
virtual void GetSrcFrameInfo (PVideoFrameInfo &info)
 Get the source frame info to be used.
virtual void GetDstFrameInfo (PVideoFrameInfo &info)
 Get the destination frame info to be used.
virtual PBoolean SetSrcFrameSize (unsigned width, unsigned height)
 Set the source frame size to be used.
virtual PBoolean SetDstFrameSize (unsigned width, unsigned height)
 Set the destination frame size to be used.
virtual PBoolean SetDstFrameSize (unsigned width, unsigned height, PBoolean bScale)
const PStringGetSrcColourFormat ()
 Get the source colour format.
const PStringGetDstColourFormat ()
 Get the destination colour format.
PINDEX GetMaxSrcFrameBytes ()
 Get the maximum frame size in bytes for source frames.
PINDEX GetMaxDstFrameBytes ()
 Get the maximum frame size in bytes for destination frames.
virtual PBoolean Convert (const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, PINDEX *bytesReturned=NULL)=0
 Convert from one colour format to another.
virtual PBoolean Convert (const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, unsigned int srcFrameBytes, PINDEX *bytesReturned=NULL)=0
virtual PBoolean ConvertInPlace (BYTE *frameBuffer, PINDEX *bytesReturned=NULL, PBoolean noIntermediateFrame=false)
 Convert from one colour format to another.
PBoolean GetDstFrameSize (unsigned &width, unsigned &height) const
 Get the output frame size.
PBoolean GetSrcFrameSize (unsigned &width, unsigned &height) const
 Get the input frame size.
unsigned GetSrcFrameWidth () const
unsigned GetSrcFrameHeight () const
unsigned GetDstFrameWidth () const
unsigned GetDstFrameHeight () const
void SetResizeMode (PVideoFrameInfo::ResizeMode mode)
 Set the resize mode to be used.
PVideoFrameInfo::ResizeMode GetResizeMode () const
 Get the resize mode to be used.

Static Public Member Functions

static PColourConverterCreate (const PVideoFrameInfo &src, const PVideoFrameInfo &dst)
 Create an instance of a colour conversion function.
static PColourConverterCreate (const PString &srcColourFormat, const PString &destColourFormat, unsigned width, unsigned height)
static void RGBtoYUV (unsigned r, unsigned g, unsigned b, unsigned &y, unsigned &u, unsigned &v)
 Convert RGB to YUV.
static void RGBtoYUV (unsigned r, unsigned g, unsigned b, BYTE &y, BYTE &u, BYTE &v)
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)
 Copy a section of the source frame to a section of the destination frame with scaling/cropping as required.
static bool FillYUV420P (unsigned x, unsigned y, int width, int height, unsigned frameWidth, unsigned frameHeight, BYTE *yuv, unsigned r, unsigned g, unsigned b)

Protected Member Functions

void Construct (const PVideoFrameInfo &src, const PVideoFrameInfo &dst)

Protected Attributes

PString srcColourFormat
PString dstColourFormat
unsigned srcFrameWidth
unsigned srcFrameHeight
unsigned srcFrameBytes
unsigned dstFrameWidth
unsigned dstFrameHeight
unsigned dstFrameBytes
PVideoFrameInfo::ResizeMode resizeMode
PBoolean verticalFlip
PBYTEArray intermediateFrameStore
struct jdec_private * jdec

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 PString srcColourFormat,
const PString dstColourFormat,
unsigned  width,
unsigned  height 
)

Create a new converter.

Parameters:
srcColourFormatName of source colour format
dstColourFormatName of destination colour format
widthWidth of frame
heightHeight of frame
Parameters:
srcSource frame info (colour formet, size etc)
dstDestination frame info

Member Function Documentation

void PColourConverter::Construct ( const PVideoFrameInfo src,
const PVideoFrameInfo dst 
) [protected]
Parameters:
srcSource frame info (colour formet, size etc)
dstDestination frame info
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

Implemented in PSynonymColour.

virtual PBoolean PColourConverter::Convert ( const BYTE *  srcFrameBuffer,
BYTE *  dstFrameBuffer,
unsigned int  srcFrameBytes,
PINDEX *  bytesReturned = NULL 
) [pure virtual]
Parameters:
srcFrameBufferFrame store for source pixels
dstFrameBufferFrame store for destination pixels
srcFrameBytesBytes used in source frame buffer
bytesReturnedBytes written to dstFrameBuffer

Implemented in PSynonymColour.

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 
) [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,
int  width,
int  height,
unsigned  frameWidth,
unsigned  frameHeight,
BYTE *  yuv,
unsigned  r,
unsigned  g,
unsigned  b 
) [static]

Get the destination colour format.

References dstColourFormat.

unsigned PColourConverter::GetDstFrameHeight ( ) const [inline]

References 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 dstFrameWidth.

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 dstFrameBytes.

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 srcFrameBytes.

Get the resize mode to be used.

References resizeMode.

Get the source colour format.

References srcColourFormat.

unsigned PColourConverter::GetSrcFrameHeight ( ) const [inline]

References 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 srcFrameWidth.

Get the video conversion vertical flip state.

References verticalFlip.

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,
unsigned &  y,
unsigned &  u,
unsigned &  v 
) [static]

Convert RGB to YUV.

static void PColourConverter::RGBtoYUV ( unsigned  r,
unsigned  g,
unsigned  b,
BYTE &  y,
BYTE &  u,
BYTE &  v 
) [static]
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

Set the resize mode to be used.

References PVideoFrameInfo::eMaxResizeMode, and resizeMode.

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 ( PBoolean  vFlipState) [inline]

Set the video conversion vertical flip state.

Parameters:
vFlipStateNew state for flipping images

References verticalFlip.


Member Data Documentation

unsigned PColourConverter::dstFrameBytes [protected]

Referenced by GetMaxDstFrameBytes().

unsigned PColourConverter::dstFrameHeight [protected]

Referenced by GetDstFrameHeight().

unsigned PColourConverter::dstFrameWidth [protected]

Referenced by GetDstFrameWidth().

struct jdec_private* PColourConverter::jdec [protected]
unsigned PColourConverter::srcFrameBytes [protected]

Referenced by GetMaxSrcFrameBytes().

unsigned PColourConverter::srcFrameHeight [protected]

Referenced by GetSrcFrameHeight().

unsigned PColourConverter::srcFrameWidth [protected]

Referenced by GetSrcFrameWidth().


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines