Ejemplo n.º 1
0
        /// <summary>
        /// gets the desired resolution based on input settings
        /// </summary>
        /// <param name="sourceWidth">the complete width of the input file without cropping</param>
        /// <param name="sourceHeight">the complete height of the input file without cropping</param>
        /// <param name="inputDAR">the input DAR value</param>
        /// <param name="cropping">the crop values</param>
        /// <param name="mod">the mod value used for the final resize values</param>
        /// <param name="resizeEnabled">true if resize can be used</param>
        /// <param name="upsizingEnabled">true if upsizing can be used</param>
        /// <param name="signalAR">whether or not ar signalling is to be used for the output
        /// (depending on this parameter, resizing changes to match the source AR)</param>
        /// <param name="suggestHeight">true if height should be calculated</param>
        /// <param name="acceptableAspectErrorPercent">acceptable aspect error if signalAR is true</param>
        /// <param name="outputWidth">the calculated output width</param>
        /// <param name="outputHeight">the calculated output height</param>
        /// <param name="outputDar">the output DAR value</param>
        /// <param name="_log">the log item</param>
        private static void getResolution(int sourceWidth, int sourceHeight, Dar inputDar,
                                          CropValues cropValues, bool cropEnabled, int mod, bool resizeEnabled,
                                          bool upsizingAllowed, bool signalAR, bool suggestHeight,
                                          decimal acceptableAspectErrorPercent, ref int outputWidth,
                                          ref int outputHeight, out Dar?outputDar, LogItem _log)
        {
            outputDar = null;

            CropValues cropping = new CropValues();

            if (cropEnabled)
            {
                cropping = cropValues.Clone();
            }

            // remove upsizing if not allowed
            if (!upsizingAllowed && sourceWidth - cropping.left - cropping.right < outputWidth)
            {
                outputWidth = sourceWidth - cropping.left - cropping.right;
                if (_log != null)
                {
                    _log.LogEvent("Lowering output width resolution to " + outputWidth + " to avoid upsizing");
                }
            }

            // correct hres if not mod compliant
            if (outputWidth % mod != 0)
            {
                int diff = outputWidth % mod;
                if (outputWidth - diff > 0)
                {
                    outputWidth -= diff;
                }
                else
                {
                    outputWidth = mod;
                }
            }

            if (suggestHeight)
            {
                int scriptVerticalResolution = Resolution.SuggestVerticalResolution(sourceHeight, sourceWidth, inputDar, cropping,
                                                                                    outputWidth, signalAR, out outputDar, mod, acceptableAspectErrorPercent);

                int iMaximum = 9999;
                if (!upsizingAllowed)
                {
                    iMaximum = sourceHeight - cropping.top - cropping.bottom;
                }

                // Reduce horizontal resolution until a fit is found
                while (scriptVerticalResolution > iMaximum && outputWidth > mod)
                {
                    outputWidth -= mod;
                    scriptVerticalResolution = Resolution.SuggestVerticalResolution(sourceHeight, sourceWidth, inputDar, cropping,
                                                                                    outputWidth, signalAR, out outputDar, mod, acceptableAspectErrorPercent);
                }
                outputHeight = scriptVerticalResolution;
            }
            else if (!resizeEnabled)
            {
                outputHeight = sourceHeight - cropping.top - cropping.bottom;
            }
        }