JPEG Wrap  0.0.1-2561
C++ JPEG Wrap for IJG's jpeglib
JWCompress Class Reference

Use JWCompress to create .jpg files using RGB or YUV image data. More...

#include <JWCompress.hpp>

Inheritance diagram for JWCompress:
Collaboration diagram for JWCompress:

Public Member Functions

 JWCompress (void)
 Constructor. More...
 
virtual ~JWCompress (void)
 Destructor. More...
 
virtual JWCompresscompress (void)
 Compress the given data. More...
 
virtual JWCompresscompress_yuv422 (const uint8_t *const data, const size_t bytes_per_row)
 Create a JPEG from 16-bit YUYV data (aka YUY2, or YUV 4:2:2 format). More...
 
virtual JWCompressset_size (const size_t width, const size_t height)
 Set the size of the image. More...
 
virtual JWCompressset_colour (const int components=3, const J_COLOR_SPACE colour_space=JCS_RGB)
 Set the number of colour components and the colour space. More...
 
virtual JWCompressset_default_parameters (const J_COLOR_SPACE colour_space=JCS_RGB)
 Set usable default values for most of the optional parameters. More...
 
virtual JWCompressset_quality (const int quality=75, const bool force_baseline=true)
 Constructs JPEG quantization tables appropriate for the indicated quality setting. More...
 
virtual JWCompressoptimized_huffman_tables (void)
 Causes the compressor to compute optimal Huffman coding tables for the image. More...
 
virtual JWCompressset_smoothing (const int smoothing=0)
 Determine if smoothing is accessed. Zero turns it off, 100 sets the maximum amount of smoothing. More...
 
virtual std::string get_filename (void) const
 The filename used for input (decompress) or output (compress) if set via set_file(). More...
 
virtual JWCompressset_output_file (const std::string &filename)
 Set the output file into which the compressed JPEG image will be stored. More...
 
virtual JWCompressset_output_file (FILE *f)
 Set the output file into which the compressed JPEG image will be stored. More...
 
virtual JWCompressuse_arithmetic_coding (void)
 Arithmetic coding will usually result in marginally smaller files, but require more CPU than Huffman coding. More...
 
virtual JWCompressuse_huffman_coding (void)
 Arithmetic coding will usually result in marginally smaller files, but require more CPU than Huffman coding. More...
 
virtual JWCompressuse_integer_slow_dct (void)
 The FLOAT method is very slightly more accurate than the ISLOW method, but may give different results on different machines due to varying roundoff behavior. More...
 
virtual JWCompressuse_integer_fast_dct (void)
 The FLOAT method is very slightly more accurate than the ISLOW method, but may give different results on different machines due to varying roundoff behavior. More...
 
virtual JWCompressuse_float_dct (void)
 The FLOAT method is very slightly more accurate than the ISLOW method, but may give different results on different machines due to varying roundoff behavior. More...
 

Public Attributes

jpeg_compress_struct cinfo
 IJG's compression structure. More...
 
jpeg_error_mgr jerr
 IJG's structures and pointers to those structures used by derived classes. More...
 
jpeg_error_mgr * jerr_ptr
 IJG's structures and pointers to those structures used by derived classes. More...
 
jpeg_compress_struct * cinfo_ptr
 IJG's structures and pointers to those structures used by derived classes. More...
 
jpeg_decompress_struct * dinfo_ptr
 IJG's structures and pointers to those structures used by derived classes. More...
 

Protected Member Functions

virtual JWset_file (const std::string &filename)
 Protected method to set the input or output file. More...
 
virtual JWset_file (FILE *f)
 

Protected Attributes

std::string fname
 The filename used for input (decompress) or output (compress) if set via set_file(). More...
 
FILE * file
 Input/output file. Used for output when compressing, and input when decompressing. More...
 

Detailed Description

Use JWCompress to create .jpg files using RGB or YUV image data.

Constructor & Destructor Documentation

