gimpcolorconfig.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  1. /* LIBGIMP - The GIMP Library
  2. * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. *
  4. * GimpColorConfig class
  5. * Copyright (C) 2004 Stefan Döhla <stefan@doehla.de>
  6. *
  7. * This library is free software: you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 3 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library. If not, see
  19. * <https://www.gnu.org/licenses/>.
  20. */
  21. #include "config.h"
  22. #include <cairo.h>
  23. #include <gegl.h>
  24. #include <gdk-pixbuf/gdk-pixbuf.h>
  25. #include "libgimpbase/gimpbase.h"
  26. #include "libgimpcolor/gimpcolor.h"
  27. #include "gimpconfigtypes.h"
  28. #include "gimpcolorconfig.h"
  29. #include "gimpconfig-error.h"
  30. #include "gimpconfig-iface.h"
  31. #include "gimpconfig-params.h"
  32. #include "gimpconfig-path.h"
  33. #include "libgimp/libgimp-intl.h"
  34. /**
  35. * SECTION: gimpcolorconfig
  36. * @title: GimpColorConfig
  37. * @short_description: Color management settings.
  38. *
  39. * Color management settings.
  40. **/
  41. #define COLOR_MANAGEMENT_MODE_BLURB \
  42. _("How images are displayed on screen.")
  43. #define DISPLAY_PROFILE_BLURB \
  44. _("The color profile of your (primary) monitor.")
  45. #define DISPLAY_PROFILE_FROM_GDK_BLURB \
  46. _("When enabled, GIMP will try to use the display color profile from " \
  47. "the windowing system. The configured monitor profile is then only " \
  48. "used as a fallback.")
  49. #define RGB_PROFILE_BLURB \
  50. _("The preferred RGB working space color profile. It will be offered " \
  51. "next to the built-in RGB profile when a color profile can be chosen.")
  52. #define GRAY_PROFILE_BLURB \
  53. _("The preferred grayscale working space color profile. It will be offered " \
  54. "next to the built-in grayscale profile when a color profile can be chosen.")
  55. #define CMYK_PROFILE_BLURB \
  56. _("The CMYK color profile used to convert between RGB and CMYK.")
  57. #define SIMULATION_PROFILE_BLURB \
  58. _("The color profile to use for soft-proofing from your image's " \
  59. "color space to some other color space, including " \
  60. "soft-proofing to a printer or other output device profile.")
  61. #define DISPLAY_RENDERING_INTENT_BLURB \
  62. _("How colors are converted from your image's color space to your " \
  63. "display device. Relative colorimetric is usually the best choice. " \
  64. "Unless you use a LUT monitor profile (most monitor profiles are " \
  65. "matrix), choosing perceptual intent really gives you relative " \
  66. "colorimetric." )
  67. #define DISPLAY_USE_BPC_BLURB \
  68. _("Do use black point compensation (unless you know you have a reason " \
  69. "not to).")
  70. #define DISPLAY_OPTIMIZE_BLURB \
  71. _("When disabled, image display might be of better quality " \
  72. "at the cost of speed.")
  73. #define SIMULATION_RENDERING_INTENT_BLURB \
  74. _("How colors are converted from your image's color space to the " \
  75. "output simulation device (usually your monitor). " \
  76. "Try them all and choose what looks the best.")
  77. #define SIMULATION_USE_BPC_BLURB \
  78. _("Try with and without black point compensation "\
  79. "and choose what looks best.")
  80. #define SIMULATION_OPTIMIZE_BLURB \
  81. _("When disabled, soft-proofing might be of better quality " \
  82. "at the cost of speed.")
  83. #define SIMULATION_GAMUT_CHECK_BLURB \
  84. _("When enabled, the soft-proofing will mark colors " \
  85. "which can not be represented in the target color space.")
  86. #define OUT_OF_GAMUT_COLOR_BLURB \
  87. _("The color to use for marking colors which are out of gamut.")
  88. #define SHOW_RGB_U8_BLURB \
  89. _("When enabled, set the color scales to display 0...255 instead " \
  90. "of percentages")
  91. #define SHOW_HSV_BLURB \
  92. _("When enabled, set the color scales to display HSV blend mode instead " \
  93. "of LCh")
  94. enum
  95. {
  96. PROP_0,
  97. PROP_MODE,
  98. PROP_RGB_PROFILE,
  99. PROP_GRAY_PROFILE,
  100. PROP_CMYK_PROFILE,
  101. PROP_DISPLAY_PROFILE,
  102. PROP_DISPLAY_PROFILE_FROM_GDK,
  103. PROP_SIMULATION_PROFILE,
  104. PROP_DISPLAY_RENDERING_INTENT,
  105. PROP_DISPLAY_USE_BPC,
  106. PROP_DISPLAY_OPTIMIZE,
  107. PROP_SIMULATION_RENDERING_INTENT,
  108. PROP_SIMULATION_USE_BPC,
  109. PROP_SIMULATION_OPTIMIZE,
  110. PROP_SIMULATION_GAMUT_CHECK,
  111. PROP_OUT_OF_GAMUT_COLOR,
  112. PROP_SHOW_RGB_U8,
  113. PROP_SHOW_HSV
  114. };
  115. struct _GimpColorConfigPrivate
  116. {
  117. GimpColorManagementMode mode;
  118. gchar *rgb_profile;
  119. gchar *gray_profile;
  120. gchar *cmyk_profile;
  121. gchar *display_profile;
  122. gboolean display_profile_from_gdk;
  123. gchar *printer_profile;
  124. GimpColorRenderingIntent display_intent;
  125. gboolean display_use_black_point_compensation;
  126. gboolean display_optimize;
  127. GimpColorRenderingIntent simulation_intent;
  128. gboolean simulation_use_black_point_compensation;
  129. gboolean simulation_optimize;
  130. gboolean simulation_gamut_check;
  131. GeglColor *out_of_gamut_color;
  132. gboolean show_rgb_u8;
  133. gboolean show_hsv;
  134. };
  135. #define GET_PRIVATE(obj) (((GimpColorConfig *) (obj))->priv)
  136. static void gimp_color_config_finalize (GObject *object);
  137. static void gimp_color_config_set_property (GObject *object,
  138. guint property_id,
  139. const GValue *value,
  140. GParamSpec *pspec);
  141. static void gimp_color_config_get_property (GObject *object,
  142. guint property_id,
  143. GValue *value,
  144. GParamSpec *pspec);
  145. static void gimp_color_config_set_rgb_profile (GimpColorConfig *config,
  146. const gchar *filename,
  147. GError **error);
  148. static void gimp_color_config_set_gray_profile (GimpColorConfig *config,
  149. const gchar *filename,
  150. GError **error);
  151. static void gimp_color_config_set_cmyk_profile (GimpColorConfig *config,
  152. const gchar *filename,
  153. GError **error);
  154. static void gimp_color_config_set_display_profile (GimpColorConfig *config,
  155. const gchar *filename,
  156. GError **error);
  157. static void gimp_color_config_set_simulation_profile (GimpColorConfig *config,
  158. const gchar *filename,
  159. GError **error);
  160. G_DEFINE_TYPE_WITH_CODE (GimpColorConfig, gimp_color_config, G_TYPE_OBJECT,
  161. G_ADD_PRIVATE (GimpColorConfig)
  162. G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG, NULL)
  163. gimp_type_set_translation_domain (g_define_type_id,
  164. GETTEXT_PACKAGE "-libgimp"))
  165. #define parent_class gimp_color_config_parent_class
  166. static void
  167. gimp_color_config_class_init (GimpColorConfigClass *klass)
  168. {
  169. GObjectClass *object_class = G_OBJECT_CLASS (klass);
  170. GeglColor *magenta;
  171. babl_init ();
  172. /* Magenta (sRGB space). */
  173. magenta = gegl_color_new (NULL);
  174. gegl_color_set_rgba (magenta, 1.0, 0.0, 1.0, 1.0);
  175. object_class->finalize = gimp_color_config_finalize;
  176. object_class->set_property = gimp_color_config_set_property;
  177. object_class->get_property = gimp_color_config_get_property;
  178. GIMP_CONFIG_PROP_ENUM (object_class, PROP_MODE,
  179. "mode",
  180. _("Mode of operation"),
  181. COLOR_MANAGEMENT_MODE_BLURB,
  182. GIMP_TYPE_COLOR_MANAGEMENT_MODE,
  183. GIMP_COLOR_MANAGEMENT_DISPLAY,
  184. GIMP_PARAM_STATIC_STRINGS);
  185. GIMP_CONFIG_PROP_PATH (object_class, PROP_RGB_PROFILE,
  186. "rgb-profile",
  187. _("Preferred RGB profile"),
  188. RGB_PROFILE_BLURB,
  189. GIMP_CONFIG_PATH_FILE, NULL,
  190. GIMP_PARAM_STATIC_STRINGS);
  191. GIMP_CONFIG_PROP_PATH (object_class, PROP_GRAY_PROFILE,
  192. "gray-profile",
  193. _("Preferred grayscale profile"),
  194. GRAY_PROFILE_BLURB,
  195. GIMP_CONFIG_PATH_FILE, NULL,
  196. GIMP_PARAM_STATIC_STRINGS);
  197. GIMP_CONFIG_PROP_PATH (object_class, PROP_CMYK_PROFILE,
  198. "cmyk-profile",
  199. _("CMYK profile"),
  200. CMYK_PROFILE_BLURB,
  201. GIMP_CONFIG_PATH_FILE, NULL,
  202. GIMP_PARAM_STATIC_STRINGS);
  203. GIMP_CONFIG_PROP_PATH (object_class, PROP_DISPLAY_PROFILE,
  204. "display-profile",
  205. _("Monitor profile"),
  206. DISPLAY_PROFILE_BLURB,
  207. GIMP_CONFIG_PATH_FILE, NULL,
  208. GIMP_PARAM_STATIC_STRINGS);
  209. GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_DISPLAY_PROFILE_FROM_GDK,
  210. "display-profile-from-gdk",
  211. _("Use the system monitor profile"),
  212. DISPLAY_PROFILE_FROM_GDK_BLURB,
  213. FALSE,
  214. GIMP_PARAM_STATIC_STRINGS);
  215. GIMP_CONFIG_PROP_PATH (object_class, PROP_SIMULATION_PROFILE,
  216. "simulation-profile",
  217. _("Simulation profile for soft-proofing"),
  218. SIMULATION_PROFILE_BLURB,
  219. GIMP_CONFIG_PATH_FILE, NULL,
  220. GIMP_PARAM_STATIC_STRINGS);
  221. GIMP_CONFIG_PROP_ENUM (object_class, PROP_DISPLAY_RENDERING_INTENT,
  222. "display-rendering-intent",
  223. _("Display rendering intent"),
  224. DISPLAY_RENDERING_INTENT_BLURB,
  225. GIMP_TYPE_COLOR_RENDERING_INTENT,
  226. GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
  227. GIMP_PARAM_STATIC_STRINGS);
  228. GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_DISPLAY_USE_BPC,
  229. "display-use-black-point-compensation",
  230. _("Use black point compensation for the display"),
  231. DISPLAY_USE_BPC_BLURB,
  232. TRUE,
  233. GIMP_PARAM_STATIC_STRINGS);
  234. GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_DISPLAY_OPTIMIZE,
  235. "display-optimize",
  236. _("Optimize display color transformations"),
  237. DISPLAY_OPTIMIZE_BLURB,
  238. TRUE,
  239. GIMP_PARAM_STATIC_STRINGS);
  240. GIMP_CONFIG_PROP_ENUM (object_class, PROP_SIMULATION_RENDERING_INTENT,
  241. "simulation-rendering-intent",
  242. _("Soft-proofing rendering intent"),
  243. SIMULATION_RENDERING_INTENT_BLURB,
  244. GIMP_TYPE_COLOR_RENDERING_INTENT,
  245. GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL,
  246. GIMP_PARAM_STATIC_STRINGS);
  247. GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_SIMULATION_USE_BPC,
  248. "simulation-use-black-point-compensation",
  249. _("Use black point compensation for soft-proofing"),
  250. SIMULATION_USE_BPC_BLURB,
  251. FALSE,
  252. GIMP_PARAM_STATIC_STRINGS);
  253. GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_SIMULATION_OPTIMIZE,
  254. "simulation-optimize",
  255. _("Optimize soft-proofing color transformations"),
  256. SIMULATION_OPTIMIZE_BLURB,
  257. TRUE,
  258. GIMP_PARAM_STATIC_STRINGS);
  259. GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_SIMULATION_GAMUT_CHECK,
  260. "simulation-gamut-check",
  261. _("Mark out of gamut colors"),
  262. SIMULATION_GAMUT_CHECK_BLURB,
  263. FALSE,
  264. GIMP_PARAM_STATIC_STRINGS);
  265. GIMP_CONFIG_PROP_COLOR (object_class, PROP_OUT_OF_GAMUT_COLOR,
  266. "out-of-gamut-color",
  267. _("Out of gamut warning color"),
  268. OUT_OF_GAMUT_COLOR_BLURB,
  269. FALSE, magenta,
  270. GIMP_PARAM_STATIC_STRINGS);
  271. GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_SHOW_RGB_U8,
  272. "show-rgb-u8",
  273. "Show RGB 0..255",
  274. _("Show RGB 0..255 scales"),
  275. FALSE,
  276. GIMP_PARAM_STATIC_STRINGS);
  277. GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_SHOW_HSV,
  278. "show-hsv",
  279. "Show HSV",
  280. _("Show HSV instead of LCH"),
  281. FALSE,
  282. GIMP_PARAM_STATIC_STRINGS);
  283. g_object_unref (magenta);
  284. }
  285. static void
  286. gimp_color_config_init (GimpColorConfig *config)
  287. {
  288. GeglColor *magenta = gegl_color_new (NULL);
  289. config->priv = gimp_color_config_get_instance_private (config);
  290. /* Magenta (sRGB space). */
  291. gegl_color_set_rgba (magenta, 1.0, 0.0, 1.0, 1.0);
  292. config->priv->out_of_gamut_color = magenta;
  293. }
  294. static void
  295. gimp_color_config_finalize (GObject *object)
  296. {
  297. GimpColorConfigPrivate *priv = GET_PRIVATE (object);
  298. g_clear_pointer (&priv->rgb_profile, g_free);
  299. g_clear_pointer (&priv->gray_profile, g_free);
  300. g_clear_pointer (&priv->cmyk_profile, g_free);
  301. g_clear_pointer (&priv->display_profile, g_free);
  302. g_clear_pointer (&priv->printer_profile, g_free);
  303. G_OBJECT_CLASS (parent_class)->finalize (object);
  304. }
  305. static void
  306. gimp_color_config_set_property (GObject *object,
  307. guint property_id,
  308. const GValue *value,
  309. GParamSpec *pspec)
  310. {
  311. GimpColorConfig *config = GIMP_COLOR_CONFIG (object);
  312. GimpColorConfigPrivate *priv = GET_PRIVATE (object);
  313. GError *error = NULL;
  314. switch (property_id)
  315. {
  316. case PROP_MODE:
  317. priv->mode = g_value_get_enum (value);
  318. break;
  319. case PROP_RGB_PROFILE:
  320. gimp_color_config_set_rgb_profile (config,
  321. g_value_get_string (value),
  322. &error);
  323. break;
  324. case PROP_GRAY_PROFILE:
  325. gimp_color_config_set_gray_profile (config,
  326. g_value_get_string (value),
  327. &error);
  328. break;
  329. case PROP_CMYK_PROFILE:
  330. gimp_color_config_set_cmyk_profile (config,
  331. g_value_get_string (value),
  332. &error);
  333. break;
  334. case PROP_DISPLAY_PROFILE:
  335. gimp_color_config_set_display_profile (config,
  336. g_value_get_string (value),
  337. &error);
  338. break;
  339. case PROP_DISPLAY_PROFILE_FROM_GDK:
  340. priv->display_profile_from_gdk = g_value_get_boolean (value);
  341. break;
  342. case PROP_SIMULATION_PROFILE:
  343. gimp_color_config_set_simulation_profile (config,
  344. g_value_get_string (value),
  345. &error);
  346. break;
  347. case PROP_DISPLAY_RENDERING_INTENT:
  348. priv->display_intent = g_value_get_enum (value);
  349. break;
  350. case PROP_DISPLAY_USE_BPC:
  351. priv->display_use_black_point_compensation = g_value_get_boolean (value);
  352. break;
  353. case PROP_DISPLAY_OPTIMIZE:
  354. priv->display_optimize = g_value_get_boolean (value);
  355. break;
  356. case PROP_SIMULATION_RENDERING_INTENT:
  357. priv->simulation_intent = g_value_get_enum (value);
  358. break;
  359. case PROP_SIMULATION_USE_BPC:
  360. priv->simulation_use_black_point_compensation = g_value_get_boolean (value);
  361. break;
  362. case PROP_SIMULATION_OPTIMIZE:
  363. priv->simulation_optimize = g_value_get_boolean (value);
  364. break;
  365. case PROP_SIMULATION_GAMUT_CHECK:
  366. priv->simulation_gamut_check = g_value_get_boolean (value);
  367. break;
  368. case PROP_OUT_OF_GAMUT_COLOR:
  369. g_clear_object (&priv->out_of_gamut_color);
  370. priv->out_of_gamut_color = gegl_color_duplicate (g_value_get_object (value));
  371. break;
  372. case PROP_SHOW_RGB_U8:
  373. priv->show_rgb_u8 = g_value_get_boolean (value);
  374. break;
  375. case PROP_SHOW_HSV:
  376. priv->show_hsv = g_value_get_boolean (value);
  377. break;
  378. default:
  379. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
  380. break;
  381. }
  382. if (error)
  383. {
  384. g_message ("%s", error->message);
  385. g_clear_error (&error);
  386. }
  387. }
  388. static void
  389. gimp_color_config_get_property (GObject *object,
  390. guint property_id,
  391. GValue *value,
  392. GParamSpec *pspec)
  393. {
  394. GimpColorConfigPrivate *priv = GET_PRIVATE (object);
  395. switch (property_id)
  396. {
  397. case PROP_MODE:
  398. g_value_set_enum (value, priv->mode);
  399. break;
  400. case PROP_RGB_PROFILE:
  401. g_value_set_string (value, priv->rgb_profile);
  402. break;
  403. case PROP_GRAY_PROFILE:
  404. g_value_set_string (value, priv->gray_profile);
  405. break;
  406. case PROP_CMYK_PROFILE:
  407. g_value_set_string (value, priv->cmyk_profile);
  408. break;
  409. case PROP_DISPLAY_PROFILE:
  410. g_value_set_string (value, priv->display_profile);
  411. break;
  412. case PROP_DISPLAY_PROFILE_FROM_GDK:
  413. g_value_set_boolean (value, priv->display_profile_from_gdk);
  414. break;
  415. case PROP_SIMULATION_PROFILE:
  416. g_value_set_string (value, priv->printer_profile);
  417. break;
  418. case PROP_DISPLAY_RENDERING_INTENT:
  419. g_value_set_enum (value, priv->display_intent);
  420. break;
  421. case PROP_DISPLAY_USE_BPC:
  422. g_value_set_boolean (value, priv->display_use_black_point_compensation);
  423. break;
  424. case PROP_DISPLAY_OPTIMIZE:
  425. g_value_set_boolean (value, priv->display_optimize);
  426. break;
  427. case PROP_SIMULATION_RENDERING_INTENT:
  428. g_value_set_enum (value, priv->simulation_intent);
  429. break;
  430. case PROP_SIMULATION_USE_BPC:
  431. g_value_set_boolean (value, priv->simulation_use_black_point_compensation);
  432. break;
  433. case PROP_SIMULATION_OPTIMIZE:
  434. g_value_set_boolean (value, priv->simulation_optimize);
  435. break;
  436. case PROP_SIMULATION_GAMUT_CHECK:
  437. g_value_set_boolean (value, priv->simulation_gamut_check);
  438. break;
  439. case PROP_OUT_OF_GAMUT_COLOR:
  440. g_value_set_object (value, priv->out_of_gamut_color);
  441. break;
  442. case PROP_SHOW_RGB_U8:
  443. g_value_set_boolean (value, priv->show_rgb_u8);
  444. break;
  445. case PROP_SHOW_HSV:
  446. g_value_set_boolean (value, priv->show_hsv);
  447. break;
  448. default:
  449. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
  450. break;
  451. }
  452. }
  453. /* public functions */
  454. /**
  455. * gimp_color_config_get_mode:
  456. * @config: a #GimpColorConfig
  457. *
  458. * Since: 2.10
  459. **/
  460. GimpColorManagementMode
  461. gimp_color_config_get_mode (GimpColorConfig *config)
  462. {
  463. g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config),
  464. GIMP_COLOR_MANAGEMENT_OFF);
  465. return GET_PRIVATE (config)->mode;
  466. }
  467. /**
  468. * gimp_color_config_get_display_intent:
  469. * @config: a #GimpColorConfig
  470. *
  471. * Since: 2.10
  472. **/
  473. GimpColorRenderingIntent
  474. gimp_color_config_get_display_intent (GimpColorConfig *config)
  475. {
  476. g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config),
  477. GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL);
  478. return GET_PRIVATE (config)->display_intent;
  479. }
  480. /**
  481. * gimp_color_config_get_display_bpc:
  482. * @config: a #GimpColorConfig
  483. *
  484. * Since: 2.10
  485. **/
  486. gboolean
  487. gimp_color_config_get_display_bpc (GimpColorConfig *config)
  488. {
  489. g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), FALSE);
  490. return GET_PRIVATE (config)->display_use_black_point_compensation;
  491. }
  492. /**
  493. * gimp_color_config_get_display_optimize:
  494. * @config: a #GimpColorConfig
  495. *
  496. * Since: 2.10
  497. **/
  498. gboolean
  499. gimp_color_config_get_display_optimize (GimpColorConfig *config)
  500. {
  501. g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), FALSE);
  502. return GET_PRIVATE (config)->display_optimize;
  503. }
  504. /**
  505. * gimp_color_config_get_display_profile_from_gdk:
  506. * @config: a #GimpColorConfig
  507. *
  508. * Since: 2.10
  509. **/
  510. gboolean
  511. gimp_color_config_get_display_profile_from_gdk (GimpColorConfig *config)
  512. {
  513. g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), FALSE);
  514. return GET_PRIVATE (config)->display_profile_from_gdk;
  515. }
  516. /**
  517. * gimp_color_config_get_simulation_intent:
  518. * @config: a #GimpColorConfig
  519. *
  520. * Since: 2.10
  521. **/
  522. GimpColorRenderingIntent
  523. gimp_color_config_get_simulation_intent (GimpColorConfig *config)
  524. {
  525. g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config),
  526. GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL);
  527. return GET_PRIVATE (config)->simulation_intent;
  528. }
  529. /**
  530. * gimp_color_config_get_simulation_bpc:
  531. * @config: a #GimpColorConfig
  532. *
  533. * Since: 2.10
  534. **/
  535. gboolean
  536. gimp_color_config_get_simulation_bpc (GimpColorConfig *config)
  537. {
  538. g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), FALSE);
  539. return GET_PRIVATE (config)->simulation_use_black_point_compensation;
  540. }
  541. /**
  542. * gimp_color_config_get_simulation_optimize:
  543. * @config: a #GimpColorConfig
  544. *
  545. * Since: 2.10
  546. **/
  547. gboolean
  548. gimp_color_config_get_simulation_optimize (GimpColorConfig *config)
  549. {
  550. g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), FALSE);
  551. return GET_PRIVATE (config)->simulation_optimize;
  552. }
  553. /**
  554. * gimp_color_config_get_simulation_gamut_check:
  555. * @config: a #GimpColorConfig
  556. *
  557. * Since: 2.10
  558. **/
  559. gboolean
  560. gimp_color_config_get_simulation_gamut_check (GimpColorConfig *config)
  561. {
  562. g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), FALSE);
  563. return GET_PRIVATE (config)->simulation_gamut_check;
  564. }
  565. /**
  566. * gimp_color_config_get_out_of_gamut_color:
  567. * @config: a #GimpColorConfig
  568. *
  569. * Returns: (transfer full): the [class@Gegl.Color] to use to represent
  570. * out-of-gamut pixels.
  571. * Since: 3.0
  572. **/
  573. GeglColor *
  574. gimp_color_config_get_out_of_gamut_color (GimpColorConfig *config)
  575. {
  576. g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), NULL);
  577. return gegl_color_duplicate (GET_PRIVATE (config)->out_of_gamut_color);
  578. }
  579. /**
  580. * gimp_color_config_get_rgb_color_profile:
  581. * @config: a #GimpColorConfig
  582. * @error: return location for a #GError
  583. *
  584. * Returns: (transfer full): the default RGB color profile.
  585. *
  586. * Since: 2.10
  587. **/
  588. GimpColorProfile *
  589. gimp_color_config_get_rgb_color_profile (GimpColorConfig *config,
  590. GError **error)
  591. {
  592. GimpColorProfile *profile = NULL;
  593. g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), NULL);
  594. g_return_val_if_fail (error == NULL || *error == NULL, NULL);
  595. if (GET_PRIVATE (config)->rgb_profile)
  596. {
  597. GFile *file = gimp_file_new_for_config_path (GET_PRIVATE (config)->rgb_profile,
  598. error);
  599. if (file)
  600. {
  601. profile = gimp_color_profile_new_from_file (file, error);
  602. if (profile && ! gimp_color_profile_is_rgb (profile))
  603. {
  604. g_object_unref (profile);
  605. profile = NULL;
  606. g_set_error (error, GIMP_CONFIG_ERROR, 0,
  607. _("Color profile '%s' is not for RGB color space."),
  608. gimp_file_get_utf8_name (file));
  609. }
  610. g_object_unref (file);
  611. }
  612. }
  613. return profile;
  614. }
  615. /**
  616. * gimp_color_config_get_gray_color_profile:
  617. * @config: a #GimpColorConfig
  618. * @error: return location for a #GError
  619. *
  620. * Returns: (transfer full): the default grayscale color profile.
  621. *
  622. * Since: 2.10
  623. **/
  624. GimpColorProfile *
  625. gimp_color_config_get_gray_color_profile (GimpColorConfig *config,
  626. GError **error)
  627. {
  628. GimpColorProfile *profile = NULL;
  629. g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), NULL);
  630. g_return_val_if_fail (error == NULL || *error == NULL, NULL);
  631. if (GET_PRIVATE (config)->gray_profile)
  632. {
  633. GFile *file = gimp_file_new_for_config_path (GET_PRIVATE (config)->gray_profile,
  634. error);
  635. if (file)
  636. {
  637. profile = gimp_color_profile_new_from_file (file, error);
  638. if (profile && ! gimp_color_profile_is_gray (profile))
  639. {
  640. g_object_unref (profile);
  641. profile = NULL;
  642. g_set_error (error, GIMP_CONFIG_ERROR, 0,
  643. _("Color profile '%s' is not for GRAY color space."),
  644. gimp_file_get_utf8_name (file));
  645. }
  646. g_object_unref (file);
  647. }
  648. }
  649. return profile;
  650. }
  651. /**
  652. * gimp_color_config_get_cmyk_color_profile:
  653. * @config: a #GimpColorConfig
  654. * @error: return location for a #GError
  655. *
  656. * Returns: (transfer full): the default CMYK color profile.
  657. *
  658. * Since: 2.10
  659. **/
  660. GimpColorProfile *
  661. gimp_color_config_get_cmyk_color_profile (GimpColorConfig *config,
  662. GError **error)
  663. {
  664. GimpColorProfile *profile = NULL;
  665. g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), NULL);
  666. g_return_val_if_fail (error == NULL || *error == NULL, NULL);
  667. if (GET_PRIVATE (config)->cmyk_profile)
  668. {
  669. GFile *file = gimp_file_new_for_config_path (GET_PRIVATE (config)->cmyk_profile,
  670. error);
  671. if (file)
  672. {
  673. profile = gimp_color_profile_new_from_file (file, error);
  674. if (profile && ! gimp_color_profile_is_cmyk (profile))
  675. {
  676. g_object_unref (profile);
  677. profile = NULL;
  678. g_set_error (error, GIMP_CONFIG_ERROR, 0,
  679. _("Color profile '%s' is not for CMYK color space."),
  680. gimp_file_get_utf8_name (file));
  681. }
  682. g_object_unref (file);
  683. }
  684. }
  685. return profile;
  686. }
  687. /**
  688. * gimp_color_config_get_display_color_profile:
  689. * @config: a #GimpColorConfig
  690. * @error: return location for a #GError
  691. *
  692. * Returns: (transfer full): the default display color profile.
  693. *
  694. * Since: 2.10
  695. **/
  696. GimpColorProfile *
  697. gimp_color_config_get_display_color_profile (GimpColorConfig *config,
  698. GError **error)
  699. {
  700. GimpColorProfile *profile = NULL;
  701. g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), NULL);
  702. g_return_val_if_fail (error == NULL || *error == NULL, NULL);
  703. if (GET_PRIVATE (config)->display_profile)
  704. {
  705. GFile *file = gimp_file_new_for_config_path (GET_PRIVATE (config)->display_profile,
  706. error);
  707. if (file)
  708. {
  709. profile = gimp_color_profile_new_from_file (file, error);
  710. g_object_unref (file);
  711. }
  712. }
  713. return profile;
  714. }
  715. /**
  716. * gimp_color_config_get_simulation_color_profile:
  717. * @config: a #GimpColorConfig
  718. * @error: return location for a #GError
  719. *
  720. * Returns: (transfer full): the default soft-proofing color
  721. * profile.
  722. *
  723. * Since: 2.10
  724. **/
  725. GimpColorProfile *
  726. gimp_color_config_get_simulation_color_profile (GimpColorConfig *config,
  727. GError **error)
  728. {
  729. GimpColorProfile *profile = NULL;
  730. g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), NULL);
  731. g_return_val_if_fail (error == NULL || *error == NULL, NULL);
  732. if (GET_PRIVATE (config)->printer_profile)
  733. {
  734. GFile *file = gimp_file_new_for_config_path (GET_PRIVATE (config)->printer_profile,
  735. error);
  736. if (file)
  737. {
  738. profile = gimp_color_profile_new_from_file (file, error);
  739. g_object_unref (file);
  740. }
  741. }
  742. return profile;
  743. }
  744. /* private functions */
  745. static void
  746. gimp_color_config_set_rgb_profile (GimpColorConfig *config,
  747. const gchar *filename,
  748. GError **error)
  749. {
  750. gboolean success = TRUE;
  751. if (filename)
  752. {
  753. GFile *file = gimp_file_new_for_config_path (filename, error);
  754. if (file)
  755. {
  756. GimpColorProfile *profile;
  757. profile = gimp_color_profile_new_from_file (file, error);
  758. if (profile)
  759. {
  760. if (! gimp_color_profile_is_rgb (profile))
  761. {
  762. g_set_error (error, GIMP_CONFIG_ERROR, 0,
  763. _("Color profile '%s' is not for RGB "
  764. "color space."),
  765. gimp_file_get_utf8_name (file));
  766. success = FALSE;
  767. }
  768. g_object_unref (profile);
  769. }
  770. else
  771. {
  772. success = FALSE;
  773. }
  774. g_object_unref (file);
  775. }
  776. else
  777. {
  778. success = FALSE;
  779. }
  780. }
  781. if (success)
  782. {
  783. g_free (GET_PRIVATE (config)->rgb_profile);
  784. GET_PRIVATE (config)->rgb_profile = g_strdup (filename);
  785. }
  786. }
  787. static void
  788. gimp_color_config_set_gray_profile (GimpColorConfig *config,
  789. const gchar *filename,
  790. GError **error)
  791. {
  792. gboolean success = TRUE;
  793. if (filename)
  794. {
  795. GFile *file = gimp_file_new_for_config_path (filename, error);
  796. if (file)
  797. {
  798. GimpColorProfile *profile;
  799. profile = gimp_color_profile_new_from_file (file, error);
  800. if (profile)
  801. {
  802. if (! gimp_color_profile_is_gray (profile))
  803. {
  804. g_set_error (error, GIMP_CONFIG_ERROR, 0,
  805. _("Color profile '%s' is not for GRAY "
  806. "color space."),
  807. gimp_file_get_utf8_name (file));
  808. success = FALSE;
  809. }
  810. g_object_unref (profile);
  811. }
  812. else
  813. {
  814. success = FALSE;
  815. }
  816. g_object_unref (file);
  817. }
  818. else
  819. {
  820. success = FALSE;
  821. }
  822. }
  823. if (success)
  824. {
  825. g_free (GET_PRIVATE (config)->gray_profile);
  826. GET_PRIVATE (config)->gray_profile = g_strdup (filename);
  827. }
  828. }
  829. static void
  830. gimp_color_config_set_cmyk_profile (GimpColorConfig *config,
  831. const gchar *filename,
  832. GError **error)
  833. {
  834. gboolean success = TRUE;
  835. if (filename)
  836. {
  837. GFile *file = gimp_file_new_for_config_path (filename, error);
  838. if (file)
  839. {
  840. GimpColorProfile *profile;
  841. profile = gimp_color_profile_new_from_file (file, error);
  842. if (profile)
  843. {
  844. if (! gimp_color_profile_is_cmyk (profile))
  845. {
  846. g_set_error (error, GIMP_CONFIG_ERROR, 0,
  847. _("Color profile '%s' is not for CMYK "
  848. "color space."),
  849. gimp_file_get_utf8_name (file));
  850. success = FALSE;
  851. }
  852. g_object_unref (profile);
  853. }
  854. else
  855. {
  856. success = FALSE;
  857. }
  858. g_object_unref (file);
  859. }
  860. else
  861. {
  862. success = FALSE;
  863. }
  864. }
  865. if (success)
  866. {
  867. g_free (GET_PRIVATE (config)->cmyk_profile);
  868. GET_PRIVATE (config)->cmyk_profile = g_strdup (filename);
  869. }
  870. }
  871. static void
  872. gimp_color_config_set_display_profile (GimpColorConfig *config,
  873. const gchar *filename,
  874. GError **error)
  875. {
  876. gboolean success = TRUE;
  877. if (filename)
  878. {
  879. GFile *file = gimp_file_new_for_config_path (filename, error);
  880. if (file)
  881. {
  882. GimpColorProfile *profile;
  883. profile = gimp_color_profile_new_from_file (file, error);
  884. if (profile)
  885. {
  886. g_object_unref (profile);
  887. }
  888. else
  889. {
  890. success = FALSE;
  891. }
  892. g_object_unref (file);
  893. }
  894. else
  895. {
  896. success = FALSE;
  897. }
  898. }
  899. if (success)
  900. {
  901. g_free (GET_PRIVATE (config)->display_profile);
  902. GET_PRIVATE (config)->display_profile = g_strdup (filename);
  903. }
  904. }
  905. static void
  906. gimp_color_config_set_simulation_profile (GimpColorConfig *config,
  907. const gchar *filename,
  908. GError **error)
  909. {
  910. gboolean success = TRUE;
  911. if (filename)
  912. {
  913. GFile *file = gimp_file_new_for_config_path (filename, error);
  914. if (file)
  915. {
  916. GimpColorProfile *profile;
  917. profile = gimp_color_profile_new_from_file (file, error);
  918. if (profile)
  919. {
  920. g_object_unref (profile);
  921. }
  922. else
  923. {
  924. success = FALSE;
  925. }
  926. g_object_unref (file);
  927. }
  928. else
  929. {
  930. success = FALSE;
  931. }
  932. }
  933. if (success)
  934. {
  935. g_free (GET_PRIVATE (config)->printer_profile);
  936. GET_PRIVATE (config)->printer_profile = g_strdup (filename);
  937. }
  938. }