I've been using WIC to encode multiple images to the JPEGXR format. Occassionally, my program logs an error for the last LogAssert in the following snippet of my Encode function.
hr = m_pFactory->CreateEncoder(GUID_ContainerFormatWmp, NULL, &pEncoder);
LogAssert(SUCCEEDED(hr),"Failed to create encoder. Err: 0x%x", hr);
hr = pEncoder->Initialize(pOutputStream, WICBitmapEncoderNoCache);
LogAssert(SUCCEEDED(hr),"Failed to initialize encoder. Err: 0x%x", hr);
hr = pEncoder->CreateNewFrame(&pBitmapFrame, &pPropertyBag);
LogAssert(SUCCEEDED(hr),"Encoder failed to create new frame. Err: 0x%x", hr);
SetEncodingProperties(pPropertyBag);
hr = pBitmapFrame->Initialize(pPropertyBag);
LogAssert(SUCCEEDED(hr),"Failed to initialize pBitmapFrame with the given properties. Err: 0x%x", hr);
hr = pBitmapFrame->SetSize(rawWidth, rawHeight);
LogAssert(SUCCEEDED(hr),"Failed to set bitmap size. Err: 0x%x", hr);
WICPixelFormatGUID formatGUID = GUID_WICPixelFormat24bppBGR;
hr = pBitmapFrame->SetPixelFormat(&formatGUID);
if(FAILED(hr) || !IsEqualGUID(formatGUID, GUID_WICPixelFormat24bppBGR))
{
LogAssert(false,"Failed to set pixel format to GUID_WICPixelFormat24bppBGR. Err: 0x%x", hr);
}
I checked the dump file and it seems the returned formatGUID is GUID_WICPixelFormat24bpp RGB.
I have the following questions:
When does the SetPixel format return a different version? What are the factors that could cause it to return a different GUID?
I am always encoding to JPEGXR, and always applying the same properties. Why is the behavior of SetPixelFormat non-deterministic? Shouldn't it either always succeed, or always return GUID_WICPixelFormat24bppRGB?
If the RGB format is supported, why isn't BGR? It's just a change in order.
My code, was written with the help of examples here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ee719871(v=vs.85).aspx