◆ JWCompress()

JWCompress::JWCompress ( void  )

Constructor.

Here is the call graph for this function:

◆ ~JWCompress()

JWCompress::~JWCompress ( void  )
virtual

Destructor.

Member Function Documentation

◆ compress()

JWCompress & JWCompress::compress ( void  )
virtual

Compress the given data.

◆ compress_yuv422()

JWCompress & JWCompress::compress_yuv422 ( const uint8_t *const  data,
const size_t  bytes_per_row 
)
virtual

Create a JPEG from 16-bit YUYV data (aka YUY2, or YUV 4:2:2 format).

This format is popular with web cams. The output file is closed in this method once the image has been written.

See also
https://linuxtv.org/downloads/v4l-dvb-apis-new/uapi/v4l/pixfmt-yuyv.html
https://www.fourcc.org/pixel-format/yuv-yuy2/
Exceptions
std::logic_errorif the output file has not been set
std::logic_errorif the image width or height is invalid or has not been set
std::invalid_argumentif the image data pointer is null
std::invalid_argumentif the bytes per row is invalid
Note
JCS_YCbCr in libjpeg needs 24-bit values. This means 8 bits each for Y, Cb, and Cr. This method automatically takes 16-bit YUV 422 values and converts them to full 24-bit values prior to calling libjpeg to do the actual encoding.
Warning
This method automatically calls set_colour() to set the number of components to 3 and the colour space to JCS_YCbCr.
Here is the call graph for this function:

◆ get_filename()

virtual std::string JW::get_filename ( void  ) const
inlinevirtualinherited

The filename used for input (decompress) or output (compress) if set via set_file().

The only way to set the input or output file is to call JWCompress::set_output_file() or JWDecompress::set_input_file().

◆ optimized_huffman_tables()

virtual JWCompress& JWCompress::optimized_huffman_tables ( void  )
inlinevirtual

Causes the compressor to compute optimal Huffman coding tables for the image.

This requires an extra pass over the data and therefore costs a good deal of space and time. The default is FALSE, which tells the compressor to use the supplied or default Huffman tables. In most cases optimal tables save only a few percent of file size compared to the default tables.

See also
use_huffman_coding()

◆ set_colour()

JWCompress & JWCompress::set_colour ( const int  components = 3,
const J_COLOR_SPACE  colour_space = JCS_RGB 
)
virtual

Set the number of colour components and the colour space.

Here is the caller graph for this function:

◆ set_default_parameters()

JWCompress & JWCompress::set_default_parameters ( const J_COLOR_SPACE  colour_space = JCS_RGB)
virtual

Set usable default values for most of the optional parameters.

This sets all JPEG parameters to reasonable defaults, using only the input image's color space. Many applications will only need to use this routine and perhaps set_quality().

Note
This is automatically called by JWCompress::JWCompress().
Here is the caller graph for this function:

◆ set_file() [1/2]

JW & JW::set_file ( const std::string &  filename)
protectedvirtualinherited

Protected method to set the input or output file.

Use the equivalent functions in the derived classes instead.

See also
JWCompress::set_output_file()
JWDecompress::set_input_file()
Exceptions
std::runtime_errorif the named file cannot be opened
Here is the caller graph for this function:

◆ set_file() [2/2]

JW & JW::set_file ( FILE *  f)
protectedvirtualinherited
Exceptions
std::runtime_errorif the file pointer is null

◆ set_output_file() [1/2]

virtual JWCompress& JWCompress::set_output_file ( const std::string &  filename)
inlinevirtual

Set the output file into which the compressed JPEG image will be stored.

Here is the call graph for this function:

◆ set_output_file() [2/2]

virtual JWCompress& JWCompress::set_output_file ( FILE *  f)
inlinevirtual

Set the output file into which the compressed JPEG image will be stored.

Here is the call graph for this function:

◆ set_quality()

