1

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:

  1. When does the SetPixel format return a different version? What are the factors that could cause it to return a different GUID?

  2. 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?

  3. 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

Sau
  • 326
  • 2
  • 15

1 Answers1

0

This is an issue that can happen with concurrent calls to SetPixelFormat. I've heard it will be fixed in Windows 8.1.

guest
  • 1