sgltk 0.6
Simple OpenGL Tool Kit
Loading...
Searching...
No Matches
sgltk::Image Class Reference

Manages images. More...

#include <image.h>

Public Member Functions

 Image (std::string filename)
 Image (unsigned int width, unsigned int height, unsigned int bytes_per_pixel, void *data)
bool create_empty (unsigned int width, unsigned int height)
 Creates an empty image.
bool load (const std::string &filename)
 Loads a new image file.
bool load (unsigned int width, unsigned int height, unsigned int bytes_per_pixel, void *data)
 Loads image from a data buffer.
bool save (const std::string &filename)
 Saves the image as a file.
bool copy_from (const Image &src, int x, int y)
 Copies an image into the current image.
bool copy_from (const Image &src, SDL_Rect &dst_rect)
 Copies an image into the current image.
bool copy_from (const Image &src, SDL_Rect &dst_rect, const SDL_Rect &src_rect)
 Copies an image into the current image.
void vertical_flip ()
 Flips the image along its x-axis.
void horizontal_flip ()
 Flips the image along its y-axis.
void set_color_key (int r, int g, int b, bool enable=true)
 Sets a color to be transparent.

Static Public Member Functions

static void add_path (std::string path)
 Adds a path to the list of paths to be searched for image files.

Public Attributes

unsigned int width
 The width of the image surface.
unsigned int height
 The width of the image surface.
unsigned int bytes_per_pixel
 The number of bytes that make up a single pixel.
void * data
 The pixel data.
SDL_Surface * image
 The image surface.

Detailed Description

Manages images.

Definition at line 12 of file image.h.

Constructor & Destructor Documentation

◆ Image() [1/3]

Image::Image ( )

Definition at line 7 of file image.cpp.

◆ Image() [2/3]

Image::Image ( std::string filename)
Parameters
filenamePath to the image file to load

Definition at line 16 of file image.cpp.

◆ Image() [3/3]

Image::Image ( unsigned int width,
unsigned int height,
unsigned int bytes_per_pixel,
void * data )
Parameters
widthThe width of the image
heightThe height of the image
bytes_per_pixelThe number of bytes that represent a pixel
dataA pointer to the buffer data

Definition at line 31 of file image.cpp.

◆ ~Image()

Image::~Image ( )

Definition at line 50 of file image.cpp.

Member Function Documentation

◆ add_path()

void Image::add_path ( std::string path)
static

Adds a path to the list of paths to be searched for image files.

Parameters
pathThe path to add to the list
Note
To avoid duplicates this function first performs a search on existing entries.

Definition at line 374 of file image.cpp.

◆ copy_from() [1/3]

bool Image::copy_from ( const Image & src,
int x,
int y )

Copies an image into the current image.

Parameters
srcThe image to be copied
xThe x coordinate to copy the image to
yThe y coordinate to copy the image to

Definition at line 282 of file image.cpp.

◆ copy_from() [2/3]

bool Image::copy_from ( const Image & src,
SDL_Rect & dst_rect )

Copies an image into the current image.

Parameters
srcThe image to be copied
dst_rectThe coordinates to copy the image to

Definition at line 289 of file image.cpp.

◆ copy_from() [3/3]

bool Image::copy_from ( const Image & src,
SDL_Rect & dst_rect,
const SDL_Rect & src_rect )

Copies an image into the current image.

Parameters
srcThe image to be copied
dst_rectThe coordinates to copy the image to
src_rectThe part of the image to copy

Definition at line 307 of file image.cpp.

◆ create_empty()

bool Image::create_empty ( unsigned int width,
unsigned int height )

Creates an empty image.

Parameters
widthThe width of the image
heightThe height of the image
Returns
Returns true on success, false otherwise

Definition at line 56 of file image.cpp.

◆ horizontal_flip()

void Image::horizontal_flip ( )

Flips the image along its y-axis.

Definition at line 350 of file image.cpp.

◆ load() [1/2]

bool Image::load ( const std::string & filename)

Loads a new image file.

Parameters
filenamePath to the image file to load
Returns
Returns true on success, false otherwise

Definition at line 97 of file image.cpp.

◆ load() [2/2]

bool Image::load ( unsigned int width,
unsigned int height,
unsigned int bytes_per_pixel,
void * data )

Loads image from a data buffer.

Parameters
widthThe width of the image
heightThe height of the image
bytes_per_pixelThe number of bytes that represent a pixel
dataA pointer to the buffer data
Returns
Returns true on success, false otherwise
Note
The image object keeps it's own copy of the data until a new image is loaded

Definition at line 135 of file image.cpp.

◆ save()

bool Image::save ( const std::string & filename)

Saves the image as a file.

Parameters
filenameThe path to save the image to
Returns
Returns true on success, false otherwise

Definition at line 205 of file image.cpp.

◆ set_color_key()

void Image::set_color_key ( int r,
int g,
int b,
bool enable = true )

Sets a color to be transparent.

Parameters
rThe red color channel
gThe green color channel
bThe blue color channel
enableTrue to enable color key, false to disable it

Definition at line 370 of file image.cpp.

◆ vertical_flip()

void Image::vertical_flip ( )

Flips the image along its x-axis.

Definition at line 330 of file image.cpp.

Member Data Documentation

◆ bytes_per_pixel

unsigned int sgltk::Image::bytes_per_pixel

The number of bytes that make up a single pixel.

Definition at line 35 of file image.h.

◆ data

void* sgltk::Image::data

The pixel data.

Definition at line 39 of file image.h.

◆ height

unsigned int sgltk::Image::height

The width of the image surface.

Definition at line 31 of file image.h.

◆ image

SDL_Surface* sgltk::Image::image

The image surface.

Definition at line 44 of file image.h.

◆ width

unsigned int sgltk::Image::width

The width of the image surface.

Definition at line 27 of file image.h.


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