Ejemplo n.º 1
0
        static int OrderComparisonTwoShotSettings(ShotSetting shotSetting1, ShotSetting shotSetting2)
        {
            int tmpCompare = shotSetting1.channelColor.CompareTo(shotSetting2.channelColor);

            if (tmpCompare != 0)
            {
                return(tmpCompare);
            }
            else
            {
                return(shotSetting1.exposureMultiplier.CompareTo(shotSetting2.exposureMultiplier));
            }
        }
Ejemplo n.º 2
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            //_totalFiles = filesInSourceFolder.Length;

            List <string[]> completeGroups = new List <string[]>();

            int frameDelay = 0;

            //byte[] RGBPositions = new byte[1];
            ShotSetting[] shotSettings             = new ShotSetting[3];
            bool          IsTIFF                   = false;
            bool          IsEXR                    = false;
            int           maxThreads               = Environment.ProcessorCount;
            string        customOutputName         = "";
            int           leadingZeros             = 0;
            bool          overwriteExisting        = false;
            float         HDRClippingPoint         = 0.99f;
            float         HDRFeatherMultiplier     = 1;
            bool          EXRIntegrityVerification = true;

            this.Dispatcher.Invoke(() =>
            {
                frameDelay = 0;
                int.TryParse(delay.Text, out frameDelay);
                int.TryParse(outputNameLeadingZeros_txt.Text, out leadingZeros);
                int.TryParse(maxThreads_txt.Text, out maxThreads);
                //RGBPositions = getRGBPositions();
                shotSettings             = getShots();
                IsTIFF                   = (bool)formatTif.IsChecked;
                IsEXR                    = (bool)formatExr.IsChecked;
                customOutputName         = outputNameBase_txt.Text;
                overwriteExisting        = !(bool)overwrite_no.IsChecked && (bool)overwrite_yes.IsChecked;
                HDRClippingPoint         = getHDRClippingpoint();
                HDRFeatherMultiplier     = getFeatherMultiplier();
                EXRIntegrityVerification = (bool)exrIntegrityVerification_check.IsChecked;
            });

            int groupLength = shotSettings.Length;

            _totalFiles = (int)Math.Floor(filesInSourceFolder.Length / (decimal)groupLength);

            if (maxThreads == 0)
            {
                maxThreads = Environment.ProcessorCount;
            }


            FORMAT inputFormat = getInputFormat();

            TARGETFORMAT targetFormat = TARGETFORMAT.EXR;

            if (IsEXR)
            {
                targetFormat = TARGETFORMAT.EXR;
            }
            else
            {
                targetFormat = TARGETFORMAT.TIF;
            }


            for (int baseIndex = frameDelay; baseIndex < filesInSourceFolder.Length; baseIndex += groupLength)
            {
                if ((baseIndex + (groupLength - 1)) > (filesInSourceFolder.Length - 1))
                {
                    MessageBox.Show("Group incomplete. Skipping.");
                    continue;
                }

                int[]    fileIndizi = new int[groupLength];
                string[] files      = new string[groupLength];
                for (var i = 0; i < groupLength; i++)
                {
                    fileIndizi[i] = baseIndex + i;
                    files[i]      = filesInSourceFolder[baseIndex + i];
                }

                //int[] RGBIndizi = new int[groupLength] { baseIndex + RGBPositions[0], baseIndex + RGBPositions[1], baseIndex + RGBPositions[2] };

                //string[] RGBFiles = new string[groupLength] { filesInSourceFolder[RGBIndizi[0]], filesInSourceFolder[RGBIndizi[1]], filesInSourceFolder[RGBIndizi[2]] };

                completeGroups.Add(files);
            }

            int processFrom = 1;
            int processTo   = completeGroups.Count();

            this.Dispatcher.Invoke(() =>
            {
                int.TryParse(processFrom_txt.Text, out processFrom);
                int.TryParse(processTo_txt.Text, out processTo);
            });

            // Index starting at 0, but GUI starts at 1
            processFrom--;
            processTo--;


            var countLock = new object();

            CurrentProgress = 0;

            _counterTotal           = 0;
            _counterSkippedRange    = 0;
            _counterDone            = 0;
            _counterSkippedExisting = 0;

            if (EXRIntegrityVerification)
            {
                IntegrityChecker.BuildIntegrityVerificationAcceptableLossCache();
            }

            integrityCheckFailCount = 0;

            Parallel.ForEach(completeGroups,
                             new ParallelOptions {
                MaxDegreeOfParallelism = maxThreads
            }, (currentGroup, loopState, index) =>
                             // foreach (string srcFileName in filesInSourceFolder)
            {
                _counterTotal++;
                var percentage = (double)_counterTotal / _totalFiles * 100.0;
                if (worker.CancellationPending == true)
                {
                    e.Cancel = true;
                    return;
                }

                if (index < processFrom || index > processTo)
                {
                    // Skip this one.
                    _counterSkippedRange++;
                    lock (countLock) { worker?.ReportProgress((int)percentage); }
                    return;
                }

                string fileNameWithoutFolder = customOutputName == "" ? Path.GetFileNameWithoutExtension(currentGroup[0]) : customOutputName + (leadingZeros == 0 ? index.ToString() : index.ToString("D" + leadingZeros.ToString()));

                string fileNameWithoutExtension =
                    targetFolder + "\\" + fileNameWithoutFolder;
                string fileName = fileNameWithoutExtension + (targetFormat == TARGETFORMAT.EXR ? ".exr" : "") + (targetFormat == TARGETFORMAT.TIF ? ".tif" : "");


                if (File.Exists(fileName) && !overwriteExisting)
                {
                    // Error: File already exists. No overwriting. Move on.
                    //continue;
                    _counterSkippedExisting++;
                    lock (countLock) { worker?.ReportProgress((int)percentage); }
                    return;
                }

                ProcessRAW(currentGroup, shotSettings, fileName, targetFormat, inputFormat, maxThreads, HDRClippingPoint, HDRFeatherMultiplier, EXRIntegrityVerification);
                _counterDone++;
                lock (countLock) { worker?.ReportProgress((int)percentage); }
            });
            this.Dispatcher.Invoke(() =>
            {
                txtStatus.Text = "Finished. " + integrityCheckFailCount + " integrity check fails";
            });
        }
