[Opalvoip-svn] SF.net SVN: opalvoip:[34636] ptlib/trunk
Brought to you by:
csoutheren,
rjongbloed
From: <rjo...@us...> - 2016-02-19 10:37:08
|
Revision: 34636 http://sourceforge.net/p/opalvoip/code/34636 Author: rjongbloed Date: 2016-02-19 10:37:06 +0000 (Fri, 19 Feb 2016) Log Message: ----------- Added some constructors to make PJPEGConverter easier to use. Also added some documentation. Modified Paths: -------------- ptlib/trunk/include/ptlib/vconvert.h ptlib/trunk/src/ptlib/common/vconvert.cxx Modified: ptlib/trunk/include/ptlib/vconvert.h =================================================================== --- ptlib/trunk/include/ptlib/vconvert.h 2016-02-18 12:30:26 UTC (rev 34635) +++ ptlib/trunk/include/ptlib/vconvert.h 2016-02-19 10:37:06 UTC (rev 34636) @@ -387,6 +387,14 @@ #if P_JPEG_DECODER +/**Class to convert a JPEG image to other formats. + Simplest usage is to load to a YUV420P buffer: + <code> + PBYTEArray yuv; + PJPEGConverter converter; + converter.Load(file, yuv) + </code> + */ class PJPEGConverter : public PColourConverter { protected: @@ -394,25 +402,53 @@ Context * m_context; public: + /**Construct a JPEG converter that outputs YUV420P at same resolution as the JPEG itself. + */ + PJPEGConverter(); + /**Construct a JPEG converter that outputs YUV420P at same resolution as the JPEG itself. + */ PJPEGConverter( + unsigned width, ///< Output width, zero indicates same is JPEG input + unsigned height, ///< Output height, zero indicates same is JPEG input + PVideoFrameInfo::ResizeMode resizeMode = PVideoFrameInfo::eScale, ///< How to produce output + const PString & colourFormat = "YUV420P" ///< Output colour format + ); + /**Construct a JPEG converter. + This is used for the PColourConverter factory. + */ + PJPEGConverter( const PColourPair & colours ); + + /**Deprecated, used for backward compatibility. + */ PJPEGConverter( const PVideoFrameInfo & src, const PVideoFrameInfo & dst ); + + /// Destroy the JPEG converter ~PJPEGConverter(); + /** Convert JPEG information in a memory buffer to another memory buffer. + Note if scaling is required + */ virtual PBoolean Convert( const BYTE * srcFrameBuffer, ///< Frame store for source pixels BYTE * dstFrameBuffer, ///< Frame store for destination pixels PINDEX * bytesReturned = NULL ///< Bytes written to dstFrameBuffer ); + /** Load a file and convert to the output format for the converter. + */ bool Load( - PFile & file, - PBYTEArray & dstFrameBuffer + const PFilePath & filename, ///< Name of file to load + PBYTEArray & dstFrameBuffer ///< Buffer to receive converted output ); + bool Load( + PFile & file, ///< File to read JPEG from. + PBYTEArray & dstFrameBuffer ///< Buffer to receive converted output + ); }; #endif // P_JPEG_DECODER Modified: ptlib/trunk/src/ptlib/common/vconvert.cxx =================================================================== --- ptlib/trunk/src/ptlib/common/vconvert.cxx 2016-02-18 12:30:26 UTC (rev 34635) +++ ptlib/trunk/src/ptlib/common/vconvert.cxx 2016-02-19 10:37:06 UTC (rev 34636) @@ -3222,6 +3222,22 @@ }; +PJPEGConverter::PJPEGConverter() + : PColourConverter(PColourPair("JPEG", "YUV420P")) + , m_context(new Context) +{ +} + + +PJPEGConverter::PJPEGConverter(unsigned width, unsigned height, PVideoFrameInfo::ResizeMode resizeMode, const PString & colourFormat) + : PColourConverter(PColourPair("JPEG", colourFormat)) + , m_context(new Context) +{ + SetResizeMode(resizeMode); + SetDstFrameSize(width, height); +} + + PJPEGConverter::PJPEGConverter(const PColourPair & colours) : PColourConverter(colours) , m_context(new Context) @@ -3257,6 +3273,13 @@ } +bool PJPEGConverter::Load(const PFilePath & filename, PBYTEArray & dstFrameBuffer) +{ + PFile file; + return file.Open(filename, PFile::ReadOnly) && Load(file, dstFrameBuffer); +} + + bool PJPEGConverter::Load(PFile & file, PBYTEArray & dstFrameBuffer) { if (!m_context->SetColourSpace(m_dstColourFormat)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |