From 9491825ddff7a294d1f49061bae7044e426aeb2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Fri, 6 Nov 2015 05:38:49 +0100 Subject: Imported Upstream version 1.8.3 --- numlib/Jamfile | 4 + numlib/LUtest.c | 0 numlib/License.txt | 0 numlib/Readme.txt | 0 numlib/aatree.c | 0 numlib/aatree.h | 0 numlib/afiles | 0 numlib/dhsx.c | 0 numlib/dhsx.h | 0 numlib/dnsq.c | 0 numlib/dnsq.h | 0 numlib/dnsqtest.c | 0 numlib/ludecomp.c | 0 numlib/ludecomp.h | 0 numlib/numlib.h | 0 numlib/numsup.c | 310 +++++++++++++++++++++++++++++++++++++++++++++++++++- numlib/numsup.h | 19 ++++ numlib/powell.c | 0 numlib/powell.h | 0 numlib/rand.c | 0 numlib/rand.h | 0 numlib/sobol.c | 0 numlib/sobol.h | 0 numlib/soboltest.c | 0 numlib/svd.c | 0 numlib/svd.h | 0 numlib/svdtest.c | 0 numlib/tdhsx.c | 0 numlib/tpowell.c | 0 numlib/ui.c | 21 +++- numlib/ui.h | 0 numlib/zbrent.c | 0 numlib/zbrent.h | 0 numlib/zbrenttest.c | 0 34 files changed, 349 insertions(+), 5 deletions(-) mode change 100644 => 100755 numlib/Jamfile mode change 100644 => 100755 numlib/LUtest.c mode change 100644 => 100755 numlib/License.txt mode change 100644 => 100755 numlib/Readme.txt mode change 100644 => 100755 numlib/aatree.c mode change 100644 => 100755 numlib/aatree.h mode change 100644 => 100755 numlib/afiles mode change 100644 => 100755 numlib/dhsx.c mode change 100644 => 100755 numlib/dhsx.h mode change 100644 => 100755 numlib/dnsq.c mode change 100644 => 100755 numlib/dnsq.h mode change 100644 => 100755 numlib/dnsqtest.c mode change 100644 => 100755 numlib/ludecomp.c mode change 100644 => 100755 numlib/ludecomp.h mode change 100644 => 100755 numlib/numlib.h mode change 100644 => 100755 numlib/numsup.c mode change 100644 => 100755 numlib/numsup.h mode change 100644 => 100755 numlib/powell.c mode change 100644 => 100755 numlib/powell.h mode change 100644 => 100755 numlib/rand.c mode change 100644 => 100755 numlib/rand.h mode change 100644 => 100755 numlib/sobol.c mode change 100644 => 100755 numlib/sobol.h mode change 100644 => 100755 numlib/soboltest.c mode change 100644 => 100755 numlib/svd.c mode change 100644 => 100755 numlib/svd.h mode change 100644 => 100755 numlib/svdtest.c mode change 100644 => 100755 numlib/tdhsx.c mode change 100644 => 100755 numlib/tpowell.c mode change 100644 => 100755 numlib/ui.c mode change 100644 => 100755 numlib/ui.h mode change 100644 => 100755 numlib/zbrent.c mode change 100644 => 100755 numlib/zbrent.h mode change 100644 => 100755 numlib/zbrenttest.c (limited to 'numlib') diff --git a/numlib/Jamfile b/numlib/Jamfile old mode 100644 new mode 100755 index 87c3c78..1053612 --- a/numlib/Jamfile +++ b/numlib/Jamfile @@ -17,6 +17,8 @@ Headers = numlib.h libui.h ; #InstallFile $(DESTDIR)$(PREFIX)/h : $(Headers) ; #InstallLib $(DESTDIR)$(PREFIX)/lib : $(Libraries) ; +HDRS = ../h ; + # Numeric library Library libnum.lib : numsup.c dnsq.c powell.c dhsx.c ludecomp.c svd.c zbrent.c rand.c sobol.c aatree.c ; @@ -33,3 +35,5 @@ if $(OS) = MACOSX { # UI setup library Library libui.lib : ui.c ; + + diff --git a/numlib/LUtest.c b/numlib/LUtest.c old mode 100644 new mode 100755 diff --git a/numlib/License.txt b/numlib/License.txt old mode 100644 new mode 100755 diff --git a/numlib/Readme.txt b/numlib/Readme.txt old mode 100644 new mode 100755 diff --git a/numlib/aatree.c b/numlib/aatree.c old mode 100644 new mode 100755 diff --git a/numlib/aatree.h b/numlib/aatree.h old mode 100644 new mode 100755 diff --git a/numlib/afiles b/numlib/afiles old mode 100644 new mode 100755 diff --git a/numlib/dhsx.c b/numlib/dhsx.c old mode 100644 new mode 100755 diff --git a/numlib/dhsx.h b/numlib/dhsx.h old mode 100644 new mode 100755 diff --git a/numlib/dnsq.c b/numlib/dnsq.c old mode 100644 new mode 100755 diff --git a/numlib/dnsq.h b/numlib/dnsq.h old mode 100644 new mode 100755 diff --git a/numlib/dnsqtest.c b/numlib/dnsqtest.c old mode 100644 new mode 100755 diff --git a/numlib/ludecomp.c b/numlib/ludecomp.c old mode 100644 new mode 100755 diff --git a/numlib/ludecomp.h b/numlib/ludecomp.h old mode 100644 new mode 100755 diff --git a/numlib/numlib.h b/numlib/numlib.h old mode 100644 new mode 100755 diff --git a/numlib/numsup.c b/numlib/numsup.c old mode 100644 new mode 100755 index 43f6e73..c08ed99 --- a/numlib/numsup.c +++ b/numlib/numsup.c @@ -17,6 +17,7 @@ #include #include #include +#include #if defined (NT) #define WIN32_LEAN_AND_MEAN #include @@ -24,8 +25,14 @@ #ifdef UNIX #include #include +#include #include #endif +#ifndef SALONEINSTLIB +#include "aconfig.h" +#else +#include "sa_config.h" +#endif #define NUMSUP_C #include "numsup.h" @@ -220,22 +227,138 @@ void check_if_not_interactive() { /* It's values can be overridden to redirect these messages. */ /******************************************************************/ +static void va_loge(a1log *p, char *fmt, ...); + #ifdef NT + +/* Get a string describing the MWin operating system */ + +typedef struct { + DWORD dwOSVersionInfoSize; + DWORD dwMajorVersion; + DWORD dwMinorVersion; + DWORD dwBuildNumber; + DWORD dwPlatformId; + WCHAR szCSDVersion[128]; + WORD wServicePackMajor; + WORD wServicePackMinor; + WORD wSuiteMask; + BYTE wProductType; + BYTE wReserved; +} osversioninfoexw; + +#define VER_NT_DOMAIN_CONTROLLER 0x0000002 +#define VER_NT_SERVER 0x0000003 +#define VER_NT_WORKSTATION 0x0000001 + +static char *get_sys_info() { + static char sysinfo[100] = { "Unknown" }; + LONG (WINAPI *pfnRtlGetVersion)(osversioninfoexw*); + + *(FARPROC *)&pfnRtlGetVersion + = GetProcAddress(GetModuleHandle("ntdll.dll"), "RtlGetVersion"); + if (pfnRtlGetVersion != NULL) { + osversioninfoexw ver = { 0 }; + ver.dwOSVersionInfoSize = sizeof(ver); + + if (pfnRtlGetVersion(&ver) == 0) { + if (ver.dwMajorVersion > 6 || (ver.dwMajorVersion == 6 && ver.dwMinorVersion > 3)) { + if (ver.wProductType == VER_NT_WORKSTATION) + sprintf(sysinfo,"Windows V%d.%d SP %d", + ver.dwMajorVersion,ver.dwMinorVersion, + ver.wServicePackMajor); + else + sprintf(sysinfo,"Windows Server 2016 V%d.%d SP %d", + ver.dwMajorVersion,ver.dwMinorVersion, + ver.wServicePackMajor); + + } else if (ver.dwMajorVersion == 6 && ver.dwMinorVersion == 3) { + if (ver.wProductType == VER_NT_WORKSTATION) + sprintf(sysinfo,"Windows V8.1 SP %d", + ver.wServicePackMajor); + else + sprintf(sysinfo,"Windows Server 2012 R2 SP %d", + ver.wServicePackMajor); + + } else if (ver.dwMajorVersion == 6 && ver.dwMinorVersion == 2) { + if (ver.wProductType == VER_NT_WORKSTATION) + sprintf(sysinfo,"Windows V8 SP %d", + ver.wServicePackMajor); + else + sprintf(sysinfo,"Windows Server SP %d", + ver.wServicePackMajor); + + } else if (ver.dwMajorVersion == 6 && ver.dwMinorVersion == 1) { + if (ver.wProductType == VER_NT_WORKSTATION) + sprintf(sysinfo,"Windows V7 SP %d", + ver.wServicePackMajor); + else + sprintf(sysinfo,"Windows Server 2008 R2 SP %d", + ver.wServicePackMajor); + + } else if (ver.dwMajorVersion == 6 && ver.dwMinorVersion == 0) { + if (ver.wProductType == VER_NT_WORKSTATION) + sprintf(sysinfo,"Windows Vista SP %d", + ver.wServicePackMajor); + else + sprintf(sysinfo,"Windows Server 2008 SP %d", + ver.wServicePackMajor); + + } else if (ver.dwMajorVersion == 5 && ver.dwMinorVersion == 2) { + // Actually could be Server 2003, Home Server, Server 2003 R2 + sprintf(sysinfo,"Windows XP Pro64 SP %d", + ver.wServicePackMajor); + + } else if (ver.dwMajorVersion == 5 && ver.dwMinorVersion == 1) { + sprintf(sysinfo,"Windows XP SP %d", + ver.wServicePackMajor); + + } else if (ver.dwMajorVersion == 5 && ver.dwMinorVersion == 0) { + sprintf(sysinfo,"Windows XP SP %d", + ver.wServicePackMajor); + + } else { + sprintf(sysinfo,"Windows Maj %d Min %d SP %d", + ver.dwMajorVersion,ver.dwMinorVersion, + ver.wServicePackMajor); + } + } + } + return sysinfo; +} + + # define A1LOG_LOCK(log) \ if (g_log_init == 0) { \ InitializeCriticalSection(&log->lock); \ + EnterCriticalSection(&log->lock); \ g_log_init = 1; \ - } \ - EnterCriticalSection(&log->lock) + va_loge(log, "Argyll 'V%s' Build '%s' System '%s'\n",ARGYLL_VERSION_STR,ARGYLL_BUILD_STR, get_sys_info()); \ + } else { \ + EnterCriticalSection(&log->lock); \ + } # define A1LOG_UNLOCK(log) LeaveCriticalSection(&log->lock) #endif #ifdef UNIX + +static char *get_sys_info() { + static char sysinfo[200] = { "Unknown" }; + struct utsname ver; + + if (uname(&ver) == 0) + sprintf(sysinfo,"%s %s %s %s",ver.sysname, ver.version, ver.release, ver.machine); + return sysinfo; +} + # define A1LOG_LOCK(log) \ if (g_log_init == 0) { \ pthread_mutex_init(&log->lock, NULL); \ + pthread_mutex_lock(&log->lock); \ g_log_init = 1; \ - } \ - pthread_mutex_lock(&log->lock) + va_loge(log, "Argyll 'V%s' Build '%s' System '%s'\n",ARGYLL_VERSION_STR,ARGYLL_BUILD_STR, get_sys_info()); \ + } else { \ + pthread_mutex_lock(&log->lock); \ + } # define A1LOG_UNLOCK(log) pthread_mutex_unlock(&log->lock) #endif @@ -257,6 +380,14 @@ static void a1_default_de_log(void *cntx, a1log *p, char *fmt, va_list args) { #define a1_default_e_log a1_default_de_log +/* Call log->loge() with variags */ +static void va_loge(a1log *p, char *fmt, ...) { + va_list args; + va_start(args, fmt); + p->loge(p->cntx, p, fmt, args); + va_end(args); +} + /* Global log */ a1log default_log = { 1, /* Refcount of 1 because this is not allocated or free'd */ @@ -597,6 +728,177 @@ size_t nsize return ptr; } +/******************************************************************/ +/* OS X App Nap fixes */ +/******************************************************************/ + +#if defined(__APPLE__) + +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 +# include +# include +#else +# include +#endif +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 +# include +#endif + +/* + OS X 10.9+ App Nap problems bug: + + + + NSProcessInfo variables: + + + + typedef enum : uint64_t { NSActivityIdleDisplaySleepDisabled = (1ULL << 40), + NSActivityIdleSystemSleepDisabled = (1ULL << 20), + NSActivitySuddenTerminationDisabled = (1ULL << 14), + NSActivityAutomaticTerminationDisabled = (1ULL << 15), + NSActivityUserInitiated = (0x00FFFFFFULL | NSActivityIdleSystemSleepDisabled ), + NSActivityUserInitiatedAllowingIdleSystemSleep = + (NSActivityUserInitiated & ~NSActivityIdleSystemSleepDisabled ), + NSActivityBackground = 0x000000FFULL, + NSActivityLatencyCritical = 0xFF00000000ULL, + } NSActivityOptions; + + See : + + @property (strong) id activity; + + if ([[NSProcessInfo processInfo] respondsToSelector:@selector(beginActivityWithOptions:reason:)]) { + self.activity = [[NSProcessInfo processInfo] beginActivityWithOptions:0x00FFFFFF reason:@"receiving OSC messages"]; +} + + + + NSProcessInfo = interface(NSObject)['{B96935F6-3809-4A49-AD4F-CBBAB0F2C961}'] + function beginActivityWithOptions(options: NSActivityOptions; reason: NSString): NSObject; cdecl; + + + +*/ + +static int osx_userinitiated_cnt = 0; +static id osx_userinitiated_activity = nil; + +/* Tell App Nap that this is user initiated */ +void osx_userinitiated_start() { + Class pic; /* Process info class */ + SEL pis; /* Process info selector */ + SEL bawo; /* Begin Activity With Options selector */ + id pi; /* Process info */ + id str; + + if (osx_userinitiated_cnt++ != 0) + return; + + a1logd(g_log, 7, "OS X - User Initiated Activity start\n"); + + /* We have to be conservative to avoid triggering an exception when run on older OS X */ + if ((pic = (Class)objc_getClass("NSProcessInfo")) == nil) { + return; + } + + if (class_getClassMethod(pic, (pis = sel_getUid("processInfo"))) == NULL) { + return; + } + + if (class_getInstanceMethod(pic, (bawo = sel_getUid("beginActivityWithOptions:reason:"))) == NULL) { + a1logd(g_log, 7, "OS X - beginActivityWithOptions not supported\n"); + return; + } + + /* Get the process instance */ + if ((pi = objc_msgSend((id)pic, pis)) == nil) { + return; + } + + /* Create a reason string */ + str = objc_msgSend(objc_getClass("NSString"), sel_getUid("alloc")); + str = objc_msgSend(str, sel_getUid("initWithUTF8String:"), "ArgyllCMS"); + + /* Start activity that tells App Nap to mind its own business. */ + /* NSActivityUserInitiatedAllowingIdleSystemSleep */ + osx_userinitiated_activity = objc_msgSend(pi, bawo, 0x00FFFFFFULL, str); +} + +/* Done with user initiated */ +void osx_userinitiated_end() { + if (osx_userinitiated_cnt > 0) { + osx_userinitiated_cnt--; + if (osx_userinitiated_cnt == 0 && osx_userinitiated_activity != nil) { + a1logd(g_log, 7, "OS X - User Initiated Activity end"); + objc_msgSend( + objc_msgSend(objc_getClass("NSProcessInfo"), sel_getUid("processInfo")), + sel_getUid("endActivity:"), osx_userinitiated_activity); + osx_userinitiated_activity = nil; + } + } +} + +static int osx_latencycritical_cnt = 0; +static id osx_latencycritical_activity = nil; + +/* Tell App Nap that this is latency critical */ +void osx_latencycritical_start() { + Class pic; /* Process info class */ + SEL pis; /* Process info selector */ + SEL bawo; /* Begin Activity With Options selector */ + id pi; /* Process info */ + id str; + + if (osx_latencycritical_cnt++ != 0) + return; + + a1logd(g_log, 7, "OS X - Latency Critical Activity start\n"); + + /* We have to be conservative to avoid triggering an exception when run on older OS X */ + if ((pic = (Class)objc_getClass("NSProcessInfo")) == nil) { + return; + } + + if (class_getClassMethod(pic, (pis = sel_getUid("processInfo"))) == NULL) { + return; + } + + if (class_getInstanceMethod(pic, (bawo = sel_getUid("beginActivityWithOptions:reason:"))) == NULL) { + a1logd(g_log, 7, "OS X - beginActivityWithOptions not supported\n"); + return; + } + + /* Get the process instance */ + if ((pi = objc_msgSend((id)pic, pis)) == nil) { + return; + } + + /* Create a reason string */ + str = objc_msgSend(objc_getClass("NSString"), sel_getUid("alloc")); + str = objc_msgSend(str, sel_getUid("initWithUTF8String:"), "Measuring Color"); + + /* Start activity that tells App Nap to mind its own business. */ + /* NSActivityUserInitiatedAllowingIdleSystemSleep | NSActivityLatencyCritical */ + osx_latencycritical_activity = objc_msgSend(pi, bawo, 0x00FFFFFFULL | 0xFF00000000ULL, str); +} + +/* Done with latency critical */ +void osx_latencycritical_end() { + if (osx_latencycritical_cnt > 0) { + osx_latencycritical_cnt--; + if (osx_latencycritical_cnt == 0 && osx_latencycritical_activity != nil) { + a1logd(g_log, 7, "OS X - Latency Critical Activity end"); + objc_msgSend( + objc_msgSend(objc_getClass("NSProcessInfo"), sel_getUid("processInfo")), + sel_getUid("endActivity:"), osx_latencycritical_activity); + osx_latencycritical_activity = nil; + } + } +} + +#endif /* __APPLE__ */ + /******************************************************************/ /* Numerical Recipes Vector/Matrix Support functions */ /******************************************************************/ diff --git a/numlib/numsup.h b/numlib/numsup.h old mode 100644 new mode 100755 index a284809..366763d --- a/numlib/numsup.h +++ b/numlib/numsup.h @@ -350,6 +350,24 @@ size_t nsize /* =========================================================== */ +#if defined(__APPLE__) + +/* Tell App Nap that this is user initiated */ +void osx_userinitiated_start(); + +/* Done with user initiated */ +void osx_userinitiated_end(); + +/* Tell App Nap that this is latency critical */ +void osx_latencycritical_start(); + +/* Done with latency critical */ +void osx_latencycritical_end(); + +#endif /* __APPLE__ */ + +/* =========================================================== */ + /* Numerical recipes vector/matrix support functions */ /* Note that the index arguments are the inclusive low and high values */ @@ -504,6 +522,7 @@ void write_INR64_le(ORD8 *p, INR64 d); #ifndef isNan #define isNan(x) ((x) != (x)) #define isFinite(x) ((x) == 0.0 || (x) * 1.0000001 != (x)) +#define isNFinite(x) ((x) != 0.0 && (x) * 1.0000001 == (x)) #endif diff --git a/numlib/powell.c b/numlib/powell.c old mode 100644 new mode 100755 diff --git a/numlib/powell.h b/numlib/powell.h old mode 100644 new mode 100755 diff --git a/numlib/rand.c b/numlib/rand.c old mode 100644 new mode 100755 diff --git a/numlib/rand.h b/numlib/rand.h old mode 100644 new mode 100755 diff --git a/numlib/sobol.c b/numlib/sobol.c old mode 100644 new mode 100755 diff --git a/numlib/sobol.h b/numlib/sobol.h old mode 100644 new mode 100755 diff --git a/numlib/soboltest.c b/numlib/soboltest.c old mode 100644 new mode 100755 diff --git a/numlib/svd.c b/numlib/svd.c old mode 100644 new mode 100755 diff --git a/numlib/svd.h b/numlib/svd.h old mode 100644 new mode 100755 diff --git a/numlib/svdtest.c b/numlib/svdtest.c old mode 100644 new mode 100755 diff --git a/numlib/tdhsx.c b/numlib/tdhsx.c old mode 100644 new mode 100755 diff --git a/numlib/tpowell.c b/numlib/tpowell.c old mode 100644 new mode 100755 diff --git a/numlib/ui.c b/numlib/ui.c old mode 100644 new mode 100755 index 31fd3b6..a3cdbe8 --- a/numlib/ui.c +++ b/numlib/ui.c @@ -12,7 +12,8 @@ * see the License.txt file for licencing details. * * Typically we need to set things up and then call the - * "normal" main, called "uimain" in ArgyllCMS utils. + * "normal" main, called "uimain" in ArgyllCMS utils, + * created by ui.h #defining main to uimain. */ #ifdef UNIX @@ -48,6 +49,14 @@ # include # include +/* (Duplicate declaration from numsup.h) */ + +/* Tell App Nap that this is user initiated */ +void osx_userinitiated_start(); + +/* Done with user initiated */ +void osx_userinitiated_end(); + /* This is a mechanism to force libui to link */ int ui_initialized = 0; @@ -57,6 +66,9 @@ static char **g_argv; pthread_t ui_thid = 0; /* Thread ID of main thread running io run loop */ pthread_t ui_main_thid = 0; /* Thread ID of thread running application main() */ +extern int uimain(int argc, char *argv[]); + +/* Thread that calls the real application main() */ static void *callMain(void *p) { int rv; @@ -64,8 +76,13 @@ static void *callMain(void *p) { NSAutoreleasePool *tpool = [NSAutoreleasePool new]; + /* Turn App Nap off */ + osx_userinitiated_start(); + rv = uimain(g_argc, g_argv); + osx_userinitiated_end(); + [tpool release]; exit(rv); @@ -204,6 +221,8 @@ int ui_initialized = 0; //# pragma comment( linker, "/subsystem:windows /ENTRY:mainCRTStartup" ) //# pragma comment( linker, "/subsystem:windows /ENTRY:WinMainCRTStartup" ) +extern int uimain(int argc, char *argv[]); + APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, diff --git a/numlib/ui.h b/numlib/ui.h old mode 100644 new mode 100755 diff --git a/numlib/zbrent.c b/numlib/zbrent.c old mode 100644 new mode 100755 diff --git a/numlib/zbrent.h b/numlib/zbrent.h old mode 100644 new mode 100755 diff --git a/numlib/zbrenttest.c b/numlib/zbrenttest.c old mode 100644 new mode 100755 -- cgit v1.2.3