MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / DoLoad

Method DoLoad

GTE/Applications/MSW/WICFileIONative.cpp:265–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

263}
264
265void WICFileIONative::DoLoad(void* factory, void* frameDecode, TextureCreator const& creator)
266{
267 auto wicFactory = reinterpret_cast<IWICImagingFactory*>(factory);
268 auto wicFrameDecode = reinterpret_cast<IWICBitmapFrameDecode*>(frameDecode);
269
270 // Get the pixel format of the image.
271 WICPixelFormatGUID wicSourceGUID;
272 HRESULT hr = wicFrameDecode->GetPixelFormat(&wicSourceGUID);
273 if (FAILED(hr))
274 {
275 throw std::runtime_error("wicFrameDecode->GetPixelFormat failed.");
276 }
277
278 // Find the supported WIC input pixel format that matches a Texture2
279 // format. If a matching format is not found, the returned texture
280 // is an R8G8B8A8 format with texels converted from the source format.
281 WICPixelFormatGUID wicConvertGUID = GUID_WICPixelFormat32bppRGBA;
282 uint32_t format = R8G8B8A8;
283 for (size_t i = 0; i < NUM_LOAD_FORMATS; ++i)
284 {
285 if (IsEqualGUID(wicSourceGUID, *msLoadFormatMap[i].wicInputGUID))
286 {
287 // Determine whether there is a conversion format.
288 if (msLoadFormatMap[i].wicConvertGUID)
289 {
290 wicConvertGUID = *msLoadFormatMap[i].wicConvertGUID;
291 }
292 else
293 {
294 wicConvertGUID = *msLoadFormatMap[i].wicInputGUID;
295 }
296 format = msLoadFormatMap[i].format;
297 break;
298 }
299 }
300
301 // The wicFrameDecode value is used when no conversion is required. If
302 // the decoder does not support the format in the texture, then a
303 // conversion is required.
304 IWICBitmapSource* wicBitmapSource = wicFrameDecode;
305 ComObject<IWICFormatConverter> wicFormatConverter;
306 if (!IsEqualGUID(wicSourceGUID, wicConvertGUID))
307 {
308 // Create a WIC format converter.
309 hr = wicFactory->CreateFormatConverter(&wicFormatConverter);
310 if (FAILED(hr))
311 {
312 throw std::runtime_error("wicFactory->CreateFormatConverter failed.");
313 }
314
315 // Initialize format converter to convert the input texture format
316 // to the nearest format supported by the decoder.
317 hr = wicFormatConverter->Initialize(wicBitmapSource, wicConvertGUID,
318 WICBitmapDitherTypeNone, nullptr, 0.0, WICBitmapPaletteTypeCustom);
319 if (FAILED(hr))
320 {
321 throw std::runtime_error("wicFormatConverter->Initialize failed.");
322 }

Callers

nothing calls this directly

Calls 3

InitializeMethod · 0.45
GetMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected