Example #1
0
        protected override void RunOverride(MainForm form, object tag)
        {
            bool info2Supported = false;

            IWICImagingFactory   factory = (IWICImagingFactory) new WICImagingFactory();
            IWICPixelFormatInfo2 info    = null;

            try
            {
                info           = factory.CreateComponentInfo(Parent.Clsid) as IWICPixelFormatInfo2;
                info2Supported = info != null;
            }
            finally
            {
                info.ReleaseComObject();
                factory.ReleaseComObject();
            }

            if (info2Supported)
            {
                ComponentInfoHelper.Check <IWICPixelFormatInfo2, object>(form, Parent.Clsid, Check, tag, this, false);
            }
            else
            {
                ComponentInfoHelper.Check <IWICPixelFormatInfo, object>(form, Parent.Clsid, Check, tag, this, false);
            }
        }
Example #2
0
        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();
            }
        }
Example #3
0
        public static void CheckEquals <TInfo>(MainForm form, Func <TInfo> method, RuleBase <ComponentRuleGroup> rule, Func <TInfo, TInfo, DataEntry[][]> compare)
            where TInfo : class, IWICComponentInfo
        {
            IWICImagingFactory factory = (IWICImagingFactory) new WICImagingFactory();
            TInfo info = factory.CreateComponentInfo(rule.Parent.Clsid) as TInfo;
            TInfo i    = null;

            try
            {
                i = method();
                if (i == null)
                {
                    form.Add(rule, method.ToString(Resources._0_NULL));
                }
                else
                {
                    foreach (DataEntry[] de in compare(info, i))
                    {
                        form.Add(rule, string.Format(CultureInfo.CurrentUICulture, Resources.InconsistentComponentInfo, typeof(TInfo).Name, method.ToString("{0}")), de);
                    }
                }
            }
            catch (Exception e)
            {
                form.Add(rule, method.ToString(Resources._0_Failed), new DataEntry(e));
            }
            finally
            {
                i.ReleaseComObject();
                info.ReleaseComObject();
                factory.ReleaseComObject();
            }
        }
Example #4
0
        public static uint GetBitPerPixel(Guid pixelFormat)
        {
            IWICImagingFactory  factory = (IWICImagingFactory) new WICImagingFactory();
            IWICPixelFormatInfo info    = null;

            try
            {
                info = (IWICPixelFormatInfo)factory.CreateComponentInfo(pixelFormat);

                return(info.GetBitsPerPixel());
            }
            finally
            {
                factory.ReleaseComObject();
                info.ReleaseComObject();
            }
        }
Example #5
0
        protected override void RunOverride(MainForm form, object tag)
        {
            TempFileCollection    files   = null;
            IWICImagingFactory    factory = (IWICImagingFactory) new WICImagingFactory();
            IWICBitmapEncoderInfo info    = null;
            IWICBitmapEncoder     encoder = null;
            IWICStream            stream  = null;
            int i = 0;

            try
            {
                files = new TempFileCollection();
                info  = (IWICBitmapEncoderInfo)factory.CreateComponentInfo(Parent.Clsid);

                do
                {
                    stream.ReleaseComObject();
                    encoder.ReleaseComObject();
                    stream = factory.CreateStream();
                    stream.InitializeFromFilename(files.AddExtension(i.ToString(CultureInfo.InvariantCulture)), NativeMethods.GenericAccessRights.GENERIC_WRITE);
                    i++;
                    try
                    {
                        encoder = info.CreateInstance();
                        encoder.Initialize(stream, WICBitmapEncoderCacheOption.WICBitmapEncoderNoCache);
                    }
                    catch (Exception e)
                    {
                        form.Add(this, e.TargetSite.ToString(Resources._0_Failed), new DataEntry(e));
                        break;
                    }
                }while(ProcessEncoder(form, encoder, tag));
            }
            finally
            {
                factory.ReleaseComObject();
                info.ReleaseComObject();
                encoder.ReleaseComObject();
                stream.ReleaseComObject();
                if (files != null)
                {
                    files.Delete();
                }
            }
        }
Example #6
0
        public static void Check <TInfo, TTag>(MainForm form, Guid clsid, Action <MainForm, TInfo, TTag> check, TTag tag, RuleBase rule, bool checkVersions)
            where TInfo : class, IWICComponentInfo
            where TTag : class
        {
            IWICImagingFactory factory = (IWICImagingFactory) new WICImagingFactory();
            TInfo info = null;

            try
            {
                info = (TInfo)factory.CreateComponentInfo(clsid);

                CheckNotEmptyString(form, info.GetAuthor, rule);
                CheckNotEmptyString(form, info.GetFriendlyName, rule);

                if ((info.GetSigningStatus() & WICComponentSigning.WICComponentDisabled) == WICComponentSigning.WICComponentDisabled)
                {
                    form.Add(rule, Resources.ComponentDisabled);
                }

                CheckNotReserverdGuid(form, info.GetVendorGUID, rule);

                if (checkVersions || info.GetSpecVersion(0, null) > 0)
                {
                    CheckVersion(form, info.GetSpecVersion, rule);
                }
                if (checkVersions || info.GetVersion(0, null) > 0)
                {
                    CheckVersion(form, info.GetVersion, rule);
                }

                check(form, info, tag);
            }
            finally
            {
                factory.ReleaseComObject();
                info.ReleaseComObject();
            }
        }
Example #7
0
        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);
        }
Example #8
0
        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();
            }
        }
Example #9
0
        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));
            }
        }