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)); } }
private void OutputWatcher_Created(object sender, FileSystemEventArgs e) { if (e.ChangeType == WatcherChangeTypes.Created) { string[] fls = Directory.GetFiles(OutputWatcher.Path, OutputWatcher.Filter); int p = fls.Count(t => Frames.Any(k => k.Filename == Path.GetFileNameWithoutExtension(t))); MainWorker.ReportProgress(0, new ProgressChangeEventArgs(p * 100 / Frames.Count, ProgressType.ProcessingImages)); } }
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)); } }
protected override void WriteFiles() { if (!IsBrightnessCalculated) { throw new RequirementsNotFulfilledException(); } for (int i = 0; i < Frames.Count; i++) { double exposure; if (Frames[i].AlternativeBrightness == 0) { exposure = 0; } else if (Frames[i].NewBrightness == 0) { exposure = Math.Log(1 / Math.Abs(Frames[i].AlternativeBrightness), 2) * Math.Sign(Frames[i].AlternativeBrightness); } else { exposure = Math.Log(Math.Abs(Frames[i].NewBrightness / Frames[i].AlternativeBrightness), 2) * Math.Sign(Frames[i].AlternativeBrightness); } Bitmap input = new Bitmap(Frames[i].FilePath); string savepath = Path.Combine(ProjectManager.ImageSavePath, Frames[i].Filename + "." + SaveFormat.ToString()); switch (input.PixelFormat) { case PixelFormat.Format24bppRgb: case PixelFormat.Format32bppArgb: case PixelFormat.Format32bppRgb: Process8bit(ref input, exposure, Frames[i].ColorSpace).Save(savepath); break; case PixelFormat.Format48bppRgb: case PixelFormat.Format64bppArgb: Process16bit(Frames[i].FilePath, savepath, exposure, Frames[i].ColorSpace); break; default: throw new FormatException("Pixelformat of image is not supported"); } MainWorker.ReportProgress(0, new ProgressChangeEventArgs(i * 100 / (Frames.Count - 1), ProgressType.ProcessingImages)); } }
protected override void readXMP() { for (int i = 0; i < Frames.Count; i++) { if (MainWorker.CancellationPending) { return; } FrameACR frame = (FrameACR)Frames[i]; if (frame.XMPFile == null) { frame.XMPFile = new XMP(frame.FilePath); } else { frame.XMPFile.Read(); } MainWorker.ReportProgress(0, new ProgressChangeEventArgs(i * 100 / (Frames.Count - 1), ProgressType.ReadXMP)); } }
private void MainWorker_DoWork(object sender, DoWorkEventArgs e) { Thread.Sleep(50); while (model.EvaluatationInProgress) { var response = service.Evaluate(); if (response.Successful) { model.OutputText = response.Output; model.GenerationCount++; } else { MessageBox.Show(response.ErrorMessage); MainWorker.CancelAsync(); } MainWorker.ReportProgress(0); Thread.Sleep(model.ThreadSleep); } }
//TODO: rework StartRT so it works with newer and older versions properly private void StartRT() { string ExecPath = RTPath; if (ProjectManager.RunningPlatform == Platform.MacOSX) { ExecPath = Path.Combine(RTPath, "Contents/MacOS/rawtherapee"); } if (!File.Exists(ExecPath)) { throw new FileNotFoundException("RawTherapee execution file not found"); } FileHandle.CreateDirectory(ProjectManager.ImageSavePath); ProcessStartInfo RTStartInfo = new ProcessStartInfo(); RTStartInfo = new ProcessStartInfo(ExecPath); RTStartInfo.UseShellExecute = false; RTStartInfo.CreateNoWindow = true; RTStartInfo.WindowStyle = ProcessWindowStyle.Hidden; RT.StartInfo = RTStartInfo; #region Build command string saveformat; string SaveFileType; string bitDepth; switch (SaveFormat) { case FileFormat.png: saveformat = "-n"; SaveFileType = "png"; bitDepth = BitDepth16 ? "-b16" : "-b8"; break; case FileFormat.tiff: saveformat = TiffCompression ? "-t[z]" : "-t"; SaveFileType = "tif"; bitDepth = BitDepth16 ? "-b16" : "-b8"; break; case FileFormat.jpg: default: saveformat = "-j[" + JpgQuality + "]"; SaveFileType = "jpg"; break; } string basecmd = (ProjectManager.RunningPlatform == Platform.Windows ? "-w" : "") + " -o \"" + ProjectManager.ImageSavePath + "\" -S " + saveformat + "" + " -c"; string command = basecmd; bool startRT = false; #endregion OutputWatcher.Filter = "*." + SaveFileType; OutputWatcher.Path = ProjectManager.ImageSavePath; OutputWatcher.EnableRaisingEvents = true; MainWorker.ReportProgress(0, new ProgressChangeEventArgs(0, ProgressType.ProcessingImages)); #region Run RawTherapee /* RT.StartInfo.Arguments = basecmd + " " + Path.GetDirectoryName(Frames[0].FilePath); * RT.Start(); * RT.WaitForExit(); * * Old code, needed if each file is listed in the command line (e.g. for different directories) * */ //Add all the files to the command and start Rawtherapee for (int i = 0; i < Frames.Count; i++) { if (MainWorker.CancellationPending) { return; } //the windows command line can't take longer commands than 8191 characters if (command.Length + Frames[i].FilePath.Length < 8191) { command += " \"" + Frames[i].FilePath + "\""; } else { startRT = true; i--; } if (startRT || i == Frames.Count - 1) { //Start RT RT.StartInfo.Arguments = command; RT.Start(); RT.WaitForExit(); //when finished, set back the command: command = basecmd; startRT = false; } } #endregion OutputWatcher.EnableRaisingEvents = false; }
private void Measure(object Data) { int end = (int)((object[])Data)[0]; Color FromColor = (Color)((object[])Data)[1]; Color ToColor = (Color)((object[])Data)[2]; bool DoFast = (bool)((object[])Data)[3]; Stopwatch watch = new Stopwatch(); Color From2Color = FromColor; ColorConverter conv = new ColorConverter(); if (DoFast) { RGBSpaceName n = ColorConverter.StandardColorspace; YCbCrSpaceName m = ColorConverter.StandardYCbCrSpace; if (ToColor.Model == ColorModel.YCbCr) { n = ((ColorYCbCr)ToColor).BaseSpaceName; m = ((ColorYCbCr)ToColor).SpaceName; } else if (ToColor.Model == ColorModel.RGB) { n = ((ColorRGB)ToColor).SpaceName; } else if (ToColor.Model == ColorModel.HSV) { n = ((ColorRGB)ToColor).SpaceName; } else if (ToColor.Model == ColorModel.HSL) { n = ((ColorRGB)ToColor).SpaceName; } if (n != ColorConverter.StandardColorspace) { conv.SetFast(FromColor, ToColor.Model, n, m); } else { conv.SetFast(FromColor, ToColor.Model, ToColor.ReferenceWhite); } } for (int i = 0; i < end / Threadcount && !MainWorker.CancellationPending; i++) { if (DoFast) { watch.Start(); conv.ConvertFast(FromColor); watch.Stop(); } else { if (FromColor.IsICCcolor && !FromColor.IsPCScolor) { watch.Start(); From2Color = conv.ToICC(FromColor); watch.Stop(); } switch (ToColor.Model) { case ColorModel.CIELab: watch.Start(); conv.ToLab(From2Color, ToColor.ReferenceWhite); watch.Stop(); break; case ColorModel.CIELCHab: watch.Start(); conv.ToLCHab(From2Color, ToColor.ReferenceWhite); watch.Stop(); break; case ColorModel.CIELCHuv: watch.Start(); conv.ToLCHuv(From2Color, ToColor.ReferenceWhite); watch.Stop(); break; case ColorModel.CIELuv: watch.Start(); conv.ToLuv(From2Color, ToColor.ReferenceWhite); watch.Stop(); break; case ColorModel.CIEXYZ: watch.Start(); conv.ToXYZ(From2Color, ToColor.ReferenceWhite); watch.Stop(); break; case ColorModel.CIEYxy: watch.Start(); conv.ToYxy(From2Color, ToColor.ReferenceWhite); watch.Stop(); break; case ColorModel.Gray: watch.Start(); conv.ToGray(From2Color, ToColor.ReferenceWhite); watch.Stop(); break; case ColorModel.HSL: RGBSpaceName n = ((ColorHSL)ToColor).SpaceName; if (n == RGBSpaceName.ICC) { goto default; } watch.Start(); conv.ToHSL(From2Color, n); watch.Stop(); break; case ColorModel.HSV: n = ((ColorHSV)ToColor).SpaceName; if (n == RGBSpaceName.ICC) { goto default; } watch.Start(); conv.ToHSV(From2Color, n); watch.Stop(); break; case ColorModel.RGB: n = ((ColorRGB)ToColor).SpaceName; if (n == RGBSpaceName.ICC) { goto default; } watch.Start(); conv.ToRGB(From2Color, n); watch.Stop(); break; case ColorModel.YCbCr: n = ((ColorYCbCr)ToColor).BaseSpaceName; YCbCrSpaceName m = ((ColorYCbCr)ToColor).SpaceName; if (m == YCbCrSpaceName.ICC) { goto default; } watch.Start(); conv.ToYCbCr(From2Color, n, m); watch.Stop(); break; case ColorModel.LCH99: watch.Start(); conv.ToLCH99(From2Color); watch.Stop(); break; case ColorModel.LCH99b: watch.Start(); conv.ToLCH99b(From2Color); watch.Stop(); break; case ColorModel.LCH99c: watch.Start(); conv.ToLCH99c(From2Color); watch.Stop(); break; case ColorModel.LCH99d: watch.Start(); conv.ToLCH99d(From2Color); watch.Stop(); break; default: watch.Start(); conv.ToICC(conv.ToICC_PCS(From2Color, ToICC), ToICC); watch.Stop(); break; } } progress++; time += watch.ElapsedTicks; if (progress % 100 == 0) { MainWorker.ReportProgress(progress * 100 / (end - 1)); } } }