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); } }
private void Check(MainForm form, IWICFormatConverterInfo info, object tag) { Guid[] pixelFormats = PixelFormatInfoRule.CheckPixelFormats(form, this, info.GetPixelFormats); Type type = Type.GetTypeFromCLSID(Parent.Clsid); if (type == null) { form.Add(this, Resources.PixelFormatConverterNotCreatable); } else { IWICImagingFactory factory = (IWICImagingFactory) new WICImagingFactory(); foreach (Guid g in pixelFormats) { bool supportsTo = false; bool supportsFrom = false; foreach (Guid c in canonical) { supportsTo |= CheckConvertion(form, info, g, c); supportsFrom |= CheckConvertion(form, info, c, g); } if (!supportsTo) { form.Add(this, Resources.ToCannonicalNotSupported, new DataEntry(Resources.PixelFormat, g)); } if (!supportsFrom) { form.Add(this, Resources.FromCannonicalNotSupported, new DataEntry(Resources.PixelFormat, g)); } } } }
void Check(MainForm form, IWICBitmapEncoderInfo 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(); }
protected override bool ProcessFrameDecode(MainForm form, IWICBitmapFrameDecode frame, DataEntry[] de, object tag) { CheckGetColorContexts(form, de, frame.GetColorContexts); CheckGetBitmapSource(form, de, frame.GetThumbnail, WinCodecError.WINCODEC_ERR_CODECNOTHUMBNAIL); uint width; uint height; frame.GetSize(out width, out height); Guid pixelFormat; frame.GetPixelFormat(out pixelFormat); uint stride = (PixelFormatInfoRule.GetBitPerPixel(pixelFormat) * width + 7) / 8; byte[] buffer = new byte[stride * height]; WICRect rect = new WICRect(); rect.Height = (int)Math.Min(height, int.MaxValue); rect.Width = (int)Math.Min(width, int.MaxValue); try { frame.CopyPixels(rect, stride, stride * height, buffer); try { frame.CopyPixels(null, stride, stride * height, buffer); } catch (Exception e) { form.Add(this, e.TargetSite.ToString(Resources._0_Failed, "NULL"), de, new DataEntry(e)); } } catch { } return(true); }
protected override bool ProcessFrameDecode(MainForm form, IWICBitmapFrameDecode frame, DataEntry[] de, object tag) { IWICBitmapSourceTransform transform = null; try { transform = (IWICBitmapSourceTransform)frame; } catch (InvalidCastException) { return(false); } if (transform == null) { form.Add(this, string.Format(CultureInfo.CurrentUICulture, Resources._0_NULL, "IWICBitmapFrameDecode::QueryInterface(IID_IWICBitmapSourceTransform, ...)"), de); } else { try { if (!transform.DoesSupportTransform(WICBitmapTransformOptions.WICBitmapTransformRotate0)) { form.Add(this, string.Format(CultureInfo.CurrentUICulture, Resources._0_NotExpectedValue, "IWICBitmapSourceTransform::DoesSupportTransform(WICBitmapTransformRotate0, ...)"), de, new DataEntry(Resources.Actual, "FALSE"), new DataEntry(Resources.Expected, "TRUE")); } uint width; uint height; frame.GetSize(out width, out height); uint widthSaved = width; uint heightSaved = height; transform.GetClosestSize(ref width, ref height); if (width != widthSaved || height != heightSaved) { form.Add(this, Resources.IWICBitmapSourceTransform_ChangedSize, de, new DataEntry(Resources.Expected, new Size((int)widthSaved, (int)heightSaved)), new DataEntry(Resources.Actual, new Size((int)width, (int)height))); } Guid pixelFormat; frame.GetPixelFormat(out pixelFormat); Guid pixelFormatSaved = pixelFormat; transform.GetClosestPixelFormat(ref pixelFormat); if (pixelFormat != pixelFormatSaved) { form.Add(this, Resources.IWICBitmapSourceTransform_ChangedPixelformat, de, new DataEntry(Resources.Expected, pixelFormatSaved), new DataEntry(Resources.Actual, pixelFormat)); } uint stride = (PixelFormatInfoRule.GetBitPerPixel(pixelFormat) * width + 7) / 8; byte[] buffer = new byte[stride * height]; try { transform.CopyPixels(null, width, height, null, WICBitmapTransformOptions.WICBitmapTransformRotate0, stride, (uint)buffer.LongLength, buffer); } catch (Exception e) { form.Add(this, e.TargetSite.ToString(Resources._0_Failed, "NULL, uiWidth, uiHeight, NULL, WICBitmapTransformRotate0, ..."), de, new DataEntry(e), new DataEntry("uiWidth", width), new DataEntry("uiHeight", height)); } } finally { transform.ReleaseComObject(); } } return(true); }
protected override bool ProcessEncoder(MainForm form, IWICBitmapEncoder encoder, object tag) { Tag t = (Tag)tag; IWICImagingFactory factory = (IWICImagingFactory) new WICImagingFactory(); IWICPalette palette = factory.CreatePalette(); palette.InitializePredefined(WICBitmapPaletteType.WICBitmapPaletteTypeFixedBW, false); IWICBitmapFrameEncode frame = null; IWICBitmapFrameEncode frame2 = null; IPropertyBag2[] bag = new IPropertyBag2[1]; try { MethodInfo mi = typeof(IWICBitmapEncoder).GetMethod("CreateNewFrame"); try { encoder.CreateNewFrame(out frame, bag); } catch (Exception e) { form.Add(this, mi.ToString(Resources._0_Failed), new DataEntry(Resources.FrameIndex, 0), new DataEntry(e)); } if (frame == null) { form.Add(this, mi.ToString(Resources._0_NULL), new DataEntry(Resources.Parameter, mi.GetParameters()[0].Name)); } else { if (bag[0] == null) { form.Add(this, mi.ToString(Resources._0_NULL), new DataEntry(Resources.Parameter, mi.GetParameters()[1].Name)); } try { frame.Initialize(bag[0]); frame.SetSize(1, 1); frame.SetPalette(palette); Guid pixelFormat = Guid.Empty; List <Guid> allPixelFormats = new List <Guid>(PixelFormatInfoRule.AllPixelFormats); allPixelFormats.Add(Consts.GUID_WICPixelFormatDontCare); foreach (Guid g in allPixelFormats) { pixelFormat = g; frame.SetPixelFormat(ref pixelFormat); if (g == pixelFormat) { if (Array.IndexOf(t.PixelFormats, g) < 0) { form.Add(this, string.Format(CultureInfo.CurrentUICulture, Resources.DidNotChangeUnsupportedPixelFormat, "IWICBitmapFrameEncode::SetPixelFormat(...)"), new DataEntry(Resources.PixelFormat, g), new DataEntry(Resources.SupportedPixelFormats, t.PixelFormats)); } } else { if (Array.IndexOf(t.PixelFormats, g) >= 0) { form.Add(this, string.Format(CultureInfo.CurrentUICulture, Resources.ChangedSupportedPixelFormat, "IWICBitmapFrameEncode::SetPixelFormat(...)"), new DataEntry(Resources.Expected, g), new DataEntry(Resources.Actual, pixelFormat)); } } } pixelFormat = Consts.GUID_WICPixelFormat32bppBGRA; frame.SetPixelFormat(ref pixelFormat); byte[] buffer = new byte[(PixelFormatInfoRule.GetBitPerPixel(pixelFormat) + 7) / 8]; frame.WritePixels(1, (uint)buffer.Length, (uint)buffer.Length, buffer); frame.Commit(); try { encoder.CreateNewFrame(out frame2, null); if (!t.SupportsMultiframe) { form.Add(this, mi.ToString(Resources._0_ShouldFail), new DataEntry(WinCodecError.WINCODEC_ERR_UNSUPPORTEDOPERATION)); } } catch (Exception e) { if (t.SupportsMultiframe) { form.Add(this, e.TargetSite.ToString(Resources._0_Failed), new DataEntry(Resources.FrameIndex, 1), new DataEntry(e)); } else { form.CheckHRESULT(this, WinCodecError.WINCODEC_ERR_UNSUPPORTEDOPERATION, e, new DataEntry(Resources.FrameIndex, 1)); } } } catch (Exception e) { form.Add(this, e.TargetSite.ToString(Resources._0_Failed), new DataEntry(e)); } } } finally { frame2.ReleaseComObject(); encoder.ReleaseComObject(); bag.ReleaseComObject(); factory.ReleaseComObject(); palette.ReleaseComObject(); } return(base.ProcessEncoder(form, encoder, tag)); }