导致IWICBitmapFrameEncode::SetPixelFormat返回与请求的格式不同的格式的原因

What causes IWICBitmapFrameEncode::SetPixelFormat to return a format different from the requested one?

本文关键字:格式 请求 IWICBitmapFrameEncode SetPixelFormat 返回 导致      更新时间:2023-10-16

我一直在使用WIC将多个图像编码为JPEGXR格式。有时,我的程序会在下面的Encode函数片段中记录最后一个LogAssert的错误。

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);
}

我检查了转储文件,返回的formatGUID似乎是GUID_WICPixelFormat24bppRGB

我有以下问题:

  1. SetPixel格式何时返回不同的版本?可能导致它返回不同GUID的因素是什么?

  2. 我总是对JPEGXR进行编码,并且总是应用相同的属性。为什么SetPixelFormat的行为是不确定的?它不是应该总是成功,还是总是返回GUID_WICPixelFormat24bppRGB?

  3. 如果支持RGB格式,为什么不支持BGR?这只是秩序的改变。

我的代码是在以下示例的帮助下编写的:

http://msdn.microsoft.com/en-us/library/windows/desktop/ee719871(v=vs.85).aspx

这是并发调用SetPixelFormat时可能发生的问题。我听说它将在Windows 8.1中修复。