| Support Forum Library Source SourceForge Page G3D Web Page |
Interface to image compression & file formats. More...
Classes | |
| class | Error |
Public Types | |
| enum | Format { JPEG, BMP, TGA, PCX, ICO, PNG, PNG8 = PNG, PNG16, PPM_BINARY, PGM_BINARY = PPM_BINARY, PPM_ASCII, PGM_ASCII = PPM_ASCII, AUTODETECT, UNKNOWN } |
PGM, PPM, and PBM all come in two versions and are classified as PPM_* files. More... | |
Public Member Functions | |
| G3D_DEPRECATED | GImage (int width, int height, int channels, const MemoryManager::Ref &m=MemoryManager::create()) |
| Create an empty image of the given size. | |
| GImage (int width=0, int height=0, const ImageFormat *imageFormat=ImageFormat::RGB8(), const MemoryManager::Ref &m=MemoryManager::create()) | |
| Create an empty image of the given size. | |
| GImage (const std::string &filename, Format format=AUTODETECT, const MemoryManager::Ref &m=MemoryManager::create()) | |
| Load an encoded image from disk and decode it. | |
| GImage (const unsigned char *data, int length, Format format=AUTODETECT, const MemoryManager::Ref &m=MemoryManager::create()) | |
| Decodes an image file format stored in a buffer. | |
| GImage (const GImage &other, const MemoryManager::Ref &m=MemoryManager::create()) | |
| virtual | ~GImage () |
| Deallocates the pixels. | |
| ImageBuffer::Ref | buffer () const |
| const uint8 * | byte () const |
| Pointer to the underlying data. | |
| uint8 * | byte () |
| int | channels () const |
| The number of channels; either 1 (luminance), 3 (RGB), or 4 (RGBA) | |
| void | clear () |
| Frees memory and resets to a 0x0 image. | |
| void | convertToL8 () |
| Averages color channels if they exist. | |
| void | convertToRGB () |
| void | convertToRGBA () |
| void | decode (BinaryInput &input, Format format) |
| Decodes the buffer into this image. | |
| void | encode (Format format, unorm8 *&outData, int &outLength) const |
| The caller must delete the returned buffer. | |
| void | encode (Format format, BinaryOutput &out) const |
| Does not commit the BinaryOutput when done. | |
| void | flipHorizontal () |
| void | flipVertical () |
| int | height () const |
| const ImageFormat * | imageFormat () const |
| Format of the data in memory. | |
| void | insertRedAsAlpha (const GImage &alpha, GImage &output) const |
| Returns a new GImage that has 4 channels. | |
| void | load (const std::string &filename, Format format=AUTODETECT) |
| Loads an image from disk (clearing the old one first), using the existing memory manager. | |
| GImage & | operator= (const GImage &other) |
| Color1unorm8 & | pixel1 (int x, int y) |
| Returns the pixel at (x, y), where (0,0) is the upper left. | |
| const Color1unorm8 & | pixel1 (int x, int y) const |
| Returns the pixel at (x, y), where (0,0) is the upper left. | |
| const Color1unorm8 * | pixel1 () const |
| Color1unorm8 * | pixel1 () |
| const Color3unorm8 * | pixel3 () const |
| Returns a pointer to the upper left pixel as Color3unorm8. | |
| const Color3unorm8 & | pixel3 (int x, int y) const |
| Returns the pixel at (x, y), where (0,0) is the upper left. | |
| Color3unorm8 & | pixel3 (int x, int y) |
| Color3unorm8 * | pixel3 () |
| Color4unorm8 * | pixel4 () |
| const Color4unorm8 & | pixel4 (int x, int y) const |
| Returns the pixel at (x, y), where (0,0) is the upper left. | |
| Color4unorm8 & | pixel4 (int x, int y) |
| const Color4unorm8 * | pixel4 () const |
| Returns a pointer to the upper left pixel as Color4unorm8. | |
| template<typename Type > | |
| const Type * | rawData () const |
| Returns a pointer to the underlying data, which is stored in row-major order without row padding. | |
| template<typename Type > | |
| Type * | rawData () |
Returns a pointer to the underlying data, which is stored in row-major order without row padding. | |
| void G3D_DEPRECATED | resize (int width, int height, int channels, bool zero=false) |
| Resizes the internal buffer to (width x height) with the number of channels specified. | |
| void | resize (int width, int height, const ImageFormat *imageFormat, bool zero=false) |
| Resizes the internal buffer to (width x height) with the number of channels specified. | |
| void | rotate90CW (int numTimes=1) |
| void | save (const std::string &filename, Format format=AUTODETECT) const |
| Encode and save to disk. | |
| int | sizeInMemory () const |
| Returns the size of this object in bytes. | |
| void | stripAlpha (GImage &output) const |
| Returns a new GImage with 3 channels, removing the alpha channel if there is one. | |
| int | width () const |
Static Public Member Functions | |
| static void | BAYER_B8G8_G8R8_to_R8G8B8_MHC (int w, int h, const unorm8 *in, unorm8 *_out) |
| static void | BAYER_G8B8_R8G8_to_Quarter_R8G8B8 (int inWidth, int inHeight, const unorm8 *in, unorm8 *out) |
| Fast conversion; the output has 1/2 the size of the input in each direction. | |
| static void | BAYER_G8B8_R8G8_to_R8G8B8_MHC (int w, int h, const unorm8 *in, unorm8 *_out) |
| Bayer demosaicing using the filter proposed in. | |
| static void | BAYER_G8R8_B8G8_to_R8G8B8_MHC (int w, int h, const unorm8 *in, unorm8 *_out) |
| static void | BAYER_R8G8_G8B8_to_R8G8B8_MHC (int w, int h, const unorm8 *in, unorm8 *_out) |
| static void | computeNormalMap (const class GImage &bump, class GImage &normal, const BumpMapPreprocess &preprocess=BumpMapPreprocess()) |
| 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. | |
| static void | computeNormalMap (int width, int height, int channels, const unorm8 *src, GImage &normal, const BumpMapPreprocess &preprocess=BumpMapPreprocess()) |
| static bool | copyRect (GImage &dest, const GImage &src, int destX, int destY, int srcX, int srcY, int srcWidth, int srcHeight) |
| Copies src sub-image data into dest at a certain offset. | |
| static bool | copyRect (GImage &dest, const GImage &src, int srcX, int srcY, int srcWidth, int srcHeight) |
| creates dest from src sub-image data. | |
| static void | decodePNG16 (BinaryInput &in, int &width, int &height, int &channels, uint16 *&byte, MemoryManager::Ref mman=MemoryManager::create()) |
| Decodes 16-bit per channel PNG. | |
| static void | encodePNG16 (BinaryOutput &out, int width, int height, int channels, const uint16 *data) |
| Encodes images as a 16-bit per channel PNG. | |
| static void | flipRGBAVertical (const unorm8 *in, unorm8 *out, int width, int height) |
| static void | flipRGBVertical (const unorm8 *in, unorm8 *out, int width, int height) |
| Flips the image along the vertical axis. | |
| static void | LtoRGB (const unorm8 *in, unorm8 *out, int numPixels) |
| static void | LtoRGBA (const unorm8 *in, unorm8 *out, int numPixels) |
| static void | makeCheckerboard (GImage &im, int checkerSize=1, const Color4unorm8 &color1=Color4unorm8(unorm8::one(), unorm8::one(), unorm8::one(), unorm8::one()), const Color4unorm8 &color2=Color4unorm8(unorm8::zero(), unorm8::zero(), unorm8::zero(), unorm8::one())) |
| Overwrites every pixel with one of the two colors in a checkerboard pattern. | |
| static void | Quarter_R8G8B8_to_BAYER_G8B8_R8G8 (int inWidth, int inHeight, const unorm8 *in, unorm8 *out) |
| Attempt to undo fast conversion of G3D::BAYER_G8B8_R8G8_to_Quarter_R8G8B8; the green channel will lose data. | |
| static void | R8G8B8_to_Y8U8V8 (int width, int height, const unorm8 *in, unorm8 *out) |
| Ok for in == out. | |
| static Format | resolveFormat (const std::string &filename) |
| Predicts the image file format of filename. | |
| static void | RGBAtoBGRA (const unorm8 *in, unorm8 *out, int numPixels) |
| Win32 32-bit HDC format. | |
| static void | RGBAtoRGB (const unorm8 *in, unorm8 *out, int numPixels) |
| static void | RGBtoARGB (const unorm8 *in, unorm8 *out, int numPixels) |
| static void | RGBtoBGR (const unorm8 *in, unorm8 *out, int numPixels) |
| Safe for in == out. | |
| static void | RGBtoBGRA (const unorm8 *in, unorm8 *out, int numPixels) |
| Win32 32-bit HDC format. | |
| static void | RGBtoRGBA (const unorm8 *in, unorm8 *out, int numPixels) |
| static void | RGBxRGBtoRGBA (const unorm8 *colorRGB, const unorm8 *alphaRGB, unorm8 *out, int numPixels) |
| Uses the red channel of the second image as an alpha channel. | |
| static Format | stringToFormat (const std::string &format) |
| Converts a string to an enum, returns UNKNOWN if not recognized. | |
| static bool | supportedFormat (const std::string &format) |
| Returns true if format is supported. | |
| static void | Y8U8V8_to_R8G8B8 (int width, int height, const unorm8 *in, unorm8 *out) |
| Ok for in == out. | |
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), which includes PPM, PGM, and PBM. (Compressed) TGA 24, (Compressed) TGA 32, 8-bit paletted PCX, 24-bit PCX, and ICO are supported for decoding only.
Sample usage:
// Loading from disk: G3D::GImage im1("test.jpg"); // Loading from memory: G3D::GImage im2(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(width, height); // (Set the pixels of im3...) unorm8* 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).
| enum G3D::GImage::Format |
| G3D_DEPRECATED G3D::GImage::GImage | ( | int | width, |
| int | height, | ||
| int | channels, | ||
| const MemoryManager::Ref & | m = MemoryManager::create() |
||
| ) |
Create an empty image of the given size.
| G3D::GImage::GImage | ( | int | width = 0, |
| int | height = 0, |
||
| const ImageFormat * | imageFormat = ImageFormat::RGB8(), |
||
| const MemoryManager::Ref & | m = MemoryManager::create() |
||
| ) |
Create an empty image of the given size.
| G3D::GImage::GImage | ( | const std::string & | filename, |
| Format | format = AUTODETECT, |
||
| const MemoryManager::Ref & | m = MemoryManager::create() |
||
| ) |
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, |
||
| const MemoryManager::Ref & | m = MemoryManager::create() |
||
| ) |
Decodes an image file format stored in a buffer.
| G3D::GImage::GImage | ( | const GImage & | other, |
| const MemoryManager::Ref & | m = MemoryManager::create() |
||
| ) |
| virtual G3D::GImage::~GImage | ( | ) | [virtual] |
Deallocates the pixels.
| static void G3D::GImage::BAYER_B8G8_G8R8_to_R8G8B8_MHC | ( | int | w, |
| int | h, | ||
| const unorm8 * | in, | ||
| unorm8 * | _out | ||
| ) | [static] |
| static void G3D::GImage::BAYER_G8B8_R8G8_to_Quarter_R8G8B8 | ( | int | inWidth, |
| int | inHeight, | ||
| const unorm8 * | in, | ||
| unorm8 * | 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 unorm8 * | in, | ||
| unorm8 * | _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 unorm8 * | in, | ||
| unorm8 * | _out | ||
| ) | [static] |
| static void G3D::GImage::BAYER_R8G8_G8B8_to_R8G8B8_MHC | ( | int | w, |
| int | h, | ||
| const unorm8 * | in, | ||
| unorm8 * | _out | ||
| ) | [static] |
| ImageBuffer::Ref G3D::GImage::buffer | ( | ) | const [inline] |
| const uint8* G3D::GImage::byte | ( | ) | const [inline] |
| uint8* G3D::GImage::byte | ( | ) | [inline] |
| int G3D::GImage::channels | ( | ) | const [inline] |
The number of channels; either 1 (luminance), 3 (RGB), or 4 (RGBA)
| void G3D::GImage::clear | ( | ) |
Frees memory and resets to a 0x0 image.
| static void G3D::GImage::computeNormalMap | ( | int | width, |
| int | height, | ||
| int | channels, | ||
| const unorm8 * | src, | ||
| GImage & | normal, | ||
| const BumpMapPreprocess & | preprocess = BumpMapPreprocess() |
||
| ) | [static] |
| static void G3D::GImage::computeNormalMap | ( | const class GImage & | bump, |
| class GImage & | normal, | ||
| const BumpMapPreprocess & | preprocess = BumpMapPreprocess() |
||
| ) | [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);
| void G3D::GImage::convertToL8 | ( | ) |
Averages color channels if they exist.
| void G3D::GImage::convertToRGB | ( | ) |
| void G3D::GImage::convertToRGBA | ( | ) |
| static bool G3D::GImage::copyRect | ( | 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 imageFormat().
| static bool G3D::GImage::copyRect | ( | 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.
| void G3D::GImage::decode | ( | BinaryInput & | input, |
| Format | format | ||
| ) |
Decodes the buffer into this image.
This will not allocate new memory for the GImage provided it is already in the correct width and height and format (known bugs: only PNG RGBA8, PNG RGB8, and PNG R8 with a height that is a multiple of 8 currently implement this behavior.)
| format | Must be the correct format. |
| static void G3D::GImage::decodePNG16 | ( | BinaryInput & | in, |
| int & | width, | ||
| int & | height, | ||
| int & | channels, | ||
| uint16 *& | byte, | ||
| MemoryManager::Ref | mman = MemoryManager::create() |
||
| ) | [static] |
Decodes 16-bit per channel PNG.
The caller must delete the returned buffer.
TODO: provide a memory manager
| void G3D::GImage::encode | ( | Format | format, |
| BinaryOutput & | out | ||
| ) | const |
Does not commit the BinaryOutput when done.
| static void G3D::GImage::encodePNG16 | ( | BinaryOutput & | out, |
| int | width, | ||
| int | height, | ||
| int | channels, | ||
| const uint16 * | data | ||
| ) | [static] |
Encodes images as a 16-bit per channel PNG.
Channels must be 1, 3, or 4.
| void G3D::GImage::flipHorizontal | ( | ) |
| static void G3D::GImage::flipRGBAVertical | ( | const unorm8 * | in, |
| unorm8 * | out, | ||
| int | width, | ||
| int | height | ||
| ) | [static] |
| static void G3D::GImage::flipRGBVertical | ( | const unorm8 * | in, |
| unorm8 * | out, | ||
| int | width, | ||
| int | height | ||
| ) | [static] |
Flips the image along the vertical axis.
Safe for in == out.
| void G3D::GImage::flipVertical | ( | ) |
| const ImageFormat* G3D::GImage::imageFormat | ( | ) | const [inline] |
Format of the data in memory.
Not all ImageFormats are supported by all methods.
| void G3D::GImage::load | ( | const std::string & | filename, |
| Format | format = AUTODETECT |
||
| ) |
Loads an image from disk (clearing the old one first), using the existing memory manager.
| static void G3D::GImage::makeCheckerboard | ( | GImage & | im, |
| int | checkerSize = 1, |
||
| const Color4unorm8 & | color1 = Color4unorm8(unorm8::one(), unorm8::one(), unorm8::one(), unorm8::one()), |
||
| const Color4unorm8 & | color2 = Color4unorm8(unorm8::zero(), unorm8::zero(), unorm8::zero(), unorm8::one()) |
||
| ) | [static] |
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.
| Color1unorm8& G3D::GImage::pixel1 | ( | int | x, |
| int | y | ||
| ) | [inline] |
Returns the pixel at (x, y), where (0,0) is the upper left.
| const Color1unorm8& G3D::GImage::pixel1 | ( | int | x, |
| int | y | ||
| ) | const [inline] |
Returns the pixel at (x, y), where (0,0) is the upper left.
| const Color1unorm8* G3D::GImage::pixel1 | ( | ) | const [inline] |
Referenced by pixel1().
| Color1unorm8* G3D::GImage::pixel1 | ( | ) | [inline] |
| const Color3unorm8& G3D::GImage::pixel3 | ( | int | x, |
| int | y | ||
| ) | const [inline] |
Returns the pixel at (x, y), where (0,0) is the upper left.
| Color3unorm8& G3D::GImage::pixel3 | ( | int | x, |
| int | y | ||
| ) | [inline] |
| const Color3unorm8* G3D::GImage::pixel3 | ( | ) | const [inline] |
Returns a pointer to the upper left pixel as Color3unorm8.
Referenced by pixel3().
| Color3unorm8* G3D::GImage::pixel3 | ( | ) | [inline] |
| const Color4unorm8& G3D::GImage::pixel4 | ( | int | x, |
| int | y | ||
| ) | const [inline] |
Returns the pixel at (x, y), where (0,0) is the upper left.
| Color4unorm8* G3D::GImage::pixel4 | ( | ) | [inline] |
| Color4unorm8& G3D::GImage::pixel4 | ( | int | x, |
| int | y | ||
| ) | [inline] |
| const Color4unorm8* G3D::GImage::pixel4 | ( | ) | const [inline] |
Returns a pointer to the upper left pixel as Color4unorm8.
The imageFormat() must be representable by four 8-bit channels.
Referenced by pixel4().
| static void G3D::GImage::Quarter_R8G8B8_to_BAYER_G8B8_R8G8 | ( | int | inWidth, |
| int | inHeight, | ||
| const unorm8 * | in, | ||
| unorm8 * | 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 unorm8 * | in, | ||
| unorm8 * | out | ||
| ) | [static] |
Ok for in == out.
| const Type* G3D::GImage::rawData | ( | ) | const [inline] |
Returns a pointer to the underlying data, which is stored in row-major order without row padding.
e.g.,
float* ptr = image.rawData<float>();
| Type* G3D::GImage::rawData | ( | ) | [inline] |
Returns a pointer to the underlying data, which is stored in row-major order without row padding.
| void G3D::GImage::resize | ( | int | width, |
| int | height, | ||
| const ImageFormat * | imageFormat, | ||
| bool | zero = false |
||
| ) |
Resizes the internal buffer to (width x height) with the number of channels specified.
| zero | If true, all data is set to 0 (black). If false, the values are unspecified. |
Guaranteed not to allocate new memory if zero == false and the current image matches these specifications.
| void G3D_DEPRECATED G3D::GImage::resize | ( | int | width, |
| int | height, | ||
| int | channels, | ||
| bool | zero = false |
||
| ) |
Resizes the internal buffer to (width x height) with the number of channels specified.
| zero | If true, all data is set to 0 (black). |
| static Format G3D::GImage::resolveFormat | ( | const std::string & | filename ) | [static] |
Predicts the image file format of filename.
Win32 32-bit HDC format.
Safe for in == out.
Win32 32-bit HDC format.
| in | RGB buffer of numPixels * 3 bytes |
| out | Buffer of numPixels * 4 bytes |
| numPixels | Number of RGB pixels to convert |
| static void G3D::GImage::RGBxRGBtoRGBA | ( | const unorm8 * | colorRGB, |
| const unorm8 * | alphaRGB, | ||
| unorm8 * | out, | ||
| int | numPixels | ||
| ) | [static] |
Uses the red channel of the second image as an alpha channel.
| void G3D::GImage::rotate90CW | ( | int | numTimes = 1 ) |
| void G3D::GImage::save | ( | const std::string & | filename, |
| Format | format = AUTODETECT |
||
| ) | const |
Encode and save to disk.
| 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.
| void G3D::GImage::stripAlpha | ( | GImage & | output ) | const |
| 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").
1.7.2