如何计算帧缓冲间距? [英] How to calculate Framebuffer pitch?
问题描述
我有一个 UI 应用程序,它分别以 16、24 或 32 bpp 将输出渲染到离屏帧缓冲区.
I got a UI application which render output to an off-screen framebuffer in 16, 24 or 32 bpp respectively.
我需要计算间距,我的理解是间距是一条扫描线中的字节数,它等于 screenx*bitsperpixel 吗?虽然显然它没有产生正确的结果.
I need to calculate pitch, my understanding is pitch is number of bytes in one scanline, is it equal to screenx*bitsperpixel? Though apparently it does not produce correct result.
我们可以有一个公式(通用)来计算音高吗?
Can we have a formula (generic) to calculate pitch?
推荐答案
根据 this:
视频内存中的缓冲区通常有一个与之相关的步幅(也称为间距).stride是以字节为单位的缓冲区的宽度
Buffers in video ram generally have a stride (also called pitch) associated with them. The stride is the width of the buffer in byte
例如,如果您有一个 16 位/像素(2 字节/像素)的 1024x768 像素缓冲区,您的步幅将是:
For example, if you have a 1024x768 pixel buffer at 16 bits/pixel (2 bytes/pixel), your stride would be:
1024 像素 * 2 字节/像素 = 2048 字节
1024 pixels * 2 bytes/pixel = 2048 bytes
所以通用的计算方式是:buffer_width * bytes_per_pixel
So the generic way to calculate it is: buffer_width * bytes_per_pixel
然而,重要的是要注意,对于平铺渲染器,帧缓冲区在内存中不是线性的,为此我认为间距是平铺的宽度(我找不到来源来确认这一点).
However it is important to note that for tile renderers the frame buffer is not linear in memory and for that i think that the pitch is the width of a tile (i can't find sources to confirm this).
这篇关于如何计算帧缓冲间距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!