protected override bool ProcessDecoder(MainForm form, IWICBitmapDecoder decoder, DataEntry[] de, object tag) { IWICBitmapDecoderInfo info = decoder.GetDecoderInfo(); try { info.GetCLSID(out var clsid); if (clsid != Parent.Clsid) { form.Add(this, Resources.IncorrectDecoderPickedUp, de, new DataEntry(Resources.Expected, Parent.Clsid), new DataEntry(Resources.Actual, clsid)); } else { Tag t = (Tag)tag; if (!t.SupportsMultiframe && decoder.GetFrameCount() > 1) { form.Add(this, Resources.DecoderDoesNotMultiframe, de, new DataEntry(Resources.FrameCount, decoder.GetFrameCount())); } } } finally { info.ReleaseComObject(); } return(true); }
protected override void RunOverride(ListView.ListViewItemCollection collection, object tag) { IWICImagingFactory factory = (IWICImagingFactory) new WICImagingFactory(); IWICBitmapDecoderInfo info = null; try { info = (IWICBitmapDecoderInfo)factory.CreateComponentInfo(Parent.Clsid); string[] mimes = Extensions.GetString(info.GetMimeTypes).Split(','); foreach (string ext in Extensions.GetString(info.GetFileExtensions).Split(',')) { using (RegistryKey rk = OpenSubKey(collection, Registry.ClassesRoot, ext, new DataEntry[] { new DataEntry("File Extension", ext) })) { if (rk != null) { Check(collection, ext, rk, info); } } } } finally { factory.ReleaseComObject(); info.ReleaseComObject(); } }
protected override void RunOverride(MainForm form, object tag) { IWICImagingFactory factory = (IWICImagingFactory) new WICImagingFactory(); IWICBitmapDecoderInfo info = (IWICBitmapDecoderInfo)factory.CreateComponentInfo(Parent.Clsid); Guid cf; info.GetContainerFormat(out cf); IWICBitmapDecoder decoder = null; try { decoder = info.CreateInstance(); Guid containerFormat; try { decoder.GetContainerFormat(out containerFormat); if (containerFormat != cf) { form.Add(this, Resources.ContainerFormatsDoNotMatch, new DataEntry(Resources.Actual, cf), new DataEntry(Resources.Expected, containerFormat)); } } catch (Exception e) { form.Add(this, e.TargetSite.ToString(Resources._0_Failed), new DataEntry(e)); } ComponentInfoHelper.CheckEquals <IWICBitmapDecoderInfo>(form, decoder.GetDecoderInfo, this, Extensions.CompareInfos); } finally { factory.ReleaseComObject(); info.ReleaseComObject(); decoder.ReleaseComObject(); } base.RunOverride(form, tag); }
IEnumerable <string> GetDecodableFiles(MainForm form, Guid decoderClsid) { IWICImagingFactory factory = (IWICImagingFactory) new WICImagingFactory(); IWICBitmapDecoderInfo info = null; IWICBitmapDecoder decoder = null; try { info = (IWICBitmapDecoderInfo)factory.CreateComponentInfo(decoderClsid); if (Settings.Default.Files != null) { foreach (string s in Settings.Default.Files) { IWICStream stream = factory.CreateStream(); try { stream.InitializeFromFilename(s, NativeMethods.GenericAccessRights.GENERIC_READ); bool matches = info.MatchesPattern(stream); stream.Seek(0, 0, IntPtr.Zero); decoder = info.CreateInstance(); if (decoder != null) { WICBitmapDecoderCapabilities?capabilities = null; try { capabilities = decoder.QueryCapability(stream); if (!matches) { QueryCapabilitiesError(form, string.Format(CultureInfo.CurrentUICulture, Resources.PatternDoesnotMatchButPassed, "IWICBitmapDecoder::QueryCapability(...)"), new DataEntry(s)); } } catch (Exception e) { if (Array.IndexOf(queryCapabilitiesErrors, (WinCodecError)Marshal.GetHRForException(e)) < 0) { QueryCapabilitiesError(form, e.TargetSite.ToString(Resources._0_FailedWithIncorrectHRESULT), new DataEntry(s), new DataEntry(Resources.Actual, e), new DataEntry(Resources.Expected, queryCapabilitiesErrors)); } } if (capabilities.HasValue && 0 != (uint)(capabilities.Value & (WICBitmapDecoderCapabilities.WICBitmapDecoderCapabilityCanDecodeSomeImages | WICBitmapDecoderCapabilities.WICBitmapDecoderCapabilityCanDecodeAllImages))) { yield return(s); } } } finally { stream.ReleaseComObject(); decoder.ReleaseComObject(); decoder = null; } } } } finally { factory.ReleaseComObject(); info.ReleaseComObject(); decoder.ReleaseComObject(); } }
protected override void RunOverride(MainForm form, object tag) { bool hasFile = false; bool processed = false; IWICImagingFactory factory = (IWICImagingFactory) new WICImagingFactory(); IWICBitmapDecoderInfo info = null; IWICBitmapDecoder decoder = null; try { info = (IWICBitmapDecoderInfo)factory.CreateComponentInfo(Parent.Clsid); foreach (string file in GetDecodableFiles(form, Parent.Clsid)) { decoder.ReleaseComObject(); decoder = info.CreateInstance(); hasFile = true; IWICStream stream = factory.CreateStream(); stream.InitializeFromFilename(file, NativeMethods.GenericAccessRights.GENERIC_READ); try { decoder.Initialize(stream, WICDecodeOptions.WICDecodeMetadataCacheOnDemand); if (ProcessDecoder(form, decoder, new DataEntry[] { new DataEntry(file) }, tag)) { for (uint index = 0; index < decoder.GetFrameCount(); index++) { IWICBitmapFrameDecode frame = decoder.GetFrame(index); try { if (ProcessFrameDecode(form, frame, new DataEntry[] { new DataEntry(file), new DataEntry(index) }, tag)) { processed = true; } } finally { frame.ReleaseComObject(); } } } else { processed = true; } } catch (Exception e) { form.Add(this, e.TargetSite.ToString(Resources._0_Failed), new DataEntry(file), new DataEntry(e)); } finally { stream.ReleaseComObject(); } } } finally { factory.ReleaseComObject(); info.ReleaseComObject(); decoder.ReleaseComObject(); } if (!hasFile) { form.Add(Parent, string.Format(CultureInfo.CurrentUICulture, Resources.NoFilesFor_0, Parent.Text)); } else if (!processed) { form.Add(this, string.Format(CultureInfo.CurrentUICulture, Resources.NoFilesFor_0, Text)); } }