JWCompress & JWCompress::set_quality ( const int  quality = 75,
const bool  force_baseline = true 
)
virtual

Constructs JPEG quantization tables appropriate for the indicated quality setting.

The quality value is expressed on the 0..100 scale recommended by IJG. The exact mapping from quality values to tables may change in future IJG releases as more is learned about DCT quantization. If the force_baseline parameter is TRUE, then the quantization table entries are constrained to the range 1..255 for full JPEG baseline compatibility. In the current implementation, this only makes a difference for quality settings below 25, and it effectively prevents very small/low quality files from being generated. The IJG decoder is capable of reading the non-baseline files generated at low quality settings when force_baseline is FALSE, but other decoders may not be.

Here is the caller graph for this function:

◆ set_size()

JWCompress & JWCompress::set_size ( const size_t  width,
const size_t  height 
)
virtual

Set the size of the image.

Here is the caller graph for this function:

◆ set_smoothing()

virtual JWCompress& JWCompress::set_smoothing ( const int  smoothing = 0)
inlinevirtual

Determine if smoothing is accessed. Zero turns it off, 100 sets the maximum amount of smoothing.

◆ use_arithmetic_coding()

virtual JWCompress& JWCompress::use_arithmetic_coding ( void  )
inlinevirtual

Arithmetic coding will usually result in marginally smaller files, but require more CPU than Huffman coding.

◆ use_float_dct()

virtual JWCompress& JWCompress::use_float_dct ( void  )
inlinevirtual

The FLOAT method is very slightly more accurate than the ISLOW method, but may give different results on different machines due to varying roundoff behavior.

The integer methods should give the same results on all machines. On machines with sufficiently fast FP hardware, the floating-point method may also be the fastest. The IFAST method is considerably less accurate than the other two; its use is not recommended if high quality is a concern.

◆ use_huffman_coding()

virtual JWCompress& JWCompress::use_huffman_coding ( void  )
inlinevirtual

Arithmetic coding will usually result in marginally smaller files, but require more CPU than Huffman coding.

◆ use_integer_fast_dct()

virtual JWCompress& JWCompress::use_integer_fast_dct ( void  )
inlinevirtual

The FLOAT method is very slightly more accurate than the ISLOW method, but may give different results on different machines due to varying roundoff behavior.

The integer methods should give the same results on all machines. On machines with sufficiently fast FP hardware, the floating-point method may also be the fastest. The IFAST method is considerably less accurate than the other two; its use is not recommended if high quality is a concern.

◆ use_integer_slow_dct()

virtual JWCompress& JWCompress::use_integer_slow_dct ( void  )
inlinevirtual

The FLOAT method is very slightly more accurate than the ISLOW method, but may give different results on different machines due to varying roundoff behavior.

The integer methods should give the same results on all machines. On machines with sufficiently fast FP hardware, the floating-point method may also be the fastest. The IFAST method is considerably less accurate than the other two; its use is not recommended if high quality is a concern.

Member Data Documentation

◆ cinfo

jpeg_compress_struct JWCompress::cinfo

IJG's compression structure.

See also
jpeglib.h

◆ cinfo_ptr

jpeg_compress_struct* JW::cinfo_ptr
inherited

IJG's structures and pointers to those structures used by derived classes.

◆ dinfo_ptr

jpeg_decompress_struct* JW::dinfo_ptr
inherited

IJG's structures and pointers to those structures used by derived classes.

◆ file

FILE* JW::file
protectedinherited

Input/output file. Used for output when compressing, and input when decompressing.

◆ fname

std::string JW::fname
protectedinherited

The filename used for input (decompress) or output (compress) if set via set_file().

See also
get_filename()

◆ jerr

jpeg_error_mgr JW::jerr
inherited

IJG's structures and pointers to those structures used by derived classes.

◆ jerr_ptr

jpeg_error_mgr* JW::jerr_ptr
inherited

IJG's structures and pointers to those structures used by derived classes.


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