Esempio n. 1
0
        protected override void WriteFiles()
        {
            XMP[]    nxmp;
            double[] ys = new double[Frames.Count];

            if (KeyframeCount > 1)
            {
                nxmp = Interpolation.Do(this);
                double[] y = Frames.Where(t => t.IsKeyframe).Select(t => ((FrameACR)t).XMPFile.Exposure).ToArray();
                double[] x = new double[y.Length];
                int      k = 0;
                for (int j = 0; j < Frames.Count; j++)
                {
                    if (Frames[j].IsKeyframe)
                    {
                        x[k] = j; k++;
                    }
                }
                ys = Interpolation.Do(x, y, Frames.Count);
            }
            else
            {
                XMP firstxmp = ((FrameACR)Frames.First(t => t.IsKeyframe)).XMPFile;
                nxmp = new XMP[Frames.Count];
                for (int j = 0; j < Frames.Count; j++)
                {
                    nxmp[j]      = firstxmp.Copy();
                    nxmp[j].Path = ((FrameACR)Frames[j]).XMPFile.Path;
                    ys[j]        = firstxmp.Exposure;
                }
            }

            for (int i = 0; i < nxmp.Length; i++)
            {
                if (IsBrightnessCalculated)
                {
                    if (i == 0 || i == nxmp.Length - 1)
                    {
                        nxmp[i].NewExposure = (ys[i] > 10) ? 10 : (ys[i] < -5) ? -5 : ys[i];
                    }
                    else
                    {
                        nxmp[i].NewExposure = Math.Log(Frames[i].NewBrightness / Frames[i].AlternativeBrightness, 2) + ((ys[i] > 5) ? 5 : (ys[i] < -5) ? -5 : ys[i]);
                        if (double.IsNaN(nxmp[i].NewExposure))
                        {
                            throw new NotFiniteNumberException();
                        }
                    }
                }
                else
                {
                    nxmp[i].NewExposure = (ys[i] > 5) ? 5 : (ys[i] < -5) ? -5 : ys[i];
                }
                nxmp[i].Write();
                MainWorker.ReportProgress(0, new ProgressChangeEventArgs(i * 100 / (nxmp.Length - 1), ProgressType.WriteXMP));
            }
        }
Esempio n. 2
0
        internal static XMP[] Do(ProjectACR CurProj)
        {
            XMP[] Output  = new XMP[CurProj.Frames.Count];
            XMP   typexmp = ((FrameACR)CurProj.Frames.First(t => t.IsKeyframe)).XMPFile;

            for (int j = 0; j < CurProj.Frames.Count; j++)
            {
                Output[j] = typexmp.Copy();
            }

            for (int i = 0; i < typexmp.Values.Count; i++)
            {
                List <KeyValuePair <int, object> > Values = new List <KeyValuePair <int, object> >();
                Type   CurType = typexmp.Values.ElementAt(i).Value.type;
                string valname = typexmp.Values.ElementAt(i).Key;

                for (int j = 0; j < CurProj.Frames.Count; j++)
                {
                    if (CurProj.Frames[j].IsKeyframe)
                    {
                        Values.Add(new KeyValuePair <int, object>(j, ((FrameACR)CurProj.Frames[j]).XMPFile.Values[valname].Value));
                    }
                    else if (j == 0)
                    {
                        Values.Add(new KeyValuePair <int, object>(j, ((FrameACR)CurProj.Frames.First(t => t.IsKeyframe)).XMPFile.Values[valname].Value));
                    }
                    else if (j == CurProj.Frames.Count - 1)
                    {
                        Values.Add(new KeyValuePair <int, object>(j, ((FrameACR)CurProj.Frames.Last(t => t.IsKeyframe)).XMPFile.Values[valname].Value));
                    }
                }

                if (CurType != typeof(bool) && CurType != typeof(string))
                {
                    PointD[] InVals  = new PointD[Values.Count];
                    PointD[] OutVals = new PointD[CurProj.Frames.Count];

                    if (CurType == typeof(int))
                    {
                        for (int k = 0; k < Values.Count; k++)
                        {
                            InVals[k] = new PointD(Values[k].Key, (int)Convert.ChangeType(Values[k].Value, typeof(int)));
                        }
                        OutVals = Do(InVals, CurProj.Frames.Count);
                        for (int k = 0; k < CurProj.Frames.Count; k++)
                        {
                            if (((FrameACR)CurProj.Frames[k]).XMPFile != null)
                            {
                                Output[k].Path        = ((FrameACR)CurProj.Frames[k]).XMPFile.Path;
                                Output[k].Exposure    = ((FrameACR)CurProj.Frames[k]).XMPFile.Exposure;
                                Output[k].FileVersion = ((FrameACR)CurProj.Frames[k]).XMPFile.FileVersion;
                                Output[k].NewExposure = ((FrameACR)CurProj.Frames[k]).XMPFile.NewExposure;
                            }
                            Output[k].Values[valname] = new XMP.XMPentry(typexmp.Values[valname].Name, (int)OutVals[k].Y, typeof(int), typexmp.Values[valname].sign, typexmp.Values[valname].min, typexmp.Values[valname].max);
                        }
                    }
                    else if (CurType == typeof(double))
                    {
                        for (int k = 0; k < Values.Count; k++)
                        {
                            InVals[k] = new PointD(Values[k].Key, (float)Convert.ChangeType(Values[k].Value, typeof(float)));
                        }
                        OutVals = Do(InVals, CurProj.Frames.Count);
                        for (int k = 0; k < CurProj.Frames.Count; k++)
                        {
                            if (((FrameACR)CurProj.Frames[k]).XMPFile != null)
                            {
                                Output[k].Path        = ((FrameACR)CurProj.Frames[k]).XMPFile.Path;
                                Output[k].Exposure    = ((FrameACR)CurProj.Frames[k]).XMPFile.Exposure;
                                Output[k].FileVersion = ((FrameACR)CurProj.Frames[k]).XMPFile.FileVersion;
                                Output[k].NewExposure = ((FrameACR)CurProj.Frames[k]).XMPFile.NewExposure;
                            }
                            Output[k].Values[valname] = new XMP.XMPentry(typexmp.Values[valname].Name, OutVals[k].Y, typeof(double), typexmp.Values[valname].sign, typexmp.Values[valname].min, typexmp.Values[valname].max);
                        }
                    }
                    else
                    {
                        throw new InterpolationNotPossibleException("Couldn't interpolate this kind of Value: " + CurType.FullName);
                    }
                }
                else
                {
                    int index = 0;
                    for (int k = 0; k < CurProj.Frames.Count; k++)
                    {
                        if (((FrameACR)CurProj.Frames[k]).XMPFile != null)
                        {
                            Output[k].Path        = ((FrameACR)CurProj.Frames[k]).XMPFile.Path;
                            Output[k].Exposure    = ((FrameACR)CurProj.Frames[k]).XMPFile.Exposure;
                            Output[k].FileVersion = ((FrameACR)CurProj.Frames[k]).XMPFile.FileVersion;
                            Output[k].NewExposure = ((FrameACR)CurProj.Frames[k]).XMPFile.NewExposure;
                        }
                        Output[k].Values[valname] = new XMP.XMPentry(typexmp.Values[valname].Name, Values[index].Value, CurType, typexmp.Values[valname].sign, typexmp.Values[valname].min, typexmp.Values[valname].max);
                        if (Values[index].Key == k)
                        {
                            index++;
                        }
                    }
                }
            }
            return(Output);
        }