BasicImage< FormatT, TraitsT > Class Template Reference

#include <Pt/Gfx/Image.h>

Image that owns or wraps pixel data. More...

Inherits ViewBase.

Public Member Functions

 BasicImage (const Format &format=FormatT::get())
 Constructs an empty image.
 BasicImage (Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding, const Format &format=FormatT::get())
 Constructs an image of the given size with row padding.
 BasicImage (Pt::ssize_t width, Pt::ssize_t height, const Format &format=FormatT::get())
 Constructs an image of the given size.
 BasicImage (Pt::uint8_t *data, Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding, const Format &format=FormatT::get())
 Constructs an image over external pixel data with row padding.
 BasicImage (Pt::uint8_t *data, Pt::ssize_t width, Pt::ssize_t height, const Format &format=FormatT::get())
 Constructs an image over external pixel data.
 BasicImage (const BasicImage &image)
 Copy constructor.
virtual ~BasicImage ()
 Destructor.
void reset (Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding, const Format &format)
 Reset to new size.
void reset (Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding)
 Reset to new size, keep existing format.
void reset (Pt::uint8_t *data, Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding, const Format &format)
 Reset to new data.
void reset (Pt::uint8_t *data, Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding)
 Reset to new data, keep existing format.
void clear ()
 Clears the image.

Detailed Description

template<typename FormatT, typename TraitsT>
class Pt::Gfx::BasicImage< FormatT, TraitsT >

BasicImage is the image type both families use. A typed image such as Argb32Image is this template with a concrete format. Image is this template with ImageFormat, so the format is chosen at run time. Width, height, and stride come from ViewBase.

Constructors that take width and height allocate a buffer the image owns. Constructors that take a data pointer wrap that buffer without copying it; the caller keeps the memory valid for the lifetime of the image. The optional padding is extra bytes after each row. reset() repeats either construction. clear() releases an owned buffer or drops a wrap. Copying an owning image copies the pixels. Copying a wrapped image copies the pointer, not the pixels, and does not take ownership.

data() is the first byte of the first row. format() is the format used to interpret those bytes. Use the free functions view(), pixelView(), and lineView() to look at a region without copying.

The example allocates an ARGB-32 image and wraps the same dimensions over an external buffer. The second image does not own bits.

Pt::Gfx::Argb32Image owned(64, 48);
std::vector<Pt::uint8_t> bits(64 * 48 * 4);
Pt::Gfx::Argb32Image wrapped(bits.data(), 64, 48);
ARGB-32 image.
Definition Api-Argb32Image.h:30