Example #1
0
        private void SetupDevelopRaw()
        {
            IWICDevelopRaw raw = frame as IWICDevelopRaw;

            if (raw != null)
            {
                WICRawCapabilitiesInfo capabilities = new WICRawCapabilitiesInfo();
                capabilities.cbSize = (uint)Marshal.SizeOf(capabilities);
                raw.QueryRawCapabilitiesInfo(ref capabilities);

                SetupTrackBar <double>(exposureTrackBar, GetValue <double>(Rules.Decoder.DevelopRawRule.GetSupported(capabilities.ExposureCompensationSupport), raw.GetExposureCompensation));
                SetupTrackBar <double>(contrastTrackBar, GetValue <double>(Rules.Decoder.DevelopRawRule.GetSupported(capabilities.ContrastSupport), raw.GetContrast));
                SetupTrackBar <double>(sharpnessTrackBar, GetValue <double>(Rules.Decoder.DevelopRawRule.GetSupported(capabilities.SharpnessSupport), raw.GetSharpness));
                SetupTrackBar <double>(tintTrackBar, GetValue <double>(Rules.Decoder.DevelopRawRule.GetSupported(capabilities.TintSupport), raw.GetTint));
                SetupTrackBar <double>(gammaTrackBar, GetValue <double>(Rules.Decoder.DevelopRawRule.GetSupported(capabilities.GammaSupport), raw.GetGamma));
                SetupTrackBar <double>(saturationTrackBar, GetValue <double>(Rules.Decoder.DevelopRawRule.GetSupported(capabilities.SaturationSupport), raw.GetSaturation));
                SetupTrackBar <double>(noiseReductionTrackBar, GetValue <double>(Rules.Decoder.DevelopRawRule.GetSupported(capabilities.NoiseReductionSupport), raw.GetNoiseReduction));

                if (Rules.Decoder.DevelopRawRule.SetSupported(capabilities.RenderModeSupport) == null)
                {
                    renderModeComboBox.Enabled       = true;
                    renderModeComboBox.SelectedIndex = 1;
                    ChangeValue <WICRawRenderMode>(raw.SetRenderMode, WICRawRenderMode.WICRawRenderModeNormal);
                }

                if (Rules.Decoder.DevelopRawRule.GetSupported(capabilities.KelvinWhitePointSupport))
                {
                    uint minTemp  = 1500;
                    uint maxTemp  = 30000;
                    uint stepTemp = 1;
                    try
                    {
                        raw.GetKelvinRangeInfo(out minTemp, out maxTemp, out stepTemp);
                    }
                    catch
                    {
                    }

                    temperatureTrackBar.Minimum       = Convert.ToInt32(minTemp);
                    temperatureTrackBar.Maximum       = Convert.ToInt32(maxTemp);
                    temperatureTrackBar.TickFrequency = Convert.ToInt32(stepTemp);

                    SetupTrackBar <uint>(temperatureTrackBar, GetValue <uint>(Rules.Decoder.DevelopRawRule.GetSupported(capabilities.KelvinWhitePointSupport), raw.GetWhitePointKelvin));
                }
            }
        }
