static Guid[] GetAllPixelFormats() { List <Guid> res = new List <Guid>(); IWICImagingFactory factory = (IWICImagingFactory) new WICImagingFactory(); IEnumUnknown eu = factory.CreateComponentEnumerator(WICComponentType.WICPixelFormat, WICComponentEnumerateOptions.WICComponentEnumerateRefresh); int hr = 0; object[] o = new object[1]; while (hr == 0) { uint fetched = 0; hr = eu.Next(1, o, ref fetched); if (fetched == 1) { IWICPixelFormatInfo info = (IWICPixelFormatInfo)o[0]; Guid guid; info.GetFormatGUID(out guid); res.Add(guid); info.ReleaseComObject(); } o.ReleaseComObject(); } return(res.ToArray()); }
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(); } }
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())); } }