Exemple #1
0
        private void Check(MainForm form, IWICBitmapDecoderInfo info, Tag tag)
        {
            ComponentInfoHelper.CheckNotReserverdGuid(form, info.GetContainerFormat, this);

            tag.PixelFormats = PixelFormatInfoRule.CheckPixelFormats(form, this, info.GetPixelFormats);

            ComponentInfoHelper.CheckVersion(form, info.GetColorManagementVersion, this);
            ComponentInfoHelper.CheckCommaSeparatedString(form, info.GetMimeTypes, ComponentInfoHelper.MimeMask, this);

            tag.Extensions = ComponentInfoHelper.CheckCommaSeparatedString(form, info.GetFileExtensions, ComponentInfoHelper.ExtensionMask, this);

            if (!info.DoesSupportMultiframe() && info.DoesSupportAnimation())
            {
                form.Add(this, Resources.DecoderAnimationIfMultiframe);
            }
            tag.SupportsMultiframe = info.DoesSupportMultiframe();

            uint size = info.GetPatterns(0, IntPtr.Zero, out var count);

            if (size != 0)
            {
                IntPtr p = Marshal.AllocCoTaskMem((int)size);
                try
                {
                    info.GetPatterns(size, p, out count);

                    WICBitmapPattern[] patterns = PropVariantMarshaler.ToArrayOf <WICBitmapPattern>(p, (int)count);
                    int index = 0;
                    var dups  = new HashSet <int>();
                    foreach (WICBitmapPattern pattern in patterns)
                    {
                        index++;
                        if (pattern.Length == 0)
                        {
                            form.Add(this, Resources.PatternZeroLength, new DataEntry(Resources.PatternIndex, index));
                        }
                        else if (index < patterns.Length)
                        {
                            if (Array.FindIndex(patterns, index, delegate(WICBitmapPattern obj) { return(obj.EndOfStream == pattern.EndOfStream && obj.Position == pattern.Position && GetNormalizedMask(obj).ItemsEqual(GetNormalizedMask(pattern))); }) >= 0)
                            {
                                dups.Add(index);
                            }
                        }
                    }
                    if (dups.Count > 0)
                    {
                        form.Add(this, Resources.PatternDuplicated, new DataEntry(Resources.PatternIndices, dups.ToArray()));
                    }
                }
                finally
                {
                    Marshal.FreeCoTaskMem(p);
                }
            }

            if (count == 0 || size == 0)
            {
                form.Add(this, Resources.PatternNo);
            }
        }
Exemple #2
0
        private static byte[] GetNormalizedMask(WICBitmapPattern pattern)
        {
            byte[] t    = PropVariantMarshaler.ToArrayOf <byte>(pattern.Pattern, (int)pattern.Length);
            byte[] mask = PropVariantMarshaler.ToArrayOf <byte>(pattern.Mask, (int)pattern.Length);

            for (int i = 0; i < t.Length; i++)
            {
                t[i] &= mask[i];
            }

            return(t);
        }
Exemple #3
0
        WICRawToneCurvePoint[] CheckGetSupported(MainForm form, bool supported, Func <uint, IntPtr, uint> getter, DataEntry[] de)
        {
            WICRawToneCurvePoint[] value = null;
            uint   size = 0;
            IntPtr p    = IntPtr.Zero;

            try
            {
                try
                {
                    size = getter(0, IntPtr.Zero);
                    if (supported)
                    {
                        if (size > 0)
                        {
                            p = Marshal.AllocCoTaskMem((int)size);
                        }
                    }
                    else
                    {
                        form.Add(this, getter.ToString(Resources._0_ShouldFail, "0, NULL, ..."), de, new DataEntry(Resources.Expected, WinCodecError.WINCODEC_ERR_UNSUPPORTEDOPERATION));
                    }
                }
                catch (Exception e)
                {
                    if (supported)
                    {
                        form.Add(this, getter.ToString(Resources._0_Failed, "0, NULL, ..."), de, new DataEntry(e));
                    }
                    else
                    {
                        form.CheckHRESULT(this, WinCodecError.WINCODEC_ERR_UNSUPPORTEDOPERATION, e, "0, NULL, ...", de);
                    }
                }

                if (size > 0)
                {
                    try
                    {
                        uint newSize = getter(size, p);
                        if (newSize == size)
                        {
                            newSize = (uint)Marshal.ReadInt32(p);
                            value   = PropVariantMarshaler.ToArrayOf <WICRawToneCurvePoint>(new IntPtr(p.ToInt64() + Marshal.SizeOf(newSize)), (int)newSize);
                        }
                        else
                        {
                            form.Add(this, getter.ToString(Resources._0_NotExpectedValue), de, new DataEntry(Resources.Expected, size), new DataEntry(Resources.Actual, newSize));
                        }
                    }
                    catch (Exception e)
                    {
                        form.Add(this, getter.ToString(Resources._0_Failed), de, new DataEntry(e));
                    }
                }
            }
            finally
            {
                Marshal.FreeCoTaskMem(p);
            }

            return(value);
        }