Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

image_util Namespace Reference

Provides a variety of straightforward calls to compress or decompress images in JPEG or PNG formats. More...

Functions

bool decodePNGToDepth (png_structp png_ptr, png_infop info_ptr, size_t &width, size_t &height, size_t &channels, char *&outbuf, size_t &outbufSize, png_cleanup_f png_cleanup=NULL)
bool decodePNGToDepth (std::istream &inStream, size_t &width, size_t &height, size_t &channels, char *&outbuf, size_t &outbufSize)
Generic File Utilities

bool loadFile (const std::string &file, char *&buf, size_t &size)
 loads a file into memory, returns true if successful, storing resulting buffer information in buf and size
void releaseFile (char *buf, size_t size)
 releases memory from a previous call to loadFile, triggering munmap() or 'delete' as appropriate
Decode Header Information (from memory buffer)

bool decodeJPEG (char *inbuf, size_t inbufSize, size_t &width, size_t &height, size_t &channels)
 decodes a JPEG header already in memory, returns true if successful
bool decodePNG (char *inbuf, size_t inbufSize, size_t &width, size_t &height, size_t &channels)
 decodes a PNG header already in memory, returns true if successful
bool decodeImage (char *inbuf, size_t inbufSize, size_t &width, size_t &height, size_t &channels)
 decodes an image header already in memory -- if it looks like a PNG decodePNG() will be called, otherwise decodeJPEG(); returns true if successful
Decode Header Information (from stream)

bool decodeJPEG (std::istream &inStream, size_t &width, size_t &height, size_t &channels)
 decodes a JPEG header already in memory, returns true if successful
bool decodePNG (std::istream &inStream, size_t &width, size_t &height, size_t &channels)
 decodes a PNG header already in memory, returns true if successful
bool decodeImage (std::istream &inStream, size_t &width, size_t &height, size_t &channels)
 decodes an image header already in memory -- if it looks like a PNG decodePNG() will be called, otherwise decodeJPEG(); returns true if successful
Decompress From Memory Buffer

bool decodeJPEG (char *inbuf, size_t inbufSize, size_t &width, size_t &height, size_t &channels, char *&outbuf, size_t &outbufSize, const std::string &filename="")
 decodes a JPEG image already in memory, returns true if successful
bool decodePNG (char *inbuf, size_t inbufSize, size_t &width, size_t &height, size_t &channels, char *&outbuf, size_t &outbufSize)
 decodes a PNG image already in memory, returns true if successful
bool decodeImage (char *inbuf, size_t inbufSize, size_t &width, size_t &height, size_t &channels, char *&outbuf, size_t &outbufSize)
 decodes an image already in memory -- if it looks like a PNG decodePNG() will be called, otherwise decodeJPEG(); returns true if successful
Decompress From Input Stream

bool decodeJPEG (std::istream &inStream, size_t &width, size_t &height, size_t &channels, char *&outbuf, size_t &outbufSize, const std::string &filename="")
 decodes a JPEG image from a standard library input stream, returns true if successful
bool decodePNG (std::istream &inStream, size_t &width, size_t &height, size_t &channels, char *&outbuf, size_t &outbufSize)
 decodes a PNG image from a standard library input stream, returns true if successful
bool decodeImage (std::istream &inStream, size_t &width, size_t &height, size_t &channels, char *&outbuf, size_t &outbufSize)
 decodes am image from a standard library input stream -- if it looks like a PNG decodePNG() will be called, otherwise decodeJPEG(); returns true if successful
Decompress from File

bool loadJPEG (const std::string &file, size_t &width, size_t &height, size_t &channels, char *&outbuf, size_t &outbufSize)
 decodes a JPEG from disk, returns true if successful
bool loadPNG (const std::string &file, size_t &width, size_t &height, size_t &channels, char *&outbuf, size_t &outbufSize)
 decodes a PNG from disk, returns true if successful
