NovaSVG 0.10.0
A header-only SVG library
Loading...
Searching...
No Matches
novasvg::Bitmap Class Reference

#include <bitmap.h>

Public Member Functions

 Bitmap ()=default
 Constructs a null bitmap.
 
 Bitmap (int width, int height)
 Constructs a bitmap with the specified width and height.
 
 Bitmap (uint8_t *data, int width, int height, int stride)
 Constructs a bitmap with the provided pixel data, width, height, and stride.
 
 Bitmap (const Bitmap &bitmap)
 Copy constructor.
 
 Bitmap (Bitmap &&bitmap)
 Move constructor.
 
 Bitmap (surface_t *surface)
 
 ~Bitmap ()
 Cleans up any resources associated with the bitmap.
 
Bitmap & operator= (const Bitmap &bitmap)
 Copy assignment operator.
 
Bitmap & operator= (Bitmap &&bitmap)
 Move assignment operator.
 
void swap (Bitmap &bitmap)
 Swaps the content of this bitmap with another.
 
uint8_t * data () const
 Gets the pointer to the raw pixel data.
 
int width () const
 Gets the width of the bitmap.
 
int height () const
 Gets the height of the bitmap.
 
int stride () const
 Gets the stride of the bitmap.
 
void clear (const Color &value)
 Clears the bitmap with the specified color.
 
void convertToRGBA ()
 Converts the bitmap pixel data from ARGB32 Premultiplied to RGBA Plain format in place.
 
bool isNull () const
 Checks if the bitmap is null.
 
bool valid () const
 Checks if the bitmap is valid.
 
bool writeToPng (const std::string &filename) const
 Writes the bitmap to a PNG file.
 
bool writeToPng (novasvg_write_func_t callback, void *closure) const
 Writes the bitmap to a PNG stream.
 
bool writeToBmp (const std::string &filename) const
 Writes the bitmap to a BMP file.
 
bool writeToBmp (novasvg_write_func_t callback, void *closure) const
 Writes the bitmap to a BMP stream.
 
bool writeToTga (const std::string &filename) const
 Writes the bitmap to a TGA file.
 
bool writeToTga (novasvg_write_func_t callback, void *closure) const
 Writes the bitmap to a TGA stream.
 
bool writeToJpg (const std::string &filename, int quality=80) const
 Writes the bitmap to a JPEG file.
 
bool writeToJpg (novasvg_write_func_t callback, void *closure, int quality=80) const
 Writes the bitmap to a JPEG stream.
 
bool write (const std::string &filename, int jpgQuality=80) const
 Writes the bitmap to a file, picking PNG/BMP/TGA/JPEG from filename's extension (.png/.bmp/.tga/.jpg/.jpeg; PNG if unrecognized or missing). A convenience over calling writeToPng()/writeToBmp()/etc yourself when the format doesn't need to be pinned down explicitly.
 
surface_t * surface () const
 

Detailed Description

Definition at line 26 of file bitmap.h.

Constructor & Destructor Documentation

◆ Bitmap() [1/6]

novasvg::Bitmap::Bitmap ( )
default

Constructs a null bitmap.

Referenced by operator=(), and operator=().

◆ Bitmap() [2/6]

NOVASVG_INLINE novasvg::Bitmap::Bitmap ( int  width,
int  height 
)

Constructs a bitmap with the specified width and height.

Note
A null bitmap will be returned if memory cannot be allocated.
Parameters
widthThe width of the bitmap in pixels.
heightThe height of the bitmap in pixels.

Definition at line 1638 of file bitmap.h.

◆ Bitmap() [3/6]

NOVASVG_INLINE novasvg::Bitmap::Bitmap ( uint8_t *  data,
int  width,
int  height,
int  stride 
)

Constructs a bitmap with the provided pixel data, width, height, and stride.

Parameters
dataA pointer to the raw pixel data in ARGB32 Premultiplied format.
widthThe width of the bitmap in pixels.
heightThe height of the bitmap in pixels.
strideThe number of bytes per row of pixel data (stride).

Definition at line 1643 of file bitmap.h.

◆ Bitmap() [4/6]

NOVASVG_INLINE novasvg::Bitmap::Bitmap ( const Bitmap &  bitmap)

