Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Protected Attributes | List of all members
BIAS::JpegHandler Class Reference

Wrapper for fast libjpeg methods. More...

#include <Base/Image/CompressJpeg.hh>

Public Member Functions

int Compress (BIAS::Image< unsigned char > &srcImg, int quality=60)
 Start compression for given BIAS::Image into buffer. More...
 
int Compress (unsigned int width, unsigned int height, unsigned int channels, unsigned char *data, int quality=60)
 Start compression for given image data from buffer. More...
 
int Compress (unsigned int width, unsigned int height, unsigned int channels, unsigned char *inData, unsigned char *outData, long &outBytes, int quality=60)
 Start compression for given image data to given output buffer. More...
 
int Decompress (BIAS::Image< unsigned char > &destImg, bool readComment=false)
 Start decompression of previously given data (from ReadJPEG() or SetCompressedData()), results will be stored in destination image. More...
 
int Decompress (unsigned int &width, unsigned int &height, unsigned int &channels, unsigned char *&data)
 Start decompression of previously given data (from ReadJPEG() or SetCompressedData()), results will be stored in data, width, ... More...
 
int Decompress (unsigned int &width, unsigned int &height, unsigned int &channels, unsigned char *inData, long inBytes, unsigned char *outData)
 Start decompression of given data and write result to given output buffer. More...
 
void GetCompressedData (void *&data, long &length)
 Get pointer to memory where to find compressed data and its length in byte. More...
 
long GetCompressedDataSize ()
 Return compressed data length in bytes. More...
 
int Init (long size=10485760)
 Initialize object with standard values and limit shared memory area to given size (in byte, default is 10 MByte). More...
 
bool IsInitialized ()
 Returns if an internal buffer has been initialized. More...
 
 JpegHandler ()
 Constructor with empty internal buffer. More...
 
 JpegHandler (long size)
 Constructor with initialized internal buffer. More...
 
int ReadJPEG (const std::string &filename)
 Read JPEG file named filename and store its informations in compressed data field. More...
 
void Release ()
 Releases allocated memory. More...
 
void SetCompressedData (void *data, long length)
 Copy memory area in which compressed data can be found and set its length in byte. More...
 
void SetVerbose (const bool verbose)
 Print error messages to standard output or keep quiet? More...
 
int WriteJPEG (const std::string &filename)
 Write previously compressed data to file named filename. More...
 
virtual ~JpegHandler ()
 Destructor releases internal buffer. More...
 

Protected Attributes

