src/java.desktop/share/native/libsplashscreen/splashscreen_impl.c
author ihse
Sat, 03 Mar 2018 08:21:47 +0100
branchihse-warnings-cflags-branch
changeset 56230 489867818774
parent 47216 71c04702a3d5
permissions -rw-r--r--
No longer disable E_OLD_STYLE_FUNC_DEF.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "splashscreen_impl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "splashscreen_gfx_impl.h"
41776
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
    28
#define BUFF_SIZE 1024
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
    29
#ifdef _MSC_VER
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
    30
# ifndef snprintf
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
    31
#       define snprintf _snprintf
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
    32
# endif
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
    33
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
int splashIsVisible = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
Splash *
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
    37
SplashGetInstance(void)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    static Splash splash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    static int preInitialized = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    if (!preInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        memset(&splash, 0, sizeof(Splash));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        splash.currentFrame = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        preInitialized = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    return &splash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
SPLASHEXPORT void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
SplashSetFileJarName(const char* fileName, const char* jarName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    Splash *splash = SplashGetInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    free(splash->fileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    splash->fileName = SplashConvertStringAlloc(fileName, &splash->fileNameLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    free(splash->jarName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    splash->jarName = SplashConvertStringAlloc(jarName, &splash->jarNameLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
SPLASHEXPORT void
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
    61
SplashInit(void)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    Splash *splash = SplashGetInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    memset(splash, 0, sizeof(Splash));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    splash->currentFrame = -1;
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 22312
diff changeset
    67
    splash->scaleFactor = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    initFormat(&splash->imageFormat, QUAD_RED_MASK, QUAD_GREEN_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        QUAD_BLUE_MASK, QUAD_ALPHA_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    SplashInitPlatform(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
SPLASHEXPORT void
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
    74
SplashClose(void)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    Splash *splash = SplashGetInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    if (splash->isVisible > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        SplashLock(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        splash->isVisible = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        SplashClosePlatform(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        SplashUnlock(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
SplashCleanup(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    splash->currentFrame = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    SplashCleanupPlatform(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    if (splash->frames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        for (i = 0; i < splash->frameCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            if (splash->frames[i].bitmapBits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                free(splash->frames[i].bitmapBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                splash->frames[i].bitmapBits = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        free(splash->frames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        splash->frames = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    if (splash->overlayData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        free(splash->overlayData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        splash->overlayData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    SplashSetFileJarName(NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 22312
diff changeset
   110
SPLASHEXPORT void
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 22312
diff changeset
   111
SplashSetScaleFactor(float scaleFactor)
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 22312
diff changeset
   112
{
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 22312
diff changeset
   113
    Splash *splash = SplashGetInstance();
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 22312
diff changeset
   114
    splash->scaleFactor = scaleFactor;
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 22312
diff changeset
   115
}
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 22312
diff changeset
   116
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
SplashDone(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    SplashCleanup(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    SplashDonePlatform(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
SplashIsStillLooping(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
{
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   127
    if (splash->currentFrame < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return 0;
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   129
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    return splash->loopCount != 1 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        splash->currentFrame + 1 < splash->frameCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
SplashUpdateScreenData(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    ImageRect srcRect, dstRect;
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   138
    if (splash->currentFrame < 0) {
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   139
        return;
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   140
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    initRect(&srcRect, 0, 0, splash->width, splash->height, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        splash->width * sizeof(rgbquad_t),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        splash->frames[splash->currentFrame].bitmapBits, &splash->imageFormat);
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   145
    if (splash->screenData) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        free(splash->screenData);
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   147
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    splash->screenStride = splash->width * splash->screenFormat.depthBytes;
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   149
    if (splash->byteAlignment > 1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        splash->screenStride =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            (splash->screenStride + splash->byteAlignment - 1) &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            ~(splash->byteAlignment - 1);
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   153
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    splash->screenData = malloc(splash->height * splash->screenStride);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    initRect(&dstRect, 0, 0, splash->width, splash->height, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        splash->screenStride, splash->screenData, &splash->screenFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    if (splash->overlayData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        convertRect2(&srcRect, &dstRect, CVT_BLEND, &splash->overlayRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        convertRect(&srcRect, &dstRect, CVT_COPY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
SplashNextFrame(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
{
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   168
    if (splash->currentFrame < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return;
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   170
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    do {
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   172
        if (!SplashIsStillLooping(splash)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            return;
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   174
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        splash->time += splash->frames[splash->currentFrame].delay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (++splash->currentFrame >= splash->frameCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            splash->currentFrame = 0;
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   178
            if (splash->loopCount > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                splash->loopCount--;
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   180
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    } while (splash->time + splash->frames[splash->currentFrame].delay -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        SplashTime() <= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
BitmapToYXBandedRectangles(ImageRect * pSrcRect, RECT_T * out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    RECT_T *pPrevLine = NULL, *pFirst = out, *pThis = pFirst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    int i, j, i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    int length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    for (j = 0; j < pSrcRect->numLines; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        /* generate data for a scanline */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        byte_t *pSrc = (byte_t *) pSrcRect->pBits + j * pSrcRect->stride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        RECT_T *pLine = pThis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            while (i < pSrcRect->numSamples &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                   getRGBA(pSrc, pSrcRect->format) < ALPHA_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                pSrc += pSrcRect->depthBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                ++i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            }
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   208
            if (i >= pSrcRect->numSamples) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                break;
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   210
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            i0 = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            while (i < pSrcRect->numSamples &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                   getRGBA(pSrc, pSrcRect->format) >= ALPHA_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                pSrc += pSrcRect->depthBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                ++i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            RECT_SET(*pThis, i0, j, i - i0, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            ++pThis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        } while (i < pSrcRect->numSamples);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        /*  check if the previous scanline is exactly the same, merge if so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
           (this is the only optimization we can use for YXBanded rectangles, and win32 supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
           YXBanded only */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        length = pThis - pLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (pPrevLine && pLine - pPrevLine == length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            for (i = 0; i < length && RECT_EQ_X(pPrevLine[i], pLine[i]); ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            if (i == pLine - pPrevLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                // do merge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                for (i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    RECT_INC_HEIGHT(pPrevLine[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                pThis = pLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        /* or else use the generated scanline */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        pPrevLine = pLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    return pThis - pFirst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
typedef struct FILEFORMAT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    int sign;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    int (*decodeStream) (Splash * splash, SplashStream * stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
} FILEFORMAT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
static const FILEFORMAT formats[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    {0x47, SplashDecodeGifStream},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    {0x89, SplashDecodePngStream},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    {0xFF, SplashDecodeJpegStream}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
SplashLoadStream(SplashStream * stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    int success = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    int c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    size_t i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    Splash *splash = SplashGetInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    if (splash->isVisible < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    SplashLock(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /* the formats we support can be easily distinguished by the first byte */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    c = stream->peek(stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    if (c != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        for (i = 0; i < sizeof(formats) / sizeof(FILEFORMAT); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            if (c == formats[i].sign) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                success = formats[i].decodeStream(splash, stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    stream->close(stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    if (!success) {             // failed to decode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (splash->isVisible == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            SplashCleanup(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        SplashUnlock(splash);   // SplashClose locks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        if (splash->isVisible == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            SplashClose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        splash->currentFrame = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (splash->isVisible == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            SplashStart(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            SplashReconfigure(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            splash->time = SplashTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        SplashUnlock(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    return success;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
SPLASHEXPORT int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
SplashLoadFile(const char *filename)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    SplashStream stream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    return SplashStreamInitFile(&stream, filename) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                SplashLoadStream(&stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
SPLASHEXPORT int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
SplashLoadMemory(void *data, int size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    SplashStream stream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    return SplashStreamInitMemory(&stream, data, size) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                SplashLoadStream(&stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
/* SplashStart MUST be called from under the lock */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
SplashStart(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    if (splash->isVisible == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        SplashCreateThread(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        splash->isVisible = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
/* SplashStream functions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
static int readFile(void* pStream, void* pData, int nBytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    FILE* f = ((SplashStream*)pStream)->arg.stdio.f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    return fread(pData, 1, nBytes, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
static int peekFile(void* pStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    FILE* f = ((SplashStream*)pStream)->arg.stdio.f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    int c = fgetc(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    if (c != EOF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        ungetc(c, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
static void closeFile(void* pStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    FILE* f = ((SplashStream*)pStream)->arg.stdio.f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    fclose(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
static int readMem(void* pStream, void* pData, int nBytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    unsigned char* pSrc = (unsigned char*)(((SplashStream*)pStream)->arg.mem.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    unsigned char* pSrcEnd = (unsigned char*)(((SplashStream*)pStream)->arg.mem.pDataEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    if (nBytes > pSrcEnd - pSrc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        nBytes = pSrcEnd - pSrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    if (nBytes>0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        memcpy(pData, pSrc, nBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        pSrc += nBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        ((SplashStream*)pStream)->arg.mem.pData = (void*)pSrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    return nBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
static int peekMem(void* pStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    unsigned char* pSrc = (unsigned char*)(((SplashStream*)pStream)->arg.mem.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    unsigned char* pSrcEnd = (unsigned char*)(((SplashStream*)pStream)->arg.mem.pDataEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    if (pSrc >= pSrcEnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return (int)*pSrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
static void closeMem(void* pStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
int SplashStreamInitFile(SplashStream * pStream, const char* filename) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    pStream->arg.stdio.f = fopen(filename, "rb");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    pStream->read = readFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    pStream->peek = peekFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    pStream->close = closeFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    return pStream->arg.stdio.f != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
int SplashStreamInitMemory(SplashStream * pStream, void* pData, int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    pStream->arg.mem.pData = (unsigned char*)pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    pStream->arg.mem.pDataEnd = (unsigned char*)pData + size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    pStream->read = readMem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    pStream->peek = peekMem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    pStream->close = closeMem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
}
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 25859
diff changeset
   397
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 25859
diff changeset
   398
SPLASHEXPORT int
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 25859
diff changeset
   399
SplashGetScaledImgNameMaxPstfixLen(const char *fileName){
41776
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   400
    return strlen(fileName) + strlen("@100pct") + 1;
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 25859
diff changeset
   401
}
41776
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   402
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   403
jboolean GetScaledImageName(const char *fileName, char *scaleImageName,
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   404
        float *scaleFactor, const size_t scaledImageLength) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   405
    if (*scaleFactor > 1.0) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   406
        FILE *fp = NULL;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   407
        char scaledImgPct[BUFF_SIZE];
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   408
        char scaledImgX[BUFF_SIZE];
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   409
        char *scaledImageXName = NULL;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   410
        char *scaledImagePctName = malloc(scaledImageLength);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   411
        char *dupFileName = strdup(fileName);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   412
        char *fileExtension = strrchr(dupFileName, '.');
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   413
        size_t lengthPct = 0;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   414
        size_t lengthX = 0;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   415
        int retValPct = 0;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   416
        int retValX = 0;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   417
        jboolean isPctScaledImage = (*scaleFactor * 100) != ((int) (*scaleFactor)) *100;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   418
        snprintf(scaledImgPct, BUFF_SIZE, "%s%d%s", "@",
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   419
                (int) (*scaleFactor * 100), "pct");
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   420
        if (!isPctScaledImage) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   421
            scaledImageXName = malloc(scaledImageLength);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   422
            snprintf(scaledImgX, BUFF_SIZE, "%s%d%s", "@", (int) (*scaleFactor), "x");
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   423
        }
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   424
        /*File is missing extension */
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   425
        if (fileExtension == NULL) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   426
            lengthPct = strlen(dupFileName) +
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   427
                    strlen(scaledImgPct) + 1;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   428
            if (!isPctScaledImage) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   429
                lengthX = strlen(dupFileName) +
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   430
                        strlen(scaledImgX) + 1;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   431
            }
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   432
            if (lengthPct > scaledImageLength || lengthX > scaledImageLength) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   433
                cleanUp(dupFileName, scaledImageXName, scaledImagePctName, scaleFactor);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   434
                return JNI_FALSE;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   435
            }
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   436
            retValPct = snprintf(scaledImagePctName, lengthPct, "%s%s", dupFileName,
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   437
                    scaledImgPct);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   438
            if (!isPctScaledImage) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   439
                retValX = snprintf(scaledImageXName, lengthX, "%s%s", dupFileName,
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   440
                        scaledImgX);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   441
            }
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   442
            if ((retValPct < 0 || (retValPct > lengthPct - 1)) ||
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   443
                    (retValX < 0 || (retValX > lengthX - 1))) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   444
                cleanUp(dupFileName, scaledImageXName, scaledImagePctName, scaleFactor);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   445
                return JNI_FALSE;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   446
            }
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   447
        } else {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   448
            int length_Without_Ext = fileExtension - dupFileName;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   449
            lengthPct = length_Without_Ext + strlen(scaledImgPct) +
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   450
                    strlen(fileExtension) + 1;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   451
            if (!isPctScaledImage) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   452
                lengthX = length_Without_Ext + strlen(scaledImgX) +
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   453
                        strlen(fileExtension) + 1;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   454
            }
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   455
            if (lengthPct > scaledImageLength || lengthX > scaledImageLength) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   456
                cleanUp(dupFileName, scaledImageXName, scaledImagePctName, scaleFactor);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   457
                return JNI_FALSE;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   458
            }
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   459
            retValPct = snprintf(scaledImagePctName, lengthPct, "%.*s%s%s",
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   460
                    length_Without_Ext, dupFileName, scaledImgPct, fileExtension);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   461
            if (!isPctScaledImage) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   462
                retValX = snprintf(scaledImageXName, lengthX, "%.*s%s%s",
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   463
                        length_Without_Ext, dupFileName, scaledImgX, fileExtension);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   464
            }
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   465
            if ((retValPct < 0 || (retValPct > lengthPct - 1)) ||
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   466
                    (retValX < 0 || (retValX > lengthX - 1))) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   467
                cleanUp(dupFileName, scaledImageXName, scaledImagePctName, scaleFactor);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   468
                return JNI_FALSE;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   469
            }
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   470
        }
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   471
        free(dupFileName);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   472
        if (!(fp = fopen(scaledImagePctName, "r"))) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   473
            if (!isPctScaledImage && (fp = fopen(scaledImageXName, "r"))) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   474
                fclose(fp);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   475
                strcpy(scaleImageName, scaledImageXName);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   476
                free(scaledImageXName);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   477
                free(scaledImagePctName);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   478
                return JNI_TRUE;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   479
            }
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   480
            cleanUp(NULL, scaledImageXName, scaledImagePctName, scaleFactor);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   481
            return JNI_FALSE;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   482
        }
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   483
        fclose(fp);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   484
        strcpy(scaleImageName, scaledImagePctName);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   485
        free(scaledImageXName);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   486
        free(scaledImagePctName);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   487
        return JNI_TRUE;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   488
    }
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   489
    return JNI_FALSE;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   490
}
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   491
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   492
void cleanUp(char *fName, char *xName, char *pctName, float *scaleFactor) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   493
    *scaleFactor = 1;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   494
    free(fName);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   495
    free(xName);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   496
    free(pctName);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   497
}