< prev index next >

src/java.desktop/share/native/libsplashscreen/splashscreen_impl.c

Print this page




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "splashscreen_impl.h"
  27 #include "splashscreen_gfx_impl.h"
  28 





  29 int splashIsVisible = 0;
  30 
  31 Splash *
  32 SplashGetInstance()
  33 {
  34     static Splash splash;
  35     static int preInitialized = 0;
  36     if (!preInitialized) {
  37         memset(&splash, 0, sizeof(Splash));
  38         splash.currentFrame = -1;
  39         preInitialized = 1;
  40     }
  41     return &splash;
  42 }
  43 
  44 SPLASHEXPORT void
  45 SplashSetFileJarName(const char* fileName, const char* jarName) {
  46     Splash *splash = SplashGetInstance();
  47 
  48     free(splash->fileName);


 375 
 376 int SplashStreamInitFile(SplashStream * pStream, const char* filename) {
 377     pStream->arg.stdio.f = fopen(filename, "rb");
 378     pStream->read = readFile;
 379     pStream->peek = peekFile;
 380     pStream->close = closeFile;
 381     return pStream->arg.stdio.f != 0;
 382 }
 383 
 384 int SplashStreamInitMemory(SplashStream * pStream, void* pData, int size) {
 385     pStream->arg.mem.pData = (unsigned char*)pData;
 386     pStream->arg.mem.pDataEnd = (unsigned char*)pData + size;
 387     pStream->read = readMem;
 388     pStream->peek = peekMem;
 389     pStream->close = closeMem;
 390     return 1;
 391 }
 392 
 393 SPLASHEXPORT int
 394 SplashGetScaledImgNameMaxPstfixLen(const char *fileName){
 395     return strlen(fileName) + strlen(".java-scale-200") + 1;







































































































 396 }



   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "splashscreen_impl.h"
  27 #include "splashscreen_gfx_impl.h"
  28 #define BUFF_SIZE 1024
  29 #ifdef _MSC_VER
  30 # ifndef snprintf
  31 #       define snprintf _snprintf
  32 # endif
  33 #endif
  34 int splashIsVisible = 0;
  35 
  36 Splash *
  37 SplashGetInstance()
  38 {
  39     static Splash splash;
  40     static int preInitialized = 0;
  41     if (!preInitialized) {
  42         memset(&splash, 0, sizeof(Splash));
  43         splash.currentFrame = -1;
  44         preInitialized = 1;
  45     }
  46     return &splash;
  47 }
  48 
  49 SPLASHEXPORT void
  50 SplashSetFileJarName(const char* fileName, const char* jarName) {
  51     Splash *splash = SplashGetInstance();
  52 
  53     free(splash->fileName);


 380 
 381 int SplashStreamInitFile(SplashStream * pStream, const char* filename) {
 382     pStream->arg.stdio.f = fopen(filename, "rb");
 383     pStream->read = readFile;
 384     pStream->peek = peekFile;
 385     pStream->close = closeFile;
 386     return pStream->arg.stdio.f != 0;
 387 }
 388 
 389 int SplashStreamInitMemory(SplashStream * pStream, void* pData, int size) {
 390     pStream->arg.mem.pData = (unsigned char*)pData;
 391     pStream->arg.mem.pDataEnd = (unsigned char*)pData + size;
 392     pStream->read = readMem;
 393     pStream->peek = peekMem;
 394     pStream->close = closeMem;
 395     return 1;
 396 }
 397 
 398 SPLASHEXPORT int
 399 SplashGetScaledImgNameMaxPstfixLen(const char *fileName){
 400     return strlen(fileName) + strlen("@100pct") + 1;
 401 }
 402 
 403 jboolean GetScaledImageName(const char *fileName, char *scaleImageName,
 404         float *scaleFactor, const size_t scaledImageLength) {
 405     if (*scaleFactor > 1.0) {
 406         FILE *fp = NULL;
 407         char scaledImgPct[BUFF_SIZE];
 408         char scaledImgX[BUFF_SIZE];
 409         char *scaledImageXName = NULL;
 410         char *scaledImagePctName = malloc(scaledImageLength);
 411         char *dupFileName = strdup(fileName);
 412         char *fileExtension = strrchr(dupFileName, '.');
 413         size_t lengthPct = 0;
 414         size_t lengthX = 0;
 415         int retValPct = 0;
 416         int retValX = 0;
 417         jboolean isPctScaledImage = (*scaleFactor * 100) != ((int) (*scaleFactor)) *100;
 418         snprintf(scaledImgPct, BUFF_SIZE, "%s%d%s", "@", (int) (*scaleFactor * 100), "pct");
 419         if (!isPctScaledImage) {
 420             scaledImageXName = malloc(scaledImageLength);
 421             snprintf(scaledImgX, BUFF_SIZE, "%s%d%s", "@", (int) (*scaleFactor), "x");
 422         }
 423         /*File is missing extension */
 424         if (fileExtension == NULL) {
 425             lengthPct = strlen(dupFileName) +
 426                     strlen(scaledImgPct) + 1;
 427             if (!isPctScaledImage) {
 428                 lengthX = strlen(dupFileName) +
 429                     strlen(scaledImgX) + 1;
 430             }
 431             if (lengthPct > scaledImageLength || lengthX > scaledImageLength) {
 432                 cleanUp(dupFileName, scaledImageXName, scaledImagePctName, scaleFactor);
 433                 return JNI_FALSE;
 434             }
 435             retValPct = snprintf(scaledImagePctName, lengthPct, "%s%s", dupFileName,
 436                     scaledImgPct);
 437             if (!isPctScaledImage) {
 438                 retValX = snprintf(scaledImageXName, lengthX, "%s%s", dupFileName,
 439                         scaledImgX);
 440             }
 441             if ((retValPct < 0 || (retValPct > lengthPct - 1)) ||
 442                     (retValX < 0 || (retValX > lengthX - 1))) {
 443                 cleanUp(dupFileName, scaledImageXName, scaledImagePctName, scaleFactor);
 444                 fprintf(stdout,"returning from here 11\n");
 445                 fflush(stdout);
 446                 return JNI_FALSE;
 447             }
 448         } else {
 449             int length_Without_Ext = fileExtension - dupFileName;
 450             lengthPct = length_Without_Ext + strlen(scaledImgPct) +
 451                     strlen(fileExtension) + 1;
 452             if (!isPctScaledImage) {
 453                 lengthX = length_Without_Ext + strlen(scaledImgX) +
 454                     strlen(fileExtension) + 1;
 455             }
 456             if (lengthPct > scaledImageLength || lengthX > scaledImageLength) {
 457                 cleanUp(dupFileName, scaledImageXName, scaledImagePctName, scaleFactor);
 458                  fprintf(stdout,"returning from here 22\n");
 459                 fflush(stdout);                
 460                 return JNI_FALSE;
 461             }
 462             retValPct = snprintf(scaledImagePctName, lengthPct, "%.*s%s%s",
 463                     length_Without_Ext, dupFileName, scaledImgPct, fileExtension);
 464             if(!isPctScaledImage) {
 465                 retValX = snprintf(scaledImageXName, lengthX, "%.*s%s%s",
 466                         length_Without_Ext, dupFileName, scaledImgX, fileExtension);
 467             }
 468             if ((retValPct < 0 || (retValPct > lengthPct - 1)) ||
 469                     (retValX < 0 || (retValX > lengthX - 1))) {
 470                cleanUp(dupFileName, scaledImageXName, scaledImagePctName, scaleFactor);
 471  fprintf(stdout,"returning from here 33\n");
 472                 fflush(stdout);
 473                return JNI_FALSE;
 474             }
 475         }
 476         free(dupFileName);
 477         if (!(fp = fopen(scaledImagePctName, "r"))) {
 478             if (!isPctScaledImage && (fp = fopen(scaledImageXName, "r"))) {
 479                 fclose(fp);
 480                 strcpy(scaleImageName, scaledImageXName);
 481                 free(scaledImageXName);
 482                 free(scaledImagePctName);
 483                 return JNI_TRUE;
 484             }
 485             cleanUp(NULL,scaledImageXName, scaledImagePctName, scaleFactor);
 486  fprintf(stdout,"returning from here 44\n");
 487                 fflush(stdout);
 488             return JNI_FALSE;
 489         }
 490         fclose(fp);
 491         strcpy(scaleImageName, scaledImagePctName);
 492         free(scaledImageXName);
 493         free(scaledImagePctName);
 494         return JNI_TRUE;
 495     }
 496     return JNI_FALSE;
 497 }
 498 
 499 void cleanUp(char *fName, char *xName, char *pctName, float *scaleFactor) {
 500     *scaleFactor = 1;
 501     free(fName);
 502     free(xName);
 503     free(pctName);
 504 }
 505 
< prev index next >