Example #2
0
        protected override bool ProcessFrameDecode(MainForm form, IWICBitmapFrameDecode frame, DataEntry[] de, object tag)
        {
            Guid pixelFormatOriginal;

            frame.GetPixelFormat(out pixelFormatOriginal);

            IWICDevelopRaw raw = null;

            try
            {
                raw = (IWICDevelopRaw)frame;
                if (raw == null)
                {
                    form.Add(this, string.Format(CultureInfo.CurrentUICulture, Resources._0_NULL, "IWICBitmapFrameDecode::QueryInterface(IID_IWICDevelopRaw, ...)"), de);
                }
                else
                {
                    CheckPixelFormat(form, raw, de, pixelFormatOriginal);

                    WICRawCapabilitiesInfo capabilities = new WICRawCapabilitiesInfo();
                    capabilities.cbSize = (uint)Marshal.SizeOf(capabilities);
                    try
                    {
                        raw.QueryRawCapabilitiesInfo(ref capabilities);
                    }
                    catch (Exception e)
                    {
                        form.Add(this, e.TargetSite.ToString(Resources._0_Failed), de, new DataEntry(e));

                        return(true);
                    }
                    bool supports = false;
                    foreach (FieldInfo fi in typeof(WICRawCapabilitiesInfo).GetFields())
                    {
                        if (fi.FieldType == typeof(WICRawCapabilities) || fi.FieldType == typeof(WICRawRotationCapabilities))
                        {
                            if (!Enum.IsDefined(fi.FieldType, fi.GetValue(capabilities)))
                            {
                                form.Add(this, string.Format(CultureInfo.CurrentUICulture, Resources._0_UnexpectedFieldValue, fi.Name), de, new DataEntry(Resources.Expected, Enum.GetValues(fi.FieldType)), new DataEntry(Resources.Actual, fi.GetValue(capabilities)));
                            }
                            supports |= 0 != (uint)Convert.ChangeType(fi.GetValue(capabilities), typeof(uint));
                        }
                    }
                    if (!supports)
                    {
                        form.Add(this, Resources.DevelopRaw_NoSupportedFeatures, de);
                    }

                    CheckGetSupported <double>(form, GetSupported(capabilities.ContrastSupport), raw.GetContrast, de, 0);
                    CheckGetSupported(form, GetSupported(capabilities.DestinationColorProfileSupport), raw.GetColorContexts, de).ReleaseComObject();
                    CheckGetSupported <double>(form, GetSupported(capabilities.ExposureCompensationSupport), raw.GetExposureCompensation, de, 0);
                    CheckGetSupported <double>(form, GetSupported(capabilities.GammaSupport), raw.GetGamma, de, 1);
                    uint?kelvinWhitePoint = CheckGetSupported <uint>(form, GetSupported(capabilities.KelvinWhitePointSupport), raw.GetWhitePointKelvin, de, null);
                    WICNamedWhitePoint?namedWhitePoint = CheckGetSupported <WICNamedWhitePoint>(form, GetSupported(capabilities.NamedWhitePointSupport), raw.GetNamedWhitePoint, de, null);
                    CheckGetSupported <double>(form, GetSupported(capabilities.NoiseReductionSupport), raw.GetNoiseReduction, de, 0);
                    uint[]           rgbWhitePoint = CheckGetSupported(form, GetSupported(capabilities.RGBWhitePointSupport), raw.GetWhitePointRGB, de, null);
                    WICRawRenderMode?renderingMode = CheckGetSupported <WICRawRenderMode>(form, GetSupported(capabilities.RenderModeSupport), raw.GetRenderMode, de, WICRawRenderMode.WICRawRenderModeNormal);
                    CheckGetSupported <double>(form, GetSupported(capabilities.RotationSupport), raw.GetRotation, de, 0);
                    CheckGetSupported <double>(form, GetSupported(capabilities.SaturationSupport), raw.GetSaturation, de, 0);
                    CheckGetSupported <double>(form, GetSupported(capabilities.SharpnessSupport), raw.GetSharpness, de, 0);
                    CheckGetSupported <double>(form, GetSupported(capabilities.TintSupport), raw.GetTint, de, 0);
                    WICRawToneCurvePoint[] toneCurve = CheckGetSupported(form, GetSupported(capabilities.ToneCurveSupport), raw.GetToneCurve, de);

                    CheckSetSupported <double>(form, SetSupported(capabilities.ContrastSupport), raw.GetContrast, raw.SetContrast, raw, WICRawChangeNotification.WICRawChangeNotification_Contrast, de, pixelFormatOriginal, -1, 0, 1);
                    CheckSetSupported <double>(form, SetSupported(capabilities.ExposureCompensationSupport), raw.GetExposureCompensation, raw.SetExposureCompensation, raw, WICRawChangeNotification.WICRawChangeNotification_ExposureCompensation, de, pixelFormatOriginal, 0, -5, 5);
                    CheckSetSupported <double>(form, SetSupported(capabilities.GammaSupport), raw.GetGamma, raw.SetGamma, raw, WICRawChangeNotification.WICRawChangeNotification_Gamma, de, pixelFormatOriginal, 1, 0.2, 5);
                    CheckSetSupported <double>(form, SetSupported(capabilities.NoiseReductionSupport), raw.GetNoiseReduction, raw.SetNoiseReduction, raw, WICRawChangeNotification.WICRawChangeNotification_NoiseReduction, de, pixelFormatOriginal, 0, 1);
                    CheckSetSupported <double>(form, SetSupported(capabilities.SaturationSupport), raw.GetSaturation, raw.SetSaturation, raw, WICRawChangeNotification.WICRawChangeNotification_Saturation, de, pixelFormatOriginal, 0, -1, 1);
                    CheckSetSupported <double>(form, SetSupported(capabilities.SharpnessSupport), raw.GetSharpness, raw.SetSharpness, raw, WICRawChangeNotification.WICRawChangeNotification_Sharpness, de, pixelFormatOriginal, 0, 1);
                    CheckSetSupported <double>(form, SetSupported(capabilities.TintSupport), raw.GetTint, raw.SetTint, raw, WICRawChangeNotification.WICRawChangeNotification_Tint, de, pixelFormatOriginal, 0, -1, 1);
                    CheckSetSupported <WICRawRenderMode>(form, SetSupported(capabilities.RenderModeSupport), raw.GetRenderMode, raw.SetRenderMode, raw, WICRawChangeNotification.WICRawChangeNotification_RenderMode, de, pixelFormatOriginal, WICRawRenderMode.WICRawRenderModeDraft, WICRawRenderMode.WICRawRenderModeNormal, WICRawRenderMode.WICRawRenderModeBestQuality);

                    try
                    {
                        uint max, min, step;
                        raw.GetKelvinRangeInfo(out min, out max, out step);
                        MethodInfo mi = typeof(IWICDevelopRaw).GetMethod("GetKelvinRangeInfo");
                        if ((max < min) ||
                            (min == max && step != 0) ||
                            (min != max && (step == 0 || ((max - min) % step) != 0)))
                        {
                            ParameterInfo[] pi = mi.GetParameters();
                            form.Add(this, mi.ToString(Resources._0_NotExpectedValue), de, new DataEntry(pi[0].Name, max), new DataEntry(pi[1].Name, min), new DataEntry(pi[2].Name, step));
                        }
                        else
                        {
                            uint[] goodTemps = min == max ? new uint[] { min } : new uint[] { min, min + step, max, max - step };
                            uint[] badTemps  = step == 1 ? new uint[] { min - step, max + step } : new uint[] { min - step, max + step, min + step / 2, max - step / 2 };

                            CheckSetSupported <uint>(form, null, raw.GetWhitePointKelvin, raw.SetWhitePointKelvin, raw, WICRawChangeNotification.WICRawChangeNotification_KelvinWhitePoint, de, pixelFormatOriginal, goodTemps);
                            CheckSetSupported <uint>(form, WinCodecError.WINCODEC_ERR_VALUEOUTOFRANGE, raw.GetWhitePointKelvin, raw.SetWhitePointKelvin, raw, WICRawChangeNotification.WICRawChangeNotification_KelvinWhitePoint, de, pixelFormatOriginal, badTemps);
                        }
                    }
                    catch (Exception e)
                    {
                        form.Add(this, e.TargetSite.ToString(Resources._0_Failed), de, new DataEntry(e));
                    }

                    CheckSetDestinationColorContextSupported(form, SetSupported(capabilities.DestinationColorProfileSupport), raw, de, pixelFormatOriginal);

                    switch (capabilities.RotationSupport)
                    {
                    case WICRawRotationCapabilities.WICRawRotationCapabilityFullySupported:
                        CheckSetSupported <double>(form, null, raw.GetRotation, raw.SetRotation, raw, WICRawChangeNotification.WICRawChangeNotification_Rotation, de, pixelFormatOriginal, rotation);
                        break;

                    case WICRawRotationCapabilities.WICRawRotationCapabilityNinetyDegreesSupported:
                        CheckSetSupported <double>(form, null, raw.GetRotation, raw.SetRotation, raw, WICRawChangeNotification.WICRawChangeNotification_Rotation, de, pixelFormatOriginal, rotation90);
                        CheckSetSupported <double>(form, WinCodecError.WINCODEC_ERR_VALUEOUTOFRANGE, raw.GetRotation, raw.SetRotation, raw, WICRawChangeNotification.WICRawChangeNotification_Rotation, de, pixelFormatOriginal, rotation90);
                        break;

                    default:
                        CheckSetSupported <double>(form, WinCodecError.WINCODEC_ERR_UNSUPPORTEDOPERATION, raw.GetRotation, raw.SetRotation, raw, WICRawChangeNotification.WICRawChangeNotification_Rotation, de, pixelFormatOriginal, rotation);
                        break;
                    }

                    CheckSetNamedWhitePointSupported(form, SetSupported(capabilities.NamedWhitePointSupport), capabilities.NamedWhitePointSupportMask, raw, de, pixelFormatOriginal);
                    CheckSetRgbWhitePointSupported(form, SetSupported(capabilities.RGBWhitePointSupport), raw, de, pixelFormatOriginal);
                    CheckSetToneCurveSupported(form, SetSupported(capabilities.ToneCurveSupport), raw, de, pixelFormatOriginal);

                    foreach (WICRawParameterSet ps in Enum.GetValues(typeof(WICRawParameterSet)))
                    {
                        try
                        {
                            raw.LoadParameterSet(ps);

                            IPropertyBag2 pb = null;
                            try
                            {
                                pb = raw.GetCurrentParameterSet();
                            }
                            catch (Exception e)
                            {
                                form.Add(this, e.TargetSite.ToString(Resources._0_Failed), de, new DataEntry(e));
                            }
                            finally
                            {
                                pb.ReleaseComObject();
                            }
                        }
                        catch (Exception e)
                        {
                            form.Add(this, e.TargetSite.ToString(Resources._0_Failed), de, new DataEntry(e), new DataEntry(Resources.Value, ps));
                        }
                    }
                }
            }
            catch (InvalidCastException)
            {
                return(false);
            }

            return(true);
        }