nomlib
Loading...
Searching...
No Matches
nom::Image Class Reference

Bitmap storage container. More...

#include <Image.hpp>

Public Types

typedef ImageRawPtr
typedef std::shared_ptr< ImageSharedPtr

Public Member Functions

 Image (void)
 Default constructor – initializes to sane defaults.
 ~Image (void)
 Destructor.
 Image (const Image &copy)
 Copy constructor.
Imageoperator= (const Image &other)
 Copy assignment constructor.
SDL_Surface * clone (void) const
 Make a copy of the existing surface.
SDL_Surface * image (void) const
 Obtain the SDL_Surface struct used in this object instance.
SDL_Texture * texture (void) const
bool valid (void) const
 Is this object initialized? Valid when NOT nullptr.
bool initialize (void *pixels, int32 width, int32 height, int bits_per_pixel, uint16 pitch, uint32 Rmask, uint32 Gmask, uint32 Bmask, uint32 Amask)
bool initialize (int32 width, int32 height, int bits_per_pixel, uint32 Rmask, uint32 Gmask, uint32 Bmask, uint32 Amask)
bool initialize (SDL_Surface *source)
 Initialize a nom::Image from an existing SDL_Surface.
bool create (const Point2i &size, uint32 pixel_format)
 Create a new memory buffer.
bool create (const Size2i &size, uint32 pixel_format)
bool initialize (const Point2i &size)
 Create a new memory buffer using the most optimal pixel format detected for your graphics hardware.
int32 width (void) const
int32 height (void) const
void * pixels (void) const
uint16 pitch (void) const
uint8 bits_per_pixel (void) const
const SDL_PixelFormat * pixel_format (void) const
uint32 red_mask (void) const
 Obtain the video surface's red alpha mask.
uint32 green_mask (void) const
 Obtain the video surface's green alpha mask.
uint32 blue_mask (void) const
 Obtain the video surface's blue alpha mask.
uint32 alpha_mask (void) const
 Obtain the video surface's alpha mask.
const IntRect bounds (void) const
bool must_lock () const
 Check to see if the video surface needs locking.
bool locked (void) const
uint8 alpha (void) const
 Obtain the alpha value of this video surface.
const Point2i position (void) const
void set_bounds (const IntRect &bounds)
bool load (const std::string &filename, uint32 pixel_format=SDL_PIXELFORMAT_ARGB8888)
bool load_memory (const char *buffer, int buffer_size, const std::string &ext, uint32 pixel_format=SDL_PIXELFORMAT_ARGB8888)
 Load an image surface from a memory source.
bool load_bmp (const std::string &filename, uint32 pixel_format=SDL_PIXELFORMAT_ARGB8888)
bool save_bmp (const std::string &filename) const
bool save_png (const std::string &filename) const
Size2i size () const
 Obtain the width and height (in pixels) of the stored bitmap buffer.
const Color4i colorkey (void) const
const SDL_BlendMode blend_mode (void) const
 Obtain the blend mode used for blitting.
const Color4i color_modulation (void) const
 Obtain the additional color value multiplied into render copy operations.
bool set_colorkey (const Color4i &colorkey, bool flag)
bool RLE (bool flag)
uint32 pixel (int x, int y) const
 Read a RGBA pixel from the video surface.
Color4i color4i_pixel (int x, int y) const
 Read a RGBA pixel from the video surface.
Color4i pixel (const Point2i &pos) const
 Read a RGBA pixel from the video surface.
void set_pixel (int x, int y, const Color4i &color)
 Blit a RGBA pixel onto the video surface.
bool set_blend_mode (const SDL_BlendMode blend)
 Set a new blending mode for blitting.
bool lock () const
void unlock (void) const
bool set_alpha (uint8 opacity)
void set_position (const Point2i &pos)
void draw (SDL_Surface *destination, const IntRect &bounds) const
bool set_color_modulation (const Color4i &color)
 Set an additional color value multiplied into render copy operations.

Private Attributes

std::shared_ptr< SDL_Surface > image_
 Container for our image pixels buffer.
