summaryrefslogtreecommitdiff
path: root/third_party/lcms/src/cmsnamed.c
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/lcms/src/cmsnamed.c')
-rw-r--r--third_party/lcms/src/cmsnamed.c81
1 files changed, 53 insertions, 28 deletions
diff --git a/third_party/lcms/src/cmsnamed.c b/third_party/lcms/src/cmsnamed.c
index ef1eb3089e..9ed4cad398 100644
--- a/third_party/lcms/src/cmsnamed.c
+++ b/third_party/lcms/src/cmsnamed.c
@@ -1,7 +1,7 @@
//---------------------------------------------------------------------------------
//
// Little Color Management System
-// Copyright (c) 1998-2012 Marti Maria Saguer
+// Copyright (c) 1998-2016 Marti Maria Saguer
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"),
@@ -92,7 +92,7 @@ cmsBool GrowMLUpool(cmsMLU* mlu)
static
cmsBool GrowMLUtable(cmsMLU* mlu)
{
- int AllocatedEntries;
+ cmsUInt32Number AllocatedEntries;
_cmsMLUentry *NewPtr;
// Sanity check
@@ -118,7 +118,7 @@ cmsBool GrowMLUtable(cmsMLU* mlu)
static
int SearchMLUEntry(cmsMLU* mlu, cmsUInt16Number LanguageCode, cmsUInt16Number CountryCode)
{
- int i;
+ cmsUInt32Number i;
// Sanity check
if (mlu == NULL) return -1;
@@ -178,15 +178,42 @@ cmsBool AddMLUBlock(cmsMLU* mlu, cmsUInt32Number size, const wchar_t *Block,
return TRUE;
}
+// Convert from a 3-char code to a cmsUInt16Number. It is done inthis way because some
+// compilers don't properly align beginning of strings
+
+static
+cmsUInt16Number strTo16(const char str[3])
+{
+ cmsUInt16Number n = ((cmsUInt16Number) str[0] << 8) | str[1];
+
+ return n; // Always big endian in this case
+}
+
+static
+void strFrom16(char str[3], cmsUInt16Number n)
+{
+ // Assiming this would be aligned
+ union {
+
+ cmsUInt16Number n;
+ char str[2];
+
+ } c;
+
+ c.n = n; // Always big endian in this case
+
+ str[0] = c.str[0]; str[1] = c.str[1]; str[2] = 0;
-// Add an ASCII entry.
+}
+
+// Add an ASCII entry. Do not add any \0 termination (ICC1v43_2010-12.pdf page 61)
cmsBool CMSEXPORT cmsMLUsetASCII(cmsMLU* mlu, const char LanguageCode[3], const char CountryCode[3], const char* ASCIIString)
{
- cmsUInt32Number i, len = (cmsUInt32Number) strlen(ASCIIString)+1;
+ cmsUInt32Number i, len = (cmsUInt32Number) strlen(ASCIIString);
wchar_t* WStr;
cmsBool rc;
- cmsUInt16Number Lang = _cmsAdjustEndianess16(*(cmsUInt16Number*) LanguageCode);
- cmsUInt16Number Cntry = _cmsAdjustEndianess16(*(cmsUInt16Number*) CountryCode);
+ cmsUInt16Number Lang = strTo16(LanguageCode);
+ cmsUInt16Number Cntry = strTo16(CountryCode);
if (mlu == NULL) return FALSE;
@@ -216,18 +243,17 @@ cmsUInt32Number mywcslen(const wchar_t *s)
return (cmsUInt32Number)(p - s);
}
-
-// Add a wide entry
+// Add a wide entry. Do not add any \0 terminator (ICC1v43_2010-12.pdf page 61)
cmsBool CMSEXPORT cmsMLUsetWide(cmsMLU* mlu, const char Language[3], const char Country[3], const wchar_t* WideString)
{
- cmsUInt16Number Lang = _cmsAdjustEndianess16(*(cmsUInt16Number*) Language);
- cmsUInt16Number Cntry = _cmsAdjustEndianess16(*(cmsUInt16Number*) Country);
+ cmsUInt16Number Lang = strTo16(Language);
+ cmsUInt16Number Cntry = strTo16(Country);
cmsUInt32Number len;
if (mlu == NULL) return FALSE;
if (WideString == NULL) return FALSE;
- len = (cmsUInt32Number) (mywcslen(WideString) + 1) * sizeof(wchar_t);
+ len = (cmsUInt32Number) (mywcslen(WideString)) * sizeof(wchar_t);
return AddMLUBlock(mlu, len, WideString, Lang, Cntry);
}
@@ -298,8 +324,8 @@ const wchar_t* _cmsMLUgetWide(const cmsMLU* mlu,
cmsUInt16Number LanguageCode, cmsUInt16Number CountryCode,
cmsUInt16Number* UsedLanguageCode, cmsUInt16Number* UsedCountryCode)
{
- int i;
- int Best = -1;
+ cmsUInt32Number i;
+ cmsInt32Number Best = -1;
_cmsMLUentry* v;
if (mlu == NULL) return NULL;
@@ -350,8 +376,8 @@ cmsUInt32Number CMSEXPORT cmsMLUgetASCII(const cmsMLU* mlu,
cmsUInt32Number StrLen = 0;
cmsUInt32Number ASCIIlen, i;
- cmsUInt16Number Lang = _cmsAdjustEndianess16(*(cmsUInt16Number*) LanguageCode);
- cmsUInt16Number Cntry = _cmsAdjustEndianess16(*(cmsUInt16Number*) CountryCode);
+ cmsUInt16Number Lang = strTo16(LanguageCode);
+ cmsUInt16Number Cntry = strTo16(CountryCode);
// Sanitize
if (mlu == NULL) return 0;
@@ -394,8 +420,8 @@ cmsUInt32Number CMSEXPORT cmsMLUgetWide(const cmsMLU* mlu,
const wchar_t *Wide;
cmsUInt32Number StrLen = 0;
- cmsUInt16Number Lang = _cmsAdjustEndianess16(*(cmsUInt16Number*) LanguageCode);
- cmsUInt16Number Cntry = _cmsAdjustEndianess16(*(cmsUInt16Number*) CountryCode);
+ cmsUInt16Number Lang = strTo16(LanguageCode);
+ cmsUInt16Number Cntry = strTo16(CountryCode);
// Sanitize
if (mlu == NULL) return 0;
@@ -427,8 +453,8 @@ CMSAPI cmsBool CMSEXPORT cmsMLUgetTranslation(const cmsMLU* mlu,
{
const wchar_t *Wide;
- cmsUInt16Number Lang = _cmsAdjustEndianess16(*(cmsUInt16Number*) LanguageCode);
- cmsUInt16Number Cntry = _cmsAdjustEndianess16(*(cmsUInt16Number*) CountryCode);
+ cmsUInt16Number Lang = strTo16(LanguageCode);
+ cmsUInt16Number Cntry = strTo16(CountryCode);
cmsUInt16Number ObtLang, ObtCode;
// Sanitize
@@ -438,10 +464,9 @@ CMSAPI cmsBool CMSEXPORT cmsMLUgetTranslation(const cmsMLU* mlu,
if (Wide == NULL) return FALSE;
// Get used language and code
- *(cmsUInt16Number *)ObtainedLanguage = _cmsAdjustEndianess16(ObtLang);
- *(cmsUInt16Number *)ObtainedCountry = _cmsAdjustEndianess16(ObtCode);
+ strFrom16(ObtainedLanguage, ObtLang);
+ strFrom16(ObtainedCountry, ObtCode);
- ObtainedLanguage[2] = ObtainedCountry[2] = 0;
return TRUE;
}
@@ -464,12 +489,12 @@ cmsBool CMSEXPORT cmsMLUtranslationsCodes(const cmsMLU* mlu,
if (mlu == NULL) return FALSE;
- if (idx >= (cmsUInt32Number) mlu->UsedEntries) return FALSE;
+ if (idx >= mlu->UsedEntries) return FALSE;
entry = &mlu->Entries[idx];
- *(cmsUInt16Number *)LanguageCode = _cmsAdjustEndianess16(entry->Language);
- *(cmsUInt16Number *)CountryCode = _cmsAdjustEndianess16(entry->Country);
+ strFrom16(LanguageCode, entry->Language);
+ strFrom16(CountryCode, entry->Country);
return TRUE;
}
@@ -514,7 +539,7 @@ cmsNAMEDCOLORLIST* CMSEXPORT cmsAllocNamedColorList(cmsContext ContextID, cmsUIn
v ->nColors = 0;
v ->ContextID = ContextID;
- while (v -> Allocated < n) {
+ while (v -> Allocated < n){
if (!GrowNamedColorList(v)) {
cmsFreeNamedColorList(v);
return NULL;
@@ -548,7 +573,7 @@ cmsNAMEDCOLORLIST* CMSEXPORT cmsDupNamedColorList(const cmsNAMEDCOLORLIST* v)
if (NewNC == NULL) return NULL;
// For really large tables we need this
- while (NewNC ->Allocated < v ->Allocated) {
+ while (NewNC ->Allocated < v ->Allocated){
if (!GrowNamedColorList(NewNC)) {
cmsFreeNamedColorList(NewNC);
return NULL;