windows - Pre-multiply pixels after WIC 'Copy Pixels' call -


i have been looking @ creating pargb32 bitmaps. seems necessary produce images work post-xp menu-items.

this example http://msdn.microsoft.com/en-us/library/bb757020.aspx?s=6 interesting rather complicated have if ever used ole interfaces before. however, after studying piece of code uses wic , ole think understand how works. 1 thing confuses me comment user 'david hellerman'. summarize, states example function not complete. not take in account potential alpha information in source icon - , if there alpha data must pre-multiplied on pixel pixel basis while scanning through ppvbuffer variable.

my question has 2 parts. how detect presence of alpha data in icons while using wic instead of gdi , how go pre-multiplying in pixels if exist?

technically, sample code wrong because not account or check format of iwicbitmap object when calling copypixels. createbitmapfromhicon presumably uses specific format (that sample suggests it's 32-bit pbgra comments suggesting it's bgra) when creating bitmap, not documented msdn, , relying on @ least bad form. wic supports many pixel formats, , not of them 32-bit or rgb.

you can use wicconvertbitmapsource function (http://msdn.microsoft.com/en-us/library/windows/desktop/ee719819(v=vs.85).aspx) convert data specific, known format, in case you'll want guid_wicpixelformat32bpppbgra (you're used seeing format written pargb, wic uses oddly sensible naming convention based on order of components in array of bytes rather 32-bit ints). if converting means premultiplying data, that, point if want specific format don't need worry how gets there. can use resulting iwicbitmapsource in same way msdn sample uses iwicbitmap.

you can use iwicbitmapsource::getpixelformat (http://msdn.microsoft.com/en-us/library/windows/desktop/ee690181(v=vs.85).aspx) determine pixel format of image. however, there no way know in general whether alpha data (if format has alpha data) premultiplied, you'd have recognize format guid. use getpixelformat when want handle more 1 format specifically, still fall on wicconvertbitmapsource formats don't handle.

edit: missed part of question. it's not possible detect based on iwicbitmap whether icon had alpha channel, because wic creates bitmap alpha channel icon in cases. it's not necessary, because premultiplying alpha no-op in case.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -