private void InterpolatePP3() { PP3[] npp3; double[] ys = new double[Frames.Count]; if (KeyframeCount > 1) { npp3 = Interpolation.Do(this); double[] y = Frames.Where(t => t.IsKeyframe).Select(t => ((FrameRT)t).PP3File.Compensation).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 { PP3 firstpp3 = ((FrameRT)Frames.First(t => t.IsKeyframe)).PP3File; npp3 = new PP3[Frames.Count]; for (int j = 0; j < Frames.Count; j++) { npp3[j] = firstpp3.Copy(); ys[j] = firstpp3.Compensation; } } for (int i = 0; i < npp3.Length; i++) { if (IsBrightnessCalculated) { if (i == 0 || i == npp3.Length - 1) { npp3[i].NewCompensation = ys[i]; } else { npp3[i].NewCompensation = Math.Log(Frames[i].NewBrightness / Frames[i].AlternativeBrightness, 2) + ys[i]; if (double.IsNaN(npp3[i].NewCompensation)) { throw new NotFiniteNumberException(); } } } else { npp3[i].NewCompensation = ys[i]; } npp3[i].NewCompensation = (npp3[i].NewCompensation > 10) ? 10 : (npp3[i].NewCompensation < -5) ? -5 : npp3[i].NewCompensation; string path = Frames[i].FilePath + ".pp3"; npp3[i].Write(path); MainWorker.ReportProgress(0, new ProgressChangeEventArgs(i * 100 / (npp3.Length - 1), ProgressType.WritePP3)); } }
internal static PP3[] Do(ProjectRT CurProj) { PP3[] Output = new PP3[CurProj.Frames.Count]; PP3 typepp3 = ((FrameRT)CurProj.Frames.First(t => t.IsKeyframe)).PP3File; if (CurProj.KeyframeCount == 1) { for (int i = 0; i < CurProj.Frames.Count; i++) { Output[i] = typepp3.Copy(); } return(Output); } for (int j = 0; j < CurProj.Frames.Count; j++) { Output[j] = typepp3.Copy(); } for (int i = 0; i < typepp3.Values.Count; i++) { List <KeyValuePair <int, object> > Values = new List <KeyValuePair <int, object> >(); Type CurType = typepp3.Values.ElementAt(i).Value.Value.GetType(); string valname = typepp3.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, ((FrameRT)CurProj.Frames[j]).PP3File.Values[valname].Value)); } else if (j == 0) { Values.Add(new KeyValuePair <int, object>(j, ((FrameRT)CurProj.Frames.First(t => t.IsKeyframe)).PP3File.Values[valname].Value)); } else if (j == CurProj.Frames.Count - 1) { Values.Add(new KeyValuePair <int, object>(j, ((FrameRT)CurProj.Frames.Last(t => t.IsKeyframe)).PP3File.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 (((FrameRT)CurProj.Frames[k]).PP3File != null) { Output[k].Path = ((FrameRT)CurProj.Frames[k]).PP3File.Path; Output[k].Compensation = ((FrameRT)CurProj.Frames[k]).PP3File.Compensation; Output[k].FileVersion = ((FrameRT)CurProj.Frames[k]).PP3File.FileVersion; Output[k].NewCompensation = ((FrameRT)CurProj.Frames[k]).PP3File.NewCompensation; } Output[k].Values[valname] = new PP3.PP3entry(typepp3.Values[valname].Name, (int)OutVals[k].Y, typepp3.Values[valname].min, typepp3.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 (((FrameRT)CurProj.Frames[k]).PP3File != null) { Output[k].Path = ((FrameRT)CurProj.Frames[k]).PP3File.Path; Output[k].Compensation = ((FrameRT)CurProj.Frames[k]).PP3File.Compensation; Output[k].FileVersion = ((FrameRT)CurProj.Frames[k]).PP3File.FileVersion; Output[k].NewCompensation = ((FrameRT)CurProj.Frames[k]).PP3File.NewCompensation; } Output[k].Values[valname] = new PP3.PP3entry(typepp3.Values[valname].Name, (double)OutVals[k].Y, typepp3.Values[valname].min, typepp3.Values[valname].max); } } else if (CurType.BaseType == typeof(PP3Curve)) { if (CurType == typeof(PP3Curve_Linear)) { int index = 0; for (int k = 0; k < CurProj.Frames.Count; k++) { if (((FrameRT)CurProj.Frames[k]).PP3File != null) { Output[k].Path = ((FrameRT)CurProj.Frames[k]).PP3File.Path; Output[k].Compensation = ((FrameRT)CurProj.Frames[k]).PP3File.Compensation; Output[k].FileVersion = ((FrameRT)CurProj.Frames[k]).PP3File.FileVersion; Output[k].NewCompensation = ((FrameRT)CurProj.Frames[k]).PP3File.NewCompensation; } Output[k].Values[valname] = new PP3.PP3entry(typepp3.Values[valname].Name, Values[index].Value, typepp3.Values[valname].min, typepp3.Values[valname].max); if (Values[index].Key == k) { index++; } } } else { PP3Curve[] OutCurves = Do(Values); for (int k = 0; k < CurProj.Frames.Count; k++) { if (((FrameRT)CurProj.Frames[k]).PP3File != null) { Output[k].Path = ((FrameRT)CurProj.Frames[k]).PP3File.Path; Output[k].Compensation = ((FrameRT)CurProj.Frames[k]).PP3File.Compensation; Output[k].FileVersion = ((FrameRT)CurProj.Frames[k]).PP3File.FileVersion; Output[k].NewCompensation = ((FrameRT)CurProj.Frames[k]).PP3File.NewCompensation; } Output[k].Values[valname] = new PP3.PP3entry(typepp3.Values[valname].Name, OutCurves[k], typepp3.Values[valname].min, typepp3.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++) { Output[k].Values[valname] = new PP3.PP3entry(typepp3.Values[valname].Name, Values[index].Value, typepp3.Values[valname].min, typepp3.Values[valname].max); if (Values[index].Key == k) { index++; } } } } return(Output); }