Width vs. Pitch

1.单位不同,width是像素,pitch是字节。因此一个640*480的8位图和640*480的32位
图他们width一样而pitch不一样。

2.pitch可能大于width个像素所占字节数。width就是图像实际显示的宽度;而pitch 是存储一行图像所占的字节(相邻两行起点指针的差值),有时为了高效处理,会将每 行图像都对齐存储,这样pitch就包括了对齐使用的填充字节。


Although the terms width and pitch are often used informally, they have very important, and distinctly different, meanings.虽然对术语宽度和pitch的使用经常不很正式,但它们有着非常重要并且完全不同的意义。As a result, you should understand the meanings for each, and how to interpret the values that Direct3D uses to describe them.因此,开发人员应该理解它们的意义,以及如何解释Microsoft® Direct3D®用于描述它们的值。

    Direct3D uses the D3DSURFACE_DESC structure to carry information describing a surface. Direct3D使用D3DSURFACE_DESC结构保存描述表面的信息。 Among other things, this structure is defined to contain information about a surface's dimensions, as well as how those dimensions are represented in memory. 其中,这个结构包含了表面的大小,以及这些大小在内存中是如何表示的。The structure uses the Height and Width members to describe the logical dimensions of the surface, Both members are measured in pixels.  结构使用Height和Width成员描述表面的逻辑大小,这两个成员都以像素为单位。Therefore, the Height and Width values for a 640 x 480 surface are the same whether it is an 8-bit surface or a 24-bit RGB surface.因此,对于一个640x480表面来说,无论它是8位表面或24位RGB表面,它的Height和Width值都是相同的。

    hen you lock a surface using the LockRect method, the method fills in a D3DLOCKED_RECT structure that contains the pitch of the surface and a pointer to the locked bits. 应用程序使用IDirect3DSurface9::LockRect方法锁定一个表面时,该方法会填写一个D3DLOCKED_RECT结构,这个结构 包含了表面的pitch值及一个指向被锁定数据的指针。The value in the Pitch member describes the surface's memory pitch, also called stride. Pitch成员的值描述了表面在内存中的pitch,也被称为跨度。Pitch is the distance, in bytes, between two memory addresses that represent the beginning of one bitmap line and the beginning of the next bitmap line.Pitch是两个内存地址间以字节为单位的距离,两个内存地址分别表示一个位图某一行的起始地址以及下一行的起始地址。Because pitch is measured in bytes rather than pixels, a 640x480x8 surface has a very different pitch value than a surface with the same dimensions but a different pixel format. 因为pitch是以字节为单位而非以像素为单位,所以一个640x480x8表面的pitch值与另一个大小相同但像素格式不同的表面的pitch值会大 不相同。 Additionally, the pitch value sometimes reflects bytes that Direct3D has reserved as a cache, so it is not safe to assume that pitch is just the width multiplied by the number of bytes per pixel. 另外,pitch值有时反映出被Direct3D保留并用作高速缓存的字节数,因此简单地认为pitch就是宽度乘以每个像素所占的字节数是不安全的。 Rather, visualize the difference between width and pitch as shown in the following illustration.如下图所示,对宽度和pitch之间的区别做一个直观的比较会更清楚。

Pitch and width difference

Aa911077.c4e12993-102e-4735-9483-303bd959554b(en-us,MSDN.10).gif

In this figure, the front buffer and back buffer are both 640x480x8, and the cache is 384x480x8. 在这张图中,前后缓存都是640x480x8, 高速缓存为384x480x8。When accessing surfaces directly, take care to stay within the memory allocated for the dimensions of the surface and stay out of any memory reserved for cache. 当 直接访问表面时要小心,不要访问为表面分配的内存以外的地方,更不要访问任何为高速缓存目的而保留的内存。Additionally, when you lock only a portion of a surface, you must stay within the rectangle you specify when locking the surface.另外,当应用程序锁定一个表面的一部分时,应用程序必须保持在锁定表面时指定的矩形区域内。Failing to follow these guidelines will have unpredictable results. 不按这些指导方针行事将会导致无法预料的结果。When rendering directly into surface memory, always use the pitch returned by the LockRect method. 当直接渲染到表面内存时,应该总是使用由IDirect3DSurface9::LockRect方法返回的pitch 值。Do not assume a pitch based solely on the display mode. 不要认为pitch仅取决于显示模式。 If your application works on some display adapters but looks garbled on others, this may be the cause of the problem.如果应用程序在一些显示适配器上运行良好,但在另一些适配器上显示不正确的话,很可能就是pitch的问题。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值