3681N/A * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved. 342N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 342N/A * This code is free software; you can redistribute it and/or modify it 342N/A * under the terms of the GNU General Public License version 2 only, as 342N/A * published by the Free Software Foundation. Oracle designates this 342N/A * particular file as subject to the "Classpath" exception as provided 342N/A * by Oracle in the LICENSE file that accompanied this code. 342N/A * This code is distributed in the hope that it will be useful, but WITHOUT 342N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 342N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 342N/A * version 2 for more details (a copy is included in the LICENSE file that 342N/A * accompanied this code). 342N/A * You should have received a copy of the GNU General Public License version 342N/A * 2 along with this work; if not, write to the Free Software Foundation, 1472N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 342N/A * or visit www.oracle.com if you need additional information or have any 2591N/A * Reads GIF images from an InputStream and reports the 2591N/A * image data to an InputStreamImageSource object. 1879N/A * The algorithm is copyright of CompuServe. 2591N/A * An error has occurred. Throw an exception. 2591N/A * Read a number of bytes into a buffer. 2591N/A * @return number of bytes that were not read due to EOF or error 2591N/A * produce an image from the stream. 2591N/A return;
//error("corrupt GIF file"); 3681N/A return;
//error("corrupt GIF file (GCE size)"); 3681N/A // Get the index of the transparent color 2591N/A return;
//error("corrupt GIF file"); 342N/A return;
//error("corrupt GIF file"); 2591N/A return;
// Unable to reset input buffer // no global colormap so make up our own // If there is a local colormap, it will override what we // have here. If there is not a local colormap, the rules // for GIF89 say that we can use whatever colormap we want. // This means that we should probably put in a full 256 colormap // at some point. REMIND! * The ImageConsumer hints flag for a non-interlaced GIF image. * The ImageConsumer hints flag for an interlaced GIF image. private short prefix[] =
new short[
4096];
private byte suffix[] =
new byte[
4096];
private byte outCode[] =
new byte[
4097];
private static native void initIDs();
/* ensure that the necessary native libraries are loaded */ // rasline[0] == pixel at coordinate (x,y) // rasline[width] == pixel at coordinate (x+width, y) width += x;
// same as (width -= rasbeg) x2 =
0;
// same as (x2 = x + rasbeg) // width -= 0; // same as (width -= rasbeg) x2 = x;
// same as (x2 = x + rasbeg) // rasline[rasbeg] == pixel at coordinate (x2,y) // rasline[width] == pixel at coordinate (x+width, y) // rasline[rasbeg + width] == pixel at coordinate (x2+width, y) // rasline[rasbeg] == pixel at coordinate (x2,y) // rasline[rasend] == pixel at coordinate (x2+width, y) // We have to do this the hard way - only transmit // the non-transparent sections of the line... // Fix for 6301050: the interlacing is ignored in this case // in order to avoid artefacts in case of animated images. byte block[] =
new byte[
256 +
3];
// Read the image descriptor * Majority of gif images have * same logical screen and frame dimensions. * Also, Photoshop and Mozilla seem to use the logical * screen dimension (from the global stream header) * if frame dimension is invalid. * We use similar heuristic and trying to recover * frame width from logical screen dimension and // We read one extra byte above so now when we must // transfer that byte as the first colormap byte // and manually read the code size when we are done // Now read the "real" code size byte which follows // Fix for 4233748: extend colormap to contain transparent pixel // Fix for 4233748: extend colormap to contain transparent pixel * If height of current image is smaller than the global height, * fill the gap with transparent pixels. // allocate the raster data (
interlace ?
"" :
"non-") +
"interlaced image...");
private static final boolean verbose =
false;
private void setPixels(
int x,
int y,
int w,
int h,
for (
int i =
0; i <
width; i++) {
// clear saved_image using transparent pixels // this will be used as the background in the next display