JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
ImageData Class Referenceabstract

Containing the pixel data of an image file. More...

#include <jngl/ImageData.hpp>

Public Member Functions

virtual int getWidth () const =0
 Returns the width of the image in pixels.
 
virtual int getHeight () const =0
 Returns the height of the image in pixels.
 
virtual int getImageWidth () const =0
 If the image has been scaled by getScaleFactor() this will return the original image width.
 
virtual int getImageHeight () const =0
 If the image has been scaled by getScaleFactor() this will return the original image height.
 
virtual const uint8_t * pixels () const =0
 RGBA values ordered row-major.
 

Static Public Member Functions

static std::unique_ptr< ImageDataload (const std::string &filename, double scaleHint=1.)
 Passing a filename will load the specified filename.
 

Detailed Description

Containing the pixel data of an image file.

Definition at line 13 of file ImageData.hpp.

Member Function Documentation

◆ load()

static std::unique_ptr< ImageData > load ( const std::string & filename,
double scaleHint = 1. )
static

Passing a filename will load the specified filename.

PNG and WebP files are supported.

scaleHint might be completely ignored, compare getImageWidth with getWidth after loading to check.

◆ pixels()

virtual const uint8_t * pixels ( ) const
pure virtual

RGBA values ordered row-major.

To access the x=5, y=7 pixel's green value: img->pixels()[5 * 4 + 7 * img->getWidth() * 4 + 1]

This function doesn't create the underlying data or loads the image (that has already happened in ImageData::load), so you may call this as often as you like.

Example:

auto img = ImageData::load("foo");
size_t x = 5;
size_t y = 7;
uint8_t r = img->pixels()[x * 4 + y * img->getWidth() * 4];
uint8_t g = img->pixels()[x * 4 + y * img->getWidth() * 4 + 1];
uint8_t b = img->pixels()[x * 4 + y * img->getWidth() * 4 + 2];
uint8_t a = img->pixels()[x * 4 + y * img->getWidth() * 4 + 3];
static std::unique_ptr< ImageData > load(const std::string &filename, double scaleHint=1.)
Passing a filename will load the specified filename.

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