--- old/src/java.desktop/windows/native/libsplashscreen/splashscreen_sys.c 2016-03-16 16:44:20.946898118 +0530 +++ new/src/java.desktop/windows/native/libsplashscreen/splashscreen_sys.c 2016-03-16 16:44:20.798898123 +0530 @@ -38,7 +38,6 @@ #include #include #include "sizecalc.h" - #ifndef WS_EX_LAYERED #define WS_EX_LAYERED 0x80000 #endif @@ -58,6 +57,8 @@ #define WM_SPLASHUPDATE WM_USER+1 #define WM_SPLASHRECONFIGURE WM_USER+2 +#define BUFF_SIZE 1024 + /* Could use npt but decided to cut down on linked code size */ char* SplashConvertStringAlloc(const char* in, int *size) { int len, outChars, rc; @@ -573,6 +574,57 @@ SplashGetScaledImageName(const char* jarName, const char* fileName, float *scaleFactor) { - *scaleFactor = 1; + float dpiScaleX = -1.0f; + float dpiScaleY = -1.0f; + *scaleFactor = 1.0; + GetScreenDpi(getPrimaryMonitor(), &dpiScaleX, &dpiScaleY); + *scaleFactor = dpiScaleX > 0 ? dpiScaleX / 96 : *scaleFactor; + + if (*scaleFactor > 1.0) { + char strDpi[BUFF_SIZE]; + _snprintf(strDpi, BUFF_SIZE, "%d", (int)dpiScaleX); + char *dupFileName = strdup(fileName); + char *fileExtension = strrchr(dupFileName, '.'); + char *scaledImgName = NULL; + char *nameToAppend = ".scale-"; + size_t length = 0; + /*File is missing extension */ + if (fileExtension == NULL) { + length = strlen(dupFileName) + strlen(nameToAppend) + + strlen(strDpi) + 1; + scaledImgName = SAFE_SIZE_ARRAY_ALLOC(malloc, length, sizeof(char)); + int retVal = _snprintf(scaledImgName, length, "%s%s%s", dupFileName, + nameToAppend, strDpi); + if (retVal < 0 || (retVal != length - 1)) { + *scaleFactor = 1; + free(dupFileName); + free(scaledImgName); + return NULL; + } + } + else { + size_t length_Without_Ext = fileExtension - dupFileName; + length = length_Without_Ext + strlen(nameToAppend) + strlen(strDpi) + + strlen(fileExtension) + 1; + scaledImgName = SAFE_SIZE_ARRAY_ALLOC(malloc, length, sizeof(char)); + int retVal = _snprintf(scaledImgName, length, "%.*s%s%s%s", + length_Without_Ext, dupFileName, nameToAppend, strDpi, fileExtension); + if (retVal < 0 || (retVal != length - 1)) { + *scaleFactor = 1; + free(dupFileName); + free(scaledImgName); + return NULL; + } + } + free(dupFileName); + FILE *fp = NULL; + if (!(fp = fopen(scaledImgName, "r"))) { + *scaleFactor = 1; + free(scaledImgName); + return NULL; + } + fclose(fp); + return scaledImgName; + } return NULL; }