Esempio n. 1
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();
            }
        }
Esempio n. 2
0
        void Check(MainForm form, IWICPixelFormatInfo info, object tag)
        {
            uint bpp = info.GetBitsPerPixel();

            if (bpp == 0)
            {
                form.Add(this, Resources.ZeroBPP);
            }

            uint count = info.GetChannelCount();

            if (count == 0)
            {
                form.Add(this, Resources.ZeroChannelCount);
            }

            byte[][] channelMasks = new byte[count][];
            Dictionary <int, List <uint> > dups = new Dictionary <int, List <uint> >();

            byte[] fullMask = new byte[(bpp + 7) / 8];
            for (uint i = 0; i < count; i++)
            {
                DataEntry[] de   = new DataEntry[] { new DataEntry(Resources.Channel, i) };
                byte[]      mask = new byte[info.GetChannelMask(i, 0, null)];
                if (mask.Length > 0)
                {
                    info.GetChannelMask(i, (uint)mask.Length, mask);
                }

                if (mask.Length != (bpp + 7) / 8)
                {
                    form.Add(this, Resources.IncorrectMaskLegth, de, new DataEntry(Resources.Expected, (bpp + 7) / 8), new DataEntry(Resources.Actual, mask.Length));
                }
                byte[] fullMaskSaved = fullMask.Clone() as byte[];
                for (int k = 0; k < fullMask.Length && k < mask.Length; k++)
                {
                    fullMask[k] |= mask[k];
                }
                if (fullMaskSaved.ItemsEqual(fullMask))
                {
                    form.Add(this, Resources.IncorrectChannelMask, de, new DataEntry(Resources.Mask, mask));
                }

                int idx = Array.FindIndex(channelMasks, mask.ItemsEqual);
                if (idx >= 0)
                {
                    List <uint> r;
                    if (!dups.TryGetValue(idx, out r))
                    {
                        r         = new List <uint>();
                        dups[idx] = r;
                        r.Add((uint)idx);
                    }
                    r.Add(i);
                }
                channelMasks[(int)i] = mask;
            }

            foreach (List <uint> l in dups.Values)
            {
                form.Add(this, Resources.DuplicatedChannelMask, new DataEntry(Resources.Channel, l.ToArray()));
            }
        }