jpeg_conversion
Public Member Functions | Static Public Attributes | List of all members
conversion::JpegConversion Class Reference

#include <jpeg_conversion.hpp>

Public Member Functions

 JpegConversion ()
 
 JpegConversion (unsigned int jpeg_quality)
 
 ~JpegConversion ()
 
void compress (base::samples::frame::Frame const &frame_input, base::samples::frame::Frame &frame_output)
 
void decompress (base::samples::frame::Frame const &frame_input, base::samples::frame::frame_mode_t const decompress_to, base::samples::frame::Frame &frame_output)
 
void decompress (uint8_t const *src, size_t src_size, int width, int height, base::samples::frame::frame_mode_t const decompress_to, uint8_t *dst)
 
J_COLOR_SPACE getJpegColorspace (base::samples::frame::frame_mode_t const frame_mode, bool &flip_rgb, bool &is_jpeg)
 
bool storeFrame (std::string filename, base::samples::frame::Frame const &frame, std::string *used_filename=NULL)
 
bool loadJpeg (std::string const &filename, uint32_t const width, uint32_t const height, base::samples::frame::Frame &frame)
 

Static Public Attributes

static const int JPEG_QUALITY = 80
 

Detailed Description

Allows to convert jpeg-frames using the IJG library. Decompress MODE_JPEG to MODE_GRAYSCALE, MODE_RGB or MODE_BGR and
compress MODE_GRAYSCALE, MODE_RGB or MODE_BGR to MODE_JPEG.

Constructor & Destructor Documentation

conversion::JpegConversion::JpegConversion ( )
inline
conversion::JpegConversion::JpegConversion ( unsigned int  jpeg_quality)
inline
conversion::JpegConversion::~JpegConversion ( )
inline

Member Function Documentation

void conversion::JpegConversion::compress ( base::samples::frame::Frame const &  frame_input,
base::samples::frame::Frame &  frame_output 
)

Compresses the passed image to JPEG. Supported frame color formats are MODE_GRAYSCALE, MODE_RGB, MODE_BGR and MODE_JPEG. To keep 'frame_input' constant, using MODE_BGR creates an extra copy of the passed image. Using the jpeg quality passed in the constructor. Throws a std::runtime_error if the color mode of the input image is not supported.

Parameters
frame_inputImage which should be converted to jpeg-format. Input frame has to have one of the valid color modes.
frame_outputWill be set to MODE_JPEG and resized if required.
void conversion::JpegConversion::decompress ( base::samples::frame::Frame const &  frame_input,
base::samples::frame::frame_mode_t const  decompress_to,
base::samples::frame::Frame &  frame_output 
)

Decompress the passed frame to the color format of 'frame_output'. Throws a std::runtime_error if the input image is not a jpeg or the color format of the output image is not supported.

Parameters
frame_inputInput image, must be of color format MODE_JPEG.
frame_outputHas to contain the color format (MODE_GRAYSCALE, MODE_RGB, MODE_BGR and MODE_JPEG) the input jpeg should be converted to. Will be resized if necessary. Color channel data depth will be set to 8.
Important: Always use frame.init(... ) to set the color format! Otherwise the internal 'init()' call could be ignored.
void conversion::JpegConversion::decompress ( uint8_t const *  src,
size_t  src_size,
int  width,
int  height,
base::samples::frame::frame_mode_t const  decompress_to,
uint8_t *  dst 
)

Required by FrameHelper, abstracting from frames. Take care to allocate enough memory for the decompressed image! If you are unsure about that, use 'decompress(frame, frame, frame_mode)' instead.

Parameters
srcPointer to JPEG data.
widthWidth of the input and the output image.
heightHeigth of the input and the output image.
decompress_toFrame mode to decompress to.
dstPointer to memory which should receive the decompressed image.
J_COLOR_SPACE conversion::JpegConversion::getJpegColorspace ( base::samples::frame::frame_mode_t const  frame_mode,
bool &  flip_rgb,
bool &  is_jpeg 
)

Maps the frame colorspace to the IJG colorspace.

Parameters
flip_rgbIs set to true if the frame colorspace is BGR (IJG just handles RGB). The R and B channel have to be switched manually before compression and accordingly after decompression.
is_jpegIs set to true if the passed frame has already a jpeg format.
bool conversion::JpegConversion::loadJpeg ( std::string const &  filename,
uint32_t const  width,
uint32_t const  height,
base::samples::frame::Frame &  frame 
)

Loads the jpeg and store its content to 'mFrameOutput'.

bool conversion::JpegConversion::storeFrame ( std::string  filename,
base::samples::frame::Frame const &  frame,
std::string *  used_filename = NULL 
)

If not empty, the Frame will be stored to 'filename'. Take care that the path is valid.

Parameters
filenameJust pass the plain name of the file without any extension.
frameFrame to store. Valid modes are MODE_RGB, MODE_BGR, MODE_GRAYSCALE and MODE_JPEG.
used_filenameAccording to the frame type the file extension will be added to the passed filename. You can pass the address of a string to 'used_filename' to receive the complete filename (file extension included) which will be used.
Returns
True if the complete image could be written.

Member Data Documentation

const int conversion::JpegConversion::JPEG_QUALITY = 80
static

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