本页内容

C

Qul::Image Struct

struct Qul::Image

一种允许直接访问像素数据的图像表示形式。更多...

Header: #include <qul/image.h>
Since: Qt Quick Ultralite 1.5

公共函数

Image()
Image(int width, int height, Qul::PixelFormat pixelFormat)
Image(uint8_t *bits, int width, int height, Qul::PixelFormat pixelFormat, int bytesPerLine = -1, Qul::Image::CleanupFunction cleanupFunction = nullptr)
void beginWrite()
uint8_t *bits()
const uint8_t *bits() const
int bitsPerPixel() const
int bytesPerLine() const
void endWrite()
int height() const
Qul::PixelFormat pixelFormat() const
void reallocate(int width, int height, Qul::PixelFormat pixelFormat)
int width() const
operator Qul::SharedImage() const

静态公共成员

const uintptr_t requiredAlignment
const uintptr_t requiredPixelWidthAlignment

详细说明

您可以使用 Image 将图像数据传递给Qt Quick Ultralite 渲染器。Image 既可以在堆上分配新的图像数据,也可以接受您单独准备的内存。

// Allocate new image data on the heap
Qul::Image image1(drawImgSize, drawImgSize, Qul::PixelFormat_ARGB32_Premultiplied);

// Uses the data at myimagedata without a copy.
// (no cleanup function passed in, so lifetime of myimagedata must exceed any use)
// Application should take care about memory and texture width alignment
Qul::Image image2(getLogoData(),
                  logoImgWidth,
                  logoImgHeight,
                  Qul::PixelFormat_ARGB32_Premultiplied);

Image 会拥有传入数据的所有权。如果当最后一个 Image 或SharedImage 引用被销毁时需要进行任何清理,请向构造函数传递一个cleanupFunction。

Image 实例一旦构建完成,图像数据仅可在调用beginWrite() 和endWrite() 之间进行修改(参见ImageWriteGuard )。

注意:某些 平台要求地址对齐,或者要求图像数据的每行字节数必须对齐到像素的特定倍数:

bytesPerLine % (bytesPerPixel * requiredPixelWidthAlignment) == 0

平台通常并不支持所有的 PixelFormats。请参阅Image::requiredAlignment 和Image::requiredPixelWidthAlignment 。

另请参阅 SharedImage 和ImageWriteGuard 。

成员函数文档

Image::Image()

创建一个空图像。

Image::Image(int width, int height, Qul::PixelFormat pixelFormat)

通过在堆上分配新的图像数据来构建。

并非所有平台都支持所有pixelFormat 。格式不受支持的图像不会被绘制,但不会引发错误。

Image::Image(uint8_t *bits, int width, int height, Qul::PixelFormat pixelFormat, int bytesPerLine = -1, Qul::Image::CleanupFunction cleanupFunction = nullptr)

从外部拥有的内存中构建。

Image 获取对bits 的所有权。当对该数据的最后一个引用(包括SharedImage 引用)被销毁时,将执行cleanupFunction 。

某些平台对图像数据有特定要求。如果未满足这些要求,应用程序将输出错误并终止。请参阅Image::requiredAlignment 和Image::requiredPixelWidthAlignment 。

并非所有平台都支持所有pixelFormat 。格式不受支持的图像不会被绘制,但不会引发错误。

bits 对应的图像数据仅可在调用beginWrite() 和endWrite() 之间进行修改。另请参阅ImageWriteGuard 。

如果bytesPerLine 为 -1,则根据width 和pixelFormat 进行计算。

void Image::beginWrite()

为写入操作准备所引用的内存。

在向分配的内存区域写入数据之前,请调用此函数,以避免可能出现的图像瑕疵。操作完成后,请调用endWrite()。

许多平台支持异步运行的硬件加速绘制操作。此函数会等待所有从指定内存区域读取数据的此类操作完成。在其他平台上,写入操作完成后可能需要将图像上传到 GPU 内存中。

注意:如果在 调用endWrite() 之前需要使用该图像进行渲染,则屏幕上将不会显示任何内容。

另请参阅 endWrite()。

uint8_t *Image::bits()

返回用于读取或写入的图像像素数据。

注意: 对像素数据的修改 必须位于调用beginWrite()和endWrite()之间。

const uint8_t *Image::bits() const

返回图像像素数据以便读取。

int Image::bitsPerPixel() const

返回图像的每像素位数。

int Image::bytesPerLine() const

返回每行的图像字节数。

void Image::endWrite()

结束对所引用的内存的写入操作。

这可能会触发 dcache 刷新以准备异步读取操作,或者将图像数据上传到 GPU 内存。

如果图像数据当前在屏幕上可见,则会为下一帧重新绘制该图像。

另请参阅 beginWrite()。

int Image::height() const

返回图像的高度(以像素为单位)。

Qul::PixelFormat Image::pixelFormat() const

返回图像PixelFormat 。

void Image::reallocate(int width, int height, Qul::PixelFormat pixelFormat)

更改图像的大小和格式,这将影响所有现有的引用。

这将对现有图像数据执行清理函数,并在堆上为给定的width 、height 和pixelFormat 分配新的图像数据以替换原有数据。

所有对该 Image 的引用都将更新为新的图像数据。

int Image::width() const

返回图像的宽度(以像素为单位)。

Image::operator Qul::SharedImage() const

隐式转换为SharedImage 。

Image和SharedImage 使用对底层数据的同一引用计数。

成员变量文档

const uintptr_t Image::requiredAlignment

该平台对图像数据要求的最小对齐程度。

另请参阅 Image::requiredPixelWidthAlignment 。

const uintptr_t Image::requiredPixelWidthAlignment

该平台要求图片宽度必须是该值的倍数。

另请参阅 Image::requiredAlignment 。

在某些 Qt 许可下可用。
了解更多信息。