jdk/src/share/native/sun/awt/splashscreen/splashscreen_gif.c
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 6830 1fe56588acb1
child 16512 024da1ae4667
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 6830
diff changeset
     2
 * Copyright (c) 2005, 2010, 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: 2608
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: 2608
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: 2608
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2608
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2608
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.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "../giflib/gif_lib.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#define GIF_TRANSPARENT     0x01
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#define GIF_USER_INPUT      0x02
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#define GIF_DISPOSE_MASK    0x07
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#define GIF_DISPOSE_SHIFT   2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#define GIF_NOT_TRANSPARENT -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#define GIF_DISPOSE_NONE    0   // No disposal specified. The decoder is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
                                // not required to take any action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#define GIF_DISPOSE_LEAVE   1   // Do not dispose. The graphic is to be left
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
                                // in place.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#define GIF_DISPOSE_BACKGND 2   // Restore to background color. The area used by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
                                // graphic must be restored to the background color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#define GIF_DISPOSE_RESTORE 3   // Restore to previous. The decoder is required to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
                                // restore the area overwritten by the graphic with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
                                // what was there prior to rendering the graphic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
static const char szNetscape20ext[11] = "NETSCAPE2.0";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#define NSEXT_LOOP      0x01    // Loop Count field code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
// convert libungif samples to our ones
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
    54