Ejemplo n.º 3
0
        private ShotSetting[] getShots()
        {
            string[]           shotTexts    = { colorA.Text, colorB.Text, colorC.Text, colorD.Text, colorE.Text, colorF.Text };
            List <ShotSetting> shotSettings = new List <ShotSetting>();

            int index = 0;

            for (int i = 0; i < 6; i++)
            {
                if (shotTexts[i].Trim() == "")
                {
                    // nothing
                }
                else
                {
                    ShotSetting shotSettingTemp = new ShotSetting();
                    shotSettingTemp.exposureMultiplier = 1;
                    shotSettingTemp.orderIndex         = index;

                    MatchCollection matches = shotSettingTextRegexp.Matches(shotTexts[i]);

                    // Try cach just in case the regexp doesnt give proper results for some reason.
                    try
                    {
                        string color    = matches[0].Groups[1].Value.ToUpper();
                        string operater = matches[0].Groups[2].Value;
                        string number   = matches[0].Groups[3].Value;

                        float numberParsed            = 1;
                        bool  numberParsingSuccessful = float.TryParse(number, out numberParsed);

                        bool isEmpty = false;

                        switch (color)
                        {
                        case "R":
                            shotSettingTemp.channelColor = CHANNELCOLOR.RED;
                            break;

                        case "G":
                            shotSettingTemp.channelColor = CHANNELCOLOR.GREEN;
                            break;

                        case "B":
                            shotSettingTemp.channelColor = CHANNELCOLOR.BLUE;
                            break;

                        case "X":
                            isEmpty = true;
                            break;

                        default:
                            break;
                        }

                        // If the number wasn't parsed properly, may as well stop here.
                        if (!isEmpty && numberParsingSuccessful)
                        {
                            switch (operater)
                            {
                            case "+":
                                shotSettingTemp.exposureMultiplier = (float)Math.Pow(2, numberParsed);
                                break;

                            case "*":
                                shotSettingTemp.exposureMultiplier = numberParsed;
                                break;

                            case "-":
                            case "/":
                            default:
                                // Not implemented. Always declare the overexposed shots!
                                shotSettingTemp.exposureMultiplier = 1;
                                break;
                            }
                        }

                        if (!isEmpty)
                        {
                            shotSettings.Add(shotSettingTemp);
                            index++;
                        }
                        else
                        {
                            // nothing
                        }
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Some weird error parsing the shot settings.");
                    }
                }
            }

            // Order by color and exposure
            // Color order is primary order: R, G, B
            // Exposure order: Starting with smallest exposure multiplier.
            shotSettings.Sort(OrderComparisonTwoShotSettings);

            return(shotSettings.ToArray());
        }