I am using WICConvertBitmapSource
function to convert pixel format from BGR to Gray and I'm getting unexpected pixel values.
...
pIDecoder->GetFrame( 0, &pIDecoderFrame );
pIDecoderFrame->GetPixelFormat( &pixelFormat ); // GUID_WICPixelFormat24bppBGR
IWICBitmapSource * dst;
WICConvertBitmapSource( GUID_WICPixelFormat8bppGray, pIDecoderFrame, &dst );
Example on 4x3 image with following BGR pixel values:
[ 0, 0, 255, 0, 255, 0, 255, 0, 0;
0, 255, 255, 255, 255, 0, 255, 0, 255;
0, 0, 0, 119, 119, 119, 255, 255, 255;
233, 178, 73, 233, 178, 73, 233, 178, 73]
Gray pixel values I am getting:
[127, 220, 76;
247, 230, 145;
0, 119, 255;
168, 168, 168]
Gray pixel values I expected to get (ITU-R BT.601 conversion)
[ 76, 149, 29;
225, 178, 105;
0, 119, 255;
152, 152, 152]
What kind of conversion is happening in the background, and is there a way to force conversion to my wanted behaviour?
Also worth mentioning, the conversions are working properly (as expected) for Gray -> BGR and BGRA -> BGR