Simple image handling class. More...
#include <Luminous/Image.hpp>
Public Member Functions | |
| void | allocate (int width, int height, const PixelFormat &pf) |
| Allocates memory, for an image of given size and format. More... | |
| float | aspect () const |
| Get the aspect ratio (width / height) of the image. More... | |
| unsigned char * | bytes () |
| Get a pointer to image data. More... | |
| const unsigned char * | bytes () const |
| Get a pointer to image data. More... | |
| void | changed () |
| Increments the generation count. More... | |
| void | clear () |
| Clears the image, freeing the data. | |
| const Luminous::Texture & | constTexture () const |
| Get a texture object based on the image This function is thread-safe so it can be used in render functions. More... | |
| bool | copyResample (const Image &source, int w, int h) |
Resample a source image using straightforward bilinear interpolation. More... | |
| unsigned char * | data () |
| Get a pointer to image data. More... | |
| const unsigned char * | data () const |
| Get a pointer to image data. More... | |
| void | flipVertical () |
| Flip the image upside down. | |
| void | forgetLastLine () |
| Removes the last line from the image. More... | |
| void | forgetLastLines (int n) |
| Remove lines from the bottom of the image. More... | |
| bool | forgetLastPixels (int n) |
| Remove pixels from the right edge of the image. More... | |
| void | fromData (const unsigned char *bytes, int width, int height, PixelFormat format) |
| Create an image object from data provided by the user. More... | |
| size_t | generation () const |
| The generation count of the image object The generation count can be used to indicate that the image has changed, and one should update the corresponding OpenGL texture wo match the same generation. More... | |
| bool | hasAlpha () const |
| Returns true if the image has an alpha channel. More... | |
| bool | hasTexture () const |
| Check if the image associated texture has been initialized. More... | |
| int | height () const |
| Get the image height. More... | |
| Image () | |
| Construct an empty image. | |
| Image (const Image &img) | |
| Copy constructor. More... | |
| Image (Image &&img) | |
| Move constructor. More... | |
| bool | isEmpty () const |
| Returns true if the image does not contain any data. More... | |
| unsigned char * | line (unsigned y) |
| Get a pointer to image data on specific line. More... | |
| const unsigned char * | line (unsigned y) const |
| Get a pointer to image data on specific line. More... | |
| int | lineSize () const |
| The number of bytes a single line in the image takes. More... | |
| void | makeValidTexture () |
| Checks that the image dimensions are feasible for a texture. More... | |
| void | minify (const Image &src, int w, int h) |
| Scale an image to a smaller size. More... | |
| Image & | operator= (const Image &img) |
| Makes a deep copy of the given image. More... | |
| Image & | operator= (Image &&img) |
| Move operator. More... | |
| Nimble::Vector4 | pixel (int x, int y) const |
| Gets the color of a given pixel. More... | |
| unsigned char | pixelAlpha (Nimble::Vector2 relativeCoord) const |
| Returns the alpha value [0,255] for the given relative coordinates in the image. More... | |
| const PixelFormat & | pixelFormat () const |
| Returns the pixel format of the image. | |
| bool | quarterSize (const Image &source) |
| Down-sample the given image to quarter size. More... | |
| bool | read (const QString &filename) |
| Load an image from the given filename. More... | |
| Nimble::Vector4 | safePixel (int x, int y) const |
| Get a pixel from the image. More... | |
| void | setPixel (unsigned x, unsigned y, const Nimble::Vector4 &pixel) |
| Set a pixel to given color. More... | |
| bool | setPixelFormat (const PixelFormat &format) |
| Sets the new format and converts the image data to new format if necessary. More... | |
| Nimble::Size | size () const |
| Get the image size. More... | |
| Luminous::Texture & | texture () const |
| Get a texture object based on the image This function is thread-safe so it can be used in render functions. More... | |
| int | width () const |
| Get the image width. More... | |
| bool | write (const QString &filename) const |
| Save the image to a file. More... | |
| void | zero () |
| Fills the image with zeros. | |
| virtual | ~Image () |
| Destructor. | |
Static Public Member Functions | |
| static CodecRegistry * | codecs () |
| Returns a pointer to the file-format codecs. More... | |
| static bool | ping (const QString &filename, ImageInfo &info) |
| Get basic image information from a file. More... | |
Protected Attributes | |
| unsigned char * | m_data |
| Pointer to the raw image data. More... | |
| size_t | m_generation |
| Generation count of the image used to indicate changes in the image data to determine when associated textures should be updated. More... | |
| int | m_height |
| Height of the image in pixels. | |
| PixelFormat | m_pixelFormat |
| Pixel format of the image data. | |
| int | m_width |
| Width of the image in pixels. | |
Simple image handling class.
This class is used mainly to load/save image data in various formats. It provides minimal image processing support (resizing).
The image data is stored in a single, straightforward buffer.
| Luminous::Image::Image | ( | const Image & | img | ) |
Copy constructor.
| img | image to copy |
| Luminous::Image::Image | ( | Image && | img | ) |
Move constructor.
| img | image to move |
| void Luminous::Image::allocate | ( | int | width, |
| int | height, | ||
| const PixelFormat & | pf | ||
| ) |
Allocates memory, for an image of given size and format.
| width | width in pixels |
| height | height in pixels |
| pf | pixel format |
|
inline |
Get the aspect ratio (width / height) of the image.
|
inline |
Get a pointer to image data.
|
inline |
Get a pointer to image data.
|
inline |
Increments the generation count.
This function should be called when the image has been modified.
|
static |
Returns a pointer to the file-format codecs.
| const Luminous::Texture& Luminous::Image::constTexture | ( | ) | const |
Get a texture object based on the image This function is thread-safe so it can be used in render functions.
| bool Luminous::Image::copyResample | ( | const Image & | source, |
| int | w, | ||
| int | h | ||
| ) |
Resample a source image using straightforward bilinear
interpolation.
| source | image to resample |
| w | new width |
| h | new height |
|
inline |
Get a pointer to image data.
|
inline |
Get a pointer to image data.
| void Luminous::Image::forgetLastLine | ( | ) |
Removes the last line from the image.
| void Luminous::Image::forgetLastLines | ( | int | n | ) |
Remove lines from the bottom of the image.
| n | number of lines to remove |
| bool Luminous::Image::forgetLastPixels | ( | int | n | ) |
Remove pixels from the right edge of the image.
Works for RGB images.
| n | number of pixels to remove |
| void Luminous::Image::fromData | ( | const unsigned char * | bytes, |
| int | width, | ||
| int | height, | ||
| PixelFormat | format | ||
| ) |
Create an image object from data provided by the user.
| bytes | pointer to image data |
| width | width of the image data |
| height | height of the image data |
| format | pixel format of the image data |
|
inline |
The generation count of the image object The generation count can be used to indicate that the image has changed, and one should update the corresponding OpenGL texture wo match the same generation.
| bool Luminous::Image::hasAlpha | ( | ) | const |
Returns true if the image has an alpha channel.
| bool Luminous::Image::hasTexture | ( | ) | const |
|
inline |
Get the image height.
|
inline |
Returns true if the image does not contain any data.
|
inline |
Get a pointer to image data on specific line.
| y | line to query for |
|
inline |
Get a pointer to image data on specific line.
| y | line to query for |
|
inline |
The number of bytes a single line in the image takes.
| void Luminous::Image::makeValidTexture | ( | ) |
Checks that the image dimensions are feasible for a texture.
In practice this functions removes pixels from the right and bottom, to make the width and height multiples of two.
| void Luminous::Image::minify | ( | const Image & | src, |
| int | w, | ||
| int | h | ||
| ) |
Scale an image to a smaller size.
The given width and height should be smaller than in the source image.
| src | source image |
| w | new width |
| h | new height |
Makes a deep copy of the given image.
| img | image to copy |
Move operator.
| img | image to move |
|
static |
Get basic image information from a file.
This function does not decode the actual image data, typically just the header.
| filename | filename to query | |
| [out] | info | image information |
| Nimble::Vector4 Luminous::Image::pixel | ( | int | x, |
| int | y | ||
| ) | const |
Gets the color of a given pixel.
The color is normalized, with each component in range 0-1.
| x | pixel x coordinate |
| y | pixel y coordinate |
| unsigned char Luminous::Image::pixelAlpha | ( | Nimble::Vector2 | relativeCoord | ) | const |
Returns the alpha value [0,255] for the given relative coordinates in the image.
| relativeCoord | relative pixel coordinate x,y in [0,1] |
| bool Luminous::Image::quarterSize | ( | const Image & | source | ) |
Down-sample the given image to quarter size.
| source | image to resample |
| bool Luminous::Image::read | ( | const QString & | filename | ) |
Load an image from the given filename.
| filename | name of the file to read from |
| Nimble::Vector4 Luminous::Image::safePixel | ( | int | x, |
| int | y | ||
| ) | const |
Get a pixel from the image.
This function does additional checks for make sure the requested pixels are within the image. If the requested pixel falls outside the image, transparent color is returned. The color is normalized.
| x | pixel x coordinate |
| y | pixel y coordinate |
| void Luminous::Image::setPixel | ( | unsigned | x, |
| unsigned | y, | ||
| const Nimble::Vector4 & | pixel | ||
| ) |
Set a pixel to given color.
The color must be normalized.
| x | x coordinate of the pixel |
| y | y coordinate of the pixel |
| pixel | pixel color |
| bool Luminous::Image::setPixelFormat | ( | const PixelFormat & | format | ) |
Sets the new format and converts the image data to new format if necessary.
| format | new pixel format for the image |
|
inline |
Get the image size.
| Luminous::Texture& Luminous::Image::texture | ( | ) | const |
Get a texture object based on the image This function is thread-safe so it can be used in render functions.
|
inline |
Get the image width.
| bool Luminous::Image::write | ( | const QString & | filename | ) | const |
Save the image to a file.
| filename | name of the file to write to |
|
protected |
Pointer to the raw image data.
|
protected |
Generation count of the image used to indicate changes in the image data to determine when associated textures should be updated.