将颜色查找表与 Win32 DIB 一起使用的正确方法是什么?
我正在编写一些代码来对 16 位 DICOM 图像(作为 16 位 DIB 加载到内存中)执行窗口调平。我的窗户调平代码已完成,并通过生成查找表将源像素值映射到所需的最终像素值来工作。
我不确定如何将此查找表应用于图像。我看到 BITMAPINFO 对象上有一个字段“bmiColors”,类型为 RGBQUAD[]。我尝试将查找表分配给此属性,但似乎没有效果。我也尝试过 SetDIBColorTable 函数,但它似乎对屏幕输出没有任何影响。
我正在尝试做的事情(在绘画时应用我的查找表而不是修改像素数据本身)甚至在 GDI 中受支持,或者实际上应该循环遍历像素数据本身,在位块传输之前一一更改像素值?
我使用 BitBlt 还是 SetDIBitsToDevice 函数似乎也没有什么区别。他们在这里的行为往往相同。
如果 DirectX 更容易实现我想要的目标,我愿意使用它。不过,我以前没有使用过它,因此如果提供示例代码作为答案,那就太好了。
我的代码对性能非常关键,因此我正在寻找实现此目的的最快方法,即使它可能需要更多的工作/代码。
I'm writing some code to perform window levelling on a 16 bit DICOM image (which is loaded in memory as a 16 bit DIB). My window levelling code is complete and works by generating a lookup table to map the source pixel values to the desired final pixel values.
What I'm not sure about is how to apply this lookup table to the image. I see that the BITMAPINFO object has a field on it 'bmiColors', of type RGBQUAD[]. I've tried assigning my lookup table to this property but it seems to have no effect. I've also tried the SetDIBColorTable function but it too doesn't seem to have any effect on the screen output.
Is what I'm trying to do (apply my lookup table while painting rather than modifying the pixel data itself) even supported in GDI, or is one actually supposed to loop through the pixel data itself changing the pixel values one by one before blitting?
It also doesn't seem to make a difference whether I use the BitBlt or SetDIBitsToDevice functions. They both tend to behave the same here.
I'm open to using DirectX if that would be easier to achive what I want. I haven't used it before though so sample code would be nice if it's offered as an answer.
My code is very performance critical so I'm looking for the fastest way to achieve this, even if it may involve more effort/code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
颜色表仅用于 8-bpp 或以下的位图,因此 GDI 将在 16-bpp 图像中忽略它们。
(该表最多可以有 256 种颜色,按字节索引。)
(从技术上讲,该表仍可用于指定哪些颜色最重要,但这对您没有帮助,而且我不确定它是否真的被任何东西使用这些天。)
我还发现 GDI 在索引颜色模式下工作不可靠,所以我不推荐它。
(请参阅我的问题,虽然它与您正在做的事情不同,但它应该让您不再依赖 GDI。它是关于从 16-bpp 或 32-bpp 转换为索引颜色,以及 GDI 在做时遇到的问题准确地说:GDI 无法转换为具有精确调色板的索引颜色?< /a> - 另外,其中链接的代码设置了一些索引颜色位图,因此您可能会发现它很有用,但我认为它们无论如何都不适用于您使用 16-bpp 数据所做的事情。
)你正在做什么,我建议你自己直接修改位图数据,使用 std::map 之类的东西作为快速查找表,用于从一组颜色转换为另一组颜色。
Color tables are only used for bitmaps which have 8-bpp or below, so GDI will ignore them in your 16-bpp images.
(The table can have at most 256 colors, indexed by bytes.)
(Technically, the table may still be used to specify which colors are most important but that doesn't help you, and I'm not sure that's really used by anything these days.)
I have also found GDI to be unreliable at working in indexed-color modes, so I would not recommend it.
(See my question here, although it's not about the same thing as you are doing it should put you off relying on GDI for this. It's about converting from 16-bpp or 32-bpp into indexed color, and the problems GDI has at doing that accurately: GDI fails conversion to indexed color with exact palette? -- Also, the code linked in there sets up some indexed-color bitmaps so you may find it useful, but I don't think they will apply to what you're doign with 16-bpp data anyway.)
For what you're doing, I'd recommend modifying the bitmap data directly yourself, using something like an std::map as a fast lookup table for converting from one set of colors to the other.