Ejemplo n.º 1
0
        public static WICBitmapPattern[] GetPatterns(this IWICBitmapDecoderInfo bitmapDecoderInfo)
        {
            int count;
            int size;

            bitmapDecoderInfo.GetPatterns(0, IntPtr.Zero, out count, out size);
            if (count == 0)
            {
                return(new WICBitmapPattern[0]);
            }
            using (var buffer = new CoTaskMemPtr(Marshal.AllocCoTaskMem(size)))
            {
                bitmapDecoderInfo.GetPatterns(size, buffer, out count, out size);
                IntPtr at       = buffer;
                var    patterns = new WICBitmapPattern[count];
                for (int i = 0, stride = Marshal.SizeOf(typeof(WICBitmapPatternRaw)); i < count; ++i, at += stride)
                {
                    var raw    = (WICBitmapPatternRaw)Marshal.PtrToStructure(at, typeof(WICBitmapPatternRaw));
                    int length = raw.Length;
                    patterns[i] = new WICBitmapPattern()
                    {
                        Length      = length,
                        Position    = raw.Position,
                        Pattern     = new byte[length],
                        Mask        = new byte[length],
                        EndOfStream = raw.EndOfStream
                    };
                    Marshal.Copy(raw.Pattern, patterns[i].Pattern, 0, length);
                    Marshal.Copy(raw.Mask, patterns[i].Mask, 0, length);
                }
                return(patterns);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        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 count;
            uint size = info.GetPatterns(0, IntPtr.Zero, out 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;
                    HashSet<int> 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);
            }
        }