Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

image_util Namespace Reference


Detailed Description

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


Functions

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
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
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 (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 (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 (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 (char *inbuf, size_t inbufSize, size_t width, size_t height, size_t inbufChannels, char *&outbuf, size_t &outbufSize, size_t outbufChannels)
 encodes a JPEG from a pixel buffer into another memory buffer, returns number of bytes used, 0 if error


Function Documentation

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.

Definition at line 429 of file ImageUtil.cc.

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

Definition at line 422 of file ImageUtil.cc.

Referenced by loadImage().

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.

Definition at line 213 of file ImageUtil.cc.

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.

Definition at line 191 of file ImageUtil.cc.

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

Definition at line 162 of file ImageUtil.cc.

Referenced by decodeImage(), decodeJPEG(), and loadJPEG().

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.

Definition at line 402 of file ImageUtil.cc.

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.

Definition at line 380 of file ImageUtil.cc.

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

Definition at line 351 of file ImageUtil.cc.

Referenced by decodeImage(), decodePNG(), and loadPNG().

size_t image_util::encodeJPEG ( 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), or 3 (color)
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.

Definition at line 483 of file ImageUtil.cc.

size_t image_util::encodeJPEG ( 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), or 3 (color)
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.

Definition at line 480 of file ImageUtil.cc.

size_t image_util::encodeJPEG ( 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), or 3 (color)
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.

Definition at line 469 of file ImageUtil.cc.

Referenced by JPEGGenerator::calcImage(), and encodeJPEG().

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

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), 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!)

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

Definition at line 581 of file ImageUtil.cc.

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()

Definition at line 27 of file ImageUtil.cc.

Referenced by loadImage(), loadJPEG(), and loadPNG().

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.

Definition at line 457 of file ImageUtil.cc.

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.

Definition at line 439 of file ImageUtil.cc.

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.

Definition at line 448 of file ImageUtil.cc.

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

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

Definition at line 79 of file ImageUtil.cc.

Referenced by loadImage(), loadJPEG(), and loadPNG().


Tekkotsu v4.0
Generated Thu Nov 22 00:58:51 2007 by Doxygen 1.5.4