Point2i position_
IntRect bounds_

Detailed Description

Bitmap storage container.

Definition at line 47 of file Image.hpp.

Member Typedef Documentation

◆ RawPtr

typedef Image* nom::Image::RawPtr

Definition at line 50 of file Image.hpp.

◆ SharedPtr

typedef std::shared_ptr<Image> nom::Image::SharedPtr

Definition at line 51 of file Image.hpp.

Constructor & Destructor Documentation

◆ ~Image()

nom::Image::~Image ( void )

Destructor.

Remarks
The video surface – if locked – will be unlocked at this time before freeing its memory.

Member Function Documentation

◆ clone()

SDL_Surface * nom::Image::clone ( void ) const

Make a copy of the existing surface.

Returns
Pointer to a new SDL_Surface structure

◆ color4i_pixel()

Color4i nom::Image::color4i_pixel ( int x,
int y ) const

Read a RGBA pixel from the video surface.

See also
Image::pixel.

◆ color_modulation()

const Color4i nom::Image::color_modulation ( void ) const

Obtain the additional color value multiplied into render copy operations.

Returns
nom::Color4i on success; nom::Color4i::null on err

◆ colorkey()

const Color4i nom::Image::colorkey ( void ) const

Obtain the set color key for this image

Returns
nom::Color4i on success; nom::Color4i::null on err

◆ create()

bool nom::Image::create ( const Point2i & size,
uint32 pixel_format )

Create a new memory buffer.

Parameters
sizePoint2i initialized with the width & height in pixels
pixel_formatPixel format to use for the memory buffer.
Deprecated

◆ draw()

void nom::Image::draw ( SDL_Surface * destination,
const IntRect & bounds ) const

Render a video surface

Todo
This method needs to mimic nom::Texture::draw

◆ initialize() [1/4]

bool nom::Image::initialize ( const Point2i & size)

Create a new memory buffer using the most optimal pixel format detected for your graphics hardware.

Parameters
sizePoint2i initialized with the width & height in pixels
Remarks
Unless you have specialized needs, this is probably the method call you want.

◆ initialize() [2/4]

bool nom::Image::initialize ( int32 width,
int32 height,
int bits_per_pixel,
uint32 Rmask,
uint32 Gmask,
uint32 Bmask,
uint32 Amask )

Constructor variant for creating a fresh, empty video surface. You should be sure to read over the details gory details scattered throughout the documentation for SDL.

◆ initialize() [3/4]

bool nom::Image::initialize ( SDL_Surface * source)

Initialize a nom::Image from an existing SDL_Surface.

Parameters
sourceExisting SDL_Surface structure

◆ initialize() [4/4]

bool nom::Image::initialize ( void * pixels,
int32 width,
int32 height,
int bits_per_pixel,
uint16 pitch,
uint32 Rmask,
uint32 Gmask,
uint32 Bmask,
uint32 Amask )

Initialize an image surface using the data from an existing pixel buffer (from a SDL_Surface).

Parameters
pixelsTypically a void pointer cast to nom::uint16 or nom::uint32
bits_per_pixelBits per pixel
Note
You maintain ownership of your pixel buffer pointer; don't forget to clean up after you're done!

◆ load()

bool nom::Image::load ( const std::string & filename,
uint32 pixel_format = SDL_PIXELFORMAT_ARGB8888 )

Supports every file type that the libSDL_image extension has been compiled with

◆ load_bmp()

bool nom::Image::load_bmp ( const std::string & filename,
uint32 pixel_format = SDL_PIXELFORMAT_ARGB8888 )

Uses SDL's built-in BMP file loader; no alpha channeling support ... perfect for setting window icons!

(I have yet to find success using IMG_Load to load an ordinary bitmap file, whereas SDL_LoadBMP does load fine).

◆ load_memory()

bool nom::Image::load_memory ( const char * buffer,
int buffer_size,
const std::string & ext,
uint32 pixel_format = SDL_PIXELFORMAT_ARGB8888 )

Load an image surface from a memory source.

