VS Image Watch extension natvis for BITMAPINFOHEADER?

ぃ、小莉子 提交于 2019-12-11 03:48:55

问题


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.

Here is what I currently have:

  <?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>

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.

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

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.


回答1:


It only takes a bit of tweaking from what you have.

  • It looks like you can use pretty much the expression from the debugger, so change to just to use "this" inplace of $
  • the stride is the size of the row in bytes.
  • For structs you have to use the tag namespace name and then add an alias to the typedef via AlternativeType.
  • My Pixel format was BGR
  • Each row's size in bytes must be a multiple of 4, so I also pad out the stride to match (Image Watch seems to discard incomplete pixels).

<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>



来源:https://stackoverflow.com/questions/25063272/vs-image-watch-extension-natvis-for-bitmapinfoheader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!