long bufferSize_
 Length in byte of compression buffer (max. More...
 
void * data_
 Pointer to compression buffer (compressed data) More...
 
long dataLength_
 Length in byte of compressed data. More...
 
bool verbose_
 Print error messages or keep quiet? More...
 

Detailed Description

Wrapper for fast libjpeg methods.

Class for memory-to-memory JPEG compression. Compress a given BIAS::Image (unsigned char) to data array in shared memory or decompress a given JPEG file located in user memory into a BIAS::Image (unsigned char).

Author
Arne Petersen
Date
15/08/2005
Examples:
ExampleJPEGCompress.cpp, and ExampleJPEGDecompress.cpp.

Definition at line 50 of file CompressJpeg.hh.

Constructor & Destructor Documentation

JpegHandler::JpegHandler ( )

Constructor with empty internal buffer.

Definition at line 678 of file CompressJpeg.cpp.

JpegHandler::JpegHandler ( long  size)

Constructor with initialized internal buffer.

Definition at line 686 of file CompressJpeg.cpp.

JpegHandler::~JpegHandler ( )
virtual

Destructor releases internal buffer.

Definition at line 695 of file CompressJpeg.cpp.

Member Function Documentation

int JpegHandler::Compress ( BIAS::Image< unsigned char > &  srcImg,
int  quality = 60 
)

Start compression for given BIAS::Image into buffer.

Returns
Returns < 0 in case of errors, 0 otherwise.
Examples:
ExampleJPEGCompress.cpp.

Definition at line 726 of file CompressJpeg.cpp.

References BIAS::ImageBase::GetChannelCount(), BIAS::ImageBase::GetHeight(), BIAS::Image< StorageType >::GetImageData(), and BIAS::ImageBase::GetWidth().

Referenced by BIAS::ImageIO::ExportLibJPEG(), and BIAS::VideoTransmitter::Process().

int JpegHandler::Compress ( unsigned int  width,
unsigned int  height,
unsigned int  channels,
unsigned char *  data,
int  quality = 60 
)

Start compression for given image data from buffer.

Returns
Returns < 0 in case of errors, 0 otherwise.

Definition at line 750 of file CompressJpeg.cpp.

int JpegHandler::Compress ( unsigned int  width,
unsigned int  height,
unsigned int  channels,
unsigned char *  inData,
unsigned char *  outData,
long &  outBytes,
int  quality = 60 
)

Start compression for given image data to given output buffer.

   The internal buffer is not used here, hence it is allowed to be
   uninitialized.
Returns
Returns < 0 in case of errors, 0 otherwise.

Definition at line 799 of file CompressJpeg.cpp.

int JpegHandler::Decompress ( BIAS::Image< unsigned char > &  destImg,
bool  readComment = false 
)

Start decompression of previously given data (from ReadJPEG() or SetCompressedData()), results will be stored in destination image.

   Decompress() will initialize destination image properly if needed.
Returns
Returns < 0 in case of errors, 0 otherwise.
Examples:
ExampleJPEGDecompress.cpp.

Definition at line 775 of file CompressJpeg.cpp.

Referenced by BIAS::VideoSource_Net::GrabSingle(), and BIAS::ImageIO::ImportLibJPEG().

int JpegHandler::Decompress ( unsigned int &  width,
unsigned int &  height,
unsigned int &  channels,
unsigned char *&  data 
)

Start decompression of previously given data (from ReadJPEG() or SetCompressedData()), results will be stored in data, width, ...

   New memory for data will only be allocated if data == NULL, else
   old allocated memory will be used, so set data = NULL if you're
   not sure about it's size!
Returns
Returns < 0 in case of errors, 0 otherwise.

Definition at line 786 of file CompressJpeg.cpp.

int JpegHandler::Decompress ( unsigned int &  width,
unsigned int &  height,
unsigned int &  channels,
unsigned char *  inData,
long  inBytes,
unsigned char *  outData 
)

Start decompression of given data and write result to given output buffer.

The internal buffer is not used here, hence it is allowed to be uninitialized.

Returns
Returns < 0 in case of errors, 0 otherwise.

Definition at line 819 of file CompressJpeg.cpp.

void BIAS::JpegHandler::GetCompressedData ( void *&  data,
long &  length 
)
inline

Get pointer to memory where to find compressed data and its length in byte.

Attention
No copy will be used, so make sure it's still valid when starting Decompress() or reusing this!

Definition at line 140 of file CompressJpeg.hh.

Referenced by BIAS::VideoTransmitter::Process().

long BIAS::JpegHandler::GetCompressedDataSize ( )
inline

Return compressed data length in bytes.

Definition at line 148 of file CompressJpeg.hh.

int JpegHandler::Init ( long  size = 10485760)

Initialize object with standard values and limit shared memory area to given size (in byte, default is 10 MByte).

   Re-initialization is only required for changing buffer size.
Attention
Initialize buffer before first use!
Returns
Returns < 0 in case of errors, 0 otherwise.
Examples:
ExampleJPEGCompress.cpp, and ExampleJPEGDecompress.cpp.

Definition at line 700 of file CompressJpeg.cpp.

Referenced by BIAS::ImageIO::ExportLibJPEG(), BIAS::ImageIO::ImportLibJPEG(), BIAS::VideoTransmitter::Init(), BIAS::VideoSource_V4L::OpenDevice(), and BIAS::VideoSource_Net::VideoSource_Net().

bool BIAS::JpegHandler::IsInitialized ( )
inline

Returns if an internal buffer has been initialized.

Definition at line 75 of file CompressJpeg.hh.

int JpegHandler::ReadJPEG ( const std::string &  filename)

Read JPEG file named filename and store its informations in compressed data field.

Returns
Returns < 0 in case of errors, 0 otherwise.
Examples:
ExampleJPEGDecompress.cpp.

Definition at line 854 of file CompressJpeg.cpp.

Referenced by BIAS::ImageIO::ImportLibJPEG().

void JpegHandler::Release ( )

Releases allocated memory.

Use it to regain memory but call Init() again bevor using object afterwards!

Definition at line 716 of file CompressJpeg.cpp.

Referenced by BIAS::VideoSource_Net::CloseDevice(), BIAS::ImageIO::ExportLibJPEG(), and BIAS::ImageIO::ImportLibJPEG().

void BIAS::JpegHandler::SetCompressedData ( void *  data,
long  length 
)
inline

Copy memory area in which compressed data can be found and set its length in byte.

Definition at line 154 of file CompressJpeg.hh.

Referenced by BIAS::VideoSource_Net::GrabSingle().

void BIAS::JpegHandler::SetVerbose ( const bool  verbose)
inline

Print error messages to standard output or keep quiet?

Definition at line 175 of file CompressJpeg.hh.

Referenced by BIAS::ImageIO::ExportLibJPEG(), and BIAS::ImageIO::ImportLibJPEG().

int JpegHandler::WriteJPEG ( const std::string &  filename)

Write previously compressed data to file named filename.

Returns
Returns < 0 in case of errors, 0 otherwise.
Examples:
ExampleJPEGCompress.cpp.

Definition at line 825 of file CompressJpeg.cpp.

Referenced by BIAS::ImageIO::ExportLibJPEG().

Member Data Documentation

long BIAS::JpegHandler::bufferSize_
protected

Length in byte of compression buffer (max.

data size)

Definition at line 186 of file CompressJpeg.hh.

void* BIAS::JpegHandler::data_
protected

Pointer to compression buffer (compressed data)

Definition at line 180 of file CompressJpeg.hh.

long BIAS::JpegHandler::dataLength_
protected

Length in byte of compressed data.

Definition at line 183 of file CompressJpeg.hh.

bool BIAS::JpegHandler::verbose_
protected

Print error messages or keep quiet?

Definition at line 189 of file CompressJpeg.hh.


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