| 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 |
#ifdef HAVE_IccProfLib |
| 10 |
#include "validate_icc.h" |
| 11 |
#include <IccProfile.h> |
| 12 |
#include <IccTag.h> |
| 13 |
#include <IccIO.h> |
| 14 |
#include <IccUtil.h> |
| 15 |
#include <regex> |
| 16 |
#include <algorithm> |
| 17 |
#include <string> |
| 18 |
#include <iostream> |
| 19 |
|
| 20 |
icc_returncode_t validate_icc_with_IccProfLib(unsigned long iccsize, const char* iccdata, unsigned long errsize, char * errorneous_value) { |
| 21 |
CIccMemIO pIO; |
| 22 |
pIO.Attach((icUInt8Number *) iccdata, iccsize, false); |
| 23 |
CIccProfile pIcc; |
| 24 |
// read and parse |
| 25 |
std::string sReport; |
| 26 |
// validate ICC profile |
| 27 |
auto nStatus = pIcc.ReadValidate(&pIO, sReport); |
| 28 |
// to handle own rules, only the sReport is used |
| 29 |
|
| 30 |
#ifdef USE_WARNING |
| 31 |
std::cout << " has Status "<< nStatus << std::endl; |
| 32 |
std::cout << sReport << std::endl; |
| 33 |
#endif |
| 34 |
// remove all carriage returns |
| 35 |
sReport.erase(std::remove(sReport.begin(), sReport.end(), '\r'),sReport.end()); |
| 36 |
cit_strcopy(errorneous_value, errsize, sReport.c_str(), sReport.size()); |
| 37 |
//strncpy(errorneous_value, sReport.c_str(), errsize); |
| 38 |
static auto regex_unregcmm_warning = std::regex("^Warning.* Unknown '.*'.*: Unregistered CMM signature"); |
| 39 |
static auto regex_7bit_warning = std::regex("^Warning.* Text does not contain just 7-bit data"); |
| 40 |
static auto regex_generic_warning = std::regex("Warning(.*)"); |
| 41 |
static auto regex_scriptcode_error = std::regex("NonCompliant.* profileDescriptionTag: - ScriptCode must contain 67 bytes."); |
| 42 |
static auto regex_generic_error = std::regex("NonCompliant(.*)"); |
| 43 |
/* errors handling */ |
| 44 |
if (std::regex_match(sReport, |
| 45 |
regex_scriptcode_error)) { |
| 46 |
return icc_error_profile_description_tag; |
| 47 |
} |
| 48 |
if (std::smatch sm; nStatus == 2 || std::regex_match(sReport, sm, regex_generic_error)) { |
| 49 |
#ifdef DEBUG |
| 50 |
std::cout << "the matches are: " << std::endl; |
| 51 |
for (unsigned i = 0; i < sm.size(); ++i) { |
| 52 |
std::cout << "[" << sm[i] << "] "; |
| 53 |
} |
| 54 |
std::cout << std::endl; |
| 55 |
#endif |
| 56 |
return icc_hard_error_found_by_IccProfLib; |
| 57 |
} |
| 58 |
#ifdef WITH_STRONG_ICC |
| 59 |
/* warnings handling */ |
| 60 |
if (std::regex_match(sReport, regex_unregcmm_warning)) { |
| 61 |
return icc_error_preferredcmmtype; |
| 62 |
} |
| 63 |
if (std::regex_match(sReport, regex_7bit_warning)) { |
| 64 |
return icc_error_not_ascii; |
| 65 |
} |
| 66 |
if (nStatus == 1 || std::regex_match(sReport, sm, regex_generic_warning)) { |
| 67 |
#ifdef DEBUG |
| 68 |
std::cout << "the matches are: " << std::endl; |
| 69 |
for (unsigned i = 0; i < sm.size(); ++i) { |
| 70 |
std::cout << "[" << sm[i] << "] "; |
| 71 |
} |
| 72 |
std::cout << std::endl; |
| 73 |
#endif |
| 74 |
return icc_error_found_by_IccProfLib; |
| 75 |
} |
| 76 |
#endif |
| 77 |
return icc_is_valid; |
| 78 |
} |
| 79 |
#endif |