示例#1
0
        void CheckSetDestinationColorContextSupported(MainForm form, WinCodecError?error, IWICDevelopRaw raw, DataEntry[] de, Guid pixelFormatOriginal)
        {
            Notification[]     notifications = new Notification[] { new Notification(), new Notification(), null };
            IWICImagingFactory factory       = new WICImagingFactory() as IWICImagingFactory;

            IWICColorContext[] contexts = { factory.CreateColorContext(), null };
            contexts[0].InitializeFromExifColorSpace(ExifColorSpace.sRGB);
            Action <IWICColorContext> setter = raw.SetDestinationColorContext;

            try
            {
                foreach (Notification n in notifications)
                {
                    try
                    {
                        raw.SetNotificationCallback(n);
                    }
                    catch (Exception e)
                    {
                        form.Add(this, n == null ? e.TargetSite.ToString(Resources._0_Failed, "NULL") : e.TargetSite.ToString(Resources._0_Failed), de, new DataEntry(e));
                    }
                    foreach (IWICColorContext c in contexts)
                    {
                        try
                        {
                            setter(c);
                            if (error.HasValue)
                            {
                                form.Add(this, setter.ToString(Resources._0_ShouldFail), de, new DataEntry(Resources.Expected, error.Value));
                            }
                            else
                            {
                                if (n != null && !n.Notified)
                                {
                                    form.Add(this, Resources.DevelopRawRule_NoNotification, de, new DataEntry(Resources.Actual, n.GetRaised()), new DataEntry(Resources.Expected, WICRawChangeNotification.WICRawChangeNotification_DestinationColorContext), new DataEntry(Resources.Method, setter.ToString("{0}")));
                                }
                                if (n != notifications[0] && notifications[0].Notified)
                                {
                                    form.Add(this, Resources.DevelopRawRule_NotificationOnWrong, de, new DataEntry(Resources.Method, setter.ToString("{0}")));
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            if (error.HasValue)
                            {
                                form.CheckHRESULT(this, error.Value, e, c == null ? "NULL" : null, de);
                            }
                            else
                            {
                                form.Add(this, c == null ? e.TargetSite.ToString(Resources._0_Failed, "NULL") : e.TargetSite.ToString(Resources._0_Failed), de, new DataEntry(e));
                            }
                        }
                    }
                }
            }
            finally
            {
                contexts.ReleaseComObject();
                factory.ReleaseComObject();
            }
        }
示例#2
0
        void CheckSetRgbWhitePointSupported(MainForm form, WinCodecError?error, IWICDevelopRaw raw, DataEntry[] de, Guid pixelFormatOriginal)
        {
            Notification[]            notifications = new Notification[] { new Notification(), new Notification(), null };
            GetTriplet <uint>         getter        = raw.GetWhitePointRGB;
            Action <uint, uint, uint> setter        = raw.SetWhitePointRGB;

            foreach (Notification n in notifications)
            {
                try
                {
                    raw.SetNotificationCallback(n);
                }
                catch (Exception e)
                {
                    form.Add(this, n == null ? e.TargetSite.ToString(Resources._0_Failed, "NULL") : e.TargetSite.ToString(Resources._0_Failed), de, new DataEntry(e));
                }

                uint r, g, b;
                r = g = b = uint.MaxValue;
                bool getSupported = false;
                try
                {
                    getter(out r, out g, out b);
                    getSupported = true;
                }
                catch
                {
                    break;
                }
                if (getSupported)
                {
                    try
                    {
                        notifications[0].Expect(WICRawChangeNotification.WICRawChangeNotification_RGBWhitePoint);
                        notifications[1].Expect(WICRawChangeNotification.WICRawChangeNotification_RGBWhitePoint);
                        setter(r, g, b);
                        if (error.HasValue)
                        {
                            form.Add(this, setter.ToString(Resources._0_ShouldFail), de, new DataEntry(Resources.Expected, error.Value));
                        }
                        else
                        {
                            if (n != null && !n.Notified)
                            {
                                form.Add(this, Resources.DevelopRawRule_NoNotification, de, new DataEntry(Resources.Actual, n.GetRaised()), new DataEntry(Resources.Expected, WICRawChangeNotification.WICRawChangeNotification_RGBWhitePoint), new DataEntry(Resources.Method, setter.ToString("{0}")), new DataEntry(Resources.Value, new uint[] { r, g, b }));
                            }
                            if (n != notifications[0] && notifications[0].Notified)
                            {
                                form.Add(this, Resources.DevelopRawRule_NotificationOnWrong, de, new DataEntry(Resources.Method, setter.ToString("{0}")), new DataEntry(Resources.Value, new uint[] { r, g, b }));
                            }

                            CheckGetSupported(form, true, getter, de, new uint[] { r, g, b });
                        }
                    }
                    catch (Exception e)
                    {
                        CheckGetSupported(form, true, getter, de, new uint[] { r, g, b });
                        if (error.HasValue)
                        {
                            form.CheckHRESULT(this, error.Value, e, de);
                        }
                        else
                        {
                            form.Add(this, setter.ToString(Resources._0_Failed), de, new DataEntry(e));
                        }
                    }
                }
                CheckPixelFormat(form, raw, de, pixelFormatOriginal);
            }
        }
示例#3
0
        void CheckSetSupported <T>(MainForm form, WinCodecError?error, Func <T> getter, Action <T> setter, IWICDevelopRaw raw, WICRawChangeNotification mask, DataEntry[] de, Guid pixelFormatOriginal, params T[] values) where T : struct
        {
            Notification[] notifications = new Notification[] { new Notification(), new Notification(), null };

            foreach (Notification n in notifications)
            {
                try
                {
                    raw.SetNotificationCallback(n);
                }
                catch (Exception e)
                {
                    form.Add(this, n == null ? e.TargetSite.ToString(Resources._0_Failed, "NULL") : e.TargetSite.ToString(Resources._0_Failed), de, new DataEntry(e));
                }

                foreach (T value in values)
                {
                    T    saved        = default(T);
                    bool getSupported = false;
                    try
                    {
                        saved        = getter();
                        getSupported = true;
                    }
                    catch
                    {
                        break;
                    }
                    if (getSupported)
                    {
                        try
                        {
                            notifications[0].Expect(mask);
                            notifications[1].Expect(mask);
                            setter(value);
                            if (error.HasValue)
                            {
                                form.Add(this, setter.ToString(Resources._0_ShouldFail), de, new DataEntry(Resources.Expected, error.Value));
                            }
                            else
                            {
                                if (n != null && !n.Notified && saved.Equals(value))
                                {
                                    form.Add(this, Resources.DevelopRawRule_NoNotification, de, new DataEntry(Resources.Actual, n.GetRaised()), new DataEntry(Resources.Expected, mask), new DataEntry(Resources.Method, setter.ToString("{0}")), new DataEntry(Resources.Value, value));
                                }
                                if (n != notifications[0] && notifications[0].Notified)
                                {
                                    form.Add(this, Resources.DevelopRawRule_NotificationOnWrong, de, new DataEntry(Resources.Method, setter.ToString("{0}")), new DataEntry(Resources.Value, value));
                                }

                                CheckGetSupported <T>(form, true, getter, de, value);
                            }
                        }
                        catch (Exception e)
                        {
                            CheckGetSupported <T>(form, true, getter, de, saved);
                            if (error.HasValue)
                            {
                                DataEntry[] de2 = de.Clone() as DataEntry[];
                                Array.Resize(ref de2, de2.Length + 1);
                                de2[de2.Length - 1] = new DataEntry(Resources.Value, value);
                                form.CheckHRESULT(this, error.Value, e, de2);
                            }
                            else
                            {
                                form.Add(this, setter.ToString(Resources._0_Failed), de, new DataEntry(e), new DataEntry(Resources.Value, value));
                            }
                        }
                    }
                    CheckPixelFormat(form, raw, de, pixelFormatOriginal);
                }
            }
        }
示例#4
0
        void CheckSetToneCurveSupported(MainForm form, WinCodecError?error, IWICDevelopRaw raw, DataEntry[] de, Guid pixelFormatOriginal)
        {
            Notification[]            notifications = new Notification[] { new Notification(), new Notification(), null };
            Func <uint, IntPtr, uint> getter        = raw.GetToneCurve;
            Action <uint, IntPtr>     setter        = raw.SetToneCurve;

            IntPtr p = IntPtr.Zero;

            try
            {
                int size = Marshal.SizeOf(typeof(WICRawToneCurvePoint)) * 2 + Marshal.SizeOf(typeof(uint));
                p = Marshal.AllocCoTaskMem(size);

                Marshal.WriteInt32(p, 2);
                Marshal.WriteInt64(new IntPtr(p.ToInt64() + Marshal.SizeOf(typeof(uint))), 0);
                Marshal.WriteInt64(new IntPtr(p.ToInt64() + Marshal.SizeOf(typeof(uint)) + Marshal.SizeOf(typeof(double))), 0);
                Marshal.WriteInt64(new IntPtr(p.ToInt64() + Marshal.SizeOf(typeof(uint)) + Marshal.SizeOf(typeof(WICRawToneCurvePoint))), BitConverter.DoubleToInt64Bits(1));
                Marshal.WriteInt64(new IntPtr(p.ToInt64() + Marshal.SizeOf(typeof(uint)) + Marshal.SizeOf(typeof(WICRawToneCurvePoint)) + Marshal.SizeOf(typeof(double))), BitConverter.DoubleToInt64Bits(1));
                foreach (Notification n in notifications)
                {
                    try
                    {
                        raw.SetNotificationCallback(n);
                    }
                    catch (Exception e)
                    {
                        form.Add(this, n == null ? e.TargetSite.ToString(Resources._0_Failed, "NULL") : e.TargetSite.ToString(Resources._0_Failed), de, new DataEntry(e));
                    }

                    bool getSupported = false;
                    try
                    {
                        getter((uint)size, p);
                        getSupported = true;
                    }
                    catch
                    {
                        break;
                    }
                    if (getSupported)
                    {
                        try
                        {
                            notifications[0].Expect(WICRawChangeNotification.WICRawChangeNotification_ToneCurve);
                            notifications[1].Expect(WICRawChangeNotification.WICRawChangeNotification_ToneCurve);
                            setter((uint)size, p);
                            if (error.HasValue)
                            {
                                form.Add(this, setter.ToString(Resources._0_ShouldFail), de, new DataEntry(Resources.Expected, error.Value));
                            }
                            else
                            {
                                if (n != null && !n.Notified)
                                {
                                    form.Add(this, Resources.DevelopRawRule_NoNotification, de, new DataEntry(Resources.Actual, n.GetRaised()), new DataEntry(Resources.Expected, WICRawChangeNotification.WICRawChangeNotification_ToneCurve), new DataEntry(Resources.Method, setter.ToString("{0}")));
                                }
                                if (n != notifications[0] && notifications[0].Notified)
                                {
                                    form.Add(this, Resources.DevelopRawRule_NotificationOnWrong, de, new DataEntry(Resources.Method, setter.ToString("{0}")));
                                }

                                CheckGetSupported(form, true, getter, de);
                            }
                        }
                        catch (Exception e)
                        {
                            CheckGetSupported(form, true, getter, de);
                            if (error.HasValue)
                            {
                                form.CheckHRESULT(this, error.Value, e, de);
                            }
                            else
                            {
                                form.Add(this, setter.ToString(Resources._0_Failed), de, new DataEntry(e));
                            }
                        }
                    }
                    CheckPixelFormat(form, raw, de, pixelFormatOriginal);
                }
            }
            finally
            {
                if (p != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(p);
                }
            }
        }