Exemple #1
0
        // Get scaling factor limited to available memory
        private static float GetUpperScalingLimit(SizeF scaledSize, float scalingFactor)
        {
            // estimate required memory and use 60% as threshold value
            var required  = EffectGraph.GetEstimatedRequiredMemory(scaledSize);
            var threshold = (EffectGraph.AvailableMemory * 100) / 60;

            if (required > threshold)
            {
                // limit scaling factor to fit available memory
                var maxPixels      = EffectGraph.GetMaximumPixelCount(threshold);
                var originalPixels = ((double)scaledSize.Width * scaledSize.Height) / scalingFactor;
                return((float)(maxPixels / originalPixels));
            }

            return(scalingFactor);
        }
        // Once the scaled style image exceed a certain size, warn the user.
        // The models are not GPU-accellerated and might be very slow to
        // calculate if the image size is rather large plus a large amount
        // of RAM is required
        private void WarnAboutImageSize()
        {
            var s       = trackBarSize.Value / 100.0;
            var pixels  = (long?)(pictureBoxStyle.Image?.Width * pictureBoxStyle.Image?.Height * s * s);
            var maximum = EffectGraph.GetMaximumPixelCount((long)(EffectGraph.AvailableMemory * 0.8));

            if (pixels > maximum)
            {
                labelStyleDimensions.ForeColor = labelSizeWarning.ForeColor;
                labelStyleDimensions.Font      = labelSizeWarning.Font;
                labelSizeWarning.Visible       = true;
                panelWarning.Visible           = true;
            }
            else
            {
                labelStyleDimensions.ForeColor = labelStyle.ForeColor;
                labelStyleDimensions.Font      = labelStyle.Font;
                labelSizeWarning.Visible       = false;
                panelWarning.Visible           = false;
            }
        }