문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top