#define MAKE_QUAD_GIF(c,a) MAKE_QUAD((c).Red, (c).Green, (c).Blue, (unsigned)(a))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
/* stdio FILE* and memory input functions for libungif */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
SplashStreamGifInputFunc(GifFileType * gif, GifByteType * buf, int n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    SplashStream* io = (SplashStream*)gif->UserData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    int rc = io->read(io, buf, n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    return rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
2603
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
    65
/* These macro help to ensure that we only take part of frame that fits into
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
    66
   logical screen. */
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
    67
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
    68
/* Ensure that p belongs to [pmin, pmax) interval. Returns fixed point (if fix is needed) */
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
    69
#define FIX_POINT(p, pmin, pmax) ( ((p) < (pmin)) ? (pmin) : (((p) > (pmax)) ? (pmax) : (p)))
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
    70
/* Ensures that line starting at point p does not exceed boundary pmax.
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
    71
   Returns fixed length (if fix is needed) */
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
    72
#define FIX_LENGTH(p, len, pmax) ( ((p) + (len)) > (pmax) ? ((pmax) - (p)) : (len))
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
    73
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
SplashDecodeGif(Splash * splash, GifFileType * gif)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    int stride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    int bufferSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    byte_t *pBitmapBits, *pOldBitmapBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    int i, j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    int imageIndex;
2603
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
    82
    int cx, cy, cw, ch; /* clamped coordinates */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    const int interlacedOffset[] = { 0, 4, 2, 1, 0 };   /* The way Interlaced image should. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    const int interlacedJumps[] = { 8, 8, 4, 2, 1 };    /* be read - offsets and jumps... */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    if (DGifSlurp(gif) == GIF_ERROR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    SplashCleanup(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
2603
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
    92
    if (!SAFE_TO_ALLOC(gif->SWidth, splash->imageFormat.depthBytes)) {
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
    93
        return 0;
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
    94
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    stride = gif->SWidth * splash->imageFormat.depthBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    if (splash->byteAlignment > 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        stride =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            (stride + splash->byteAlignment - 1) & ~(splash->byteAlignment - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
2603
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   100
    if (!SAFE_TO_ALLOC(gif->SHeight, stride)) {
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   101
        return 0;
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   102
    }
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   103
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   104
    if (!SAFE_TO_ALLOC(gif->ImageCount, sizeof(SplashImage*))) {
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   105
        return 0;
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   106
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    bufferSize = stride * gif->SHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    pBitmapBits = (byte_t *) malloc(bufferSize);
2603
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   109
    if (!pBitmapBits) {
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   110
        return 0;
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   111
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    pOldBitmapBits = (byte_t *) malloc(bufferSize);
2603
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   113
    if (!pOldBitmapBits) {
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   114
        free(pBitmapBits);
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   115
        return 0;
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   116
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    memset(pBitmapBits, 0, bufferSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    splash->width = gif->SWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    splash->height = gif->SHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    splash->frameCount = gif->ImageCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    splash->frames = (SplashImage *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        malloc(sizeof(SplashImage) * gif->ImageCount);
2603
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   124
    if (!splash->frames) {
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   125
      free(pBitmapBits);
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   126
      free(pOldBitmapBits);
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   127
      return 0;
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   128
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    memset(splash->frames, 0, sizeof(SplashImage) * gif->ImageCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    splash->loopCount = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    for (imageIndex = 0; imageIndex < gif->ImageCount; imageIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        SavedImage *image = &(gif->SavedImages[imageIndex]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        GifImageDesc *desc = &(image->ImageDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        ColorMapObject *colorMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            desc->ColorMap ? desc->ColorMap : gif->SColorMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        int transparentColor = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        int frameDelay = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        int disposeMethod = GIF_DISPOSE_RESTORE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        int colorCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        rgbquad_t colorMapBuf[SPLASH_COLOR_MAP_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
2603
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   144
        cx = FIX_POINT(desc->Left, 0, gif->SWidth);
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   145
        cy = FIX_POINT(desc->Top, 0, gif->SHeight);
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   146
        cw = FIX_LENGTH(desc->Left, desc->Width, gif->SWidth);
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   147
        ch = FIX_LENGTH(desc->Top, desc->Height, gif->SHeight);
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   148
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (colorMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            if (colorMap->ColorCount <= SPLASH_COLOR_MAP_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                colorCount = colorMap->ColorCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            } else  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                colorCount = SPLASH_COLOR_MAP_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        /* the code below is loosely based around gif extension processing from win32 libungif sample */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        for (i = 0; i < image->ExtensionBlockCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            byte_t *pExtension = (byte_t *) image->ExtensionBlocks[i].Bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            unsigned size = image->ExtensionBlocks[i].ByteCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            switch (image->ExtensionBlocks[i].Function) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            case GRAPHICS_EXT_FUNC_CODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    int flag = pExtension[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   168
                    frameDelay = (((int)pExtension[2]) << 8) | pExtension[1];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    if (frameDelay < 10)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                        frameDelay = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    if (flag & GIF_TRANSPARENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                        transparentColor = pExtension[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                        transparentColor = GIF_NOT_TRANSPARENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    disposeMethod =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                        (flag >> GIF_DISPOSE_SHIFT) & GIF_DISPOSE_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            case APPLICATION_EXT_FUNC_CODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    if (size == sizeof(szNetscape20ext)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                        && memcmp(pExtension, szNetscape20ext, size) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                        int iSubCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                        if (++i >= image->ExtensionBlockCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                        pExtension = (byte_t *) image->ExtensionBlocks[i].Bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                        if (image->ExtensionBlocks[i].ByteCount != 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                        iSubCode = pExtension[0] & 0x07;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        if (iSubCode == NSEXT_LOOP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                            splash->loopCount =
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   194
                                (pExtension[1] | (((int)pExtension[2]) << 8)) - 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (colorMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            for (i = 0; i < colorCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                colorMapBuf[i] = MAKE_QUAD_GIF(colorMap->Colors[i], 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            byte_t *pSrc = image->RasterBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            ImageFormat srcFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            ImageRect srcRect, dstRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            int pass, npass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            if (desc->Interlace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                pass = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                npass = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                pass = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                npass = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            srcFormat.colorMap = colorMapBuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            srcFormat.depthBytes = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            srcFormat.byteOrder = BYTE_ORDER_NATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            srcFormat.transparentColor = transparentColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            srcFormat.fixedBits = QUAD_ALPHA_MASK;      // fixed 100% alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            srcFormat.premultiplied = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            for (; pass < npass; ++pass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                int jump = interlacedJumps[pass];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                int ofs = interlacedOffset[pass];
2603
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   235
                /* Number of source lines for current pass */
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   236
                int numPassLines = (desc->Height + jump - ofs - 1) / jump;
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   237
                /* Number of lines that fits to dest buffer */
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   238
                int numLines = (ch + jump - ofs - 1) / jump;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                initRect(&srcRect, 0, 0, desc->Width, numLines, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    desc->Width, pSrc, &srcFormat);
2603
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   242
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   243
                if (numLines > 0) {
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   244
                    initRect(&dstRect, cx, cy + ofs, cw,
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   245
                             numLines , jump, stride, pBitmapBits, &splash->imageFormat);
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   246
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   247
                    pSrc += convertRect(&srcRect, &dstRect, CVT_ALPHATEST);
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   248
                }
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   249
                // skip extra source data
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   250
                pSrc += (numPassLines - numLines) * srcRect.stride;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        // now dispose of the previous frame correctly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        splash->frames[imageIndex].bitmapBits =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            (rgbquad_t *) malloc(bufferSize);
2603
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   258
        if (!splash->frames[imageIndex].bitmapBits) {
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   259
            free(pBitmapBits);
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   260
            free(pOldBitmapBits);
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   261
            /* Assuming that callee will take care of splash frames we have already allocated */
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   262
            return 0;
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   263
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        memcpy(splash->frames[imageIndex].bitmapBits, pBitmapBits, bufferSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        SplashInitFrameShape(splash, imageIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        splash->frames[imageIndex].delay = frameDelay * 10;     // 100ths of second to milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        switch (disposeMethod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        case GIF_DISPOSE_LEAVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            memcpy(pOldBitmapBits, pBitmapBits, bufferSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        case GIF_DISPOSE_NONE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        case GIF_DISPOSE_BACKGND:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                ImageRect dstRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                rgbquad_t fillColor = 0;                        // 0 is transparent
2603
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   279
6812
83cac1fcd3ed 6853488: REGRESSION : A black background is seen for a transparent animated gif image for splash screen
bae
parents: 5506
diff changeset
   280
                if (transparentColor < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    fillColor= MAKE_QUAD_GIF(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                        colorMap->Colors[gif->SBackGroundColor], 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                }
2603
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   284
                initRect(&dstRect,
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   285
                         cx, cy, cw, ch,
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   286
                         1, stride,
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   287
                         pBitmapBits, &splash->imageFormat);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                fillRect(fillColor, &dstRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        case GIF_DISPOSE_RESTORE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            {
2603
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   293
                int lineSize = cw * splash->imageFormat.depthBytes;
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   294
                if (lineSize > 0) {
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   295
                    int lineOffset = cx * splash->imageFormat.depthBytes;
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   296
                    int lineIndex = cy * stride + lineOffset;
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   297
                    for (j=0; j<ch; j++) {
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   298
                        memcpy(pBitmapBits + lineIndex, pOldBitmapBits + lineIndex,
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   299
                               lineSize);
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   300
                        lineIndex += stride;
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
   301
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    free(pBitmapBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    free(pOldBitmapBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    DGifCloseFile(gif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
SplashDecodeGifStream(Splash * splash, SplashStream * stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    GifFileType *gif = DGifOpen((void *) stream, SplashStreamGifInputFunc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    if (!gif)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    return SplashDecodeGif(splash, gif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
}