The image class has a strict internal representation so we dont need "format". PixelFormat enum can be passed to functions that modify the pixel data (like setPixels()) so that a proper convertion can be done.
69 lines
1.4 KiB
C++
69 lines
1.4 KiB
C++
|
|
#ifndef SPECTRE_GRAPHICS_IMAGE_H
|
|
#define SPECTRE_GRAPHICS_IMAGE_H
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <Spectre/Math/Color.h>
|
|
#include <Spectre/Math/Vector2.h>
|
|
#include <Spectre/Graphics/PixelFormat.h>
|
|
|
|
namespace sp {
|
|
|
|
class Image
|
|
{
|
|
public :
|
|
enum Channels {
|
|
Alpha,
|
|
RGB,
|
|
RGBA
|
|
};
|
|
|
|
Image();
|
|
|
|
void create(unsigned width, unsigned height, const Color& color = Color::Black, enum Channels comp = Channels::RGBA);
|
|
void create(unsigned width, unsigned height, const void* pixels, PixelFormat format = PixelFormat::PF_RGBA);
|
|
|
|
const Vector2u& getSize() const;
|
|
|
|
unsigned int getWidth() const;
|
|
|
|
unsigned int getHeight() const;
|
|
|
|
unsigned int getNumChannels() const;
|
|
|
|
unsigned int getStride() const;
|
|
|
|
PixelFormat getFormat() const;
|
|
|
|
// Returns true if the image has a alpha channel.
|
|
bool hasAlpha() const;
|
|
|
|
bool loadFromFile(const std::string& filename);
|
|
|
|
bool loadFromMemory(const void *data, unsigned int size);
|
|
|
|
void saveToFile(const std::string& filename) const;
|
|
|
|
void setPixel(unsigned x, unsigned y, const Color& c);
|
|
|
|
Color getPixel(unsigned x, unsigned y) const;
|
|
|
|
void setPixels(const void* pixels, PixelFormat format = PixelFormat::PF_RGBA);
|
|
|
|
const unsigned char* getPixels() const;
|
|
|
|
void flipY();
|
|
|
|
private :
|
|
|
|
Vector2u m_size;
|
|
|
|
enum Channels m_channels;
|
|
|
|
std::vector<unsigned char> m_pixels;
|
|
};
|
|
|
|
} //namespace sp
|
|
|
|
#endif /* SPECTRE_GRAPHICS_IMAGE_H */
|