mousetrap v0.2.0
Loading...
Searching...
No Matches
mousetrap::Image Class Reference

a 2d buffer container RGBA pixels More...

#include <image.hpp>

Public Member Functions

 Image ()
 default ctor, initialize as image of size 0x0
 
 Image (const std::string &path)
 construct from file
 
 Image (uint64_t width, uint64_t height, RGBA rgba=RGBA(0, 0, 0, 0))
 construct as single-color image
 
 ~Image ()
 destruct, frees data
 
 Image (const Image &other)
 copy ctor, invokes deep copy of the data
 
 Image (Image &&other) noexcept
 move ctor, moves data, empties original image
 
Imageoperator= (const Image &other)
 copy assignment, invokes deep copy of the data
 
Imageoperator= (Image &&other) noexcept
 move assignment, empties original image
 
 operator GdkPixbuf * () const
 expose as GdkPixbuf, for interal use only
 
void create (uint64_t width, uint64_t height, RGBA default_color=RGBA(0, 0, 0, 1))
 create image of given size and identical color
 
bool create_from_file (const std::string &path)
 create an image by reading a file
 
bool save_to_file (const std::string &path) const
 sae to file
 
void * data () const
 expose pixel data, linear array of RGBA values. For internal use only
 
uint64_t get_data_size () const
 get length of linear data
 
uint64_t get_n_pixels () const
 get number of pixels
 
Vector2ui get_size () const
 get dimensions
 
Image as_scaled (uint64_t size_x, uint64_t size_y, InterpolationType interpolation_type=InterpolationType::TILES) const
 create a new image, scaled according to the scale mode
 
Image as_cropped (int offset_x, int offset_y, uint64_t new_width, uint64_t new_height) const
 create a new image, cropped
 
Image as_flipped (bool flip_horizontally, bool flip_vertically) const
 create a new image, flipped
 
void set_pixel (uint64_t x, uint64_t y, RGBA new_color)
 set value of individual pixel, prints soft warning if indices out of bounds
 
void set_pixel (uint64_t x, uint64_t y, HSVA new_color)
 set value of individual pixel, prints soft warning if indices out of bounds
 
RGBA get_pixel (uint64_t x, uint64_t y) const
 get value of individual pixel, prints soft warning if indices out of bounds
 
void set_pixel (uint64_t linear_index, RGBA new_color)
 set value of individual pixel, linear indexing. Prints soft warning if index out of bounds
 
void set_pixel (uint64_t linear_index, HSVA new_color)
 set value of individual pixel, linear indexing. Prints soft warning if index out of bounds
 
RGBA get_pixel (uint64_t linear_index) const
 get value of individual pixel, linear indexing.
 

Detailed Description

a 2d buffer container RGBA pixels

Constructor & Destructor Documentation

◆ Image() [1/4]

mousetrap::Image::Image ( const std::string &  path)

construct from file

Parameters
path

References create_from_file().

◆ Image() [2/4]

mousetrap::Image::Image ( uint64_t  width,
uint64_t  height,
RGBA  rgba = RGBA(0, 0, 0, 0) 
)

construct as single-color image

Parameters
width
height
rgbadefault color for all pixels

References create().

◆ Image() [3/4]

mousetrap::Image::Image ( const Image other)

copy ctor, invokes deep copy of the data

Parameters
other

◆ Image() [4/4]

mousetrap::Image::Image ( Image &&  other)
noexcept

move ctor, moves data, empties original image

Parameters
other

Member Function Documentation

◆ as_cropped()

Image mousetrap::Image::as_cropped ( int  offset_x,
int  offset_y,
uint64_t  new_width,
uint64_t  new_height 
) const

create a new image, cropped

Parameters
offset_xleft most anchor of the newly cropped image, may be negative
offset_ytop most anchor of the newly cropped image, may be negative
new_widthnew width
new_heightnew height
Returns
newly allocated image
Note
pixels outside the original image bounds will be set to RBGA(0, 0, 0, 0)

References get_pixel(), get_size(), and Image().

◆ as_flipped()

Image mousetrap::Image::as_flipped ( bool  flip_horizontally,
bool  flip_vertically 
) const

create a new image, flipped

Parameters
flip_horizontallyflip along the x-axis
flip_verticallyflip along the y-axis
Returns
newly allocated image, same size as original image

References get_pixel(), and Image().

◆ as_scaled()

Image mousetrap::Image::as_scaled ( uint64_t  size_x,
uint64_t  size_y,
InterpolationType  interpolation_type = InterpolationType::TILES 
) const

