All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vconvert.h
Go to the documentation of this file.
/*
* vconvert.h
*
* Classes to support streaming video input (grabbing) and output.
*
* Portable Windows Library
*
* Copyright (c) 1993-2000 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Contributor(s): Derek Smithies (derek@indranet.co.nz)
* Thorsten Westheider (thorsten.westheider@teleos-web.de)
* Mark Cooke (mpc@star.sr.bham.ac.uk)
*
* $Revision: 26686 $
* $Author: rjongbloed $
* $Date: 2011-11-23 20:22:20 -0600 (Wed, 23 Nov 2011) $
*/
#ifndef PTLIB_CONVERT_H
#define PTLIB_CONVERT_H
#ifdef P_USE_PRAGMA
#ifndef P_MACOSX
#pragma interface
#endif
#endif
#include <ptbuildopts.h>
#if P_VIDEO
#include <ptlib/videoio.h>
struct jdec_private;
class PColourConverterRegistration : public PCaselessString
{
PCLASSINFO(PColourConverterRegistration, PCaselessString);
public:
PColourConverterRegistration(
const PString & srcColourFormat,
const PString & destColourFormat
);
protected:
virtual PColourConverter * Create(
const PVideoFrameInfo & src,
const PVideoFrameInfo & dst
) const = 0;
PColourConverterRegistration * link;
friend class PColourConverter;
};
class PColourConverter : public PObject
{
PCLASSINFO(PColourConverter, PObject);
public:
PColourConverter(
const PString & srcColourFormat,
const PString & dstColourFormat,
unsigned width,
unsigned height
);
PColourConverter(
const PVideoFrameInfo & src,
const PVideoFrameInfo & dst
);
virtual void PrintOn(
ostream & strm
) const;
PBoolean GetVFlipState()
{ return verticalFlip; }
void SetVFlipState(
PBoolean vFlipState
) { verticalFlip = vFlipState; }
virtual PBoolean SetFrameSize(
unsigned width,
unsigned height
);
virtual PBoolean SetSrcFrameInfo(
const PVideoFrameInfo & info
);
virtual PBoolean SetDstFrameInfo(
const PVideoFrameInfo & info
);
virtual void GetSrcFrameInfo(
PVideoFrameInfo & info
);
virtual void GetDstFrameInfo(
PVideoFrameInfo & info
);
virtual PBoolean SetSrcFrameSize(
unsigned width,
unsigned height
);
virtual PBoolean SetDstFrameSize(
unsigned width,
unsigned height
);
virtual PBoolean SetDstFrameSize(
unsigned width,
unsigned height,
PBoolean bScale
);
const PString & GetSrcColourFormat() { return srcColourFormat; }
const PString & GetDstColourFormat() { return dstColourFormat; }
PINDEX GetMaxSrcFrameBytes() { return srcFrameBytes; }
PINDEX GetMaxDstFrameBytes() { return dstFrameBytes; }
virtual PBoolean Convert(
const BYTE * srcFrameBuffer,
BYTE * dstFrameBuffer,
PINDEX * bytesReturned = NULL
) = 0;
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
);
static PColourConverter * Create(
const PVideoFrameInfo & src,
const PVideoFrameInfo & dst
);
static PColourConverter * Create(
const PString & srcColourFormat,
const PString & destColourFormat,
unsigned width,
unsigned height
);
PBoolean GetDstFrameSize(
unsigned & width,
unsigned & height
) const;
PBoolean GetSrcFrameSize(
unsigned & width,
unsigned & height
) const;
unsigned GetSrcFrameWidth() const { return srcFrameWidth; }
unsigned GetSrcFrameHeight() const { return srcFrameHeight; }
unsigned GetDstFrameWidth() const { return dstFrameWidth; }
unsigned GetDstFrameHeight() const { return dstFrameHeight; }
void SetResizeMode(
PVideoFrameInfo::ResizeMode mode
) { if (mode < PVideoFrameInfo::eMaxResizeMode) resizeMode = mode; }
PVideoFrameInfo::ResizeMode GetResizeMode() const { return resizeMode; }
static void RGBtoYUV(
unsigned r, unsigned g, unsigned b,
unsigned & y, unsigned & u, unsigned & v
);
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
);
static bool FillYUV420P(
unsigned x, unsigned y, int width, int height,
unsigned frameWidth, unsigned frameHeight, BYTE * yuv,
unsigned r, unsigned g, unsigned b
);
protected:
void Construct(
const PVideoFrameInfo & src,
const PVideoFrameInfo & dst
);
PString srcColourFormat;
PString dstColourFormat;
unsigned srcFrameWidth;
unsigned srcFrameHeight;
unsigned srcFrameBytes;
// Needed for resizing
unsigned dstFrameWidth;
unsigned dstFrameHeight;
unsigned dstFrameBytes;
PVideoFrameInfo::ResizeMode resizeMode;
PBoolean verticalFlip;
PBYTEArray intermediateFrameStore;
#ifndef P_MACOSX
/* Use by the jpeg decompressor */
struct jdec_private *jdec;
#endif
friend class PColourConverterRegistration;
};
#define PCOLOUR_CONVERTER2(cls,ancestor,srcFmt,dstFmt) \
class cls : public ancestor { \
public: \
cls(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) \
: ancestor(src, dst) { } \
virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX * = NULL); \
virtual PBoolean Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL); \
}; \
static class cls##_Registration : public PColourConverterRegistration { \
public: cls##_Registration() \
: PColourConverterRegistration(srcFmt,dstFmt) { } \
protected: virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const; \
} p_##cls##_registration_instance; \
PColourConverter * cls##_Registration::Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const \
{ return new cls(src, dst); } \
PBoolean cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, unsigned int p_srcFrameBytes, PINDEX * bytesReturned) \
{ srcFrameBytes = p_srcFrameBytes;return Convert(srcFrameBuffer, dstFrameBuffer, bytesReturned); } \
PBoolean cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, PINDEX * bytesReturned)
#define PCOLOUR_CONVERTER(cls,src,dst) \
PCOLOUR_CONVERTER2(cls,PColourConverter,src,dst)
class PSynonymColour : public PColourConverter {
public:
PSynonymColour(
const PVideoFrameInfo & src,
const PVideoFrameInfo & dst
) : PColourConverter(src, dst) { }
virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX * = NULL);
virtual PBoolean Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL);
};
class PSynonymColourRegistration : public PColourConverterRegistration {
public:
PSynonymColourRegistration(
const char * srcFmt,
const char * dstFmt
);
protected:
virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const;
};
#define PSYNONYM_COLOUR_CONVERTER(from,to) \
static PSynonymColourRegistration p_##from##_##to##_registration_instance(#from,#to)
#endif // P_VIDEO
#endif // PTLIB_CONVERT_H
// End of file ///////////////////////////////////////////////////////////////
PColourConverter::GetSrcFrameInfo
virtual void GetSrcFrameInfo(PVideoFrameInfo &info)
Get the source frame info to be used.
PSynonymColourRegistration::Create
virtual PColourConverter * Create(const PVideoFrameInfo &src, const PVideoFrameInfo &dst) const
PColourConverter::PrintOn
virtual void PrintOn(ostream &strm) const
Print description of converter.
PColourConverter::SetDstFrameSize
virtual PBoolean SetDstFrameSize(unsigned width, unsigned height)
Set the destination frame size to be used.
PVideoFrameInfo::ResizeMode
ResizeMode
Definition: videoio.h:54
PColourConverter::dstFrameWidth
unsigned dstFrameWidth
Definition: vconvert.h:338
PColourConverter::SetFrameSize
virtual PBoolean SetFrameSize(unsigned width, unsigned height)
Set the frame size to be used.
PColourConverter::CopyYUV420P
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 req...
PColourConverter::SetSrcFrameSize
virtual PBoolean SetSrcFrameSize(unsigned width, unsigned height)
Set the source frame size to be used.
PColourConverterRegistration::link
PColourConverterRegistration * link
Definition: vconvert.h:71
PColourConverter::GetDstFrameInfo
virtual void GetDstFrameInfo(PVideoFrameInfo &info)
Get the destination frame info to be used.
PColourConverter::GetMaxDstFrameBytes
PINDEX GetMaxDstFrameBytes()
Get the maximum frame size in bytes for destination frames.
Definition: vconvert.h:205
PColourConverter::GetDstColourFormat
const PString & GetDstColourFormat()
Get the destination colour format.
Definition: vconvert.h:191
PColourConverter::GetDstFrameHeight
unsigned GetDstFrameHeight() const
Definition: vconvert.h:285
PColourConverter::RGBtoYUV
static void RGBtoYUV(unsigned r, unsigned g, unsigned b, unsigned &y, unsigned &u, unsigned &v)
Convert RGB to YUV.
PColourConverter::ConvertInPlace
virtual PBoolean ConvertInPlace(BYTE *frameBuffer, PINDEX *bytesReturned=NULL, PBoolean noIntermediateFrame=false)
Convert from one colour format to another.
PSynonymColour::PSynonymColour
PSynonymColour(const PVideoFrameInfo &src, const PVideoFrameInfo &dst)
Definition: vconvert.h:398
PColourConverter::GetVFlipState
PBoolean GetVFlipState()
Get the video conversion vertical flip state.
Definition: vconvert.h:104
PColourConverter::intermediateFrameStore
PBYTEArray intermediateFrameStore
Definition: vconvert.h:346
PCaselessString
This class is a variation of a string that ignores case.
Definition: pstring.h:1708
PColourConverter::GetDstFrameWidth
unsigned GetDstFrameWidth() const
Definition: vconvert.h:284
videoio.h
PVideoFrameInfo::eMaxResizeMode
Definition: videoio.h:59
PColourConverter::Convert
virtual PBoolean Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, PINDEX *bytesReturned=NULL)=0
Convert from one colour format to another.
PColourConverter::verticalFlip
PBoolean verticalFlip
Definition: vconvert.h:344
PColourConverter::Construct
void Construct(const PVideoFrameInfo &src, const PVideoFrameInfo &dst)
PColourConverter::srcFrameHeight
unsigned srcFrameHeight
Definition: vconvert.h:334
PColourConverter::srcFrameWidth
unsigned srcFrameWidth
Definition: vconvert.h:333
PColourConverter::srcFrameBytes
unsigned srcFrameBytes
Definition: vconvert.h:335
PBoolean
BOOL PBoolean
Definition: object.h:102
PColourConverter::GetSrcFrameWidth
unsigned GetSrcFrameWidth() const
Definition: vconvert.h:282
PVideoFrameInfo
Definition: videoio.h:49
PBYTEArray
Array of unsigned characters.
Definition: array.h:670
PColourConverter::GetSrcFrameSize
PBoolean GetSrcFrameSize(unsigned &width, unsigned &height) const
Get the input frame size.
PColourConverter::SetVFlipState
void SetVFlipState(PBoolean vFlipState)
Set the video conversion vertical flip state.
Definition: vconvert.h:109
PColourConverter::SetResizeMode
void SetResizeMode(PVideoFrameInfo::ResizeMode mode)
Set the resize mode to be used.
Definition: vconvert.h:289
PColourConverterRegistration::Create
virtual PColourConverter * Create(const PVideoFrameInfo &src, const PVideoFrameInfo &dst) const =0
PSynonymColourRegistration
Define synonym colour format registration.
Definition: vconvert.h:411
PColourConverter::GetSrcColourFormat
const PString & GetSrcColourFormat()
Get the source colour format.
Definition: vconvert.h:187
PColourConverter::PColourConverter
PColourConverter(const PString &srcColourFormat, const PString &dstColourFormat, unsigned width, unsigned height)
Create a new converter.
PColourConverter::GetSrcFrameHeight
unsigned GetSrcFrameHeight() const
Definition: vconvert.h:283
PColourConverterRegistration::PColourConverterRegistration
PColourConverterRegistration(const PString &srcColourFormat, const PString &destColourFormat)
PColourConverter::SetDstFrameInfo
virtual PBoolean SetDstFrameInfo(const PVideoFrameInfo &info)
Set the destination frame info to be used.
PString
The character string class.
Definition: pstring.h:108
PColourConverter::Create
static PColourConverter * Create(const PVideoFrameInfo &src, const PVideoFrameInfo &dst)
Create an instance of a colour conversion function.
PSynonymColour::Convert
virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX *=NULL)
Convert from one colour format to another.
PColourConverter::FillYUV420P
static bool FillYUV420P(unsigned x, unsigned y, int width, int height, unsigned frameWidth, unsigned frameHeight, BYTE *yuv, unsigned r, unsigned g, unsigned b)
PColourConverter::GetDstFrameSize
PBoolean GetDstFrameSize(unsigned &width, unsigned &height) const
Get the output frame size.
PSynonymColour
Define synonym colour format converter.
Definition: vconvert.h:396
PColourConverter::srcColourFormat
PString srcColourFormat
Definition: vconvert.h:331
PColourConverterRegistration
This class registers a colour conversion class.
Definition: vconvert.h:56
PColourConverter
This class defines a means to convert an image from one colour format to another. ...
Definition: vconvert.h:80
PColourConverter::dstFrameHeight
unsigned dstFrameHeight
Definition: vconvert.h:339
PColourConverter::GetMaxSrcFrameBytes
PINDEX GetMaxSrcFrameBytes()
Get the maximum frame size in bytes for source frames.
Definition: vconvert.h:198
PColourConverter::dstFrameBytes
unsigned dstFrameBytes
Definition: vconvert.h:340
PColourConverter::resizeMode
PVideoFrameInfo::ResizeMode resizeMode
Definition: vconvert.h:342
PSynonymColourRegistration::PSynonymColourRegistration
PSynonymColourRegistration(const char *srcFmt, const char *dstFmt)
PObject
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PColourConverter::dstColourFormat
PString dstColourFormat
Definition: vconvert.h:332
PColourConverter::GetResizeMode
PVideoFrameInfo::ResizeMode GetResizeMode() const
Get the resize mode to be used.
Definition: vconvert.h:295
PColourConverter::SetSrcFrameInfo
virtual PBoolean SetSrcFrameInfo(const PVideoFrameInfo &info)
Set the source frame info to be used.
PColourConverter::jdec
struct jdec_private * jdec
Definition: vconvert.h:350