Copy constructor.

Parameters
bitmapThe bitmap to copy.

Definition at line 1648 of file bitmap.h.

◆ Bitmap() [5/6]

NOVASVG_INLINE novasvg::Bitmap::Bitmap ( Bitmap &&  bitmap)

Move constructor.

Parameters
bitmapThe bitmap to move.

Definition at line 1653 of file bitmap.h.

◆ Bitmap() [6/6]

novasvg::Bitmap::Bitmap ( surface_t *  surface)
inline

Definition at line 66 of file bitmap.h.

◆ ~Bitmap()

NOVASVG_INLINE novasvg::Bitmap::~Bitmap ( )

Cleans up any resources associated with the bitmap.

Definition at line 1658 of file bitmap.h.

References novasvg::render::surface_destroy().

Member Function Documentation

◆ clear()

NOVASVG_INLINE void novasvg::Bitmap::clear ( const Color &  value)

Clears the bitmap with the specified color.

Parameters
valueThe color to clear with.

Definition at line 1702 of file bitmap.h.

References novasvg::render::color_init_rgba32(), novasvg::render::surface_clear(), and novasvg::Color::value().

Referenced by novasvg::Element::renderToBitmap().

◆ convertToRGBA()

NOVASVG_INLINE void novasvg::Bitmap::convertToRGBA ( )

Converts the bitmap pixel data from ARGB32 Premultiplied to RGBA Plain format in place.

Definition at line 1711 of file bitmap.h.

References novasvg::render::convert_argb_to_rgba(), data(), height(), stride(), novasvg::render::surface_get_data(), novasvg::render::surface_get_height(), novasvg::render::surface_get_stride(), novasvg::render::surface_get_width(), and width().

◆ data()

NOVASVG_INLINE uint8_t * novasvg::Bitmap::data ( ) const

Gets the pointer to the raw pixel data.

Returns
A pointer to the raw pixel data.

Definition at line 1674 of file bitmap.h.

References novasvg::render::surface_get_data().

Referenced by convertToRGBA().

◆ height()

NOVASVG_INLINE int novasvg::Bitmap::height ( ) const

Gets the height of the bitmap.

Returns
The height of the bitmap in pixels.

Definition at line 1688 of file bitmap.h.

References novasvg::render::surface_get_height().

Referenced by convertToRGBA(), and novasvg::SVGImageElement::render().

◆ isNull()

bool novasvg::Bitmap::isNull ( ) const
inline

Checks if the bitmap is null.

Returns
True if the bitmap is null, false otherwise.

Definition at line 132 of file bitmap.h.

Referenced by novasvg::Element::render(), and novasvg::SVGImageElement::render().

◆ operator=() [1/2]

Move assignment operator.

Parameters
bitmapThe bitmap to move.
Returns
A reference to this bitmap.

Definition at line 1722 of file bitmap.h.

References Bitmap(), swap(), and width().

◆ operator=() [2/2]

Copy assignment operator.

Parameters
bitmapThe bitmap to copy.
Returns
A reference to this bitmap.

Definition at line 1663 of file bitmap.h.

References Bitmap(), swap(), and width().

◆ stride()

NOVASVG_INLINE int novasvg::Bitmap::stride ( ) const

Gets the stride of the bitmap.

Returns
The number of bytes per row of pixel data (stride).

Definition at line 1695 of file bitmap.h.

References novasvg::render::surface_get_stride().

Referenced by convertToRGBA().

◆ surface()

surface_t * novasvg::Bitmap::surface ( ) const
inline

Definition at line 202 of file bitmap.h.

◆ swap()

NOVASVG_INLINE void novasvg::Bitmap::swap ( Bitmap &  bitmap)

Swaps the content of this bitmap with another.

Parameters
bitmapThe bitmap to swap with.

Definition at line 1669 of file bitmap.h.

References width().

Referenced by operator=(), and operator=().

◆ valid()

bool novasvg::Bitmap::valid ( ) const
inline

Checks if the bitmap is valid.

Deprecated:
This function has been deprecated. Use isNull() instead to check whether the bitmap is null.
Returns
True if the bitmap is valid, false otherwise.

Definition at line 139 of file bitmap.h.

◆ width()

