0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A/****************************************************************************** 0N/A * "Gif-Lib" - Yet another gif library. 0N/A * Written by: Gershon Elber IBM PC Ver 1.1, Aug. 1990 0N/A ****************************************************************************** 0N/A * The kernel of the GIF Decoding process can be found here. 0N/A ****************************************************************************** 0N/A * 16 Jun 89 - Version 1.0 by Gershon Elber. 0N/A * 3 Sep 90 - Version 1.1 by Gershon Elber (Support for Gif89, Unique names). 0N/A *****************************************************************************/ 0N/A#
endif /* __MSDOS__ */ 0N/A/* avoid extra function call in case we use fread (TVT) */ 0N/A/****************************************************************************** 0N/A * Open a new gif file for read, given by its name. 0N/A * Returns GifFileType pointer dynamically allocated which serves as the gif 0N/A * info record. _GifError is cleared if succesfull. 0N/A *****************************************************************************/ 0N/A#
endif /* __MSDOS__ || _OPEN_BINARY */ 0N/A/****************************************************************************** 0N/A * Update a new gif file, given its file handle. 0N/A * Returns GifFileType pointer dynamically allocated which serves as the gif 0N/A * info record. _GifError is cleared if succesfull. 0N/A *****************************************************************************/ 0N/A#
endif /* __MSDOS__ */ 0N/A#
endif /* __MSDOS__ */ 0N/A /* Lets see if this is a GIF file: */ 0N/A /* The GIF Version number is ignored at this time. Maybe we should do 0N/A * something more useful with it. */ 0N/A/****************************************************************************** 0N/A * GifFileType constructor with user supplied input function (TVT) 0N/A *****************************************************************************/ 0N/A /* Lets see if this is a GIF file: */ 0N/A /* The GIF Version number is ignored at this time. Maybe we should do 0N/A * something more useful with it. */ 0N/A/****************************************************************************** 0N/A * This routine should be called before any other DGif calls. Note that 0N/A * this routine is called automatically from DGif file open routines. 0N/A *****************************************************************************/ 0N/A /* This file was NOT open for reading: */ 0N/A /* Put the screen descriptor into the file: */ 0N/A if (
Buf[0] &
0x80) {
/* Do we have global color map? */ 0N/A /* Get the global color map: */ 0N/A/****************************************************************************** 0N/A * This routine should be called before any attempt to read an image. 0N/A *****************************************************************************/ 0N/A /* This file was NOT open for reading: */ 0N/A/****************************************************************************** 0N/A * This routine should be called before any attempt to read an image. 0N/A * Note it is assumed the Image desc. header (',') has been read. 0N/A *****************************************************************************/ 0N/A /* This file was NOT open for reading: */ 0N/A if (
Buf[0] &
0x80) {
/* Does this image have local color map? */ 0N/A /*** FIXME: Why do we check both of these in order to do this? 0N/A * Why do we have both Image and SavedImages? */ 0N/A /* Get the image local color map: */ 0N/A/****************************************************************************** 0N/A * Get one full scanned line (Line) of length LineLen from GIF file. 0N/A *****************************************************************************/ 0N/A /* This file was NOT open for reading: */ 0N/A#
endif /* __MSDOS__ */ 0N/A /* We probably would not be called any more, so lets clean 0N/A * everything before we return: need to flush out all rest of 0N/A * image until empty block (size 0) detected. We use GetCodeNext. */ 0N/A/****************************************************************************** 0N/A * Put one pixel (Pixel) into GIF file. 0N/A *****************************************************************************/ 0N/A /* This file was NOT open for reading: */ 0N/A#
endif /* __MSDOS__ */ 0N/A /* We probably would not be called any more, so lets clean 0N/A * everything before we return: need to flush out all rest of 0N/A * image until empty block (size 0) detected. We use GetCodeNext. */ 0N/A/****************************************************************************** 0N/A * Get an extension block (see GIF manual) from gif file. This routine only 0N/A * returns the first data block, and DGifGetExtensionNext should be called 0N/A * after this one until NULL extension is returned. 0N/A * The Extension should NOT be freed by the user (not dynamically allocated). 0N/A * Note it is assumed the Extension desc. header ('!') has been read. 0N/A *****************************************************************************/ 0N/A /* This file was NOT open for reading: */ 0N/A/****************************************************************************** 0N/A * Get a following extension block (see GIF manual) from gif file. This 0N/A * routine should be called until NULL Extension is returned. 0N/A * The Extension should NOT be freed by the user (not dynamically allocated). 0N/A *****************************************************************************/ 0N/A/****************************************************************************** 0N/A * This routine should be called last, to close the GIF file. 0N/A *****************************************************************************/ 0N/A /* This file was NOT open for reading: */ 0N/A/****************************************************************************** 0N/A * Get 2 bytes (word) from the given file: 0N/A *****************************************************************************/ 0N/A *
Word = (((
unsigned int)c[
1]) <<
8) + c[0];
0N/A/****************************************************************************** 0N/A * Get the image code in compressed form. This routine can be called if the 0N/A * information needed to be piped out as is. Obviously this is much faster 0N/A * than decoding and encoding again. This routine should be followed by calls 0N/A * to DGifGetCodeNext, until NULL block is returned. 0N/A * The block should NOT be freed by the user (not dynamically allocated). 0N/A *****************************************************************************/ 0N/A /* This file was NOT open for reading: */ 0N/A/****************************************************************************** 0N/A * Continue to get the image code in compressed form. This routine should be 0N/A * called until NULL block is returned. 0N/A * The block should NOT be freed by the user (not dynamically allocated). 0N/A *****************************************************************************/ 0N/A/****************************************************************************** 0N/A * Setup the LZ decompression for this image: 0N/A *****************************************************************************/ 1126N/A /* Invalid initial code size: report failure */ 0N/A/****************************************************************************** 0N/A * The LZ decompression routine: 0N/A * This version decompress the given gif file into Line of length LineLen. 0N/A * This routine can be called few times (one per scan line, for example), in 0N/A * order the complete the whole image. 0N/A *****************************************************************************/ 0N/A /* Let pop the stack off before continueing to read the gif file: */ 0N/A /* Note however that usually we will not be here as we will stop 0N/A * decoding as soon as we got all the pixel, or EOF code will 0N/A /* We need to start over again: */ 0N/A /* Its regular code - if in pixel range simply add it to output 0N/A * stream, otherwise trace to codes linked list until the prefix 0N/A * is in pixel range: */ 0N/A /* This is simple - its pixel scalar, so add it to output: */ 0N/A /* Its a code to needed to be traced: trace the linked list 0N/A * until the prefix is a pixel, while pushing the suffix 0N/A * pixels on our stack. If we done, pop the stack in reverse 0N/A * (thats what stack is good for!) order to output. */ 0N/A /* Only allowed if CrntCode is exactly the running code: 0N/A * In that case CrntCode = XXXCode, CrntCode or the 0N/A * prefix code is last code and the suffix char is 0N/A * exactly the prefix of last code! */ 0N/A /* Now (if image is O.K.) we should not get an NO_SUCH_CODE 0N/A * During the trace. As we might loop forever, in case of 0N/A * defective image, we count the number of loops we trace 0N/A * and stop if we got LZ_MAX_CODE. obviously we can not 0N/A * loop more than that. */ 0N/A /* Push the last character on stack: */ 0N/A /* Now lets pop all the stack into output: */ 0N/A /* Only allowed if CrntCode is exactly the running code: 0N/A * In that case CrntCode = XXXCode, CrntCode or the 0N/A * prefix code is last code and the suffix char is 0N/A * exactly the prefix of last code! */ 0N/A/****************************************************************************** 0N/A * Routine to trace the Prefixes linked list until we get a prefix which is 0N/A * not code, but a pixel value (less than ClearCode). Returns that pixel value. 0N/A * If image is defective, we might loop here forever, so we limit the loops to 0N/A * the maximum possible if image O.k. - LZ_MAX_CODE times. 0N/A *****************************************************************************/ 0N/A/****************************************************************************** 0N/A * Interface for accessing the LZ codes directly. Set Code to the real code 0N/A * (12bits), or to -1 if EOF code is returned. 0N/A *****************************************************************************/ 0N/A /* This file was NOT open for reading: */ 0N/A /* Skip rest of codes (hopefully only NULL terminating block): */ 0N/A /* We need to start over again: */ 0N/A/****************************************************************************** 0N/A * The LZ decompression input routine: 0N/A * This routine is responsable for the decompression of the bit stream from 0N/A * 8 bits (bytes) packets, into the real codes. 0N/A * Returns GIF_OK if read succesfully. 0N/A *****************************************************************************/ 0N/A 0x0000,
0x0001,
0x0003,
0x0007,
0N/A 0x000f,
0x001f,
0x003f,
0x007f,
0N/A 0x00ff,
0x01ff,
0x03ff,
0x07ff,
0N/A /* Needs to get more bytes from input stream for next code: */ 0N/A /* If code cannot fit into RunningBits bits, must raise its size. Note 0N/A * however that codes above 4095 are used for special signaling. */ 0N/A/****************************************************************************** 0N/A * This routines read one gif data block at a time and buffers it internally 0N/A * so that the decompression routine could access it. 0N/A * The routine returns the next byte from its internal buffer (or read next 0N/A * block in if buffer empty) and returns GIF_OK if succesful. 0N/A *****************************************************************************/ 0N/A /* Needs to read the next buffer - this one is empty: */ 0N/A Buf[
1] =
2;
/* We use now the second place as last char read! */ 0N/A/****************************************************************************** 0N/A * This routine reads an entire GIF into core, hanging all its state info off 0N/A * the GifFileType pointer. Call DGifOpenFileName() or DGifOpenFileHandle() 0N/A * first to initialize I/O. Its inverse is EGifSpew(). 0N/A ******************************************************************************/ 0N/A /* FIXME: The following is wrong. It is left in only for 0N/A * backwards compatibility. Someday it should go away. Use 0N/A * the sp->ExtensionBlocks->Function variable instead. */ 0N/A /* Create an extension block with our data */ 0N/A default:
/* Should be trapped by DGifGetRecordType */ 0N/A /* Just in case the Gif has an extension block without an associated 0N/A * image... (Should we save this into a savefile structure with no image 0N/A * instead? Have to check if the present writing code can handle that as