用于 BITMAPINFOHEADER 的 VS Image Watch 扩展 natvis? [英] VS Image Watch extension natvis for BITMAPINFOHEADER?
问题描述
Visual Studio 的 Image Watch 扩展 (http://goo.gl/TWre0X) 允许您查看调试时内存中的位图.非常有用,但是我试图定义一个 natvis 文件以允许查看 DIB 或 BITMAPINFOHEADER 甚至只是 BITMAPINFOH 对象.
The Image Watch extension for Visual Studio (http://goo.gl/TWre0X) allows you to see a bitmap in memory while debugging. Extremely useful, however I am stuck trying to define a natvis file to allow for viewing DIBs or BITMAPINFOHEADER or even just BITMAPINFO objects.
这是我目前拥有的:
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<UIVisualizer ServiceId="{A452AFEA-3DF6-46BB-9177-C0B08F318025}" Id="1"
MenuName="Add to Image Watch"/>
<Type Name="BITMAPINFOHEADER">
<UIVisualizer ServiceId="{A452AFEA-3DF6-46BB-9177-C0B08F318025}" Id="1" />
</Type>
<Type Name="BITMAPINFOHEADER">
<Expand>
<Synthetic Name="[type]">
<DisplayString>UINT8</DisplayString>
</Synthetic>
<Synthetic Name="[channels]">
<DisplayString>RGB</DisplayString>
</Synthetic>
<Item Name="[width]">biWidth</Item>
<Item Name="[height]">biHeight</Item>
<Item Name="[data]">(BYTE *)$ + sizeof(BITMAPINFOHEADER) + biClrUsed * 4</Item>
<Item Name="[stride]">biBitCount*3</Item>
</Expand>
</Type>
</AutoVisualizer>
问题显然是[data]"部分,试图计算像素数据的偏移量.$ 是试图了解 natvis 文件真正在做什么的一个弱尝试.
The problem is clearly the "[data]" portion, trying to calculate the offset for the pixel data. The $ is a weak attempt at trying to understand what the natvis file is truly doing.
Image Watch 文档和一些用户定义类型的示例 natvis 文件(BITMAPINFOHEADER 如何属于用户定义,不知道为什么):http://goo.gl/zt2uCh
Docs for Image Watch and some example natvis files for user defined types (how BITMAPINFOHEADER falls under user defined, no idea why): http://goo.gl/zt2uCh
是否有人已经有一个 natvis 文件来处理和显示 Image Watch 的 BITMAPINFOHEADER 类型?或者有关于如何让这个工作的建议.谢谢.
Does anyone already have a natvis file that handles and displays the BITMAPINFOHEADER type for Image Watch? Or have a suggestion as to how to get this one to work. Thanks.
推荐答案
只需对您现有的内容稍作调整即可.
It only takes a bit of tweaking from what you have.
- 看起来您几乎可以使用调试器中的表达式,因此更改为仅使用this"代替 $
- 步幅是行的大小(以字节为单位).
- 对于结构,您必须使用标签命名空间名称,然后通过 AlternativeType 向 typedef 添加别名.
- 我的像素格式是 BGR
- 每行的字节大小必须是 4 的倍数,因此我还填充了步幅以匹配(Image Watch 似乎会丢弃不完整的像素).
<Type Name="tagBITMAPINFOHEADER">
<AlternativeType Name="BITMAPINFOHEADER"></AlternativeType>
<Expand>
<Synthetic Name="[type]">
<DisplayString Condition="biBitCount==24">UINT8</DisplayString>
<DisplayString Condition="biBitCount==32">UINT8</DisplayString>
<DisplayString Condition="biBitCount==48">UINT16</DisplayString>
</Synthetic>
<Synthetic Name="[channels]">
<DisplayString Condition="biBitCount==32">BGRA</DisplayString>
<DisplayString Condition="biBitCount==24">BGR</DisplayString>
<DisplayString Condition="biBitCount==48">BGR</DisplayString>
</Synthetic>
<Item Name="[width]">biWidth</Item>
<Item Name="[height]">biHeight</Item>
<Item Name="[data]">((BYTE *)this) + sizeof(BITMAPINFOHEADER) + (biClrUsed * 4)</Item>
<Item Name="[stride]">((biBitCount/8)*biWidth)+((4 - (((biBitCount/8)*biWidth)%4))%4)</Item>
</Expand>
</Type>
这篇关于用于 BITMAPINFOHEADER 的 VS Image Watch 扩展 natvis?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!