bool loadImage (const std::string &file, size_t &width, size_t &height, size_t &channels, char *&outbuf, size_t &outbufSize)
 decodes an image from file on disk -- if it looks like a PNG decodePNG() will be called, otherwise decodeJPEG(); returns true if successful
Compression (In-Memory only)

size_t encodeJPEG (const char *inbuf, size_t inbufSize, size_t width, size_t height, size_t inbufChannels, char *&outbuf, size_t &outbufSize, size_t outbufChannels, int quality)
 encodes a JPEG from a pixel buffer into another memory buffer, returns number of bytes used, 0 if error
size_t encodeJPEG (const char *inbuf, size_t inbufSize, size_t width, size_t height, size_t inbufChannels, char *&outbuf, size_t &outbufSize, size_t outbufChannels, int quality, jpeg_compress_struct &cinfo)
 encodes a JPEG from a pixel buffer into another memory buffer, returns number of bytes used, 0 if error
size_t encodeJPEG (const char *inbuf, size_t inbufSize, size_t width, size_t height, size_t inbufChannels, char *&outbuf, size_t &outbufSize, size_t outbufChannels, int quality, unsigned int yskip, unsigned int uvskip, jpeg_compress_struct &cinfo)
 encodes a JPEG from a pixel buffer into another memory buffer, returns number of bytes used, 0 if error
size_t encodePNG (const char *inbuf, size_t inbufSize, size_t width, size_t height, size_t inbufChannels, char *&outbuf, size_t &outbufSize, size_t outbufChannels)
 encodes a PNG from a pixel buffer into another memory buffer, returns number of bytes used, 0 if error
size_t encodePNG (const char *inbuf, size_t inbufSize, size_t width, size_t height, size_t inbufChannels, char *&outbuf, size_t &outbufSize, size_t outbufChannels, int compressionLevel)
 encodes a PNG from a pixel buffer into another memory buffer, returns number of bytes used, 0 if error

Variables

const unsigned int TEST_HEADER_LEN = 8

Detailed Description

Provides a variety of straightforward calls to compress or decompress images in JPEG or PNG formats.


Function Documentation

bool image_util::decodeImage ( std::istream &  inStream,
size_t &  width,
size_t &  height,
size_t &  channels,
char *&  outbuf,
size_t &  outbufSize 
)

decodes am image from a standard library input stream -- if it looks like a PNG decodePNG() will be called, otherwise decodeJPEG(); returns true if successful

Parameters:
inStream input stream from which to read images
width the image width
height the image height
channels the number of color channels
outbuf on input, a buffer to use for decompression; if NULL, a new buffer will be allocated and assigned
outbufSize if outbuf is non-NULL, this should indicate the size of outbuf

If outbuf is pre-allocated and outbufSize is less than width*height*channels, the function will return false. The image will be written in row order, with channels interleaved.

bool image_util::decodeImage ( std::istream &  inStream,
size_t &  width,
size_t &  height,
size_t &  channels 
)

decodes an image header already in memory -- if it looks like a PNG decodePNG() will be called, otherwise decodeJPEG(); returns true if successful

Parameters:
inbuf input memory buffer containing compressed image
inbufSize the size of inbuf allocation
width the image width
height the image height
channels the number of color channels
bool image_util::decodeImage ( char *  inbuf,
size_t  inbufSize,
size_t &  width,
size_t &  height,
size_t &  channels,
char *&  outbuf,
size_t &  outbufSize 
)

decodes an image already in memory -- if it looks like a PNG decodePNG() will be called, otherwise decodeJPEG(); returns true if successful

Parameters:
inbuf input memory buffer containing compressed image
inbufSize the size of inbuf allocation
width the image width
height the image height
channels the number of color channels
outbuf on input, a buffer to use for decompression; if NULL, a new buffer will be allocated and assigned
outbufSize if outbuf is non-NULL, this should indicate the size of outbuf

