Debian Codegraph @

src/lib/tagrules/check_icc.c

raw
1 /* 'checkit_tiff' is a conformance checker for baseline TIFFs
2 *
3 * author: Andreas Romeyke, 2015-2022
4 * licensed under conditions of libtiff
5 * (see http://libtiff.maptools.org/misc.html)
6 *
7 */
8
9 #include <assert.h>
10
11 #include "check.h"
12 #include "check_helper.h"
13 #include "validate_icc.h"
14 #include "ctstring.h"
15
16 /** checks a ICC tag, see Annex B of http://www.color.org/specification/ICC1v43_2010-12.pdf
17 */
18 ret_t check_icc(ctiff_t * ctif ) {
19 GET_EMPTY_RET(ret);
20 TIFP_CHECK( ctif, ret);
21 EXIST_TAG(ctif, TIFFTAG_ICCPROFILE, ret)
22 ifd_entry_t ifd_entry = TIFFGetRawIFDEntry(ctif, ctif->ifd0, TIFFTAG_ICCPROFILE);
23 uint32 icc_profile_size;
24 char * icc_profile = NULL;
25 switch (ifd_entry.datatype) { /* icc datatype should be undefined (val=7) */
26 case TIFF_UNDEFINED: {
27 icc_profile_size = ifd_entry.count;
28 /* offset */
29 if (ifd_entry.value_or_offset == is_offset) {
30 offset_t offset;
31 ret = read_offsetdata(ctif, ifd_entry.data32offset, icc_profile_size, ifd_entry.datatype, &offset, &ret);
32 if (ret.returncode != is_valid) return ret;
33 icc_profile = (char *)offset.data32p;
34 } else {
35 ret.returncode = tagerror_encoded_as_value_excited_space;
36 return ret;
37 }
38 break;
39 }
40 default: { /* none */
41 ret = set_value_found_ret_with_returncode(&ret, const_str(TIFFTypeName(ifd_entry.datatype)),
42 tagerror_unexpected_type_found);
43 return ret;
44 /* break; */
45 }
46 }
47
48 //printf("DEBUG: iccprofile_size=%i\n", icc_profile_size);
49 // printf("DEBUG: iccprofile='%s'\n", icc_profile);
50 /* DEBUG
51 char * p = icc_profile;
52 int i=0;
53 for (i = 0; i< icc_profile_size; i++, p++) {
54 if (0 == i % 8) printf("|");
55 printf("%c(%0x) ", (isalnum(*p)?*p:' '),*p);
56 }
57 printf("\n");
58 */
59 char * errmessage = calloc(VALUESTRLEN, sizeof(char));
60 unsigned long errsize = VALUESTRLEN-1;
61 icc_returncode_t icc_ret = parse_icc(icc_profile_size, icc_profile, errsize, errmessage);
62 free(icc_profile);
63 ret.returncode = should_not_occur;
64 switch (icc_ret) { /* map between returncodes icc profile and tag check */
65 case icc_is_valid: ret.returncode = is_valid; break;
66 case icc_error_profileclass:
67 case icc_error_colorspacedata:
68 case icc_error_connectionspacedata:
69 case icc_error_primaryplatformsignature:
70 case icc_error_header_1v43_2010:
71 case icc_error_header_v240_v430:
72 case icc_error_header_generic:
73 case icc_error_preferredcmmtype:
74 case icc_error_committed_size_differs:
75 case icc_error_header_v500_2016:
76 case icc_error_header_version_undefined:
77 case icc_error_header_version_outdated:
78 case icc_error_profile_description_tag:
79 case icc_error_not_ascii:
80 case icc_error_badprofile_id:
81 case icc_error_found_by_IccProfLib:
82 case icc_hard_error_found_by_IccProfLib:
83 ret.returncode = (returncode_t) icc_ret; /* cast because should have same enum offset */
84 break;
85 case icc_should_not_occur: ret.returncode = should_not_occur;
86 }
87 ret = set_value_found_ret(&ret, str(errmessage));
88 free (errmessage);
89 /* printf("icc_ret=%i\n", icc_ret); */
90 assert( ret.returncode != (returncode_t) icc_should_not_occur);
91 assert( ret.returncode != should_not_occur);
92 return ret;
93 }
94
95 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 smarttab expandtab :*/