Esempio n. 1
0
        private void ShotInner([NotNull] string carId, [NotNull] string skinId, [CanBeNull] string destination,
                               [CanBeNull] ImageUtils.ImageInformation information, [CanBeNull] Action callback)
        {
            if (destination == null)
            {
                destination = Path.Combine(AcPaths.GetCarSkinDirectory(_acRoot, carId, skinId), _options.PreviewName);
            }

            var shotStream = new MemoryStream(_approximateSize ?? 100000);

            _renderer.Shot(_renderer.Width, _renderer.Height, _options.SoftwareDownsize ? 1d : 1d / _options.SsaaMultiplier, 1d, shotStream,
                           RendererShotFormat.Png);
            if (!_approximateSize.HasValue || _approximateSize < shotStream.Position)
            {
                _approximateSize = (int)(shotStream.Position * 1.2);
            }

            shotStream.Position = 0;
            ProcessConvertation(() => {
                using (var stream = File.Open(destination, FileMode.Create, FileAccess.ReadWrite)) {
                    ImageUtils.Convert(shotStream, stream,
                                       _options.SoftwareDownsize ? new Size(_options.PreviewWidth, _options.PreviewHeight) : (Size?)null, exif: information,
                                       format: destination.EndsWith(".png") ? ImageFormat.Png : ImageFormat.Jpeg);
                    callback?.Invoke();
                }
            }, DisposeCallback(shotStream));
        }
Esempio n. 2
0
        private static ImageUtils.ImageInformation GetInformation(CarObject car, CarSkinObject skin, string presetName, string checksum)
        {
            var result = new ImageUtils.ImageInformation {
                Software = $"ContentManager {BuildInformation.AppVersion}",
                Comment  = presetName == null ? $"Settings checksum: {checksum}" : $"Used preset: {presetName} (checksum: {checksum})"
            };

            if (SettingsHolder.CustomShowroom.DetailedExifForPreviews)
            {
                result.Subject = $"{car.DisplayName}";
                result.Title   = $"{car.DisplayName} ({skin.DisplayName})";
                result.Tags    = car.Tags.ToArray();
                result.Author  = skin.Author ?? car.Author;
            }

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Update preview.
        /// </summary>
        /// <param name="carId">Car ID.</param>
        /// <param name="skinId">Skin ID.</param>
        /// <param name="destination">Destination filename.</param>
        /// <param name="carData">Car data (provide it only if it’s already loaded, so Updater won’t load it again).</param>
        /// <param name="information">Some lines for EXIF data, optional.</param>
        /// <param name="callback">Callback in Task version? Because, with Delayed Convertation enabled, image might be saved later.</param>
        public async Task ShotAsync(string carId, string skinId, string destination = null, DataWrapper carData = null,
                                    ImageUtils.ImageInformation information         = null, Action callback     = null)
        {
            if (_carId != carId)
            {
                if (_renderer == null)
                {
                    _renderer = await Task.Run(() => CreateRenderer(_acRoot, _options, GetCarDescription(carId, carData), skinId)).ConfigureAwait(false);
                }
                else
                {
                    await _renderer.SetCarAsync(GetCarDescription(carId, carData), skinId);
                }
                _carId = carId;
                UpdateCamera();
            }
            else
            {
                _renderer.SelectSkin(skinId);
            }

            await ShotInnerAsync(carId, skinId, destination, information, callback).ConfigureAwait(false);
        }
Esempio n. 4
0
        /// <summary>
        /// Update preview.
        /// </summary>
        /// <param name="carId">Car ID.</param>
        /// <param name="skinId">Skin ID.</param>
        /// <param name="destination">Destination filename.</param>
        /// <param name="carData">Car data (provide it only if it’s already loaded, so Updater won’t load it again).</param>
        /// <param name="information">Some lines for EXIF data, optional.</param>
        /// <param name="callback">Callback in sync version? Because, with Delayed Convertation enabled, even sync version is not so sync.</param>
        public void Shot([NotNull] string carId, [NotNull] string skinId, string destination = null, DataWrapper carData = null, ImageUtils.ImageInformation information = null,
                         Action callback = null)
        {
            if (_carId != carId)
            {
                if (_renderer == null)
                {
                    _renderer = CreateRenderer(_acRoot, _options, GetCarDescription(carId, carData), skinId);
                }
                else
                {
                    _renderer.MainSlot.SetCar(GetCarDescription(carId, carData), skinId);
                }
                _carId = carId;
                UpdateCamera();
            }
            else
            {
                _renderer.SelectSkin(skinId);
            }

            _renderer.OnTick(float.MaxValue);
            ShotInner(carId, skinId, destination, information, callback);
        }
Esempio n. 5
0
 private Task ShotInnerAsync([NotNull] string carId, [NotNull] string skinId, [CanBeNull] string destination,
                             [CanBeNull] ImageUtils.ImageInformation information, [CanBeNull] Action callback)
 {
     return(Task.Run(() => ShotInner(carId, skinId, destination, information, callback)));
 }
Esempio n. 6
0
 private Task ShotInnerAsync(string carId, string skinId, string destination, ImageUtils.ImageInformation information, Action callback)
 {
     return(Task.Run(() => ShotInner(carId, skinId, destination, information, callback)));
 }