![]() |
Gorgon Game Engine
|
This class is a container for image data. More...
Public Member Functions | |
basic_Image () | |
Constructs an empty image data. More... | |
basic_Image (basic_Image &&data) | |
Move constructor. More... | |
basic_Image (const basic_Image &)=delete | |
Copy constructor is disabled. More... | |
basic_Image (const Geometry::Size &size, Graphics::ColorMode mode) | |
Constructs a new image data with the given width, height and color mode. More... | |
~basic_Image () | |
Destructor. More... | |
void | Assign (Byte *newdata) |
Assigns the image to the copy of the given data. More... | |
void | Assign (Byte *newdata, const Geometry::Size &size, Graphics::ColorMode mode) |
Assigns the image to the copy of the given data. More... | |
void | Assume (Byte *newdata) |
Assumes the ownership of the given data. More... | |
void | Assume (Byte *newdata, const Geometry::Size &size, Graphics::ColorMode mode) |
Assumes the ownership of the given data. More... | |
void | ChangeMode (Graphics::ColorMode value) |
Changes the color mode of the image. More... | |
void | Clear () |
Cleans the contents of the buffer by setting every byte it contains to 0. More... | |
void | ConvertToRGBA () |
Converts this image data to RGBA buffer. More... | |
bool | CopyTo (basic_Image &dest, Geometry::Bounds source, Geometry::Point target={0, 0}) const |
Copies data from one image to another. More... | |
bool | CopyTo (basic_Image &dest, Geometry::Point target={0, 0}) const |
Copies data from one image to another. More... | |
void | CopyToBGRABuffer (Byte *buffer) const |
Copies this image to a RGBA buffer, buffer should be resize before calling this function. More... | |
void | CopyToBGRABufferLong (unsigned long *buffer) const |
Copies this image to a RGBA buffer, buffer should be resize before calling this function. More... | |
void | CopyToRGBABuffer (Byte *buffer) const |
Copies this image to a RGBA buffer, buffer should be resize before calling this function. More... | |
void | Destroy () |
Destroys this image by setting width and height to 0 and freeing the memory used by its data. More... | |
basic_Image | Duplicate () const |
Duplicates this image, essentially performing the work of copy constructor. More... | |
bool | ExportBMP (const std::string &filename, bool usev4=false, bool dib=false) |
Exports the image as a bitmap. More... | |
bool | ExportBMP (std::ostream &file, bool usev4=false, bool dib=false) |
Exports the image as a bitmap. More... | |
Byte | Get (const Geometry::Point &p, Byte def, unsigned component=0) const |
Provides access to the given component in x and y coordinates. More... | |
Byte | Get (const Geometry::Point &p, unsigned component=0) const |
Provides access to the given component in x and y coordinates. More... | |
Byte | Get (int x, int y, unsigned component=0) const |
Provides access to the given component in x and y coordinates. More... | |
Byte | GetAlphaAt (int x, int y) const |
Returns the alpha at the given location. More... | |
int | GetAlphaIndex () const |
Returns the index of alpha channel. Value of -1 denotes no alpha channel. More... | |
unsigned | GetChannelsPerPixel () const |
Returns the number units occupied by a single pixel of this image. More... | |
int | GetHeight () const |
Returns the height of the image. More... | |
Graphics::ColorMode | GetMode () const |
Returns the color mode of the image. More... | |
Graphics::RGBA | GetRGBAAt (Geometry::Point p) const |
Returns the alpha at the given location. More... | |
Graphics::RGBA | GetRGBAAt (int x, int y) const |
Returns the alpha at the given location. More... | |
Geometry::Size | GetSize () const |
Returns the size of the image. More... | |
unsigned long | GetTotalSize () const |
Total size of this image in number units. More... | |
int | GetWidth () const |
Returns the width of the image. More... | |
bool | HasAlpha () const |
Returns if this image has alpha channel. More... | |
bool | ImportBMP (const std::string &filename, bool dib=false) |
Imports a given bitmap file. BMP RLE compression and colorspaces are not supported. More... | |
bool | ImportBMP (std::istream &file, bool dib=false) |
Imports a given bitmap file. BMP RLE compression and colorspaces are not supported. More... | |
Byte & | operator() (const Geometry::Point &p, unsigned component=0) |
Provides access to the given component in x and y coordinates. More... | |
Byte | operator() (const Geometry::Point &p, unsigned component=0) const |
Provides access to the given component in x and y coordinates. More... | |
Byte & | operator() (int x, int y, unsigned component=0) |
Provides access to the given component in x and y coordinates. More... | |
Byte | operator() (int x, int y, unsigned component=0) const |
Provides access to the given component in x and y coordinates. More... | |
basic_Image & | operator= (basic_Image &&other) |
Move assignment. More... | |
basic_Image & | operator= (const basic_Image &)=delete |
Copy assignment is disabled. More... | |
Byte * | RawData () |
Returns the raw data pointer. More... | |
const Byte * | RawData () const |
Returns the raw data pointer. More... | |
Byte * | Release () |
Returns and disowns the current data buffer. If image is empty, this method will return a nullptr. More... | |
void | Resize (const Geometry::Size &size, Graphics::ColorMode mode) |
Resizes the image to the given size and color mode. More... | |
void | SetRGBAAt (Geometry::Point p, Graphics::RGBA color) |
Sets the color at the given location to the specified RGBA value. More... | |
void | SetRGBAAt (int x, int y, Graphics::RGBA color) |
Sets the color at the given location to the specified RGBA value. More... | |
void | Swap (basic_Image &other) |
Swaps this image with another. This function is used to implement move semantics. More... | |
Protected Attributes | |
int | alphaloc |
Location of the alpha channel, -1 means it does not exits. More... | |
unsigned | cpp |
Channels per pixel information. More... | |
T_ * | data |
Data that stores pixels of the image. More... | |
Graphics::ColorMode | mode |
Color mode of the image. More... | |
Geometry::Size | size |
Width of the image. More... | |
This class is a container for image data.
It supports different color modes and access to the underlying data through () operator. This object implements move semantics. Since copy constructor is expensive, it is deleted against accidental use. If a copy of the object is required, use Duplicate function.
basic_Image | ( | ) |
Constructs an empty image data.
basic_Image | ( | const Geometry::Size & | size, |
Graphics::ColorMode | mode | ||
) |
Constructs a new image data with the given width, height and color mode.
This constructor does not initialize data inside the image
References basic_Image< T_ >::alphaloc, basic_Size< T_ >::Area(), basic_Image< T_ >::cpp, basic_Image< T_ >::data, Gorgon::Graphics::GetAlphaIndex(), Gorgon::Graphics::GetChannelsPerPixel(), Gorgon::Graphics::HasAlpha(), basic_Image< T_ >::mode, and basic_Image< T_ >::size.
|
delete |
Copy constructor is disabled.
basic_Image | ( | basic_Image< T_ > && | data | ) |
Move constructor.
References basic_Image< T_ >::data, and basic_Image< T_ >::Swap().
~basic_Image | ( | ) |
Destructor.
References basic_Image< T_ >::Destroy().
void Assign | ( | Byte * | newdata | ) |
Assigns the image to the copy of the given data.
Ownership of the given data is not transferred. If the given data is not required elsewhere, consider using Assume function. The size and color mode of the image stays the same. The given data should have the size of width*height*Graphics::GetBytesPerPixel(mode)*sizeof(T_). This function does not perform any checks for the data size while copying it.t
References basic_Size< T_ >::Area(), basic_Image< T_ >::cpp, basic_Image< T_ >::data, and basic_Image< T_ >::size.
void Assign | ( | Byte * | newdata, |
const Geometry::Size & | size, | ||
Graphics::ColorMode | mode | ||
) |
Assigns the image to the copy of the given data.
Ownership of the given data is not transferred. If the given data is not required elsewhere, consider using Assume function. This variant performs resize and copy at the same time. The given data should have the size of width*height*Graphics::GetBytesPerPixel(mode)*sizeof(T_). This function does not perform any checks for the data size while copying it. If width or height is 0, the newdata is not accessed and this method effectively Destroys the current image. In this case, both width and height should be specified as 0.
References basic_Image< T_ >::alphaloc, basic_Size< T_ >::Area(), basic_Image< T_ >::cpp, basic_Image< T_ >::data, Gorgon::Graphics::GetAlphaIndex(), Gorgon::Graphics::GetChannelsPerPixel(), Gorgon::Graphics::HasAlpha(), basic_Size< T_ >::IsValid(), basic_Image< T_ >::mode, and basic_Image< T_ >::size.
void Assume | ( | Byte * | newdata | ) |
Assumes the ownership of the given data.
The size and color mode of the image stays the same. The given data should have the size of width*height*Graphics::GetBytesPerPixel(mode)*sizeof(T_). This function does not perform any checks for the data size while assuming it.
References basic_Image< T_ >::data.
void Assume | ( | Byte * | newdata, |
const Geometry::Size & | size, | ||
Graphics::ColorMode | mode | ||
) |
Assumes the ownership of the given data.
This variant changes the size and color mode of the image. The given data should have the size of width*height*Graphics::GetBytesPerPixel(mode)*sizeof(T_). This function does not perform any checks for the data size while assuming it. newdata could be nullptr however, in this case width, height should be 0. mode is not assumed to be ColorMode::Invalid while the image is empty, therefore it could be specified as any value.
References basic_Image< T_ >::alphaloc, basic_Image< T_ >::cpp, basic_Image< T_ >::data, Gorgon::Graphics::GetAlphaIndex(), Gorgon::Graphics::GetChannelsPerPixel(), Gorgon::Graphics::HasAlpha(), basic_Size< T_ >::IsValid(), basic_Image< T_ >::mode, and basic_Image< T_ >::size.
void ChangeMode | ( | Graphics::ColorMode | value | ) |
Changes the color mode of the image.
Only works if the bits/pixel of the target mode is the same as the original
References basic_Image< T_ >::alphaloc, Gorgon::Graphics::GetAlphaIndex(), Gorgon::Graphics::GetChannelsPerPixel(), Gorgon::Graphics::HasAlpha(), and basic_Image< T_ >::mode.
void Clear | ( | ) |
Cleans the contents of the buffer by setting every byte it contains to 0.
References basic_Size< T_ >::Area(), basic_Image< T_ >::cpp, basic_Image< T_ >::data, and basic_Image< T_ >::size.
void ConvertToRGBA | ( | ) |
Converts this image data to RGBA buffer.
References Gorgon::Graphics::Alpha, basic_Size< T_ >::Area(), basic_Image< T_ >::data, Gorgon::Graphics::Grayscale, Gorgon::Graphics::Invalid, basic_Image< T_ >::mode, Gorgon::Graphics::RGB, Gorgon::Graphics::RGBA, basic_Image< T_ >::size, and Gorgon::Containers::swap().
bool CopyTo | ( | basic_Image< T_ > & | dest, |
Geometry::Bounds | source, | ||
Geometry::Point | target = {0, 0} |
||
) | const |
Copies data from one image to another.
This operation does not perform blending. Additionally, color modes should be the same. However, this function will do clipping. Source bounds should be within the image. Will return false if nothing is copied.
bool CopyTo | ( | basic_Image< T_ > & | dest, |
Geometry::Point | target = {0, 0} |
||
) | const |
Copies data from one image to another.
This operation does not perform blending. Additionally, color modes should be the same. However, this function will do clipping for overflows. Do not use negative values for target. Will return false if nothing is copied.
void CopyToBGRABuffer | ( | Byte * | buffer | ) | const |
Copies this image to a RGBA buffer, buffer should be resize before calling this function.
This function is here mostly to create icon for Win32
References Gorgon::Graphics::Alpha, basic_Size< T_ >::Area(), basic_Image< T_ >::data, Gorgon::Graphics::Grayscale, Gorgon::Graphics::Invalid, basic_Image< T_ >::mode, Gorgon::Graphics::RGB, Gorgon::Graphics::RGBA, and basic_Image< T_ >::size.
void CopyToBGRABufferLong | ( | unsigned long * | buffer | ) | const |
Copies this image to a RGBA buffer, buffer should be resize before calling this function.
This function is here mostly to create icon for X11
References Gorgon::Graphics::Alpha, basic_Size< T_ >::Area(), basic_Image< T_ >::data, Gorgon::Graphics::Grayscale, Gorgon::Graphics::Invalid, basic_Image< T_ >::mode, Gorgon::Graphics::RGB, Gorgon::Graphics::RGBA, and basic_Image< T_ >::size.
void CopyToRGBABuffer | ( | Byte * | buffer | ) | const |
Copies this image to a RGBA buffer, buffer should be resize before calling this function.
References Gorgon::Graphics::Alpha, basic_Size< T_ >::Area(), basic_Image< T_ >::data, Gorgon::Graphics::Grayscale, Gorgon::Graphics::Invalid, basic_Image< T_ >::mode, Gorgon::Graphics::RGB, Gorgon::Graphics::RGBA, and basic_Image< T_ >::size.
void Destroy | ( | ) |
Destroys this image by setting width and height to 0 and freeing the memory used by its data.
Also color mode is set to ColorMode::Invalid
References basic_Image< T_ >::cpp, basic_Image< T_ >::data, Gorgon::Graphics::Invalid, basic_Image< T_ >::mode, and basic_Image< T_ >::size.
basic_Image Duplicate | ( | ) | const |
Duplicates this image, essentially performing the work of copy constructor.
References basic_Image< T_ >::Assign(), basic_Image< T_ >::data, basic_Image< T_ >::mode, and basic_Image< T_ >::size.
bool ExportBMP | ( | const std::string & | filename, |
bool | usev4 = false , |
||
bool | dib = false |
||
) |
Exports the image as a bitmap.
RGB is exported as 24-bit, RGBA, BGR, BGRA is exported as 32-bit, Grayscale exported as 8-bit, Grayscale alpha, alpha only is exported as 16-bit
bool ExportBMP | ( | std::ostream & | file, |
bool | usev4 = false , |
||
bool | dib = false |
||
) |
Exports the image as a bitmap.
RGB is exported as 24-bit, RGBA, BGR, BGRA is exported as 32-bit, Grayscale exported as 8-bit, Grayscale alpha, alpha only is exported as 16-bit
References basic_Image< T_ >::data, basic_Size< T_ >::Height, basic_Image< T_ >::mode, basic_Image< T_ >::size, basic_Size< T_ >::Width, Gorgon::IO::WriteArray(), Gorgon::IO::WriteInt32(), Gorgon::IO::WriteString(), Gorgon::IO::WriteUInt16(), Gorgon::IO::WriteUInt32(), and Gorgon::IO::WriteUInt8().
Byte Get | ( | const Geometry::Point & | p, |
Byte | def, | ||
unsigned | component = 0 |
||
) | const |
Provides access to the given component in x and y coordinates.
This function returns 0 if the given coordinates are out of bounds. This function works slower than the () operator.
References basic_Image< T_ >::cpp, basic_Image< T_ >::data, basic_Size< T_ >::Height, basic_Image< T_ >::size, basic_Size< T_ >::Width, basic_Point< T_ >::X, and basic_Point< T_ >::Y.
Byte Get | ( | const Geometry::Point & | p, |
unsigned | component = 0 |
||
) | const |
Provides access to the given component in x and y coordinates.
This function returns 0 if the given coordinates are out of bounds. This function works slower than the () operator.
References basic_Image< T_ >::cpp, basic_Image< T_ >::data, basic_Size< T_ >::Height, basic_Image< T_ >::size, basic_Size< T_ >::Width, basic_Point< T_ >::X, and basic_Point< T_ >::Y.
Byte Get | ( | int | x, |
int | y, | ||
unsigned | component = 0 |
||
) | const |
Provides access to the given component in x and y coordinates.
This function returns 0 if the given coordinates are out of bounds. This function works slower than the () operator.
References basic_Image< T_ >::cpp, basic_Image< T_ >::data, basic_Size< T_ >::Height, basic_Image< T_ >::size, and basic_Size< T_ >::Width.
Byte GetAlphaAt | ( | int | x, |
int | y | ||
) | const |
Returns the alpha at the given location.
If the given location does not exits this function will return 0. If there is no alpha channel, image is assumed to be opaque.
References basic_Image< T_ >::alphaloc, basic_Image< T_ >::cpp, basic_Image< T_ >::data, basic_Size< T_ >::Height, basic_Image< T_ >::size, and basic_Size< T_ >::Width.
int GetAlphaIndex | ( | ) | const |
Returns the index of alpha channel. Value of -1 denotes no alpha channel.
References basic_Image< T_ >::alphaloc.
unsigned GetChannelsPerPixel | ( | ) | const |
Returns the number units occupied by a single pixel of this image.
References basic_Image< T_ >::cpp.
int GetHeight | ( | ) | const |
Returns the height of the image.
References basic_Size< T_ >::Height, and basic_Image< T_ >::size.
Graphics::ColorMode GetMode | ( | ) | const |
Returns the color mode of the image.
References basic_Image< T_ >::mode.
Graphics::RGBA GetRGBAAt | ( | Geometry::Point | p | ) | const |
Returns the alpha at the given location.
If the given location does not exits this function will return 0. If there is no alpha channel, image is assumed to be opaque.
References basic_Image< T_ >::GetRGBAAt(), basic_Point< T_ >::X, and basic_Point< T_ >::Y.
Graphics::RGBA GetRGBAAt | ( | int | x, |
int | y | ||
) | const |
Returns the alpha at the given location.
If the given location does not exits this function will return 0. If there is no alpha channel, image is assumed to be opaque.
References Gorgon::Graphics::Alpha, Gorgon::Graphics::Grayscale, basic_Size< T_ >::Height, Gorgon::Graphics::Invalid, basic_Image< T_ >::mode, Gorgon::Graphics::RGB, Gorgon::Graphics::RGBA, basic_Image< T_ >::size, and basic_Size< T_ >::Width.
Geometry::Size GetSize | ( | ) | const |
Returns the size of the image.
References basic_Image< T_ >::size.
unsigned long GetTotalSize | ( | ) | const |
Total size of this image in number units.
References basic_Size< T_ >::Area(), basic_Image< T_ >::cpp, and basic_Image< T_ >::size.
int GetWidth | ( | ) | const |
Returns the width of the image.
References basic_Image< T_ >::size, and basic_Size< T_ >::Width.
bool HasAlpha | ( | ) | const |
Returns if this image has alpha channel.
References basic_Image< T_ >::alphaloc.
bool ImportBMP | ( | const std::string & | filename, |
bool | dib = false |
||
) |
Imports a given bitmap file. BMP RLE compression and colorspaces are not supported.
bool ImportBMP | ( | std::istream & | file, |
bool | dib = false |
||
) |
Imports a given bitmap file. BMP RLE compression and colorspaces are not supported.
References Gorgon::Input::Keyboard::Keycodes::A, Gorgon::Graphics::Alpha, Gorgon::Graphics::Grayscale, Gorgon::Graphics::Invalid, basic_Image< T_ >::operator()(), Gorgon::IO::ReadInt16(), Gorgon::IO::ReadInt32(), Gorgon::IO::ReadString(), Gorgon::IO::ReadUInt16(), Gorgon::IO::ReadUInt32(), Gorgon::IO::ReadUInt8(), basic_Image< T_ >::Resize(), Gorgon::Graphics::RGB, and Gorgon::Graphics::RGBA.
Byte& operator() | ( | const Geometry::Point & | p, |
unsigned | component = 0 |
||
) |
Provides access to the given component in x and y coordinates.
This function performs bounds checking only on debug mode.
References basic_Image< T_ >::cpp, basic_Image< T_ >::data, basic_Size< T_ >::Height, basic_Image< T_ >::size, basic_Size< T_ >::Width, basic_Point< T_ >::X, and basic_Point< T_ >::Y.
Byte operator() | ( | const Geometry::Point & | p, |
unsigned | component = 0 |
||
) | const |
Provides access to the given component in x and y coordinates.
This function performs bounds checking only on debug mode.
References basic_Image< T_ >::cpp, basic_Image< T_ >::data, basic_Size< T_ >::Height, basic_Image< T_ >::size, basic_Size< T_ >::Width, basic_Point< T_ >::X, and basic_Point< T_ >::Y.
Byte& operator() | ( | int | x, |
int | y, | ||
unsigned | component = 0 |
||
) |
Provides access to the given component in x and y coordinates.
This function performs bounds checking only on debug mode.
References basic_Image< T_ >::cpp, basic_Image< T_ >::data, basic_Size< T_ >::Height, basic_Image< T_ >::size, and basic_Size< T_ >::Width.
Byte operator() | ( | int | x, |
int | y, | ||
unsigned | component = 0 |
||
) | const |
Provides access to the given component in x and y coordinates.
This function performs bounds checking only on debug mode.
References basic_Image< T_ >::cpp, basic_Image< T_ >::data, basic_Size< T_ >::Height, basic_Image< T_ >::size, and basic_Size< T_ >::Width.
basic_Image& operator= | ( | basic_Image< T_ > && | other | ) |
Move assignment.
References basic_Image< T_ >::Destroy(), and basic_Image< T_ >::Swap().
|
delete |
Copy assignment is disabled.
Byte* RawData | ( | ) |
Returns the raw data pointer.
References basic_Image< T_ >::data.
const Byte* RawData | ( | ) | const |
Returns the raw data pointer.
References basic_Image< T_ >::data.
Byte* Release | ( | ) |
Returns and disowns the current data buffer. If image is empty, this method will return a nullptr.
References basic_Image< T_ >::data, and basic_Image< T_ >::Destroy().
void Resize | ( | const Geometry::Size & | size, |
Graphics::ColorMode | mode | ||
) |
Resizes the image to the given size and color mode.
This function discards the contents of the image and does not perform any initialization.
References basic_Image< T_ >::alphaloc, basic_Size< T_ >::Area(), basic_Image< T_ >::cpp, basic_Image< T_ >::data, Gorgon::Graphics::GetAlphaIndex(), Gorgon::Graphics::GetChannelsPerPixel(), Gorgon::Graphics::HasAlpha(), basic_Size< T_ >::IsValid(), basic_Image< T_ >::mode, and basic_Image< T_ >::size.
void SetRGBAAt | ( | Geometry::Point | p, |
Graphics::RGBA | color | ||
) |
Sets the color at the given location to the specified RGBA value.
If pixel does not exists, the call will be ignored.
References basic_Image< T_ >::SetRGBAAt(), basic_Point< T_ >::X, and basic_Point< T_ >::Y.
void SetRGBAAt | ( | int | x, |
int | y, | ||
Graphics::RGBA | color | ||
) |
Sets the color at the given location to the specified RGBA value.
If pixel does not exists, the call will be ignored.
References RGBA::A, Gorgon::Graphics::Alpha, RGBA::B, RGBA::G, Gorgon::Graphics::Grayscale, basic_Size< T_ >::Height, Gorgon::Graphics::Invalid, RGBA::Luminance(), basic_Image< T_ >::mode, RGBA::R, Gorgon::Graphics::RGB, Gorgon::Graphics::RGBA, basic_Image< T_ >::size, and basic_Size< T_ >::Width.
void Swap | ( | basic_Image< T_ > & | other | ) |
Swaps this image with another. This function is used to implement move semantics.
References basic_Image< T_ >::alphaloc, basic_Image< T_ >::cpp, basic_Image< T_ >::data, basic_Image< T_ >::mode, basic_Image< T_ >::size, and Gorgon::Containers::swap().
|
protected |
Location of the alpha channel, -1 means it does not exits.
|
protected |
Channels per pixel information.
|
protected |
Data that stores pixels of the image.
|
protected |
Color mode of the image.
|
protected |
Width of the image.