G3D::GImage Class ReferenceInterface to image compression & file formats.
More...
#include <GImage.h>
List of all members.
|
Public Types |
| enum | Format {
JPEG,
BMP,
TGA,
PCX,
ICO,
PNG,
PPM_ASCII,
PPM,
AUTODETECT,
UNKNOWN
} |
Public Member Functions |
| uint8 * | byte () |
| const uint8 * | byte () const |
| void | clear () |
| void | convertToL8 () |
| void | convertToRGB () |
| void | convertToRGBA () |
| void | decode (BinaryInput &input, Format format) |
| void | encode (Format format, BinaryOutput &out) const |
| void | encode (Format format, uint8 *&outData, int &outLength) const |
| | GImage (const GImage &other) |
| | GImage (int width, int height, int channels=3) |
| | GImage (const unsigned char *data, int length, Format format=AUTODETECT) |
| | GImage (const std::string &filename, Format format=AUTODETECT) |
| | GImage () |
| GImage | insertRedAsAlpha (const GImage &alpha) const |
| void | load (const std::string &filename, Format format=AUTODETECT) |
| GImage & | operator= (const GImage &other) |
| Color1uint8 & | pixel1 (int x, int y) |
| const Color1uint8 & | pixel1 (int x, int y) const |
| Color1uint8 * | pixel1 () |
| const Color1uint8 * | pixel1 () const |
| Color3uint8 * | pixel3 () |
| Color3uint8 & | pixel3 (int x, int y) |
| const Color3uint8 & | pixel3 (int x, int y) const |
| const Color3uint8 * | pixel3 () const |
| Color4uint8 * | pixel4 () |
| Color4uint8 & | pixel4 (int x, int y) |
| const Color4uint8 & | pixel4 (int x, int y) const |
| const Color4uint8 * | pixel4 () const |
| void | resize (int width, int height, int channels) |
| void | save (const std::string &filename, Format format=AUTODETECT) const |
| int | sizeInMemory () const |
| GImage | stripAlpha () const |
| virtual | ~GImage () |
Static Public Member Functions |
| static void | BAYER_B8G8_G8R8_to_R8G8B8_MHC (int w, int h, const uint8 *in, uint8 *_out) |
| static void | BAYER_G8B8_R8G8_to_Quarter_R8G8B8 (int inWidth, int inHeight, const uint8 *in, uint8 *out) |
| static void | BAYER_G8B8_R8G8_to_R8G8B8_MHC (int w, int h, const uint8 *in, uint8 *_out) |
| static void | BAYER_G8R8_B8G8_to_R8G8B8_MHC (int w, int h, const uint8 *in, uint8 *_out) |
| static void | BAYER_R8G8_G8B8_to_R8G8B8_MHC (int w, int h, const uint8 *in, uint8 *_out) |
| static void | computeNormalMap (int width, int height, int channels, const uint8 *src, GImage &normal, float whiteHeightInPixels, bool lowPassBump, bool scaleHeightByNz) |
| static void | computeNormalMap (const class GImage &bump, class GImage &normal, float whiteHeightInPixels=-1.0f, bool lowPassBump=false, bool scaleHeightByNz=false) |
| static bool | copySubImage (GImage &dest, const GImage &src, int srcX, int srcY, int srcWidth, int srcHeight) |
| static void | flipRGBAVertical (const uint8 *in, uint8 *out, int width, int height) |
| static void | flipRGBVertical (const uint8 *in, uint8 *out, int width, int height) |
| static void | makeCheckerboard (GImage &im, int checkerSize=1, const Color4uint8 &color1=Color4uint8(255, 255, 255, 255), const Color4uint8 &color2=Color4uint8(0, 0, 0, 255)) |
| static bool | pasteSubImage (GImage &dest, const GImage &src, int destX, int destY, int srcX, int srcY, int srcWidth, int srcHeight) |
| static void | Quarter_R8G8B8_to_BAYER_G8B8_R8G8 (int inWidth, int inHeight, const uint8 *in, uint8 *out) |
| static void | R8G8B8_to_Y8U8V8 (int width, int height, const uint8 *in, uint8 *out) |
| static Format | resolveFormat (const std::string &filename) |
| static void | RGBAtoRGB (const uint8 *in, uint8 *out, int numPixels) |
| static void | RGBtoARGB (const uint8 *in, uint8 *out, int numPixels) |
| static void | RGBtoBGR (const uint8 *in, uint8 *out, int numPixels) |
| static void | RGBtoBGRA (const uint8 *in, uint8 *out, int numPixels) |
| static void | RGBtoRGBA (const uint8 *in, uint8 *out, int numPixels) |
| static void | RGBxRGBtoRGBA (const uint8 *colorRGB, const uint8 *alphaRGB, uint8 *out, int numPixels) |
| static Format | stringToFormat (const std::string &format) |
| static bool | supportedFormat (const std::string &format) |
| static void | Y8U8V8_to_R8G8B8 (int width, int height, const uint8 *in, uint8 *out) |
Public Attributes |
| int | channels |
| int | height |
| int | width |
Classes |
| class | Error |
Detailed Description
Interface to image compression & file formats.
Supported formats (decode and encode): Color JPEG, PNG, (Uncompressed)TGA 24, (Uncompressed)TGA 32, BMP 1, BMP 4, BMP 8, BMP 24, PPM (P6), and PPM ASCII (P1, P2, P3). 8-bit paletted PCX, 24-bit PCX, and ICO are supported for decoding only.
Sample usage:
include "graphics3D.h"
Loading from disk:
G3D::GImage im1 = G3D::GImage("test.jpg");
Loading from memory:
G3D::GImage im2 = G3D::GImage(data, length);
im.pixel is a pointer to RGB color data. If you want
an alpha channel, call RGBtoRGBA or RGBtoARGB for
conversion.
Saving to memory:
G3D::GImage im3 = G3D::GImage(width, height);
(Set the pixels of im3...)
uint8* data2;
int len2;
im3.encode(G3D::GImage::JPEG, data2, len2);
Saving to disk
im3.save("out.jpg");
The free Image Magick Magick Wand API (http://www.imagemagick.org/www/api/magick_wand.html) provides a more powerful API for image manipulation and wider set of image load/save formats. It is recommended over GImage (we don't include it directly in G3D because their license is more restrictive than the BSD one).
Member Enumeration Documentation
- Enumerator:
-
| JPEG |
|
| BMP |
|
| TGA |
|
| PCX |
|
| ICO |
|
| PNG |
|
| PPM_ASCII |
|
| PPM |
|
| AUTODETECT |
|
| UNKNOWN |
|
Constructor & Destructor Documentation
| G3D::GImage::GImage |
( |
|
) |
[inline] |
| G3D::GImage::GImage |
( |
const std::string & |
filename, |
|
|
Format |
format = AUTODETECT | |
|
) |
| | |
Load an encoded image from disk and decode it.
Throws GImage::Error if something goes wrong.
| G3D::GImage::GImage |
( |
const unsigned char * |
data, |
|
|
int |
length, |
|
|
Format |
format = AUTODETECT | |
|
) |
| | |
Decodes an image stored in a buffer.
| G3D::GImage::GImage |
( |
int |
width, |
|
|
int |
height, |
|
|
int |
channels = 3 | |
|
) |
| | |
Create an empty image of the given size.
| G3D::GImage::GImage |
( |
const GImage & |
other |
) |
|
| virtual G3D::GImage::~GImage |
( |
|
) |
[virtual] |
Member Function Documentation
| static void G3D::GImage::BAYER_B8G8_G8R8_to_R8G8B8_MHC |
( |
int |
w, |
|
|
int |
h, |
|
|
const uint8 * |
in, |
|
|
uint8 * |
_out | |
|
) |
| | [static] |
| static void G3D::GImage::BAYER_G8B8_R8G8_to_Quarter_R8G8B8 |
( |
int |
inWidth, |
|
|
int |
inHeight, |
|
|
const uint8 * |
in, |
|
|
uint8 * |
out | |
|
) |
| | [static] |
Fast conversion; the output has 1/2 the size of the input in each direction.
Assumes in != out. See G3D::BAYER_G8B8_R8G8_to_R8G8B8_MHC for a much better result.
| static void G3D::GImage::BAYER_G8B8_R8G8_to_R8G8B8_MHC |
( |
int |
w, |
|
|
int |
h, |
|
|
const uint8 * |
in, |
|
|
uint8 * |
_out | |
|
) |
| | [static] |
Bayer demosaicing using the filter proposed in.
HIGH-QUALITY LINEAR INTERPOLATION FOR DEMOSAICING OF BAYER-PATTERNED COLOR IMAGES Henrique S. Malvar, Li-wei He, and Ross Cutler
The filter wraps at the image boundaries.
Assumes in != out.
| static void G3D::GImage::BAYER_G8R8_B8G8_to_R8G8B8_MHC |
( |
int |
w, |
|
|
int |
h, |
|
|
const uint8 * |
in, |
|
|
uint8 * |
_out | |
|
) |
| | [static] |
| static void G3D::GImage::BAYER_R8G8_G8B8_to_R8G8B8_MHC |
( |
int |
w, |
|
|
int |
h, |
|
|
const uint8 * |
in, |
|
|
uint8 * |
_out | |
|
) |
| | [static] |
| uint8* G3D::GImage::byte |
( |
|
) |
[inline] |
| const uint8* G3D::GImage::byte |
( |
|
) |
const [inline] |
| void G3D::GImage::clear |
( |
|
) |
|
Frees memory and resets to a 0x0 image.
| static void G3D::GImage::computeNormalMap |
( |
int |
width, |
|
|
int |
height, |
|
|
int |
channels, |
|
|
const uint8 * |
src, |
|
|
GImage & |
normal, |
|
|
float |
whiteHeightInPixels, |
|
|
bool |
lowPassBump, |
|
|
bool |
scaleHeightByNz | |
|
) |
| | [static] |
| static void G3D::GImage::computeNormalMap |
( |
const class GImage & |
bump, |
|
|
class GImage & |
normal, |
|
|
float |
whiteHeightInPixels = -1.0f, |
|
|
bool |
lowPassBump = false, |
|
|
bool |
scaleHeightByNz = false | |
|
) |
| | [static] |
Given a tangent space bump map, computes a new image where the RGB channels are a tangent space normal map and the alpha channel is the original bump map.
Assumes the input image is tileable.
In the resulting image, x = red = tangent, y = green = binormal, and z = blue = normal.
Particularly useful as part of the idiom:
GImage normal;
computeNormalMap(GImage(filename), normal);
return Texture::fromGImage(filename, normal);
- Parameters:
-
| lowPassBump | If true, a 9x9 filter of 1's is used to low-pass filter the elevations, which produces better results for parallax mapping. |
| scaleHeightByNz | After computing normals, scale the height by |N.z|, a trick that reduces texture swim in steep areas for parallax mapping. |
| whiteHeightInPixels | How high should the brightest input value be considered for purposes of normal computation, compared to the horizontal and vertical size of a pixel. A value of 255 means that a 255 x 255 bump image with a full black-to-white gradient will produce a 45-degree ramp (this also results in "cubic" voxels). A special (default) value of -1 means scale the effective white height so that it is equal to the larger spatial dimension. |
| void G3D::GImage::convertToL8 |
( |
|
) |
|
Averages color channels if they exist.
| void G3D::GImage::convertToRGB |
( |
|
) |
|
| void G3D::GImage::convertToRGBA |
( |
|
) |
|
| static bool G3D::GImage::copySubImage |
( |
GImage & |
dest, |
|
|
const GImage & |
src, |
|
|
int |
srcX, |
|
|
int |
srcY, |
|
|
int |
srcWidth, |
|
|
int |
srcHeight | |
|
) |
| | [static] |
creates dest from src sub-image data.
Returns true on success and false if the src sub-image is not within src.
Decodes the buffer into this image.
Must be the correct format.
| void G3D::GImage::encode |
( |
Format |
format, |
|
|
uint8 *& |
outData, |
|
|
int & |
outLength | |
|
) |
| | const |
The caller must delete the returned buffer.
| static void G3D::GImage::flipRGBAVertical |
( |
const uint8 * |
in, |
|
|
uint8 * |
out, |
|
|
int |
width, |
|
|
int |
height | |
|
) |
| | [static] |
| static void G3D::GImage::flipRGBVertical |
( |
const uint8 * |
in, |
|
|
uint8 * |
out, |
|
|
int |
width, |
|
|
int |
height | |
|
) |
| | [static] |
Flips the image along the vertical axis.
Safe for in == out.
| GImage G3D::GImage::insertRedAsAlpha |
( |
const GImage & |
alpha |
) |
const |
Returns a new GImage that has 4 channels.
RGB is taken from this GImage and the alpha from the red channel of the second image.
| void G3D::GImage::load |
( |
const std::string & |
filename, |
|
|
Format |
format = AUTODETECT | |
|
) |
| | |
Loads an image from disk (clearing the old one first).
Overwrites every pixel with one of the two colors in a checkerboard pattern.
The fields used from the two colors depend on the current number of channels in im.
| static bool G3D::GImage::pasteSubImage |
( |
GImage & |
dest, |
|
|
const GImage & |
src, |
|
|
int |
destX, |
|
|
int |
destY, |
|
|
int |
srcX, |
|
|
int |
srcY, |
|
|
int |
srcWidth, |
|
|
int |
srcHeight | |
|
) |
| | [static] |
Copies src sub-image data into dest at a certain offset.
The dest variable must already contain an image that is large enough to contain the src sub-image at the specified offset. Returns true on success and false if the src sub-image cannot completely fit within dest at the specified offset. Both src and dest must have the same number of channels.
| Color1uint8& G3D::GImage::pixel1 |
( |
int |
x, |
|
|
int |
y | |
|
) |
| | [inline] |
Returns the pixel at (x, y), where (0,0) is the upper left.
| const Color1uint8& G3D::GImage::pixel1 |
( |
int |
x, |
|
|
int |
y | |
|
) |
| | const [inline] |
Returns the pixel at (x, y), where (0,0) is the upper left.
| const Color1uint8* G3D::GImage::pixel1 |
( |
|
) |
const [inline] |
| Color3uint8& G3D::GImage::pixel3 |
( |
int |
x, |
|
|
int |
y | |
|
) |
| | [inline] |
| const Color3uint8& G3D::GImage::pixel3 |
( |
int |
x, |
|
|
int |
y | |
|
) |
| | const [inline] |
Returns the pixel at (x, y), where (0,0) is the upper left.
| const Color3uint8* G3D::GImage::pixel3 |
( |
|
) |
const [inline] |
Returns a pointer to the upper left pixel as Color3uint8.
| Color4uint8& G3D::GImage::pixel4 |
( |
int |
x, |
|
|
int |
y | |
|
) |
| | [inline] |
| const Color4uint8& G3D::GImage::pixel4 |
( |
int |
x, |
|
|
int |
y | |
|
) |
| | const [inline] |
Returns the pixel at (x, y), where (0,0) is the upper left.
| const Color4uint8* G3D::GImage::pixel4 |
( |
|
) |
const [inline] |
Returns a pointer to the upper left pixel as Color4uint8.
| static void G3D::GImage::Quarter_R8G8B8_to_BAYER_G8B8_R8G8 |
( |
int |
inWidth, |
|
|
int |
inHeight, |
|
|
const uint8 * |
in, |
|
|
uint8 * |
out | |
|
) |
| | [static] |
Attempt to undo fast conversion of G3D::BAYER_G8B8_R8G8_to_Quarter_R8G8B8; the green channel will lose data.
Assumes in != out The input should have size 3 * inWidth * inHeight. The output should have size 2 * inWidth * 2 * inHeight.
| static void G3D::GImage::R8G8B8_to_Y8U8V8 |
( |
int |
width, |
|
|
int |
height, |
|
|
const uint8 * |
in, |
|
|
uint8 * |
out | |
|
) |
| | [static] |
| void G3D::GImage::resize |
( |
int |
width, |
|
|
int |
height, |
|
|
int |
channels | |
|
) |
| | |
Resizes the internal buffer to (width x height) with the number of channels specified.
All data is set to 0 (black).
| static Format G3D::GImage::resolveFormat |
( |
const std::string & |
filename |
) |
[static] |
| static void G3D::GImage::RGBAtoRGB |
( |
const uint8 * |
in, |
|
|
uint8 * |
out, |
|
|
int |
numPixels | |
|
) |
| | [static] |
| static void G3D::GImage::RGBtoARGB |
( |
const uint8 * |
in, |
|
|
uint8 * |
out, |
|
|
int |
numPixels | |
|
) |
| | [static] |
| static void G3D::GImage::RGBtoBGR |
( |
const uint8 * |
in, |
|
|
uint8 * |
out, |
|
|
int |
numPixels | |
|
) |
| | [static] |
| static void G3D::GImage::RGBtoBGRA |
( |
const uint8 * |
in, |
|
|
uint8 * |
out, |
|
|
int |
numPixels | |
|
) |
| | [static] |
| static void G3D::GImage::RGBtoRGBA |
( |
const uint8 * |
in, |
|
|
uint8 * |
out, |
|
|
int |
numPixels | |
|
) |
| | [static] |
- Parameters:
-
| in | RGB buffer of numPixels * 3 bytes |
- Parameters:
-
| out | Buffer of numPixels * 4 bytes |
| numPixels | Number of RGB pixels to convert |
| static void G3D::GImage::RGBxRGBtoRGBA |
( |
const uint8 * |
colorRGB, |
|
|
const uint8 * |
alphaRGB, |
|
|
uint8 * |
out, |
|
|
int |
numPixels | |
|
) |
| | [static] |
Uses the red channel of the second image as an alpha channel.
| void G3D::GImage::save |
( |
const std::string & |
filename, |
|
|
Format |
format = AUTODETECT | |
|
) |
| | const |
| int G3D::GImage::sizeInMemory |
( |
|
) |
const |
Returns the size of this object in bytes.
| static Format G3D::GImage::stringToFormat |
( |
const std::string & |
format |
) |
[static] |
Converts a string to an enum, returns UNKNOWN if not recognized.
| GImage G3D::GImage::stripAlpha |
( |
|
) |
const |
Returns a new GImage with 3 channels, removing the alpha channel if there is one.
| static bool G3D::GImage::supportedFormat |
( |
const std::string & |
format |
) |
[static] |
Returns true if format is supported.
Format should be an extension string (e.g. "BMP").
| static void G3D::GImage::Y8U8V8_to_R8G8B8 |
( |
int |
width, |
|
|
int |
height, |
|
|
const uint8 * |
in, |
|
|
uint8 * |
out | |
|
) |
| | [static] |
Member Data Documentation
The number of channels; either 3 (RGB) or 4 (RGBA).
The documentation for this class was generated from the following file:
Generated on Thu Aug 2 11:40:45 2007 for G3D by
1.5.2
Hosted by
|