If outbuf is pre-allocated and outbufSize is less than width*height*channels, the function will return false. (This is a handy way to read the image header only -- pass ((char*)NULL)-1 as outbuf and 0 for outbufSize, the function will return false after reading the header and filling in width, height, and channels) The image will be written in row order, with channels interleaved.

bool image_util::decodeImage ( char *  inbuf,
size_t  inbufSize,
size_t &  width,
size_t &  height,
size_t &  channels 
)

decodes an image header already in memory -- if it looks like a PNG decodePNG() will be called, otherwise decodeJPEG(); returns true if successful

Parameters:
inbuf input memory buffer containing compressed image
inbufSize the size of inbuf allocation
width the image width
height the image height
channels the number of color channels
bool image_util::decodeJPEG ( std::istream &  inStream,
size_t &  width,
size_t &  height,
size_t &  channels,
char *&  outbuf,
size_t &  outbufSize,
const std::string &  filename = "" 
)

decodes a JPEG image from a standard library input stream, returns true if successful

Parameters:
inStream input stream providing image
width the image width
height the image height
channels the number of color channels
outbuf on input, a buffer to use for decompression; if NULL, a new buffer will be allocated and assigned
outbufSize if outbuf is non-NULL, this should indicate the size of outbuf
filename optional parameter, used if warnings are raised

If outbuf is pre-allocated and outbufSize is less than width*height*channels, the function will return false. The image will be written in row order, with channels interleaved.

< used to interface with libjpeg - holds compression parameters and state

< used to interface with libjpeg - gives us access to error information

bool image_util::decodeJPEG ( char *  inbuf,
size_t  inbufSize,
size_t &  width,
size_t &  height,
size_t &  channels,
char *&  outbuf,
size_t &  outbufSize,
const std::string &  filename = "" 
)

decodes a JPEG image already in memory, returns true if successful

Parameters:
inbuf input memory buffer containing compressed image
inbufSize the size of inbuf allocation
width the image width
height the image height
channels the number of color channels
outbuf on input, a buffer to use for decompression; if NULL, a new buffer will be allocated and assigned
outbufSize if outbuf is non-NULL, this should indicate the size of outbuf
filename optional parameter, used if warnings are raised

If outbuf is pre-allocated and outbufSize is less than width*height*channels, the function will return false. The image will be written in row order, with channels interleaved.

< used to interface with libjpeg - holds compression parameters and state

< used to interface with libjpeg - gives us access to error information

bool image_util::decodeJPEG ( std::istream &  inStream,
size_t &  width,
size_t &  height,
size_t &  channels 
)

decodes a JPEG header already in memory, returns true if successful

Parameters:
inbuf input memory buffer containing compressed image
inbufSize the size of inbuf allocation
width the image width
height the image height
channels the number of color channels

< used to interface with libjpeg - holds compression parameters and state

< used to interface with libjpeg - gives us access to error information

bool image_util::decodeJPEG ( char *  inbuf,
size_t  inbufSize,
size_t &  width,
size_t &  height,
size_t &  channels 
)

decodes a JPEG header already in memory, returns true if successful

Parameters:
inbuf input memory buffer containing compressed image
inbufSize the size of inbuf allocation
width the image width
height the image height
channels the number of color channels

< used to interface with libjpeg - holds compression parameters and state

< used to interface with libjpeg - gives us access to error information

bool image_util::decodePNG ( std::istream &  inStream,
size_t &  width,
size_t &  height,
size_t &  channels,
char *&  outbuf,
size_t &  outbufSize 
)

decodes a PNG image from a standard library input stream, returns true if successful

Parameters:
inStream input stream from which to read images
width the image width
height the image height
channels the number of color channels
outbuf on input, a buffer to use for decompression; if NULL, a new buffer will be allocated and assigned
outbufSize if outbuf is non-NULL, this should indicate the size of outbuf

