Loading...
Searching...
No Matches
CImage Class Reference

Image loaded from file. More...

`#include <src/common/image.h>`

## Public Member Functions

| CImage ()
| Constructs empty image (with nullptr data).
| CImage (Math::IntPoint size)
| Constructs a RGBA image of given size.
virtual | ~CImage ()
| Destroys image, calling Free().
| CImage (const CImage &other)=delete
void | operator= (const CImage &other)=delete
void | Free ()
| Frees the allocated image data.
bool | IsEmpty () const
| Returns whether the image is empty (has null data).
ImageData * | GetData ()
| Returns the image data; if empty - returns nullptr.
Math::IntPoint | GetSize () const
| Returns the image size.
void | Fill (Gfx::IntColor color)
| Fills the whole image with given color.
void | SetPixel (Math::IntPoint pixel, Gfx::Color color)
| Sets the color at given pixel.
void | SetPixelInt (Math::IntPoint pixel, Gfx::IntColor color)
| Sets the precise color at given pixel.
Gfx::Color | GetPixel (Math::IntPoint pixel)
| Returns the color at given pixel.
Gfx::IntColor | GetPixelInt (Math::IntPoint pixel)
| Returns the precise color at given pixel.
void | PadToNearestPowerOfTwo ()
| Pads the image to nearest power of 2 dimensions.
void | ConvertToRGBA ()
| Convert the image to RGBA surface.
bool | Load (const std::string &fileName)
| Loads an image from the specified file.
bool | SavePNG (const std::string &fileName)
| Saves the image to the specified file in PNG format.
std::string | GetError ()
| Returns the last error.
void | FlipVertically ()
| Flips the image vertically.
void | SetDataPixels (void *pixels)
| sets/replaces the pixels from the surface

## Detailed Description

Image loaded from file.

Wrapper around SDL_Image library to load images. Also contains function for saving images to PNG.

## Constructor & Destructor Documentation

## CImage() [1/2]

CImage::CImage | ( |  | ) |

Constructs empty image (with nullptr data).

## CImage() [2/2]

CImage::CImage | ( | Math::IntPoint | size | ) |

Constructs a RGBA image of given size.

## ~CImage()

CImage::~CImage | ( |  | ) |

virtual

Destroys image, calling Free().

## Member Function Documentation

## Free()

void CImage::Free | ( |  | ) |

Frees the allocated image data.

## IsEmpty()

bool CImage::IsEmpty | ( |  | ) | const

Returns whether the image is empty (has null data).

## GetData()

ImageData * CImage::GetData | ( |  | ) |

Returns the image data; if empty - returns nullptr.

## GetSize()

Math::IntPoint CImage::GetSize | ( |  | ) | const

Returns the image size.

## Fill()

void CImage::Fill | ( | Gfx::IntColor | color | ) |

Fills the whole image with given color.

Image must be valid.

## SetPixel()

void CImage::SetPixel | ( | Math::IntPoint | pixel,
|  | Gfx::Color | color )

Sets the color at given pixel.

Image must be valid and pixel coords in valid range.

Parameters

  pixel | pixel coords (range x: 0..width-1 y: 0..height-1)
  color | color

## SetPixelInt()

void CImage::SetPixelInt | ( | Math::IntPoint | pixel,
|  | Gfx::IntColor | color )

Sets the precise color at given pixel.

Image must be valid and pixel coords in valid range.

Parameters

  pixel | pixel coords (range x: 0..width-1 y: 0..height-1)
  color | color

## GetPixel()

Gfx::Color CImage::GetPixel | ( | Math::IntPoint | pixel | ) |

Returns the color at given pixel.

Image must be valid and pixel coords in valid range.

Parameters

  pixel | pixel coords (range x: 0..width-1 y: 0..height-1)

Returns
  color

## GetPixelInt()

Gfx::IntColor CImage::GetPixelInt | ( | Math::IntPoint | pixel | ) |

Returns the precise color at given pixel.

Image must be valid and pixel coords in valid range.

Parameters

  pixel | pixel coords (range x: 0..width-1 y: 0..height-1)

Returns
  color

## PadToNearestPowerOfTwo()

void CImage::PadToNearestPowerOfTwo | ( |  | ) |

Pads the image to nearest power of 2 dimensions.

Image must be valid.

The dimensions are increased to nearest even power of two values. If image is already in power-of-two format, nothing is done.

## ConvertToRGBA()

void CImage::ConvertToRGBA | ( |  | ) |

Convert the image to RGBA surface.

## Load()

bool CImage::Load | ( | const std::string & | fileName | ) |

Loads an image from the specified file.

## SavePNG()

bool CImage::SavePNG | ( | const std::string & | fileName | ) |

Saves the image to the specified file in PNG format.

## GetError()

std::string CImage::GetError | ( |  | ) |

Returns the last error.

## FlipVertically()

void CImage::FlipVertically | ( |  | ) |

Flips the image vertically.

## SetDataPixels()

void CImage::SetDataPixels | ( | void * | pixels | ) |

sets/replaces the pixels from the surface

The documentation for this class was generated from the following files:

- src/common/image.h
- src/common/image.cpp