WIC HEIF HEIC image decoding C++

1.7k views Asked by At

Windows Imaging Component is used for decoding heif images. However extra apps from the microsoft store (heif image extension, hevc video extensions) are required for a successful decoding of the images.

Without them the WIC api returns blank image. Now I want to be able to programatically determine whether the heif file can be correctly decoded.

I have tried to locate the existence of required decoder type using DXVA Checker which is supposed to be WIC_HEIF_Decoder. But I can't find it registered anywhere.

enter image description here

There is a GUID key however CLSID_WICHeifDecoder documented here which I think can be registered in the system even if the decoder is missing.

Does anyone have any idea how to do this?

2

There are 2 answers

1
mbaros On BEST ANSWER

Since the HEIF decoders are still recognized on Windows that can't decode them this is the best hack imo:

In order to decode HEIF images HEVC video extension should be installed on the machine. So the right check is to see if there is any decoding type matching the HEVC input

MFStartup(MF_VERSION);
IMFActivate** activate {};
unsigned int count {};
// Set the HEVC GUID
MFT_REGISTER_TYPE_INFO input;
input.guidMajorType = MFMediaType_Video;
input.guidSubtype = MFVideoFormat_HEVC;
// Get all available output types for HEVC input
MFTEnumEx(MFT_CATEGORY_VIDEO_DECODER, MFT_ENUM_FLAG_SORTANDFILTER | MFT_ENUM_FLAG_SYNCMFT, &input, nullptr, &activate, &count);
// Release interface pointers
for (size_t i = 0; i < count; i++) {
    activate[i]->Release();
}
CoTaskMemFree(activate);
MFShutdown();
return (count > 0);
7
Roman Ryltsov On

If you plan to use WIC decoder, you should rather use WIC API to check the availability and not Media Foundation API, even if both decoders are known - at the moment - to be packaged together and belong to the same Windows Store application (extension).

You should be able to use IWICImagingFactory::CreateComponentEnumerator to enumerate decoders and identify if HEIF is among the available ones.

Microsoft HEIF Decoder

  • Class Identifier: CLSID_WICHeifDecoder
  • Signing Status: WICComponentSigned
  • Author: Microsoft
  • Vendor Identifier: {F0E749CA-EDEF-4589-A73A-EE0E626A2A2B}
  • Version: 1.0.0.0
  • Spec Version: 1.0.0.0
  • Friendly Name: Microsoft HEIF Decoder
  • IWICBitmapCodecInfo:
    • Container Format: GUID_ContainerFormatHeif
    • Pixel Formats: GUID_WICPixelFormat32bppBGR
    • Color Management Version: 1.0.0.0
    • MIME Types: image/heic,image/heif,image/avci,image/heic-sequence,image/heif-sequence,image/avcs,image/avif,image/avif-sequence
    • File Extensions: .heic,.heif,.avci,.heics,.heifs,.avcs,.avif,.avifs
    • Patterns: 576

You might prefer to use IWICImagingFactory::CreateDecoder with GUID_ContainerFormatHeif because you should be more interested in ability to decode rather that in specific decoder implementation.

Check for specific CLSID is trivial, using either registry query or direct CoCreateInstance call but it does not make much sense for the specified task.