Parameters
bufferThe input buffer contents.
buffer_sizeThe integral size of the image data.
extThe file extension of the image data.
pixel_formatThe pixel format of the image data.
Note
Uses SDL2_image extension.

◆ lock()

bool nom::Image::lock ( ) const

Lock the video surface; this must be done before you attempt to write directly to video memory (pixel manipulation).

◆ locked()

bool nom::Image::locked ( void ) const

Obtain the locked status of the video surface memory

Note
This method accesses internal (private) data within our SDL_Surface structure.
Todo
Verify if the SDL_MUSTLOCK macro does the same thing here

◆ pixel() [1/2]

Color4i nom::Image::pixel ( const Point2i & pos) const

Read a RGBA pixel from the video surface.

See also
Image::color4i_pixel, Image::pixel.

◆ pixel() [2/2]

uint32 nom::Image::pixel ( int x,
int y ) const

Read a RGBA pixel from the video surface.

Returns
A 32-bit encoded color value, dependent upon the pixel format.
Remarks
You are responsible for any necessary video surface locking and unlocking.
Note
The color depth is determined by the existing color depth of the nom::Image – 8-bit, 15/16-bit, 24-bit or 32-bit bits per pixel depths are supported. When a color depth cannot be determined, it is assumed 32-bit.
Todo
Test 8-bit, 15/16-bit & 24-bit pixel blits

◆ RLE()

bool nom::Image::RLE ( bool flag)

Set RLE acceleration for this image

If enabled, color keying and alpha blending blits are much faster, but at the cost of requiring surface locking before directly accessing pixels.

Parameters
TRUEto enable RLE acceleration; FALSE to disable

◆ save_bmp()

bool nom::Image::save_bmp ( const std::string & filename) const

Save a screen shot of this image surface as an uncompressed BMP file

Parameters
filenameOutput filename path
Note
SDL2 appears to be saving bitmap files with ARGB pixel ordering; SDL_PIXELFORMAT_ARGB8888

◆ save_png()

bool nom::Image::save_png ( const std::string & filename) const

Save a screen shot as a Portable Network Graphics (PNG) file.

Parameters
filenameOutput filename path
Note
SDL2_image appears to be saving PNG files with ARGB pixel ordering; SDL_PIXELFORMAT_ARGB8888

◆ set_color_modulation()

bool nom::Image::set_color_modulation ( const Color4i & color)

Set an additional color value multiplied into render copy operations.

Parameters
nom::Color4ired, green & blue values multiplied into color operations
Returns
TRUE on success; FALSE on failure
Remarks
SDL2 color modulation formula: srcC = srcC * ( color / 255 )

◆ set_colorkey()

bool nom::Image::set_colorkey ( const Color4i & colorkey,
bool flag )

Set a new color key on the image loaded into memory.

Parameters
colorkeyPixel color to mark transparent
flagTRUE to enable color key; FALSE to disable color key

◆ set_pixel()

void nom::Image::set_pixel ( int x,
int y,
const Color4i & color )

Blit a RGBA pixel onto the video surface.

Remarks
You are responsible for any necessary video surface locking and unlocking.
Note
The color depth is determined by the existing color depth of the nom::Image – 8-bit, 15/16-bit, 24-bit or 32-bit bits per pixel depths are supported.
Todo
Test 8-bit, 15/16-bit & 24-bit pixel blits

◆ unlock()

void nom::Image::unlock ( void ) const

Unlocks the video surface; this must be done after you are finished writing to the video buffer. During the time that the video surface is locked, no updates (think: rendering) outside of your local access can occur until the surfaces affected by the lock are relinquished.

Member Data Documentation

◆ bounds_

IntRect nom::Image::bounds_
private

Definition at line 311 of file Image.hpp.

◆ image_

std::shared_ptr<SDL_Surface> nom::Image::image_
private

Container for our image pixels buffer.

Definition at line 308 of file Image.hpp.

◆ position_

Point2i nom::Image::position_
private

Definition at line 310 of file Image.hpp.


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