If outbuf is pre-allocated and outbufSize is less than width*height*channels, the function will return false. The image will be written in row order, with channels interleaved.

bool image_util::decodePNG ( char *  inbuf,
size_t  inbufSize,
size_t &  width,
size_t &  height,
size_t &  channels,
char *&  outbuf,
size_t &  outbufSize 
)

decodes a PNG image already in memory, returns true if successful

Parameters:
inbuf input memory buffer containing compressed image
inbufSize the size of inbuf allocation
width the image width
height the image height
channels the number of color channels
outbuf on input, a buffer to use for decompression; if NULL, a new buffer will be allocated and assigned
outbufSize if outbuf is non-NULL, this should indicate the size of outbuf

If outbuf is pre-allocated and outbufSize is less than width*height*channels, the function will return false. The image will be written in row order, with channels interleaved.

bool image_util::decodePNG ( std::istream &  inStream,
size_t &  width,
size_t &  height,
size_t &  channels 
)

decodes a PNG header already in memory, returns true if successful

Parameters:
inbuf input memory buffer containing compressed image
inbufSize the size of inbuf allocation
width the image width
height the image height
channels the number of color channels
bool image_util::decodePNG ( char *  inbuf,
size_t  inbufSize,
size_t &  width,
size_t &  height,
size_t &  channels 
)

decodes a PNG header already in memory, returns true if successful

Parameters:
inbuf input memory buffer containing compressed image
inbufSize the size of inbuf allocation
width the image width
height the image height
channels the number of color channels
bool image_util::decodePNGToDepth ( std::istream &  inStream,
size_t &  width,
size_t &  height,
size_t &  channels,
char *&  outbuf,
size_t &  outbufSize 
)
bool image_util::decodePNGToDepth ( png_structp  png_ptr,
png_infop  info_ptr,
size_t &  width,
size_t &  height,
size_t &  channels,
char *&  outbuf,
size_t &  outbufSize,
png_cleanup_f  png_cleanup = NULL 
)

Definition at line 484 of file ImageUtil.cc.

size_t image_util::encodeJPEG ( const char *  inbuf,
size_t  inbufSize,
size_t  width,
size_t  height,
size_t  inbufChannels,
char *&  outbuf,
size_t &  outbufSize,
size_t  outbufChannels,
int  quality,
unsigned int  yskip,
unsigned int  uvskip,
jpeg_compress_struct &  cinfo 
)

encodes a JPEG from a pixel buffer into another memory buffer, returns number of bytes used, 0 if error

Parameters:
inbuf input memory buffer containing the image
inbufSize the size of inbuf allocation
width the image width
height the image height
inbufChannels the number of color channels in the source image; either 1 (grayscale), 3 (YUV), or -3U (RGB)
outbuf on input, a buffer to use for decompression; if NULL, a new buffer will be allocated and assigned
outbufSize if outbuf is non-NULL, this should indicate the size of outbuf
outbufChannels the number of color channels desired in the destination image (only downsample from color to grayscale)
quality how well to reproduce the image, 0-100
yskip increment for the y channel
uvskip increment for the u and v channels
cinfo allows you to use a pre-allocated jpeg structure instead of having the function recreate it each time

