Пример #1
0
        /// <summary>
        ///     Generates the <see cref="ContrastConfig"/> for a flatbed/feeder <paramref name="config"/>.
        /// </summary>
        internal static ContrastConfig GenerateContrastConfig(IImageScannerSourceConfiguration config)
        {
            if (config.ContrastStep == 0)
            {
                return(null);
            }

            ContrastConfig result = new ContrastConfig
            {
                MinContrast     = config.MinContrast,
                MaxContrast     = config.MaxContrast,
                ContrastStep    = (int)config.ContrastStep,
                DefaultContrast = config.DefaultContrast,
            };

            // determine virtual default contrast
            if (Math.Abs(Math.Abs(result.DefaultContrast + result.ContrastStep)
                         - Math.Abs(result.MaxContrast))
                <=
                Math.Abs(Math.Abs(result.DefaultContrast - result.ContrastStep)
                         - Math.Abs(result.MinContrast)))
            {
                result.VirtualDefaultContrast = result.DefaultContrast
                                                - result.ContrastStep;
            }
            else
            {
                result.VirtualDefaultContrast = result.DefaultContrast
                                                + result.ContrastStep;
            }

            return(result);
        }
Пример #2
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // CONSTRUCTORS / FACTORIES /////////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public DiscoveredScanner(ImageScanner device, string name)
        {
            Device = device;
            Id     = Device.DeviceId;

            Name = name;

            try
            {
                IsAutoAllowed    = device.IsScanSourceSupported(ImageScannerScanSource.AutoConfigured);
                IsFeederAllowed  = device.IsScanSourceSupported(ImageScannerScanSource.Feeder);
                IsFlatbedAllowed = device.IsScanSourceSupported(ImageScannerScanSource.Flatbed);
            }
            catch (Exception exc)
            {
                LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine supported scan sources.");
                throw;
            }

            // auto mode
            if (IsAutoAllowed)
            {
                LogService.Log.Information("DiscoveredScanner: Processing auto mode");
                IsAutoPreviewAllowed = device.IsPreviewSupported(ImageScannerScanSource.AutoConfigured);

                AutoFormats = GenerateFormats(device.AutoConfiguration);
            }

            // flatbed mode
            if (IsFlatbedAllowed)
            {
                LogService.Log.Information("DiscoveredScanner: Processing flatbed mode");
                IsFlatbedColorAllowed      = device.FlatbedConfiguration.IsColorModeSupported(ImageScannerColorMode.Color);
                IsFlatbedGrayscaleAllowed  = device.FlatbedConfiguration.IsColorModeSupported(ImageScannerColorMode.Grayscale);
                IsFlatbedMonochromeAllowed = device.FlatbedConfiguration.IsColorModeSupported(ImageScannerColorMode.Monochrome);
                IsFlatbedAutoColorAllowed  = device.FlatbedConfiguration.IsColorModeSupported(ImageScannerColorMode.AutoColor);

                if (!IsFlatbedColorAllowed && !IsFlatbedGrayscaleAllowed && !IsFlatbedMonochromeAllowed && !IsFlatbedAutoColorAllowed)
                {
                    // no color mode allowed, source mode is invalid
                    IsFlatbedAllowed = false;
                    LogService.Log.Warning("DiscoveredScanner: No color mode for flatbed allowed, invalid source mode");
                }
                else
                {
                    LogService.Log.Information("DiscoveredScanner: Flatbed supports at least one color mode");

                    try
                    {
                        IsFlatbedPreviewAllowed = device.IsPreviewSupported(ImageScannerScanSource.Flatbed);
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine preview support for flatbed.");
                        throw;
                    }

                    try
                    {
                        IsFlatbedAutoCropSingleRegionAllowed = device.FlatbedConfiguration
                                                               .IsAutoCroppingModeSupported(ImageScannerAutoCroppingMode.SingleRegion);
                        IsFlatbedAutoCropMultiRegionAllowed = device.FlatbedConfiguration
                                                              .IsAutoCroppingModeSupported(ImageScannerAutoCroppingMode.MultipleRegion);
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine auto crop support for flatbed.");
                        throw;
                    }

                    FlatbedResolutions = GenerateResolutions(device.FlatbedConfiguration);
                    LogService.Log.Information("Generated {@Resolutions} for flatbed.", FlatbedResolutions);

                    FlatbedFormats = GenerateFormats(device.FlatbedConfiguration);
                    LogService.Log.Information("Generated {@Formats} for feeder.", FlatbedFormats);

                    try
                    {
                        if (device.FlatbedConfiguration.BrightnessStep != 0)
                        {
                            FlatbedBrightnessConfig = GenerateBrightnessConfig(device.FlatbedConfiguration);
                        }
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine BrightnessConfig for flatbed.");
                        throw;
                    }

                    try
                    {
                        if (device.FlatbedConfiguration.ContrastStep != 0)
                        {
                            FlatbedContrastConfig = GenerateContrastConfig(device.FlatbedConfiguration);
                        }
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine ContrastConfig for flatbed.");
                        throw;
                    }
                }
            }

            // feeder mode
            if (IsFeederAllowed)
            {
                LogService.Log.Information("DiscoveredScanner: Processing feeder mode");
                IsFeederColorAllowed      = device.FeederConfiguration.IsColorModeSupported(ImageScannerColorMode.Color);
                IsFeederGrayscaleAllowed  = device.FeederConfiguration.IsColorModeSupported(ImageScannerColorMode.Grayscale);
                IsFeederMonochromeAllowed = device.FeederConfiguration.IsColorModeSupported(ImageScannerColorMode.Monochrome);
                IsFeederAutoColorAllowed  = device.FeederConfiguration.IsColorModeSupported(ImageScannerColorMode.AutoColor);

                if (!IsFeederColorAllowed && !IsFeederGrayscaleAllowed && !IsFeederMonochromeAllowed && !IsFeederAutoColorAllowed)
                {
                    // no color mode allowed, source mode is invalid
                    IsFeederAllowed = false;
                    LogService.Log.Warning("DiscoveredScanner: No color mode for feeder allowed, invalid source mode");
                }
                else
                {
                    LogService.Log.Information("DiscoveredScanner: Feeder supports at least one color mode");

                    try
                    {
                        IsFeederDuplexAllowed = device.FeederConfiguration.CanScanDuplex;
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine duplex support for feeder.");
                        throw;
                    }

                    try
                    {
                        IsFeederPreviewAllowed = device.IsPreviewSupported(ImageScannerScanSource.Feeder);
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine preview support for feeder.");
                        throw;
                    }

                    try
                    {
                        IsFeederAutoCropSingleRegionAllowed = device.FeederConfiguration
                                                              .IsAutoCroppingModeSupported(ImageScannerAutoCroppingMode.SingleRegion);
                        IsFeederAutoCropMultiRegionAllowed = device.FeederConfiguration
                                                             .IsAutoCroppingModeSupported(ImageScannerAutoCroppingMode.MultipleRegion);
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine auto crop support for feeder.");
                        throw;
                    }

                    FeederResolutions = GenerateResolutions(device.FeederConfiguration);
                    LogService.Log.Information("Generated {@Resolutions} for feeder.", FeederResolutions);

                    FeederFormats = GenerateFormats(device.FeederConfiguration);
                    LogService.Log.Information("Generated {@Formats} for feeder.", FeederFormats);

                    try
                    {
                        if (device.FeederConfiguration.BrightnessStep != 0)
                        {
                            FeederBrightnessConfig = GenerateBrightnessConfig(device.FeederConfiguration);
                        }
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine BrightnessConfig for feeder.");
                        throw;
                    }

                    try
                    {
                        if (device.FeederConfiguration.ContrastStep != 0)
                        {
                            FeederContrastConfig = GenerateContrastConfig(device.FeederConfiguration);
                        }
                    }
                    catch (Exception exc)
                    {
                        LogService.Log.Error(exc, "DiscoveredScanner: Couldn't determine ContrastConfig for feeder.");
                        throw;
                    }
                }
            }

            if (!IsAutoAllowed && !IsFlatbedAllowed && !IsFeederAllowed)
            {
                // no source mode allowed, scanner is invalid and useless
                throw new ArgumentException("Scanner doesn't support any source mode and can't be used.");
            }

            LogService.Log.Information("Created {@DiscoveredScanner}", this);
        }