NOVASVG_INLINE int novasvg::Bitmap::width ( ) const

Gets the width of the bitmap.

Returns
The width of the bitmap in pixels.

Definition at line 1681 of file bitmap.h.

References novasvg::render::surface_get_width().

Referenced by convertToRGBA(), operator=(), operator=(), novasvg::SVGImageElement::render(), swap(), write(), writeToBmp(), writeToJpg(), writeToJpg(), writeToPng(), and writeToTga().

◆ write()

NOVASVG_INLINE bool novasvg::Bitmap::write ( const std::string &  filename,
int  jpgQuality = 80 
) const

Writes the bitmap to a file, picking PNG/BMP/TGA/JPEG from filename's extension (.png/.bmp/.tga/.jpg/.jpeg; PNG if unrecognized or missing). A convenience over calling writeToPng()/writeToBmp()/etc yourself when the format doesn't need to be pinned down explicitly.

Parameters
filenameThe name of the file to write.
jpgQualityJPEG quality (1-100), used only when the extension picks JPEG.
Returns
True if the file was written successfully, false otherwise.

Definition at line 1838 of file bitmap.h.

References width(), writeToBmp(), writeToJpg(), writeToPng(), and writeToTga().

◆ writeToBmp() [1/2]

NOVASVG_INLINE bool novasvg::Bitmap::writeToBmp ( const std::string &  filename) const

Writes the bitmap to a BMP file.

Definition at line 1790 of file bitmap.h.

References novasvg::BitmapCodec::write_bmp().

Referenced by write().

◆ writeToBmp() [2/2]

NOVASVG_INLINE bool novasvg::Bitmap::writeToBmp ( novasvg_write_func_t  callback,
void *  closure 
) const

Writes the bitmap to a BMP stream.

Definition at line 1798 of file bitmap.h.

References width(), and novasvg::BitmapCodec::write_bmp_to_func().

◆ writeToJpg() [1/2]

NOVASVG_INLINE bool novasvg::Bitmap::writeToJpg ( const std::string &  filename,
int  quality = 80 
) const

Writes the bitmap to a JPEG file.

Parameters
qualityJPEG quality, from 1 to 100.

Definition at line 1822 of file bitmap.h.

References width(), and novasvg::BitmapCodec::write_jpg().

Referenced by write().

◆ writeToJpg() [2/2]

NOVASVG_INLINE bool novasvg::Bitmap::writeToJpg ( novasvg_write_func_t  callback,
void *  closure,
int  quality = 80 
) const

Writes the bitmap to a JPEG stream.

Parameters
qualityJPEG quality, from 1 to 100.

Definition at line 1830 of file bitmap.h.

References width(), and novasvg::BitmapCodec::write_jpg_to_func().

◆ writeToPng() [1/2]

NOVASVG_INLINE bool novasvg::Bitmap::writeToPng ( const std::string &  filename) const

Writes the bitmap to a PNG file.

Parameters
filenameThe name of the file to write.
Returns
True if the file was written successfully, false otherwise.

Definition at line 1774 of file bitmap.h.

References novasvg::BitmapCodec::write_png().

Referenced by write().

◆ writeToPng() [2/2]

NOVASVG_INLINE bool novasvg::Bitmap::writeToPng ( novasvg_write_func_t  callback,
void *  closure 
) const

Writes the bitmap to a PNG stream.

Parameters
callbackCallback function for writing data.
closureUser-defined data passed to the callback.
Returns
True if successful, false otherwise.

Definition at line 1782 of file bitmap.h.

References width(), and novasvg::BitmapCodec::write_png_to_func().

◆ writeToTga() [1/2]

NOVASVG_INLINE bool novasvg::Bitmap::writeToTga ( const std::string &  filename) const

Writes the bitmap to a TGA file.

Definition at line 1806 of file bitmap.h.

References novasvg::BitmapCodec::write_tga().

Referenced by write().

◆ writeToTga() [2/2]

NOVASVG_INLINE bool novasvg::Bitmap::writeToTga ( novasvg_write_func_t  callback,
void *  closure 
) const

Writes the bitmap to a TGA stream.

Definition at line 1814 of file bitmap.h.

References width(), and novasvg::BitmapCodec::write_tga_to_func().


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