1//========================================================================
2//
3// sanitychecks.cc
4//
5// This file is licensed under the GPLv2 or later
6//
7// Copyright (C) 2020 Philipp Knechtges <philipp-dev@knechtges.com>
8//
9// To see a description of the changes please see the Changelog file that
10// came with your tarball or type make ChangeLog if you are building from git
11//
12//========================================================================
13
14#include <cstdio>
15#include <cstddef>
16#include <cstring>
17#include <cstdlib>
18#include <cctype>
19#include "sanitychecks.h"
20
21#ifdef USE_CMS
22bool checkICCProfile(const GfxLCMSProfilePtr &profile, const char *filename, cmsUInt32Number UsedDirection, cmsColorSpaceSignature expectedColorSpace)
23{
24 if (!profile) {
25 fprintf(stderr, "Could not open the ICC profile \"%s\".\n", filename);
26 return false;
27 }
28 if (!cmsIsIntentSupported(profile.get(), INTENT_RELATIVE_COLORIMETRIC, UsedDirection) && !cmsIsIntentSupported(profile.get(), INTENT_ABSOLUTE_COLORIMETRIC, UsedDirection)
29 && !cmsIsIntentSupported(profile.get(), INTENT_SATURATION, UsedDirection) && !cmsIsIntentSupported(profile.get(), INTENT_PERCEPTUAL, LCMS_USED_AS_OUTPUT)) {
30 if (UsedDirection == LCMS_USED_AS_OUTPUT) {
31 fprintf(stderr, "ICC profile \"%s\" is not an output profile.\n", filename);
32 } else if (UsedDirection == LCMS_USED_AS_INPUT) {
33 fprintf(stderr, "ICC profile \"%s\" is not an input profile.\n", filename);
34 } else {
35 fprintf(stderr, "ICC profile \"%s\" is not suitable.\n", filename);
36 }
37 return false;
38 }
39 auto profilecolorspace = cmsGetColorSpace(profile.get());
40 if (profilecolorspace != expectedColorSpace) {
41 if (expectedColorSpace == cmsSigCmykData) {
42 fprintf(stderr, "Supplied ICC profile \"%s\" is not a CMYK profile.\n", filename);
43 } else if (expectedColorSpace == cmsSigGrayData) {
44 fprintf(stderr, "Supplied ICC profile \"%s\" is not a monochrome profile.\n", filename);
45 } else if (expectedColorSpace == cmsSigRgbData) {
46 fprintf(stderr, "Supplied ICC profile \"%s\" is not a RGB profile.\n", filename);
47 }
48 return false;
49 }
50 return true;
51}
52#endif
53

source code of poppler/utils/sanitychecks.cc