If outbuf is NULL, one of size $ width \cdot height \cdot outbufChannels \cdot (quality/2+25)/100+500 $ will be allocated for you. (just a heuristic size... note that this won't all be used, and can't entirely guarantee it'll be enough!)

If inbufChannels is 3, outbufChannels can be either 3 or 1. If 1, the first channel of inbuf is used. (pre-increment inbuf to use a different channel...) If inbufChannels is 1, outbufChannels must also be 1.

size_t image_util::encodeJPEG ( const char *  inbuf,
size_t  inbufSize,
size_t  width,
size_t  height,
size_t  inbufChannels,
char *&  outbuf,
size_t &  outbufSize,
size_t  outbufChannels,
int  quality,
jpeg_compress_struct &  cinfo 
)

encodes a JPEG from a pixel buffer into another memory buffer, returns number of bytes used, 0 if error

Parameters:
inbuf input memory buffer containing the image
inbufSize the size of inbuf allocation
width the image width
height the image height
inbufChannels the number of color channels in the source image; either 1 (grayscale), 3 (YUV), or -3U (RGB)
outbuf on input, a buffer to use for decompression; if NULL, a new buffer will be allocated and assigned
outbufSize if outbuf is non-NULL, this should indicate the size of outbuf
outbufChannels the number of color channels desired in the destination image (only downsample from color to grayscale)
quality how well to reproduce the image, 0-100
cinfo allows you to use a pre-allocated jpeg structure instead of having the function recreate it each time

If outbuf is NULL, one of size $ width \cdot height \cdot outbufChannels \cdot (quality/2+25)/100+500 $ will be allocated for you. (just a heuristic size... note that this won't all be used, and can't entirely guarantee it'll be enough!)

If inbufChannels is 3, outbufChannels can be either 3 or 1. If 1, the first channel of inbuf is used. (pre-increment inbuf to use a different channel...) If inbufChannels is 1, outbufChannels must also be 1.

size_t image_util::encodeJPEG ( const char *  inbuf,
size_t  inbufSize,
size_t  width,
size_t  height,
size_t  inbufChannels,
char *&  outbuf,
size_t &  outbufSize,
size_t  outbufChannels,
int  quality 
)

encodes a JPEG from a pixel buffer into another memory buffer, returns number of bytes used, 0 if error

Parameters:
inbuf input memory buffer containing the image
inbufSize the size of inbuf allocation
width the image width
height the image height
inbufChannels the number of color channels in the source image; either 1 (grayscale), 3 (YUV), or -3U (RGB)
outbuf on input, a buffer to use for decompression; if NULL, a new buffer will be allocated and assigned
outbufSize if outbuf is non-NULL, this should indicate the size of outbuf
outbufChannels the number of color channels desired in the destination image (only downsample from color to grayscale)
quality how well to reproduce the image, 0-100

If outbuf is NULL, one of size $ width \cdot height \cdot outbufChannels \cdot (quality/2+25)/100+500 $ will be allocated for you. (just a heuristic size... note that this won't all be used, and can't entirely guarantee it'll be enough!)

If inbufChannels is 3, outbufChannels can be either 3 or 1. If 1, the first channel of inbuf is used. (pre-increment inbuf to use a different channel...) If inbufChannels is 1, outbufChannels must also be 1.

Referenced by JPEGGenerator::calcImage(), and LGmixin::uploadSketch().

size_t image_util::encodePNG ( const char *  inbuf,
size_t  inbufSize,
size_t  width,
size_t  height,
size_t  inbufChannels,
char *&  outbuf,
size_t &  outbufSize,
size_t  outbufChannels,
int  compressionLevel 
)

encodes a PNG from a pixel buffer into another memory buffer, returns number of bytes used, 0 if error

Parameters:
inbuf input memory buffer containing the image
inbufSize the size of inbuf allocation
width the image width
height the image height
inbufChannels the number of color channels in the source image; either 1 (grayscale), or 3 (color); must match outbufChannels
outbuf on input, a buffer to use for decompression; if NULL, a new buffer will be allocated and assigned
outbufSize if outbuf is non-NULL, this should indicate the size of outbuf
outbufChannels the number of color channels desired in the destination image; must match inbufChannels
compressionLevel a value 0 (none, grows slightly) through 9 (slow, but smallest) to pass to zlib for size vs. speed. Compression is always lossless, so this does not affect image quality.

If outbuf is NULL, one of size $ width \cdot height \cdot outbufChannels + 500 $ will be allocated for you. (just a heuristic size... note that this won't all be used, and can't entirely guarantee it'll be enough!)

Currently doesn't support changes in channels, so inbufChannels must match outbufChannels

size_t image_util::encodePNG ( const char *  inbuf,
size_t  inbufSize,
size_t  width,
size_t  height,
size_t  inbufChannels,
char *&  outbuf,
size_t &  outbufSize,
size_t  outbufChannels 
)

encodes a PNG from a pixel buffer into another memory buffer, returns number of bytes used, 0 if error

Parameters:
inbuf input memory buffer containing the image
inbufSize the size of inbuf allocation
width the image width
height the image height
inbufChannels the number of color channels in the source image; either 1 (grayscale), or 3 (color); must match outbufChannels
outbuf on input, a buffer to use for decompression; if NULL, a new buffer will be allocated and assigned
outbufSize if outbuf is non-NULL, this should indicate the size of outbuf
outbufChannels the number of color channels desired in the destination image; must match inbufChannels

If outbuf is NULL, one of size $ width \cdot height \cdot outbufChannels + 500 $ will be allocated for you. (just a heuristic size... note that this won't all be used, and can't entirely guarantee it'll be enough!)

Uses the default compression level, which gets most of the compression available without encurring excessive computation. According to libpng documentation, is equivalent to passing '6' as compressionLevel to the other version of the function.

Currently doesn't support changes in channels, so inbufChannels must match outbufChannels

Referenced by PNGGenerator::calcImage().

bool image_util::loadFile ( const std::string &  file,
char *&  buf,
size_t &  size 
)

loads a file into memory, returns true if successful, storing resulting buffer information in buf and size

uses mmap unless LOADFILE_NO_MMAP is defined, in which case it uses 'new' and fread()

bool image_util::loadImage ( const std::string &  file,
size_t &  width,
size_t &  height,
size_t &  channels,
char *&  outbuf,
size_t &  outbufSize 
)

decodes an image from file on disk -- if it looks like a PNG decodePNG() will be called, otherwise decodeJPEG(); returns true if successful

Parameters:
file path to file to load
width the image width
height the image height
channels the number of color channels
outbuf on input, a buffer to use for decompression; if NULL, a new buffer will be allocated and assigned
outbufSize if outbuf is non-NULL, this should indicate the size of outbuf

If outbuf is pre-allocated and outbufSize is less than width*height*channels, the function will return false. The image will be written in row order, with channels interleaved.

bool image_util::loadJPEG ( const std::string &  file,
size_t &  width,
size_t &  height,
size_t &  channels,
char *&  outbuf,
size_t &  outbufSize 
)

decodes a JPEG from disk, returns true if successful

Parameters:
file path to file to load
width the image width
height the image height
channels the number of color channels
outbuf on input, a buffer to use for decompression; if NULL, a new buffer will be allocated and assigned
outbufSize if outbuf is non-NULL, this should indicate the size of outbuf

If outbuf is pre-allocated and outbufSize is less than width*height*channels, the function will return false. The image will be written in row order, with channels interleaved.

bool image_util::loadPNG ( const std::string &  file,
size_t &  width,
size_t &  height,
size_t &  channels,
char *&  outbuf,
size_t &  outbufSize 
)

decodes a PNG from disk, returns true if successful

Parameters:
file path to file to load
width the image width
height the image height
channels the number of color channels
outbuf on input, a buffer to use for decompression; if NULL, a new buffer will be allocated and assigned
outbufSize if outbuf is non-NULL, this should indicate the size of outbuf

If outbuf is pre-allocated and outbufSize is less than width*height*channels, the function will return false. The image will be written in row order, with channels interleaved.

void image_util::releaseFile ( char *  buf,
size_t  size 
)

releases memory from a previous call to loadFile, triggering munmap() or 'delete' as appropriate


Variable Documentation

const unsigned int image_util::TEST_HEADER_LEN = 8

Definition at line 619 of file ImageUtil.cc.


Tekkotsu v5.1CVS
Generated Mon May 9 04:59:23 2016 by Doxygen 1.6.3