Example #1
0
        private void BuildCollections()
        {
            string dir = Bovender.Unmanaged.Pinvoke.GetColorDirectory();

            Logger.Info("BuildCollections: Dir: {0}", dir);
            if (String.IsNullOrEmpty(dir))
            {
                Logger.Fatal("BuildCollections: No color profile directory!");
                throw new InvalidOperationException(
                          "Windows did not tell color profile directory");
            }

            using (Bovender.Unmanaged.DllManager dllManager = new Bovender.Unmanaged.DllManager())
            {
                ColorProfileViewModel           vm;
                ColorProfileViewModelCollection coll;
                dllManager.LoadDll("lcms2.dll");
                foreach (string fn in System.IO.Directory.EnumerateFiles(dir,
                                                                         "*" + Lcms.Constants.COLOR_PROFILE_EXTENSION))
                {
                    vm = ColorProfileViewModel.CreateFromFile(fn);
                    if (vm != null)
                    {
                        if (!_profiles.TryGetValue(vm.ColorSpace, out coll))
                        {
                            coll = new ColorProfileViewModelCollection();
                            _profiles.Add(vm.ColorSpace, coll);
                        }
                        coll.Add(vm);
                    }
                }
            }
            OnPropertyChanged("Profiles");
        }
Example #2
0
        /// <summary>
        /// Creates a new ColorProfileViewModel from a given file, but only
        /// if the color profile's color space is known by the view model.
        /// Note that the lcms2.dll must have been loaded prior to calling
        /// this method!
        /// </summary>
        /// <param name="fileName">Full file name of the ICS color profile.</param>
        /// <returns>Instance of ColorProfileViewModel, or null if the color
        /// profile has an unknown color space.</returns>
        public static ColorProfileViewModel CreateFromFile(string fileName)
        {
            cmsHProfile           h    = cmsOpenProfileFromFile(fileName, "r");
            ColorProfileViewModel cpvm = null;

            if (h != IntPtr.Zero)
            {
                ColorSpaceSignature c;
                try
                {
                    // Only create a view model if we can handle
                    // the current profile's color space.
                    // Attempt to convert the CMS color space signature
                    // to an XL Toolbox ColorSpaceSignature enum value.
                    // If this fails, cpvm will remain null.
                    c = cmsGetColorSpace(h);
                    ColorSpace colorSpace = c.ToColorSpace();
                    cpvm            = new ColorProfileViewModel(fileName);
                    cpvm.ColorSpace = colorSpace;
                }
                catch (NotImplementedException)
                {
                    // NO-OP
                }
                finally
                {
                    cmsCloseProfile(h);
                }
            }
            return(cpvm);
        }
Example #3
0
        /// <summary>
        /// Selects a color profile for the current color space by name,
        /// if it exists.
        /// </summary>
        /// <param name="colorProfile">Color profile to select in the
        /// current color space.</param>
        /// <returns>True if the profile is exists and was selected,
        /// false if not.</returns>
        public bool SelectIfExists(string colorProfile)
        {
            ColorProfileViewModel vm = Profiles.FirstOrDefault(
                c => String.Equals(c.Name, colorProfile));

            if (vm != null)
            {
                SelectedProfile = vm;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #4
0
 private void ConvertColor(FreeImageBitmap freeImageBitmap)
 {
     if (Preset.UseColorProfile)
     {
         Logger.Info("ConvertColor: Convert color using profile");
         ViewModels.ColorProfileViewModel targetProfile =
             ViewModels.ColorProfileViewModel.CreateFromName(Preset.ColorProfile);
         targetProfile.TransformFromStandardProfile(freeImageBitmap);
         freeImageBitmap.ConvertColorDepth(Preset.ColorSpace.ToFreeImageColorDepth());
     }
     else
     {
         Logger.Info("ConvertColor: Convert color without profile");
         freeImageBitmap.ConvertColorDepth(Preset.ColorSpace.ToFreeImageColorDepth());
     }
     if (Preset.ColorSpace == ColorSpace.Monochrome)
     {
         SetMonochromePalette(freeImageBitmap);
     }
 }