Skip to content

Commit

Permalink
lcms2: Import upstream release 2.16.
Browse files Browse the repository at this point in the history
  • Loading branch information
julliard committed Feb 17, 2024
1 parent 041167b commit b15d012
Show file tree
Hide file tree
Showing 20 changed files with 992 additions and 148 deletions.
1 change: 1 addition & 0 deletions libs/lcms2/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Philipp Knechtges
Amyspark
Lovell Fuller
Eli Schwartz
Diogo Teles Sant'Anna

Special Thanks
--------------
Expand Down
53 changes: 46 additions & 7 deletions libs/lcms2/include/lcms2.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//
//---------------------------------------------------------------------------------
//
// Version 2.15
// Version 2.16
//

#ifndef _lcms2_H
Expand Down Expand Up @@ -76,12 +76,15 @@

#ifndef CMS_USE_CPP_API
# ifdef __cplusplus
# if __cplusplus >= 201703L
# define CMS_NO_REGISTER_KEYWORD 1
# endif
extern "C" {
# endif
#endif

// Version/release
#define LCMS_VERSION 2150
#define LCMS_VERSION 2160

// I will give the chance of redefining basic types for compilers that are not fully C99 compliant
#ifndef CMS_BASIC_TYPES_ALREADY_DEFINED
Expand Down Expand Up @@ -325,7 +328,8 @@ typedef enum {
cmsSigUInt8ArrayType = 0x75693038, // 'ui08'
cmsSigVcgtType = 0x76636774, // 'vcgt'
cmsSigViewingConditionsType = 0x76696577, // 'view'
cmsSigXYZType = 0x58595A20 // 'XYZ '
cmsSigXYZType = 0x58595A20, // 'XYZ '
cmsSigMHC2Type = 0x4D484332 // 'MHC2'


} cmsTagTypeSignature;
Expand Down Expand Up @@ -403,7 +407,8 @@ typedef enum {
cmsSigVcgtTag = 0x76636774, // 'vcgt'
cmsSigMetaTag = 0x6D657461, // 'meta'
cmsSigcicpTag = 0x63696370, // 'cicp'
cmsSigArgyllArtsTag = 0x61727473 // 'arts'
cmsSigArgyllArtsTag = 0x61727473, // 'arts'
cmsSigMHC2Tag = 0x4D484332 // 'MHC2'

} cmsTagSignature;

Expand Down Expand Up @@ -948,6 +953,7 @@ typedef void* cmsHTRANSFORM;
#define TYPE_RGB_DBL (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(0))
#define TYPE_BGR_DBL (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(0)|DOSWAP_SH(1))
#define TYPE_CMYK_DBL (FLOAT_SH(1)|COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(0))
#define TYPE_OKLAB_DBL (FLOAT_SH(1)|COLORSPACE_SH(PT_MCH3)|CHANNELS_SH(3)|BYTES_SH(0))

// IEEE 754-2008 "half"
#define TYPE_GRAY_HALF_FLT (FLOAT_SH(1)|COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(2))
Expand Down Expand Up @@ -1048,6 +1054,19 @@ typedef struct {

} cmsVideoSignalType;

typedef struct {
cmsUInt32Number CurveEntries;
cmsFloat64Number* RedCurve;
cmsFloat64Number* GreenCurve;
cmsFloat64Number* BlueCurve;

cmsFloat64Number MinLuminance; // ST.2086 min luminance in nits
cmsFloat64Number PeakLuminance; // ST.2086 peak luminance in nits

cmsFloat64Number XYZ2XYZmatrix[3][4];

} cmsMHC2Type;



// Get LittleCMS version (for shared objects) -----------------------------------------------------------------------------
Expand Down Expand Up @@ -1220,7 +1239,8 @@ CMSAPI cmsBool CMSEXPORT cmsIsToneCurveMonotonic(const cmsToneCurve* t
CMSAPI cmsBool CMSEXPORT cmsIsToneCurveDescending(const cmsToneCurve* t);
CMSAPI cmsInt32Number CMSEXPORT cmsGetToneCurveParametricType(const cmsToneCurve* t);
CMSAPI cmsFloat64Number CMSEXPORT cmsEstimateGamma(const cmsToneCurve* t, cmsFloat64Number Precision);
CMSAPI cmsFloat64Number* CMSEXPORT cmsGetToneCurveParams(const cmsToneCurve* t);

CMSAPI const cmsCurveSegment* CMSEXPORT cmsGetToneCurveSegment(cmsInt32Number n, const cmsToneCurve* t);

// Tone curve tabular estimation
CMSAPI cmsUInt32Number CMSEXPORT cmsGetToneCurveEstimatedTableEntries(const cmsToneCurve* t);
Expand Down Expand Up @@ -1314,8 +1334,11 @@ CMSAPI cmsBool CMSEXPORT cmsSliceSpaceFloat(cmsUInt32Number nInputs, c

typedef struct _cms_MLU_struct cmsMLU;

#define cmsNoLanguage "\0\0"
#define cmsNoCountry "\0\0"
#define cmsNoLanguage "\0\0"
#define cmsNoCountry "\0\0"

// Special language/country to retrieve unicode field for description in V2 profiles. Use with care.
#define cmsV2Unicode "\xff\xff"

CMSAPI cmsMLU* CMSEXPORT cmsMLUalloc(cmsContext ContextID, cmsUInt32Number nItems);
CMSAPI void CMSEXPORT cmsMLUfree(cmsMLU* mlu);
Expand All @@ -1327,6 +1350,9 @@ CMSAPI cmsBool CMSEXPORT cmsMLUsetASCII(cmsMLU* mlu,
CMSAPI cmsBool CMSEXPORT cmsMLUsetWide(cmsMLU* mlu,
const char LanguageCode[3], const char CountryCode[3],
const wchar_t* WideString);
CMSAPI cmsBool CMSEXPORT cmsMLUsetUTF8(cmsMLU* mlu,
const char LanguageCode[3], const char CountryCode[3],
const char* UTF8String);

CMSAPI cmsUInt32Number CMSEXPORT cmsMLUgetASCII(const cmsMLU* mlu,
const char LanguageCode[3], const char CountryCode[3],
Expand All @@ -1335,6 +1361,10 @@ CMSAPI cmsUInt32Number CMSEXPORT cmsMLUgetASCII(const cmsMLU* mlu,
CMSAPI cmsUInt32Number CMSEXPORT cmsMLUgetWide(const cmsMLU* mlu,
const char LanguageCode[3], const char CountryCode[3],
wchar_t* Buffer, cmsUInt32Number BufferSize);
CMSAPI cmsUInt32Number CMSEXPORT cmsMLUgetUTF8(const cmsMLU* mlu,
const char LanguageCode[3], const char CountryCode[3],
char* Buffer, cmsUInt32Number BufferSize);


CMSAPI cmsBool CMSEXPORT cmsMLUgetTranslation(const cmsMLU* mlu,
const char LanguageCode[3], const char CountryCode[3],
Expand Down Expand Up @@ -1559,6 +1589,10 @@ CMSAPI cmsUInt32Number CMSEXPORT cmsGetProfileInfoASCII(cmsHPROFILE hProfile,
const char LanguageCode[3], const char CountryCode[3],
char* Buffer, cmsUInt32Number BufferSize);

CMSAPI cmsUInt32Number CMSEXPORT cmsGetProfileInfoUTF8(cmsHPROFILE hProfile, cmsInfoType Info,
const char LanguageCode[3], const char CountryCode[3],
char* Buffer, cmsUInt32Number BufferSize);

// IO handlers ----------------------------------------------------------------------------------------------------------

typedef struct _cms_io_handler cmsIOHANDLER;
Expand Down Expand Up @@ -1621,6 +1655,9 @@ CMSAPI cmsHPROFILE CMSEXPORT cmsCreateInkLimitingDeviceLinkTHR(cmsContext C

CMSAPI cmsHPROFILE CMSEXPORT cmsCreateInkLimitingDeviceLink(cmsColorSpaceSignature ColorSpace, cmsFloat64Number Limit);

CMSAPI cmsHPROFILE CMSEXPORT cmsCreateDeviceLinkFromCubeFile(const char* cFileName);

CMSAPI cmsHPROFILE CMSEXPORT cmsCreateDeviceLinkFromCubeFileTHR(cmsContext ContextID, const char* cFileName);

CMSAPI cmsHPROFILE CMSEXPORT cmsCreateLab2ProfileTHR(cmsContext ContextID, const cmsCIExyY* WhitePoint);
CMSAPI cmsHPROFILE CMSEXPORT cmsCreateLab2Profile(const cmsCIExyY* WhitePoint);
Expand All @@ -1633,6 +1670,8 @@ CMSAPI cmsHPROFILE CMSEXPORT cmsCreateXYZProfile(void);
CMSAPI cmsHPROFILE CMSEXPORT cmsCreate_sRGBProfileTHR(cmsContext ContextID);
CMSAPI cmsHPROFILE CMSEXPORT cmsCreate_sRGBProfile(void);

CMSAPI cmsHPROFILE CMSEXPORT cmsCreate_OkLabProfile(cmsContext ctx);

CMSAPI cmsHPROFILE CMSEXPORT cmsCreateBCHSWabstractProfileTHR(cmsContext ContextID,
cmsUInt32Number nLUTPoints,
cmsFloat64Number Bright,
Expand Down
8 changes: 4 additions & 4 deletions libs/lcms2/include/lcms2_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,9 @@ typedef void (* _cmsTransformFn)(struct _cmstransform_struct *CMMcargo, //
typedef void (*_cmsTransform2Fn)(struct _cmstransform_struct *CMMcargo,
const void* InputBuffer,
void* OutputBuffer,
cmsUInt32Number PixelsPerLine,
cmsUInt32Number LineCount,
const cmsStride* Stride);
cmsUInt32Number PixelsPerLine,
cmsUInt32Number LineCount,
const cmsStride* Stride);

typedef cmsBool (* _cmsTransformFactory)(_cmsTransformFn* xform,
void** UserData,
Expand Down Expand Up @@ -648,7 +648,7 @@ typedef struct {
} cmsPluginTransform;

//----------------------------------------------------------------------------------------------------------
// Mutex
// Mutex

typedef void* (* _cmsCreateMutexFnPtrType)(cmsContext ContextID);
typedef void (* _cmsDestroyMutexFnPtrType)(cmsContext ContextID, void* mtx);
Expand Down
30 changes: 16 additions & 14 deletions libs/lcms2/src/cmsalpha.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ static cmsFormatterAlphaFn FormattersAlpha[6][6] = {

// This function computes the distance from each component to the next one in bytes.
static
void ComputeIncrementsForChunky(cmsUInt32Number Format,
cmsBool ComputeIncrementsForChunky(cmsUInt32Number Format,
cmsUInt32Number ComponentStartingOrder[],
cmsUInt32Number ComponentPointerIncrements[])
{
Expand All @@ -416,7 +416,7 @@ void ComputeIncrementsForChunky(cmsUInt32Number Format,

// Sanity check
if (total_chans <= 0 || total_chans >= cmsMAXCHANNELS)
return;
return FALSE;

memset(channels, 0, sizeof(channels));

Expand Down Expand Up @@ -453,13 +453,15 @@ void ComputeIncrementsForChunky(cmsUInt32Number Format,

for (i = 0; i < extra; i++)
ComponentStartingOrder[i] = channels[i + nchannels];

return TRUE;
}



// On planar configurations, the distance is the stride added to any non-negative
static
void ComputeIncrementsForPlanar(cmsUInt32Number Format,
cmsBool ComputeIncrementsForPlanar(cmsUInt32Number Format,
cmsUInt32Number BytesPerPlane,
cmsUInt32Number ComponentStartingOrder[],
cmsUInt32Number ComponentPointerIncrements[])
Expand All @@ -473,7 +475,7 @@ void ComputeIncrementsForPlanar(cmsUInt32Number Format,

// Sanity check
if (total_chans <= 0 || total_chans >= cmsMAXCHANNELS)
return;
return FALSE;

memset(channels, 0, sizeof(channels));

Expand Down Expand Up @@ -509,29 +511,29 @@ void ComputeIncrementsForPlanar(cmsUInt32Number Format,

for (i = 0; i < extra; i++)
ComponentStartingOrder[i] = channels[i + nchannels];

return TRUE;
}



// Dispatcher por chunky and planar RGB
static
void ComputeComponentIncrements(cmsUInt32Number Format,
cmsBool ComputeComponentIncrements(cmsUInt32Number Format,
cmsUInt32Number BytesPerPlane,
cmsUInt32Number ComponentStartingOrder[],
cmsUInt32Number ComponentPointerIncrements[])
{
if (T_PLANAR(Format)) {

ComputeIncrementsForPlanar(Format, BytesPerPlane, ComponentStartingOrder, ComponentPointerIncrements);
return ComputeIncrementsForPlanar(Format, BytesPerPlane, ComponentStartingOrder, ComponentPointerIncrements);
}
else {
ComputeIncrementsForChunky(Format, ComponentStartingOrder, ComponentPointerIncrements);
return ComputeIncrementsForChunky(Format, ComponentStartingOrder, ComponentPointerIncrements);
}

}



// Handles extra channels copying alpha if requested by the flags
void _cmsHandleExtraChannels(_cmsTRANSFORM* p, const void* in,
void* out,
Expand Down Expand Up @@ -565,9 +567,11 @@ void _cmsHandleExtraChannels(_cmsTRANSFORM* p, const void* in,
if (nExtra == 0)
return;

// Compute the increments
ComputeComponentIncrements(p->InputFormat, Stride->BytesPerPlaneIn, SourceStartingOrder, SourceIncrements);
ComputeComponentIncrements(p->OutputFormat, Stride->BytesPerPlaneOut, DestStartingOrder, DestIncrements);
// Compute the increments
if (!ComputeComponentIncrements(p->InputFormat, Stride->BytesPerPlaneIn, SourceStartingOrder, SourceIncrements))
return;
if (!ComputeComponentIncrements(p->OutputFormat, Stride->BytesPerPlaneOut, DestStartingOrder, DestIncrements))
return;

// Check for conversions 8, 16, half, float, dbl
copyValueFn = _cmsGetFormatterAlpha(p->ContextID, p->InputFormat, p->OutputFormat);
Expand Down Expand Up @@ -642,5 +646,3 @@ void _cmsHandleExtraChannels(_cmsTRANSFORM* p, const void* in,
}
}
}


44 changes: 28 additions & 16 deletions libs/lcms2/src/cmscnvrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,16 @@ int BlackPreservingGrayOnlySampler(CMSREGISTER const cmsUInt16Number In[], CMSRE
return TRUE;
}


// Check whatever the profile is a CMYK->CMYK devicelink
static
cmsBool is_cmyk_devicelink(cmsHPROFILE hProfile)
{
return cmsGetDeviceClass(hProfile) == cmsSigLinkClass &&
cmsGetColorSpace(hProfile) == cmsSigCmykData &&
cmsGetColorSpace(hProfile) == cmsSigCmykData;
}

// This is the entry for black-preserving K-only intents, which are non-ICC
static
cmsPipeline* BlackPreservingKOnlyIntents(cmsContext ContextID,
Expand Down Expand Up @@ -747,14 +757,16 @@ cmsPipeline* BlackPreservingKOnlyIntents(cmsContext ContextID,
lastProfilePos = nProfiles - 1;
hLastProfile = hProfiles[lastProfilePos];

while (lastProfilePos > 1)
// Skip CMYK->CMYK devicelinks on ending
while (is_cmyk_devicelink(hLastProfile))
{
hLastProfile = hProfiles[--lastProfilePos];
if (cmsGetColorSpace(hLastProfile) != cmsSigCmykData ||
cmsGetDeviceClass(hLastProfile) != cmsSigLinkClass)
if (lastProfilePos < 2)
break;

hLastProfile = hProfiles[--lastProfilePos];
}


preservationProfilesCount = lastProfilePos + 1;

// Check for non-cmyk profiles
Expand All @@ -771,7 +783,7 @@ cmsPipeline* BlackPreservingKOnlyIntents(cmsContext ContextID,

// Create a LUT holding normal ICC transform
bp.cmyk2cmyk = DefaultICCintents(ContextID,
preservationProfilesCount,
preservationProfilesCount,
ICCIntents,
hProfiles,
BPC,
Expand All @@ -783,7 +795,7 @@ cmsPipeline* BlackPreservingKOnlyIntents(cmsContext ContextID,
// Now, compute the tone curve
bp.KTone = _cmsBuildKToneCurve(ContextID,
4096,
preservationProfilesCount,
preservationProfilesCount,
ICCIntents,
hProfiles,
BPC,
Expand Down Expand Up @@ -973,13 +985,14 @@ cmsPipeline* BlackPreservingKPlaneIntents(cmsContext ContextID,
lastProfilePos = nProfiles - 1;
hLastProfile = hProfiles[lastProfilePos];

while (lastProfilePos > 1)
{
// Skip CMYK->CMYK devicelinks on ending
while (is_cmyk_devicelink(hLastProfile))
{
if (lastProfilePos < 2)
break;

hLastProfile = hProfiles[--lastProfilePos];
if (cmsGetColorSpace(hLastProfile) != cmsSigCmykData ||
cmsGetDeviceClass(hLastProfile) != cmsSigLinkClass)
break;
}
}

preservationProfilesCount = lastProfilePos + 1;

Expand Down Expand Up @@ -1148,8 +1161,7 @@ cmsUInt32Number CMSEXPORT cmsGetSupportedIntentsTHR(cmsContext ContextID, cmsUIn
cmsIntentsList* pt;
cmsUInt32Number nIntents;


for (nIntents=0, pt = ctx->Intents; pt != NULL; pt = pt -> Next)
for (nIntents=0, pt = DefaultIntents; pt != NULL; pt = pt -> Next)
{
if (nIntents < nMax) {
if (Codes != NULL)
Expand All @@ -1162,7 +1174,7 @@ cmsUInt32Number CMSEXPORT cmsGetSupportedIntentsTHR(cmsContext ContextID, cmsUIn
nIntents++;
}

for (nIntents=0, pt = DefaultIntents; pt != NULL; pt = pt -> Next)
for (pt = ctx->Intents; pt != NULL; pt = pt -> Next)
{
if (nIntents < nMax) {
if (Codes != NULL)
Expand All @@ -1174,6 +1186,7 @@ cmsUInt32Number CMSEXPORT cmsGetSupportedIntentsTHR(cmsContext ContextID, cmsUIn

nIntents++;
}

return nIntents;
}

Expand Down Expand Up @@ -1211,4 +1224,3 @@ cmsBool _cmsRegisterRenderingIntentPlugin(cmsContext id, cmsPluginBase* Data)

return TRUE;
}

Loading

0 comments on commit b15d012

Please sign in to comment.