create a new image, scaled according to the scale mode

Parameters
size_xnew width
size_ynew height
interpolation_typeinterpolation algorithm to use
Returns
newly allocated image

References Image().

◆ create()

void mousetrap::Image::create ( uint64_t  width,
uint64_t  height,
RGBA  default_color = RGBA(0, 0, 0, 1) 
)

create image of given size and identical color

Parameters
widthnew x-dimension
heightnew y-dimension
default_colorcolor of all pixels after initialization

References mousetrap::RGBA::a, mousetrap::RGBA::b, mousetrap::RGBA::g, mousetrap::RGBA::r, and set_pixel().

Referenced by Image().

◆ create_from_file()

bool mousetrap::Image::create_from_file ( const std::string &  path)

create an image by reading a file

Parameters
path
Returns
true if successfull, false otherwise

References mousetrap::log::critical().

Referenced by Image().

◆ data()

void * mousetrap::Image::data ( ) const

expose pixel data, linear array of RGBA values. For internal use only

Returns
void pointer to data
Note
This function is not available in the Julia binding

Referenced by mousetrap::Texture::create_from_image(), get_pixel(), and set_pixel().

◆ get_data_size()

uint64_t mousetrap::Image::get_data_size ( ) const

get length of linear data

Returns
n

Referenced by get_pixel(), and set_pixel().

◆ get_n_pixels()

uint64_t mousetrap::Image::get_n_pixels ( ) const

get number of pixels

Returns
n, equal to width * height

References get_size().

◆ get_pixel() [1/2]

RGBA mousetrap::Image::get_pixel ( uint64_t  linear_index) const

get value of individual pixel, linear indexing.

Parameters
linear_index
Returns
RGBA
Note
This function is not available in the Julia binding

References data().

◆ get_pixel() [2/2]

RGBA mousetrap::Image::get_pixel ( uint64_t  x,
uint64_t  y 
) const

get value of individual pixel, prints soft warning if indices out of bounds

Parameters
xrow-index
ycolumn-index
Returns
pixel if indices in bounds, RGBA(0, 0, 0, 0) otherwise

References mousetrap::log::critical(), data(), and get_data_size().

Referenced by as_cropped(), and as_flipped().

◆ get_size()

Vector2ui mousetrap::Image::get_size ( ) const

◆ operator=() [1/2]

Image & mousetrap::Image::operator= ( const Image other)

copy assignment, invokes deep copy of the data

Parameters
other
Returns
self after assignment

◆ operator=() [2/2]

Image & mousetrap::Image::operator= ( Image &&  other)
noexcept

move assignment, empties original image

Parameters
other
Returns
self after assignment

◆ save_to_file()

bool mousetrap::Image::save_to_file ( const std::string &  path) const

sae to file

Parameters
path
Returns
true if successfull, false otherwise

References mousetrap::log::critical().

◆ set_pixel() [1/4]

void mousetrap::Image::set_pixel ( uint64_t  linear_index,
HSVA  new_color 
)

set value of individual pixel, linear indexing. Prints soft warning if index out of bounds

Parameters
linear_index
new_colorHSVA
Note
This function is not available in the Julia binding

References set_pixel().

◆ set_pixel() [2/4]

void mousetrap::Image::set_pixel ( uint64_t  linear_index,
RGBA  new_color 
)

set value of individual pixel, linear indexing. Prints soft warning if index out of bounds

Parameters
linear_index
new_colorRBGA
Note
This function is not available in the Julia binding

References mousetrap::RGBA::a, mousetrap::RGBA::b, mousetrap::log::critical(), data(), mousetrap::RGBA::g, get_data_size(), and mousetrap::RGBA::r.

◆ set_pixel() [3/4]

void mousetrap::Image::set_pixel ( uint64_t  x,
uint64_t  y,
HSVA  new_color 
)

set value of individual pixel, prints soft warning if indices out of bounds

Parameters
xrow-index
ycolumn-index
new_colorHSVA

References set_pixel().

◆ set_pixel() [4/4]

void mousetrap::Image::set_pixel ( uint64_t  x,
uint64_t  y,
RGBA  new_color 
)

set value of individual pixel, prints soft warning if indices out of bounds

Parameters
xrow-index
ycolumn-index
new_colorRGBA

References mousetrap::RGBA::a, mousetrap::RGBA::b, data(), mousetrap::RGBA::g, get_data_size(), and mousetrap::RGBA::r.

Referenced by create(), and set_pixel().


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