Blend2D
2D Vector Graphics Engine
2D raster image [C++ API].
Raster image holds pixel data and additional information such as pixel format. The underlying image data can be shared between multiple instances of BLImage, which can be used by multiple threads. Atomic reference counting is used to safely manage the internal reference count of the underlying image data.
When an image is copied to another BLImage instance its called a weak-copy as the underlying data is not copied, but the reference count is increased instead (atomically). Since atomic operations involve a minor overhead Blend2D implements also move operations, which are the most efficient operations that can be used to move one instance to another.
Creates a default constructed image, which is an empty image having pixel format equal to BL_FORMAT_NONE.
Copy constructor creates a weak copy of other
image by incrementing the reference count of the underlying representation.
Move constructor moves other
image this this image and sets other
image to a default constructed state.
This is the most efficient operation as the reference count of the underlying image is not touched by a move operation.
Creates a new image data of [w, h]
size (specified in pixels) having the given pixel format
.
To create a valid image, both w
and h
must be greater than zero and the pixel format
cannot be BL_FORMAT_NONE.
operator bool()
or verifying the image is not empty(). Destroys the image data held by the instance.
The pixel data held by the image will only be deallocated if the reference count of the underlying representation gets decremented to zero.
Returns whether the image holds any data, which means that both width and height are greater than zero and that the pixel format is not BL_FORMAT_NONE (which would never be true if the size is non-zero).
Copy assignment replaces the underlying data of this image with a weak-copy of the other
image.
Move assignment replaces the underlying data of this image with the other
image and resets other
image to a default constructed image. This operation is the fastest operation to change the underlying data of an image as moving doesn't involve reference counting in most cases.
Tests whether this image is equal with other
image , see equals() for more details about image equality.
Tests whether this image is not equal with other
image , see equals() for more details about image equality.
Resets the image to a default constructed image.
A default constructed image has zero size and a pixel format equal to BL_FORMAT_NONE. Such image is considered empty() and holds no data that could be used by the rendering context or as a pattern.
Copy assignment replaces the underlying data of this image with other
, see operator=() for more details.
Move assignment replaces the underlying data of this image with other
and resets other
image to a default constructed state, see operator=() for more details.
Create a deep copy of the other
image.
Tests whether the image is empty (such image has no size and a pixel format is equal to BL_FORMAT_NONE).
operator bool()
, which does the reverse of empty() - it checks whether the image is actually holding pixel data. Tests whether the image is equal to other
image.
Images are equal when the size, pixel format, and pixel data match. This means that this operation could be very expensive if the images are large.
Creates a new image of a specified width w
, height h
, and format
.
Creates a new image from external data passed in pixelData
.
Blend2D can use pixel-data allocated outside of Blend2D, which is useful for rendering into images that can be allocated by other libraries such as AGG, Cairo, Qt, Windows API (DIBSECTION), etc.. The only thing that the user should pay extra attention to is the passed pixel format
and stride
.
If the image data you are passing is read-only, pass BL_DATA_ACCESS_READ in accessFlags
, in that case Blend2D would never attempt to modify the passed data and would create a copy instead if such image gets modified.
Additionally, if you would like to get notified about the destruction of the image (and thus Blend2D not holding the passed pixelData
anymore, pass your own function in destroyFunc
parameter with an optional userData
).
Returns image width (in pixels).
Returns image height (in pixels).
Returns image format, see BLFormat.
Returns image depth (in bits).
Returns immutable in dataOut
, which contains pixel pointer, stride, and other image properties like size and pixel format.
pixelData
pointer, the data is immutable. If you intend to modify the data, use makeMutable() function instead, which would copy the image data if it's shared with another BLImage instance. Makes the image data mutable and returns them in dataOut
.
Converts the image to a different pixel format
.
This operation could be lossy if the given pixel format
has less channels than this image.
Reads an image from a file specified by fileName
.
Image reader will automatically detect the image format by checking whether it's supported by available image codecs, which can be retrieved by BLImageCodec::builtInCodecs().
Reads an image from a file specified by fileName
by using image codecs passed via codecs
parameter.
Image reader will automatically detect the image format by checking whether it's supported by the passed image codecs
- only codecs passed in will be considered.
Reads an image from an existing byte-array starting at data
and having size
bytes.
Image reader will automatically detect the image format by checking whether it's supported by available image codecs, which can be retrieved by BLImageCodec::builtInCodecs().
Reads an image from an existing byte-array starting at data
and having size
bytes by using image codecs passed via codecs
parameter.
Image reader will automatically detect the image format by checking whether it's supported by the passed image codecs
- only codecs passed in will be considered.
Reads an image from an existing byte-buffer passed via array
.
Image reader will automatically detect the image format by checking whether it's supported by available image codecs, which can be retrieved by BLImageCodec::builtInCodecs().
Reads an image from an existing byte-buffer passed via array
by using image codecs passed via codecs
parameter.
Image reader will automatically detect the image format by checking whether it's supported by the passed image codecs
- only codecs passed in will be considered.
Reads an image from an existing byte-view passed via view
.
Image reader will automatically detect the image format by checking whether it's supported by available image codecs, which can be retrieved by BLImageCodec::builtInCodecs().
Reads an image from an existing byte-view passed via view
by using image codecs passed via codecs
parameter.
Image reader will automatically detect the image format by checking whether it's supported by the passed image codecs
- only codecs passed in will be considered.
Writes an encoded image to a file specified by fileName
.
Image writer detects the image codec by inspecting the extension of a file passed via fileName
.
Writes an encoded image to a file specified by fileName
using the specified image codec
to encode the image.
Writes an encoded image to a buffer dst
using the specified image codec
to encode the image.
Scales the src
image to the specified size
by using filter
and writes the scaled image to dst
.
If the destination image dst
doesn't match size
and the source pixel format the underlying image data will be re-created.