add oversampler
This commit is contained in:
36
oversampling/WDL/giflib/AUTHORS
Normal file
36
oversampling/WDL/giflib/AUTHORS
Normal file
@@ -0,0 +1,36 @@
|
||||
Lennie Araki
|
||||
Windows code providing a nicer interface and example program
|
||||
|
||||
Michael Brown <michael_brown_uk[AT]hotmail.com>
|
||||
callbacks to write data via user defined function
|
||||
|
||||
Daniel Eisenbud <eisenbud[AT]google.com>
|
||||
Fixes for crashes with invalid gif files and double freeing of
|
||||
colormaps
|
||||
|
||||
Gershon Elber
|
||||
original giflib code
|
||||
|
||||
Marc Ewing <marc[AT]redhat.com>
|
||||
spec file (for rpms) updates
|
||||
|
||||
Toshio Kuratomi <toshio[AT]tiki-lounge.com>
|
||||
uncompressed gif writing code
|
||||
autoconf/automake process
|
||||
current maintainer
|
||||
|
||||
marek <marwaw[AT]users.sourceforge.net>
|
||||
Gif initialization fix
|
||||
windows build code
|
||||
|
||||
Peter Mehlitz <peter[AT]transvirtual.com>
|
||||
callbacks to read data from arbitrary sources (like libjpeg/libpng)
|
||||
|
||||
Dick Porter <dick[AT]cymru.net>
|
||||
int/pointer fixes for Alpha
|
||||
|
||||
Eric Raymond <esr[AT]snark.thyrsus.com>
|
||||
long time maintainer of giflib code
|
||||
|
||||
Georg Schwarz <geos[AT]epost.de>
|
||||
IRIX fixes
|
||||
19
oversampling/WDL/giflib/COPYING
Normal file
19
oversampling/WDL/giflib/COPYING
Normal file
@@ -0,0 +1,19 @@
|
||||
The GIFLIB distribution is Copyright (c) 1997 Eric S. Raymond
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
549
oversampling/WDL/giflib/ChangeLog
Normal file
549
oversampling/WDL/giflib/ChangeLog
Normal file
@@ -0,0 +1,549 @@
|
||||
2005-10-09 Toshio Kuratomi <toshio@tiki-lounge.com> - r94
|
||||
* Sync with libungif r93.
|
||||
* ChangeLog: Update to r92.
|
||||
* NEWS: Update with combined libungif/giflib changes.
|
||||
|
||||
2005-10-09 Toshio Kuratomi <toshio@tiki-lounge.com> - r92
|
||||
* lib/gif_lib.h: Change GifPrefixType to unsigned.
|
||||
|
||||
2005-10-09 Toshio Kuratomi <toshio@tiki-lounge.com> - r91
|
||||
* ChangeLog: Update to r90.
|
||||
* NEWS: Update on GBA and Windows fixes.
|
||||
|
||||
2005-10-06 Toshio Kuratomi <toshio@tiki-lounge.com> - r90
|
||||
Changes from Lennie Araki:
|
||||
* gba/giftest.mak: Prefix the names of defines for the GBA build with _GBA.
|
||||
* lib/dgif_lib.c, lib/gif_lib_private.h, lib/gif_err.c:
|
||||
- When Compiling for Game Boy Advance, file functions are not needed so
|
||||
exclude DGifOpenFileName(), DGifOpenFileHandle(), DGifSlurp(), and
|
||||
PrintGifError().
|
||||
- On Game Boy Advance we need to reduce memory usage. Change values to
|
||||
short int where appropriate.
|
||||
* lib/gif_lib.h:
|
||||
- Handle te GBA changes by defining GifPrefixType and GifWord to int
|
||||
unless compiling on GBA. Then use unsigned short and short
|
||||
respectively.
|
||||
- Fix a problem with the API on _WIN32. DrawText conflicts with the
|
||||
Windows API. Call it DrawGifText instead.
|
||||
|
||||
2005-09-27 Toshio Kuratomi <toshio@tiki-lounge.com> - r86
|
||||
* Sync with libungif r85.
|
||||
|
||||
2005-09-27 Toshio Kuratomi <toshio@tiki-lounge.com> - r82
|
||||
* AUTHORS: Add Daniel Eisenbud. Obscure email addresses.
|
||||
* libungif.spec: Bump to version 4.1.4.
|
||||
* configure.ac: Bump to 4.1.4. No longer check for ranlib.
|
||||
* doc/lzgif.txt: Change dos line encoding to UNIX.
|
||||
* lib/dgif_lib.c: (eisenbud)
|
||||
- Set GifFile's ColorMaps to NULL when we free a colormap object.
|
||||
- Detect some cases of corrupted GIFs which were crashing the library.
|
||||
* lib/egif_lib.c: Set ColorMaps to NULL when we free a colormap object.
|
||||
* lib/gifalloc.c: Set ColorMaps to NULL when we free a colormap object.
|
||||
* lib/dev2gif.c: Fix redefinition problem on IRIX.
|
||||
* NEWS: Update to 4.1.4
|
||||
* util/gifcomb.c: Set a olorMap to NULL.
|
||||
|
||||
2004-07-11 Toshio Kuratomi <toshio@tiki-lounge.com> - r79
|
||||
* gif2iris.c: Fixes from Georg Schwarz <geos[AT]epost.de>.
|
||||
- stdlib.h is available and needs to be included on IRIX.
|
||||
- ColorMapSize was being set from non-existent variables.
|
||||
|
||||
2004-05-29 Toshio Kuratomi <toshio@tiki-lounge.com> - r76
|
||||
* Sync with libungif-4.1.3.
|
||||
|
||||
2004-05-29 Toshio Kuratomi <toshio@tiki-lounge.com> - r74
|
||||
* ChangeLog, prop=lastlog: Sync with the subversion logs.
|
||||
|
||||
2004-05-29 Toshio Kuratomi <toshio@tiki-lounge.com> - r73
|
||||
* test-unx: Add a test of extension code.
|
||||
* lib/egif_lib.c: Remove a debugging statement
|
||||
|
||||
2004-05-29 Toshio Kuratomi <toshio@tiki-lounge.com> - r72
|
||||
* Makefile.am, doc/Makefile.am, pic/Makefile.am: Change wildcarded entries
|
||||
into explicit filenames so make distcheck will succeed.
|
||||
|
||||
2004-05-29 Toshio Kuratomi <toshio@tiki-lounge.com> - r71
|
||||
* ChangeLog, prop=lastlog: Sync the ChangeLog for the release.
|
||||
|
||||
2004-05-29 Toshio Kuratomi <toshio@tiki-lounge.com> - r70
|
||||
* AUTHORS: Add Lennie Araki to the list of contributers.
|
||||
* windows: The windows subdirectory and all files under it are contributions
|
||||
from Lennie Araki to provide a nice interface on MS Windows.
|
||||
* README: Redundancy fix.
|
||||
* doc/gif_lib.html: Add EGifPutExtension{First,Next,Last} to the documentation
|
||||
so people know they should use it instead of EGifPutExtension.
|
||||
* Makefile.am: Mark the windows files to be distributed.
|
||||
* NEWS: Complete the NEWS item for 4.1.3.
|
||||
|
||||
2004-05-29 Toshio Kuratomi <toshio@tiki-lounge.com> - r69
|
||||
* libungif.spec: Some updates from the latest RedHat spec.
|
||||
* configure.ac: Bump version to 4.1.3.
|
||||
* lib/gifalloc.c: Add to my comments on ESR's note about Extension blocks.
|
||||
* lib/egif_lib.c:
|
||||
- EGifPutComment(): reimplemented using EGifPutExtensionFirst, Next, and
|
||||
Last so that it won't break on unusually long comments.
|
||||
- EGifPutExtension{First,Next,Last}: Changed fwrites to WRITE so any
|
||||
user defined write function will get called properly.
|
||||
- EGifPutExtensionLast: if the Extension block is empty (Zero length)
|
||||
then don't attempt to output a last extension block, just output the
|
||||
block terminator.
|
||||
- EGifPutExtension: Comment that this function does not work when there
|
||||
are multiple subblocks in an Extension block. Use the functions
|
||||
EGifPutExtension{First,Next,Last} instead.
|
||||
- EGifSpew: Reimplement to use EGifPutExtension{First,Next,Last} so we
|
||||
don't output broken GIFs when there are multiple sub-blocks on an
|
||||
extension.
|
||||
* lib/Makefile.am: Bump version to 4.1.3.
|
||||
* NEWS: Begin writing an entry for 4.1.3.
|
||||
* util/icon2gif.c: Few casting fixes to make gcc -Wall happy.
|
||||
* util/gif2ps.c: printf format string corrections.
|
||||
|
||||
2004-05-26 Toshio Kuratomi <toshio@tiki-lounge.com> - r67
|
||||
* Clean up some typos.
|
||||
|
||||
2004-05-25 Toshio Kuratomi <toshio@tiki-lounge.com> - r66
|
||||
* Sync with libungif-4.1.2.
|
||||
|
||||
2004-03-03 Toshio Kuratomi <toshio@tiki-lounge.com> - r64
|
||||
Last minute updates to the release notes in various files.
|
||||
|
||||
2004-03-03 Toshio Kuratomi <toshio@tiki-lounge.com> - r63
|
||||
* Set property lastlog to remind me when I last synced the ChangeLog
|
||||
|
||||
2004-03-03 Toshio Kuratomi <toshio@tiki-lounge.com> - r62
|
||||
* ChangeLog: Update
|
||||
|
||||
2004-03-03 Toshio Kuratomi <toshio@tiki-lounge.com> - r61
|
||||
* configure.ac: Bump version to 4.1.2
|
||||
|
||||
2004-02-22 Toshio Kuratomi <toshio@tiki-lounge.com> - r59
|
||||
* configure.ac, lib/Makefile.am: Bump version. Forgot to do this for 4.1.1...
|
||||
|
||||
2004-02-22 Toshio Kuratomi <toshio@tiki-lounge.com> - r58
|
||||
* TODO: Take out -Wall as that's all ready now.
|
||||
|
||||
2004-02-22 Toshio Kuratomi <toshio@tiki-lounge.com> - r57
|
||||
Merge changes to the code from branch indent-audit r55
|
||||
* README: MakeExtension deprecation note.
|
||||
* TODO: Bunch of things I need to fix or check that I saw while doing the
|
||||
indentation of the code.
|
||||
* lib/getarg.h: indent changes
|
||||
* lib/dgif_lib.c: indent changes
|
||||
- Move stdlib.h out of #ifdef's as it's included on all platforms.
|
||||
- Add checks to be sure malloc and MakeMapObject succeed.
|
||||
* lib/quantize.c: indent changes
|
||||
- Move stdlib.h out of #ifdef's as it's included on all platforms.
|
||||
- _GifError already pulled in through gif_lib_private.h. Remove decl.
|
||||
- Make Count in NewColorMapType be unsigned.
|
||||
- Separated mallocs from conditionals in a few places. Easier reading.
|
||||
* lib/gifalloc.c: indent changes
|
||||
- Added four FIXME's where I think the code might not be doing what we
|
||||
want. Need to do more research to figure out.
|
||||
- Add note to MakeExtension that I think it needs to be deprecated.
|
||||
- Separated mallocs from conditionals in a few places. Easier reading.
|
||||
- FreeLastSavedImage: New private function to free the last image in a
|
||||
GifFile structure. Used to back out when unable to completely
|
||||
allocate a new SavedImage structure.
|
||||
- check for NULL values before deallocating in Free* functions and make
|
||||
sure all Free* functions set the pointer to NULL after they deallocate
|
||||
the memory.
|
||||
* lib/egif_lib.c: indent changes
|
||||
- EGifPutScreenDesc: If we have no colormap, output a default value for
|
||||
its size instead of trying to reference its unallocated BitsPerPixel
|
||||
field. (Fixes bug noted in r46)
|
||||
* lib/gif_lib.h: indent changes
|
||||
- Condense the #else #if VARARGS to #elif VARARGS check.
|
||||
* lib/qprintf.c: indent changes
|
||||
- Condense the #else #if VARARGS to #elif VARARGS check.
|
||||
* lib/dev2gif.c: indent changes
|
||||
* lib/getarg.c: indent changes
|
||||
* lib/gif_lib_private.h: indent changes
|
||||
* lib/gif_font.c: indent changes
|
||||
* lib/gif_err.c: indent changes
|
||||
|
||||
2004-02-22 Toshio Kuratomi <toshio@tiki-lounge.com> - r56
|
||||
* lib/Makefile.am, util/Makefile.am: Add -Wall to the compilation flags so
|
||||
we can keep the code from acquiring too much bad style.
|
||||
|
||||
2004-02-20 Toshio Kuratomi <toshio@tiki-lounge.com> - r46
|
||||
* egif_lib.c: Note for a bug fix (Can wait until after indent because
|
||||
there's no patch.)
|
||||
* gif_lib.h, dev2gif.c: Change int type to explicit long type in
|
||||
DumpScreen2Gif.
|
||||
* util/gifinto.c: Give the fprintf back its %d format.
|
||||
GifFile->ImageCount is used as the Image number.
|
||||
|
||||
2004-02-20 Toshio Kuratomi <toshio@tiki-lounge.com> - r45
|
||||
* README: add varargs to the deprecation list
|
||||
|
||||
2004-02-20 Toshio Kuratomi <toshio@tiki-lounge.com> - r44
|
||||
* test-unx: Quote the program names.
|
||||
* lib/dgif_lib.c:
|
||||
- Make sure memory was allocated for the colormap
|
||||
- Some reformatting of code but no syntactic changes.
|
||||
* lib/gif_lib.h:
|
||||
- C++ extern "C" fix
|
||||
- Fix typo with EGifOpen
|
||||
* lib/qprintf.c, lib/getarg.c: Update the varargs code. Some users reported
|
||||
that not all systems can handle the hybridized varargs parameter lists
|
||||
we had. Need to use old-style declarations instead.
|
||||
|
||||
2004-02-20 Toshio Kuratomi <toshio@tiki-lounge.com> - r43
|
||||
* NEWS: Note bugfixes and deprecations
|
||||
* README: Deprecation list is now being compiled in this file.
|
||||
* TODO: Notes about interlace bug, -Wall status, merging of old bug status
|
||||
|
||||
2004-02-19 Toshio Kuratomi <toshio@tiki-lounge.com> - r42
|
||||
* Makefile.am: Disable testing for now because gif2x11 is broken so none
|
||||
of the tests _appear_ to complete successfully.
|
||||
|
||||
2004-02-19 Toshio Kuratomi <toshio@tiki-lounge.com> - r38
|
||||
Merge -Wall fixes from branches/Wall-audit r29
|
||||
* configure.ac:
|
||||
- Make the stdarg vs varargs check simpler by relying on
|
||||
AC_CHECK_HEADERS() magic.
|
||||
- Check for unistd.h
|
||||
* dgif_lib.c, gif_lib.h, egif_lib.c, gifalloc.c, quantize.c, dev2gif.c,
|
||||
getarg.c, gif_lib_private.h, gif_font.c gif_err.c, gifinto.c, icon2gif.c,
|
||||
raw2gif.c, gifcolor.c, gifasm.c, gif2epsn.c, gif2iris.c, gifrotat.c,
|
||||
gifovly.c, gif2x11.c, rle2gif.c, gif2rle.c, text2gif.c, gifspnge.c,
|
||||
gifclrmp.c, giffiltr.c, giftext.c, gifinfo.c, rgb2gif.c, gif2rgb.c, gif2ps.c
|
||||
- Changes to get rid of -Wall compile warnings.
|
||||
+ Casting of types
|
||||
+ New header includes for unistd.h and fcntl.h
|
||||
+ Explicit declaration of many types to unsigned
|
||||
+ Removed unused variables and functions
|
||||
+ Removed VersionStr from every library file. Instead include it via
|
||||
gif_lib_private.h
|
||||
* gif_lib.h, gif_lib_private.h: Moved the VersionStr into gif_lib_private.h
|
||||
and made it a #define instead of a static char *.
|
||||
|
||||
2004-02-19 Toshio Kuratomi <toshio@tiki-lounge.com> - r37
|
||||
Deprecation notes
|
||||
|
||||
2004-02-19 Toshio Kuratomi <toshio@tiki-lounge.com> - r36
|
||||
Add notes about security things to do and giflib syncing
|
||||
|
||||
2004-02-18 Toshio Kuratomi <toshio@tiki-lounge.com> - r32
|
||||
* TODO: Add notes about how to go about syncing Wall-audit and indent changes
|
||||
into giflib. It won't be pretty.
|
||||
* svn:ignore: Change the tarball names from libungif to giflib
|
||||
|
||||
2004-02-18 Toshio Kuratomi <toshio@tiki-lounge.com> - r31
|
||||
Add config.h include to gif_hash.c
|
||||
|
||||
2004-02-17 Toshio Kuratomi <toshio@tiki-lounge.com> - r30
|
||||
Sync up with libungif 4.1.1
|
||||
|
||||
2004-02-17 Toshio Kuratomi <toshio@tiki-lounge.com> - r26
|
||||
Updated ChangeLog
|
||||
|
||||
2004-02-17 Toshio Kuratomi <toshio@tiki-lounge.com>
|
||||
* Updated libungif.spec to look more like fedora core spec
|
||||
* Updated version numbers in all files
|
||||
|
||||
2004-02-17 Toshio Kuratomi <toshio@tiki-lounge.com>
|
||||
* Add the libungif*.tar.bz2 distribution tarball to the ignored files
|
||||
* configure.ac, lib/getarg.c, lib/getarg.h, lib/gif_lib.h, lib/qprintf.c:
|
||||
Prefer stdarg.h over vararg.h
|
||||
* TODO: Add information about functions that will go away in 5.0
|
||||
(In reality, I don't think new software uses libungif, so there may never
|
||||
be a 5.0 release.)
|
||||
* lib/gif_lib.h: Change version from 4.0 to 4.1
|
||||
* NEWS: add deprecation warning for the qprintf stuff: GifQuietPrint var and
|
||||
GifQprintf function.
|
||||
|
||||
2004-02-16 Toshio Kuratomi <toshio@tiki-lounge.com>
|
||||
* util/gif2iris.c, util/gif2rle.c, util/gifinfo.c: Fix problems with fprintf error statements in the utils
|
||||
|
||||
2004-02-16 Toshio Kuratomi <toshio@tiki-lounge.com>
|
||||
Add DEVELOPERS file to the distribution.
|
||||
|
||||
2004-02-16 Toshio Kuratomi <toshio@tiki-lounge.com>
|
||||
* AUTHORS, libungif.spec, libungif.lsm, README, BUGS, NEWS:
|
||||
Lots of changes to my email address and the website/download. (libungif is
|
||||
moving to sourceforge.)
|
||||
* TODO: Few notes on cleanups that need to happen. State what needs to be done
|
||||
for 4.1.1 to be released.
|
||||
|
||||
2004-02-15 Toshio Kuratomi <toshio@tiki-lounge.com>
|
||||
Changes imported from last cvs checkout
|
||||
* TODO: note to check return of malloc everywhere
|
||||
* lib/dgif_lib.c, lib/egif_lib.c: Fix some deallocation bugs
|
||||
* lib/gifalloc.c: Fix a colormap allocation problem
|
||||
* lib/gif_font.c: Fix to drawing text
|
||||
|
||||
2004-02-15 Toshio Kuratomi <toshio@tiki-lounge.com>
|
||||
Added libgetarg.a to the ignore list.
|
||||
|
||||
2004-02-15 Toshio Kuratomi <toshio@tiki-lounge.com>
|
||||
Changes to the build infrastructure to build under current libtool, automake,
|
||||
and libtool.
|
||||
* configure.in: renamed to configure.ac
|
||||
* acconfig.h: deleted. Functionality moved into the configure.ac
|
||||
* autogen.sh: now runs libtoolize --automake
|
||||
* lib/Makefile.am, util/Makefile.am: CFLAGS=>AM_CFLAGS; INCLUDES=>AM_CPPFLAGS
|
||||
* configure.ac:
|
||||
- initialization macros for automake and autoconf have changed
|
||||
- removed checks for C++ compiler and Awk
|
||||
- acconfig.h functionality moved here.
|
||||
- add other X11 libraries to the X11_LIB define
|
||||
|
||||
2004-02-15 Toshio Kuratomi <toshio@tiki-lounge.com>
|
||||
* Remove INSTALL file as it's autogenerated.\n* Add stamp-h1 to ignored files
|
||||
|
||||
2004-02-15 Toshio Kuratomi <toshio@tiki-lounge.com>
|
||||
Additional adds and deletes to make version 4.1.0b1
|
||||
|
||||
2004-02-15 Toshio Kuratomi <toshio@tiki-lounge.com>
|
||||
Import of version 4.1.0b1
|
||||
|
||||
2004-02-15 Toshio Kuratomi <toshio@tiki-lounge.com> - r10
|
||||
Import giflib 4.1.0
|
||||
|
||||
2004-02-15 Toshio Kuratomi <toshio@tiki-lounge.com> - r9
|
||||
Copy the 4.1.0 libungif release to be the base of the 4.1.0 giflib release.
|
||||
|
||||
2004-02-15 Toshio Kuratomi <toshio@tiki-lounge.com> - r7
|
||||
Release 4.1.0
|
||||
|
||||
2004-02-15 Toshio Kuratomi <toshio@tiki-lounge.com> - r6
|
||||
Import of version 4.1.0
|
||||
|
||||
2004-02-15 Toshio Kuratomi <toshio@tiki-lounge.com> - r5
|
||||
Set ignore patterns on the project directories.
|
||||
|
||||
2004-02-15 Toshio Kuratomi <toshio@tiki-lounge.com> - r3
|
||||
Remove a Makefile.in that was left in in the first commit.
|
||||
|
||||
2004-02-14 Toshio Kuratomi <toshio@tiki-lounge.com> - r2
|
||||
Commit revision 3.1.0 to subversion
|
||||
|
||||
2004-02-14 Toshio Kuratomi <toshio@tiki-lounge.com> - r1
|
||||
Initial SVN Repository Layout
|
||||
|
||||
2000 6 Feb Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* configure.in: Change to using config.h
|
||||
- Every .c file: Change to using config.h.
|
||||
* configure.in: added check for varargs header.
|
||||
* lib/getarg.c: Changed the ifdef USE_VARARGS to ifdef HAVE_VARARGS_H.
|
||||
- lib/getarg.h: Ditto.
|
||||
- lib/gif_lib.h: Ditto.
|
||||
- lib/qprintf.h: Ditto.
|
||||
|
||||
2000 6 Feb Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* lib/getarg.h: Prepend an underscore to the header file define.
|
||||
* lib/gif_lib.h: Ditto
|
||||
* lib/gif_lib_private.h: Ditto
|
||||
* lib/getarg.c: ifdef'd MyMalloc so it actually won't define if it already
|
||||
is.
|
||||
|
||||
2000 3 Feb Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* A new cvs repository based my private tree from home. It now goes back
|
||||
to giflib-3.0.
|
||||
* Updated the cvs repository to make multiple developers possible.
|
||||
* Merge all of Michael's patches into the distribution.
|
||||
* DEVELOPER: Updated to reflect the new versions of
|
||||
autoconf/automake/libtool we're using.
|
||||
* libungif.spec: Updated a few things from the latest redhat spec file.
|
||||
|
||||
1999 5 Dec Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* Update links to the web pages as I have reorganized them somewhat.
|
||||
* Add the welcome2.gif to the pic directory and a test that utilizes
|
||||
it to test-unx.
|
||||
|
||||
1999 17 Nov Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* New cvs Repository. Hopefully I've got everything that was in the
|
||||
old one. This one is available on anonymous cvs.
|
||||
* Update to libtool 1.3.3, automake 1.4, and autoconf 2.13
|
||||
|
||||
1999 23 May Michael R Brown <michael@arrakeen.demon.co.uk>
|
||||
* Lots of 'const' qualifiers added, thanks Alexis
|
||||
Wilke for finding these.
|
||||
|
||||
1999 22 Mar Michael R Brown <michael@arrakeen.demon.co.uk>
|
||||
* util/gif2x11.c: Patch by (who?) to fix lots of memory leeks.
|
||||
* util/*.c:
|
||||
lib/dgif_lib.c:
|
||||
Makefile.in:
|
||||
Patch by David Kaelbling to compile on IRIX 6.x. Basically fixing
|
||||
lots of bad/missing parameter passing to printf, scanf and similar.
|
||||
* Added pics/welcome2.gif, from Peter Merz which provokes a bug prior
|
||||
to patch 19990224 to do with colour map management. There is still
|
||||
a problem with util/gifspnge processing this image, so it will not
|
||||
be added to test-unx yet.
|
||||
|
||||
1999 05 Mar Michael R Brown <michael@arrakeen.demon.co.uk>
|
||||
* lib/getarg.c: Lines 107 and 189
|
||||
Added ifdef's to use stdarg when available. On dec-alpha the
|
||||
default code was causing programs to crash, probably because
|
||||
it assumes a stack that grows-up.
|
||||
|
||||
1999 24 Feb Michael R Brown <michael@arrakeen.demon.co.uk>
|
||||
* lib/dgif_lib.c: Lines 363 and 367
|
||||
Bug reported by Steve Sanders, where &'s where causing the
|
||||
memcpy to overwrite the pointers. Fixed by removing the &'s
|
||||
so that memcpy overwrote the memory pointed to.
|
||||
|
||||
1999 09 Feb Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* Release 4.1.0
|
||||
|
||||
1999 09 Feb Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* Merge libungif changes into the giflib tree:
|
||||
- upgrade to libtool 1.2b
|
||||
- util/Makefile.am: Minor change to allow compilation outside the
|
||||
source_dir.
|
||||
- lib/egif_lib.c: FILE_STATE_WRITE, FILE_STATE_SCREEN,
|
||||
FILE_STATE_IMAGE, IS_WRITEABLE are now in gif_lib_private.h
|
||||
- lib/dgif_lib.c: FILE_STATE_READ and IS_READABLE are now in
|
||||
gif_lib_private.h
|
||||
- lib/gif_lib_private.h: Above mentioned constants and macros are now
|
||||
here. FILE_STATE_READ is now 0x08 instead of 0x00.
|
||||
- configure.in: Update version to 4.1.0
|
||||
- lib/Makefile.am: Update libtool version to 5:0:1 (libtool)
|
||||
- giflib.spec: Update for version 4.1.0 (Add libungif-4.1
|
||||
compatibility stuff and change version.)
|
||||
- giflib.lsm: Update for version 4.1.0
|
||||
- lib/egif_lib.c: (WRITE) change from a function to a macro.
|
||||
- lib/dgif_lib.c: (DGifOpenFileName) close FileHandle on error.
|
||||
- lib/dgif_lib.c: (DGifOpenFileHandle) make sure the FILE stream is
|
||||
closed if we hit an error.
|
||||
- lib/dev2gif.c, lib/quantize.c, lib/gif_err.c, lib/gif_lib_private.h:
|
||||
Reflect Eric's copyright notice rather than Gershon's
|
||||
|
||||
1999 14 Jan Michael R Brown <michael@arrakeen.demon.co.uk>
|
||||
* lib/gif_lib.h: Add OutputFunc type
|
||||
* lib/gif_lib.h: Add EGifOpen for user supplied output function
|
||||
* lib/egif_lib.c: (EGifOpenFileName) Fixed wasted memory when an
|
||||
error occurs in EGifOpenFileHandle
|
||||
* lib/egif_lib.c: Add EGifOpen, WRITE, and lots of changes to
|
||||
support user supplied output function. Basically changing
|
||||
all fwrite's to WRITE, and then all of the knock on effects.
|
||||
|
||||
1998 17 Dec Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* configure.in: Change references to libungif to giflib.
|
||||
* libungif.lsm: Rename to giflib.lsm and change to reflect giflib
|
||||
rather than libungif.
|
||||
* libungif.spec: Rename to giflib.spec and change to reflect giflib
|
||||
rather than libungif.
|
||||
* UNCOMPRESSED_GIF: Removed from this branch.
|
||||
* PATENT_PROBLEMS: Add file explaining Unisys's patent claims.
|
||||
* Makefile.am: Replace libungif with giflib.
|
||||
* README: Adapted language to giflib.
|
||||
* lib/Makefile.am: Changed references to libungif to libgif.
|
||||
* util/Makefile.am: Changed references to libungif to libgif.
|
||||
|
||||
1998 17 Dec Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* lib/egif_lib.c: Merge LZW stuff into this branch of the library.
|
||||
This includes numerous changes to initialize the hash table as well
|
||||
as the code forthe encoder.
|
||||
* lib/gif_hash.c: Functions needed for the LZW encoder.
|
||||
* lib/gif_hash.h: Functions needed for the LZW encoder.
|
||||
* lib/Makefile.am: Add gif_hash.c gif_hash.h to the list of sources.
|
||||
|
||||
1998 15 Dec Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* lib/dgif_lib.c: (DGifSlurp) Fix a Seg Fault when an image contains
|
||||
no extension blocks.
|
||||
|
||||
1998 14 Dec Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* configure.in: Update version to 4.0
|
||||
* lib/Makefile.am: Update libtool version to 4:0:0 (libtool)
|
||||
* libungif.spec: Update for version 4.0 (not binary compatible with
|
||||
giflib, change version.)
|
||||
* lib/gif_lib_private.h: (PrivateType) New header for common stuff
|
||||
private to the library. Currently, this is only the Private struct.
|
||||
* lib/dgif_lib.c: (PrivateType) Extract the Private struct to
|
||||
gif_lib_private.h
|
||||
* lib/egif_lib.c: (PrivateType) Extract the Private struct to
|
||||
gif_lib_private.h
|
||||
* lib/Makefile.am: Add gif_lib_private.h to the list of source files.
|
||||
* lib/gif_lib.h: (ExtensionBlock) Add a Function entry to the
|
||||
ExtensionBlock record. Note that this is not entirely correct:
|
||||
the GifLib ExtensionBlock structure is actually a data sub-block
|
||||
record. By adding the function entry here, we are pushing the
|
||||
ExtensionBlockType in with the DataSubBlock.
|
||||
Sometime in the future, we need to change the API to have true
|
||||
ExtensionBlocks which have DataSubBlocks belonging to them.
|
||||
* lib/gif_lib.h: (ExtensionBlock) Deprecate the use of Function in
|
||||
the SavedImage struct. Use ExtensionBlock's Function instead.
|
||||
* lib/egif_lib.c: (EGifSpew) Changes to use the new Function variable.
|
||||
* lib/dgif_lib.c: (DGifSlurp) Changes to put data into the new
|
||||
Function variable.
|
||||
|
||||
1998 3 Dec Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* lib/dgif_lib.c: (DGifSlurp) Three changes:
|
||||
- No longer allocate SaveImage in this function. All allocations
|
||||
of SaveImage take place in DGifGetImageDesc.
|
||||
- Extension blocks are now associated with the Image Block that is
|
||||
read in subsequent to them, not before. This should now be
|
||||
conformant to the gif89a specification.
|
||||
- Fix an off-by-one error when copying extension data from structure
|
||||
to structure.
|
||||
* lib/dgif_lib.c: (DGifGetImageDesc) Change the function to do its own
|
||||
allocation of space for the SavedImage structure no matter what.
|
||||
* lib/egif_lib.c: (EGifSpew) The function now spits out
|
||||
ExtensionBlocks before the associated Image Block to conform with
|
||||
the gif89a specification.
|
||||
* lib/egif_lib.c: (EGifOpenFileHandle) Move the write of the
|
||||
GifVersion (gif87a or gif89a) from this function into
|
||||
EGifPutScreenDesc so that it can be controlled by EGifSpew. Note
|
||||
that this is still a hack as the GifVersion write doesn't really
|
||||
belong in either of these functions.
|
||||
* lib/egif_lib.c: (EGifPutScreenDesc) Moved writing the version
|
||||
(gif87a or gif89a) into the file into this function from
|
||||
EGifOpenFileHandle.
|
||||
* test-unx: Now test the extension code.
|
||||
* pic/x-trans.gif: New image with Comments and transparency to test
|
||||
the extension code with.
|
||||
|
||||
1998 29 Nov Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* lib/dgif_lib.c: (DGifSlurp) Fix a few of the minor bugs plaguing
|
||||
this function. At this point, the function should no longer cause
|
||||
a Seg Fault. It is now losing all extension data however. I know
|
||||
how to hack a fix in, but I need to commit these changes first.
|
||||
* lib/dgif_lib.c: (DGifGetImageDesc) Fix my bug fix: the colormap is
|
||||
now only copied if it exists :-).
|
||||
|
||||
1998 10 Nov Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* test-unx: Add a test for DGifSlurp and EGifSpew
|
||||
|
||||
1998 14 Oct Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* lib/dgif_lib.c: (DGifGetImageDesc) Fix a bug where the Colormap for
|
||||
the image description and the SaveImage were pointers to the same
|
||||
structure, causing a SegV when DGifClosing the file.
|
||||
|
||||
1998 9 Oct Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* lib/dgif_lib.c: (DGifSlurp) memory for the extensions was not being
|
||||
allocated. Now I call AddExtensionBlock when I add an extension to
|
||||
the structure. Additionally, fix a memory leak here.
|
||||
* configure.in, NEWS, lib/Makefile.am: Update to version 3.1.1
|
||||
* ltmain.sh, ltconfig: removed from the cvs repository
|
||||
* BUGS: add the BUGS file to list unresolved BUGS.
|
||||
|
||||
1998 9 Sep Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* libungif.spec: Fix wrong version in %files and %install section.
|
||||
|
||||
1998 8 Sep Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* lib/gif_hash.c, lib/gif_hash.h: Removed these because a hash table
|
||||
is not needed to create uncompressed gifs.
|
||||
* lib/egif_lib.c: Remove all references to the hash functions.
|
||||
* lib/Makefile.am: Remove gif_hash.c gif_hash.h from the source files.
|
||||
* libungif.lsm: added this file
|
||||
|
||||
1998 7 Sep Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* lib/dgif_lib.c, lib/gif_lib.h: (DGifOpen) Add callback to read gif
|
||||
image through user supplied function (Peter Mehlitz).
|
||||
|
||||
1998 6 Sep Toshio Kuratomi <badger@prtr-13.ucsc.edu>
|
||||
* util/*.{gif.rle}: removed files that were left by my testing
|
||||
process and shouldn't have been in the distribution.
|
||||
* UNCOMPRESSED_GIF: add section on why software that can decode
|
||||
LZW compressed gifs (but not write them) is legal.
|
||||
* .cvsignore: added .cvsignore files to ignore Makefiles and other
|
||||
generated files in my cvs repository.
|
||||
* Makefile.am's: Fixes to allow the dist* family of targets to work
|
||||
correctly. Preliminary support for make check as well.
|
||||
* configure.in: Update version to 3.1.0
|
||||
* lib/Makefile.am: Update libtool version to 4:0:1 libtool)
|
||||
* libungif-3.0.spec: Update from Marc Ewing.
|
||||
* Add int/pointer Alpha fixes from Dick Porter to many source files.
|
||||
29
oversampling/WDL/giflib/DEVELOPERS
Normal file
29
oversampling/WDL/giflib/DEVELOPERS
Normal file
@@ -0,0 +1,29 @@
|
||||
Things to tell developers of libungif....
|
||||
|
||||
=======
|
||||
Build Tools:
|
||||
libungif presently uses autoconf, automake, and libtool in order to build
|
||||
shared libraries for a wide variety of platforms. The distributed tarball has
|
||||
files prebuilt from these tools. The cvs repository does not. If you want to
|
||||
build libungif you will need to have these tools available. I currently run
|
||||
with the following versions:
|
||||
autoconf 2.57
|
||||
automake 1.7.8
|
||||
libtool 1.5
|
||||
|
||||
(P.S. I use the autogen.sh script in the top level directory to generate
|
||||
configure, Makefile.in, etc using these tools.)
|
||||
|
||||
=======
|
||||
cvs:
|
||||
I currently do my work in a subversion repository. Since sourceforge is still
|
||||
using cvs and not subversion, there's nothing in the sourceforge tree.
|
||||
|
||||
If someone else wants to do development we can definitely talk about the best
|
||||
way to share version control access.
|
||||
|
||||
=======
|
||||
I create the distribution tar ball by using the `make dist` command.... After
|
||||
hacking all I want, I check my sources into cvs, checkout a clean tree, run
|
||||
./autogen.sh; make dist and then attempt to compile from the libungif-*.tar.gz
|
||||
file that is generated.
|
||||
69
oversampling/WDL/giflib/README
Normal file
69
oversampling/WDL/giflib/README
Normal file
@@ -0,0 +1,69 @@
|
||||
This is giflib version 4.1.2, a library for manipulating gif files. It is based
|
||||
on Eric S. Raymond's giflib-3.0 with bugfixes and changes generated for the
|
||||
libungif library.
|
||||
|
||||
PLEASE BE AWARE OF POSSIBLE LEGAL PROBLEMS WITH USING THIS LIBRARY: READ
|
||||
THE PATENT_PROBLEMS FILE NOW!
|
||||
|
||||
=======
|
||||
Latest versions of giflib, as well as a library which does not have the
|
||||
mentioned patent problems (libungif), are available from:
|
||||
http://sourceforge.net/projects/libungif
|
||||
|
||||
====
|
||||
Building this package should be as simple as:
|
||||
|
||||
./configure
|
||||
gmake
|
||||
gmake install
|
||||
|
||||
====
|
||||
Deprecation list. Will be removed in giflib 5.0:
|
||||
* GIF_ERROR and GIF_MESSAGE are on the deprecation list as they are also
|
||||
utility helper functions rather than essential to the functioning of the
|
||||
library.
|
||||
* The qprintf methods of the library are now deprecated. Do not use
|
||||
GifQuietPrint or GifQprintf. These should have been pushed out into the
|
||||
utility helper library instead of sitting around in the library proper at
|
||||
the same time as the getarg functions were moved out. Getting rid of these
|
||||
will let us get rid of our dependence on stdarg.h/varargs.h (Which a Gif
|
||||
reading library has no business requiring.)
|
||||
* In the SavedImage struct: int Function will be removed. Use
|
||||
SavedImage.ExtensionBlocks[x].Function instead.
|
||||
* In gifalloc.c: MakeExtension is deprecated as well. Use AddExtensionBlock
|
||||
instead. (This and the previous int Function were deprecated because they
|
||||
only handle one Extension per image. The new code handles multiple
|
||||
extensions.)
|
||||
* varargs style interface in qprintf and getarg: It's a mistake to have two
|
||||
different interfaces that depend on compile time choices between varargs
|
||||
and stdargs. The future is to get rid of varargs style altogether.
|
||||
(Also: these are probably going strictly into the utility functions so
|
||||
the library won't have to worry about them at all.)
|
||||
====
|
||||
|
||||
I have found that automake currently generates Makefile's containing some
|
||||
GNUmake specific syntax. If you're having troubles building with your
|
||||
system provided make, please install GNU make and try rebuilding.
|
||||
|
||||
====
|
||||
This package uses autoconf, automake, and libtool to create the configure
|
||||
script, so if you need to edit the configure.ac or change a makefile target
|
||||
you should read the DEVELOPER file for hints on recreating the distribution
|
||||
using these tools.
|
||||
|
||||
Good luck!
|
||||
-Toshio Kuratomi <toshio@tiki-lounge.com>
|
||||
|
||||
==== READ.ME file for giflib version 3.0:
|
||||
|
||||
READ ME for GIFLIB
|
||||
|
||||
For complete documentation on the package, point a web browser at
|
||||
doc/index.html. See the file INSTALL for instructions on how to
|
||||
install and test the package.
|
||||
|
||||
GIFLIB has a home page at http://www.ccil.org/~esr/giflib.
|
||||
|
||||
Eric S. Raymond
|
||||
esr@snark.thyrsus.com.
|
||||
(http://www.ccil.org/~esr)
|
||||
14
oversampling/WDL/giflib/config.h
Normal file
14
oversampling/WDL/giflib/config.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef _CONFIG_H_
|
||||
#define _CONFIG_H_
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#define _OPEN_BINARY
|
||||
#else
|
||||
typedef unsigned int UINT32;
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
962
oversampling/WDL/giflib/dgif_lib.c
Normal file
962
oversampling/WDL/giflib/dgif_lib.c
Normal file
@@ -0,0 +1,962 @@
|
||||
/******************************************************************************
|
||||
* "Gif-Lib" - Yet another gif library.
|
||||
*
|
||||
* Written by: Gershon Elber IBM PC Ver 1.1, Aug. 1990
|
||||
******************************************************************************
|
||||
* The kernel of the GIF Decoding process can be found here.
|
||||
******************************************************************************
|
||||
* History:
|
||||
* 16 Jun 89 - Version 1.0 by Gershon Elber.
|
||||
* 3 Sep 90 - Version 1.1 by Gershon Elber (Support for Gif89, Unique names).
|
||||
*****************************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#if defined (__MSDOS__) && !defined(__DJGPP__) && !defined(__GNUC__)
|
||||
#include <io.h>
|
||||
#include <alloc.h>
|
||||
#include <sys\stat.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#endif /* __MSDOS__ */
|
||||
|
||||
#ifdef HAVE_IO_H
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif /* HAVE_FCNTL_H */
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "gif_lib.h"
|
||||
#include "gif_lib_private.h"
|
||||
|
||||
#define COMMENT_EXT_FUNC_CODE 0xfe /* Extension function code for
|
||||
comment. */
|
||||
|
||||
/* avoid extra function call in case we use fread (TVT) */
|
||||
#define READ(_gif,_buf,_len) \
|
||||
(((GifFilePrivateType*)_gif->Private)->Read ? \
|
||||
((GifFilePrivateType*)_gif->Private)->Read(_gif,_buf,_len) : \
|
||||
fread(_buf,1,_len,((GifFilePrivateType*)_gif->Private)->File))
|
||||
|
||||
static int DGifGetWord(GifFileType *GifFile, GifWord *Word);
|
||||
static int DGifSetupDecompress(GifFileType *GifFile);
|
||||
static int DGifDecompressLine(GifFileType *GifFile, GifPixelType *Line,
|
||||
int LineLen);
|
||||
static int DGifGetPrefixChar(GifPrefixType *Prefix, int Code, int ClearCode);
|
||||
static int DGifDecompressInput(GifFileType *GifFile, int *Code);
|
||||
static int DGifBufferedInput(GifFileType *GifFile, GifByteType *Buf,
|
||||
GifByteType *NextByte);
|
||||
#ifndef _GBA_NO_FILEIO
|
||||
|
||||
/******************************************************************************
|
||||
* Open a new gif file for read, given by its name.
|
||||
* Returns GifFileType pointer dynamically allocated which serves as the gif
|
||||
* info record. _GifError is cleared if succesfull.
|
||||
*****************************************************************************/
|
||||
GifFileType *
|
||||
DGifOpenFileName(const char *FileName) {
|
||||
int FileHandle;
|
||||
GifFileType *GifFile;
|
||||
|
||||
if ((FileHandle = open(FileName, O_RDONLY
|
||||
#if defined(__MSDOS__) || defined(_OPEN_BINARY)
|
||||
| O_BINARY
|
||||
#endif /* __MSDOS__ || _OPEN_BINARY */
|
||||
)) == -1) {
|
||||
_GifError = D_GIF_ERR_OPEN_FAILED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GifFile = DGifOpenFileHandle(FileHandle);
|
||||
if (GifFile == (GifFileType *)NULL)
|
||||
close(FileHandle);
|
||||
return GifFile;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Update a new gif file, given its file handle.
|
||||
* Returns GifFileType pointer dynamically allocated which serves as the gif
|
||||
* info record. _GifError is cleared if succesfull.
|
||||
*****************************************************************************/
|
||||
GifFileType *
|
||||
DGifOpenFileHandle(int FileHandle) {
|
||||
|
||||
unsigned char Buf[GIF_STAMP_LEN + 1];
|
||||
GifFileType *GifFile;
|
||||
GifFilePrivateType *Private;
|
||||
FILE *f;
|
||||
|
||||
GifFile = (GifFileType *)malloc(sizeof(GifFileType));
|
||||
if (GifFile == NULL) {
|
||||
_GifError = D_GIF_ERR_NOT_ENOUGH_MEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(GifFile, '\0', sizeof(GifFileType));
|
||||
|
||||
Private = (GifFilePrivateType *)malloc(sizeof(GifFilePrivateType));
|
||||
if (Private == NULL) {
|
||||
_GifError = D_GIF_ERR_NOT_ENOUGH_MEM;
|
||||
free((char *)GifFile);
|
||||
return NULL;
|
||||
}
|
||||
#ifdef __MSDOS__
|
||||
setmode(FileHandle, O_BINARY); /* Make sure it is in binary mode. */
|
||||
#endif /* __MSDOS__ */
|
||||
|
||||
f = fdopen(FileHandle, "rb"); /* Make it into a stream: */
|
||||
|
||||
#ifdef __MSDOS__
|
||||
setvbuf(f, NULL, _IOFBF, GIF_FILE_BUFFER_SIZE); /* And inc. stream
|
||||
buffer. */
|
||||
#endif /* __MSDOS__ */
|
||||
|
||||
GifFile->Private = (VoidPtr)Private;
|
||||
Private->FileHandle = FileHandle;
|
||||
Private->File = f;
|
||||
Private->FileState = FILE_STATE_READ;
|
||||
Private->Read = 0; /* don't use alternate input method (TVT) */
|
||||
GifFile->UserData = 0; /* TVT */
|
||||
|
||||
/* Lets see if this is a GIF file: */
|
||||
if (READ(GifFile, Buf, GIF_STAMP_LEN) != GIF_STAMP_LEN) {
|
||||
_GifError = D_GIF_ERR_READ_FAILED;
|
||||
fclose(f);
|
||||
free((char *)Private);
|
||||
free((char *)GifFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* The GIF Version number is ignored at this time. Maybe we should do
|
||||
* something more useful with it. */
|
||||
Buf[GIF_STAMP_LEN] = 0;
|
||||
if (strncmp(GIF_STAMP, (char*)Buf, GIF_VERSION_POS) != 0) {
|
||||
_GifError = D_GIF_ERR_NOT_GIF_FILE;
|
||||
fclose(f);
|
||||
free((char *)Private);
|
||||
free((char *)GifFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (DGifGetScreenDesc(GifFile) == GIF_ERROR) {
|
||||
fclose(f);
|
||||
free((char *)Private);
|
||||
free((char *)GifFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
_GifError = 0;
|
||||
|
||||
return GifFile;
|
||||
}
|
||||
|
||||
#endif /* _GBA_NO_FILEIO */
|
||||
|
||||
/******************************************************************************
|
||||
* GifFileType constructor with user supplied input function (TVT)
|
||||
*****************************************************************************/
|
||||
GifFileType *
|
||||
DGifOpen(void *userData,
|
||||
InputFunc readFunc) {
|
||||
|
||||
unsigned char Buf[GIF_STAMP_LEN + 1];
|
||||
GifFileType *GifFile;
|
||||
GifFilePrivateType *Private;
|
||||
|
||||
GifFile = (GifFileType *)malloc(sizeof(GifFileType));
|
||||
if (GifFile == NULL) {
|
||||
_GifError = D_GIF_ERR_NOT_ENOUGH_MEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(GifFile, '\0', sizeof(GifFileType));
|
||||
|
||||
Private = (GifFilePrivateType *)malloc(sizeof(GifFilePrivateType));
|
||||
if (!Private) {
|
||||
_GifError = D_GIF_ERR_NOT_ENOUGH_MEM;
|
||||
free((char *)GifFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GifFile->Private = (VoidPtr)Private;
|
||||
Private->FileHandle = 0;
|
||||
Private->File = 0;
|
||||
Private->FileState = FILE_STATE_READ;
|
||||
|
||||
Private->Read = readFunc; /* TVT */
|
||||
GifFile->UserData = userData; /* TVT */
|
||||
|
||||
/* Lets see if this is a GIF file: */
|
||||
if (READ(GifFile, Buf, GIF_STAMP_LEN) != GIF_STAMP_LEN) {
|
||||
_GifError = D_GIF_ERR_READ_FAILED;
|
||||
free((char *)Private);
|
||||
free((char *)GifFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* The GIF Version number is ignored at this time. Maybe we should do
|
||||
* something more useful with it. */
|
||||
Buf[GIF_STAMP_LEN] = 0;
|
||||
if (strncmp(GIF_STAMP, (char*)Buf, GIF_VERSION_POS) != 0) {
|
||||
_GifError = D_GIF_ERR_NOT_GIF_FILE;
|
||||
free((char *)Private);
|
||||
free((char *)GifFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (DGifGetScreenDesc(GifFile) == GIF_ERROR) {
|
||||
free((char *)Private);
|
||||
free((char *)GifFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
_GifError = 0;
|
||||
|
||||
return GifFile;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* This routine should be called before any other DGif calls. Note that
|
||||
* this routine is called automatically from DGif file open routines.
|
||||
*****************************************************************************/
|
||||
int
|
||||
DGifGetScreenDesc(GifFileType * GifFile) {
|
||||
|
||||
int i, BitsPerPixel;
|
||||
GifByteType Buf[3];
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
if (!IS_READABLE(Private)) {
|
||||
/* This file was NOT open for reading: */
|
||||
_GifError = D_GIF_ERR_NOT_READABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
/* Put the screen descriptor into the file: */
|
||||
if (DGifGetWord(GifFile, &GifFile->SWidth) == GIF_ERROR ||
|
||||
DGifGetWord(GifFile, &GifFile->SHeight) == GIF_ERROR)
|
||||
return GIF_ERROR;
|
||||
|
||||
if (READ(GifFile, Buf, 3) != 3) {
|
||||
_GifError = D_GIF_ERR_READ_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
GifFile->SColorResolution = (((Buf[0] & 0x70) + 1) >> 4) + 1;
|
||||
BitsPerPixel = (Buf[0] & 0x07) + 1;
|
||||
GifFile->SBackGroundColor = Buf[1];
|
||||
if (Buf[0] & 0x80) { /* Do we have global color map? */
|
||||
|
||||
GifFile->SColorMap = MakeMapObject(1 << BitsPerPixel, NULL);
|
||||
if (GifFile->SColorMap == NULL) {
|
||||
_GifError = D_GIF_ERR_NOT_ENOUGH_MEM;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
/* Get the global color map: */
|
||||
for (i = 0; i < GifFile->SColorMap->ColorCount; i++) {
|
||||
if (READ(GifFile, Buf, 3) != 3) {
|
||||
FreeMapObject(GifFile->SColorMap);
|
||||
GifFile->SColorMap = NULL;
|
||||
_GifError = D_GIF_ERR_READ_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
GifFile->SColorMap->Colors[i].Red = Buf[0];
|
||||
GifFile->SColorMap->Colors[i].Green = Buf[1];
|
||||
GifFile->SColorMap->Colors[i].Blue = Buf[2];
|
||||
}
|
||||
} else {
|
||||
GifFile->SColorMap = NULL;
|
||||
}
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* This routine should be called before any attempt to read an image.
|
||||
*****************************************************************************/
|
||||
int
|
||||
DGifGetRecordType(GifFileType * GifFile,
|
||||
GifRecordType * Type) {
|
||||
|
||||
GifByteType Buf;
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
if (!IS_READABLE(Private)) {
|
||||
/* This file was NOT open for reading: */
|
||||
_GifError = D_GIF_ERR_NOT_READABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
if (READ(GifFile, &Buf, 1) != 1) {
|
||||
_GifError = D_GIF_ERR_READ_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
switch (Buf) {
|
||||
case ',':
|
||||
*Type = IMAGE_DESC_RECORD_TYPE;
|
||||
break;
|
||||
case '!':
|
||||
*Type = EXTENSION_RECORD_TYPE;
|
||||
break;
|
||||
case ';':
|
||||
*Type = TERMINATE_RECORD_TYPE;
|
||||
break;
|
||||
default:
|
||||
*Type = UNDEFINED_RECORD_TYPE;
|
||||
_GifError = D_GIF_ERR_WRONG_RECORD;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* This routine should be called before any attempt to read an image.
|
||||
* Note it is assumed the Image desc. header (',') has been read.
|
||||
*****************************************************************************/
|
||||
int
|
||||
DGifGetImageDesc(GifFileType * GifFile) {
|
||||
|
||||
int i, BitsPerPixel;
|
||||
GifByteType Buf[3];
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
if (!IS_READABLE(Private)) {
|
||||
/* This file was NOT open for reading: */
|
||||
_GifError = D_GIF_ERR_NOT_READABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
if (DGifGetWord(GifFile, &GifFile->Image.Left) == GIF_ERROR ||
|
||||
DGifGetWord(GifFile, &GifFile->Image.Top) == GIF_ERROR ||
|
||||
DGifGetWord(GifFile, &GifFile->Image.Width) == GIF_ERROR ||
|
||||
DGifGetWord(GifFile, &GifFile->Image.Height) == GIF_ERROR)
|
||||
return GIF_ERROR;
|
||||
if (READ(GifFile, Buf, 1) != 1) {
|
||||
_GifError = D_GIF_ERR_READ_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
BitsPerPixel = (Buf[0] & 0x07) + 1;
|
||||
GifFile->Image.Interlace = (Buf[0] & 0x40);
|
||||
if (Buf[0] & 0x80) { /* Does this image have local color map? */
|
||||
|
||||
if (GifFile->Image.ColorMap)
|
||||
FreeMapObject(GifFile->Image.ColorMap);
|
||||
|
||||
GifFile->Image.ColorMap = MakeMapObject(1 << BitsPerPixel, NULL);
|
||||
if (GifFile->Image.ColorMap == NULL) {
|
||||
_GifError = D_GIF_ERR_NOT_ENOUGH_MEM;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
/* Get the image local color map: */
|
||||
for (i = 0; i < GifFile->Image.ColorMap->ColorCount; i++) {
|
||||
if (READ(GifFile, Buf, 3) != 3) {
|
||||
FreeMapObject(GifFile->Image.ColorMap);
|
||||
_GifError = D_GIF_ERR_READ_FAILED;
|
||||
GifFile->Image.ColorMap = NULL;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
GifFile->Image.ColorMap->Colors[i].Red = Buf[0];
|
||||
GifFile->Image.ColorMap->Colors[i].Green = Buf[1];
|
||||
GifFile->Image.ColorMap->Colors[i].Blue = Buf[2];
|
||||
}
|
||||
} else if (GifFile->Image.ColorMap) {
|
||||
FreeMapObject(GifFile->Image.ColorMap);
|
||||
GifFile->Image.ColorMap = NULL;
|
||||
}
|
||||
|
||||
GifFile->ImageCount++;
|
||||
|
||||
Private->PixelCount = (long)GifFile->Image.Width *
|
||||
(long)GifFile->Image.Height;
|
||||
|
||||
DGifSetupDecompress(GifFile); /* Reset decompress algorithm parameters. */
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Get one full scanned line (Line) of length LineLen from GIF file.
|
||||
*****************************************************************************/
|
||||
int
|
||||
DGifGetLine(GifFileType * GifFile,
|
||||
GifPixelType * Line,
|
||||
int LineLen) {
|
||||
|
||||
GifByteType *Dummy;
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
|
||||
|
||||
if (!IS_READABLE(Private)) {
|
||||
/* This file was NOT open for reading: */
|
||||
_GifError = D_GIF_ERR_NOT_READABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
if (!LineLen)
|
||||
LineLen = GifFile->Image.Width;
|
||||
|
||||
#if defined(__MSDOS__) || defined(__GNUC__)
|
||||
if ((Private->PixelCount -= LineLen) > 0xffff0000UL) {
|
||||
#else
|
||||
if ((Private->PixelCount -= LineLen) > 0xffff0000) {
|
||||
#endif /* __MSDOS__ */
|
||||
_GifError = D_GIF_ERR_DATA_TOO_BIG;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
if (DGifDecompressLine(GifFile, Line, LineLen) == GIF_OK) {
|
||||
if (Private->PixelCount == 0) {
|
||||
/* We probably would not be called any more, so lets clean
|
||||
* everything before we return: need to flush out all rest of
|
||||
* image until empty block (size 0) detected. We use GetCodeNext. */
|
||||
do
|
||||
if (DGifGetCodeNext(GifFile, &Dummy) == GIF_ERROR)
|
||||
return GIF_ERROR;
|
||||
while (Dummy != NULL) ;
|
||||
}
|
||||
return GIF_OK;
|
||||
} else
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Put one pixel (Pixel) into GIF file.
|
||||
*****************************************************************************/
|
||||
int
|
||||
DGifGetPixel(GifFileType * GifFile,
|
||||
GifPixelType Pixel) {
|
||||
|
||||
GifByteType *Dummy;
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
|
||||
|
||||
if (!IS_READABLE(Private)) {
|
||||
/* This file was NOT open for reading: */
|
||||
_GifError = D_GIF_ERR_NOT_READABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
#if defined(__MSDOS__) || defined(__GNUC__)
|
||||
if (--Private->PixelCount > 0xffff0000UL)
|
||||
#else
|
||||
if (--Private->PixelCount > 0xffff0000)
|
||||
#endif /* __MSDOS__ */
|
||||
{
|
||||
_GifError = D_GIF_ERR_DATA_TOO_BIG;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
if (DGifDecompressLine(GifFile, &Pixel, 1) == GIF_OK) {
|
||||
if (Private->PixelCount == 0) {
|
||||
/* We probably would not be called any more, so lets clean
|
||||
* everything before we return: need to flush out all rest of
|
||||
* image until empty block (size 0) detected. We use GetCodeNext. */
|
||||
do
|
||||
if (DGifGetCodeNext(GifFile, &Dummy) == GIF_ERROR)
|
||||
return GIF_ERROR;
|
||||
while (Dummy != NULL) ;
|
||||
}
|
||||
return GIF_OK;
|
||||
} else
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Get an extension block (see GIF manual) from gif file. This routine only
|
||||
* returns the first data block, and DGifGetExtensionNext should be called
|
||||
* after this one until NULL extension is returned.
|
||||
* The Extension should NOT be freed by the user (not dynamically allocated).
|
||||
* Note it is assumed the Extension desc. header ('!') has been read.
|
||||
*****************************************************************************/
|
||||
int
|
||||
DGifGetExtension(GifFileType * GifFile,
|
||||
int *ExtCode,
|
||||
GifByteType ** Extension) {
|
||||
|
||||
GifByteType Buf;
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
if (!IS_READABLE(Private)) {
|
||||
/* This file was NOT open for reading: */
|
||||
_GifError = D_GIF_ERR_NOT_READABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
if (READ(GifFile, &Buf, 1) != 1) {
|
||||
_GifError = D_GIF_ERR_READ_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
*ExtCode = Buf;
|
||||
|
||||
return DGifGetExtensionNext(GifFile, Extension);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Get a following extension block (see GIF manual) from gif file. This
|
||||
* routine should be called until NULL Extension is returned.
|
||||
* The Extension should NOT be freed by the user (not dynamically allocated).
|
||||
*****************************************************************************/
|
||||
int
|
||||
DGifGetExtensionNext(GifFileType * GifFile,
|
||||
GifByteType ** Extension) {
|
||||
|
||||
GifByteType Buf;
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
if (READ(GifFile, &Buf, 1) != 1) {
|
||||
_GifError = D_GIF_ERR_READ_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
if (Buf > 0) {
|
||||
*Extension = Private->Buf; /* Use private unused buffer. */
|
||||
(*Extension)[0] = Buf; /* Pascal strings notation (pos. 0 is len.). */
|
||||
if (READ(GifFile, &((*Extension)[1]), Buf) != Buf) {
|
||||
_GifError = D_GIF_ERR_READ_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
} else
|
||||
*Extension = NULL;
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* This routine should be called last, to close the GIF file.
|
||||
*****************************************************************************/
|
||||
int
|
||||
DGifCloseFile(GifFileType * GifFile) {
|
||||
|
||||
GifFilePrivateType *Private;
|
||||
FILE *File;
|
||||
|
||||
if (GifFile == NULL)
|
||||
return GIF_ERROR;
|
||||
|
||||
Private = (GifFilePrivateType *) GifFile->Private;
|
||||
|
||||
if (!IS_READABLE(Private)) {
|
||||
/* This file was NOT open for reading: */
|
||||
_GifError = D_GIF_ERR_NOT_READABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
File = Private->File;
|
||||
|
||||
if (GifFile->Image.ColorMap) {
|
||||
FreeMapObject(GifFile->Image.ColorMap);
|
||||
GifFile->Image.ColorMap = NULL;
|
||||
}
|
||||
|
||||
if (GifFile->SColorMap) {
|
||||
FreeMapObject(GifFile->SColorMap);
|
||||
GifFile->SColorMap = NULL;
|
||||
}
|
||||
|
||||
if (Private) {
|
||||
free((char *)Private);
|
||||
Private = NULL;
|
||||
}
|
||||
|
||||
free(GifFile);
|
||||
|
||||
if (File && (fclose(File) != 0)) {
|
||||
_GifError = D_GIF_ERR_CLOSE_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Get 2 bytes (word) from the given file:
|
||||
*****************************************************************************/
|
||||
static int
|
||||
DGifGetWord(GifFileType * GifFile,
|
||||
GifWord *Word) {
|
||||
|
||||
unsigned char c[2];
|
||||
|
||||
if (READ(GifFile, c, 2) != 2) {
|
||||
_GifError = D_GIF_ERR_READ_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
*Word = (((unsigned int)c[1]) << 8) + c[0];
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Get the image code in compressed form. This routine can be called if the
|
||||
* information needed to be piped out as is. Obviously this is much faster
|
||||
* than decoding and encoding again. This routine should be followed by calls
|
||||
* to DGifGetCodeNext, until NULL block is returned.
|
||||
* The block should NOT be freed by the user (not dynamically allocated).
|
||||
*****************************************************************************/
|
||||
int
|
||||
DGifGetCode(GifFileType * GifFile,
|
||||
int *CodeSize,
|
||||
GifByteType ** CodeBlock) {
|
||||
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
if (!IS_READABLE(Private)) {
|
||||
/* This file was NOT open for reading: */
|
||||
_GifError = D_GIF_ERR_NOT_READABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
*CodeSize = Private->BitsPerPixel;
|
||||
|
||||
return DGifGetCodeNext(GifFile, CodeBlock);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Continue to get the image code in compressed form. This routine should be
|
||||
* called until NULL block is returned.
|
||||
* The block should NOT be freed by the user (not dynamically allocated).
|
||||
*****************************************************************************/
|
||||
int
|
||||
DGifGetCodeNext(GifFileType * GifFile,
|
||||
GifByteType ** CodeBlock) {
|
||||
|
||||
GifByteType Buf;
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
if (READ(GifFile, &Buf, 1) != 1) {
|
||||
_GifError = D_GIF_ERR_READ_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
if (Buf > 0) {
|
||||
*CodeBlock = Private->Buf; /* Use private unused buffer. */
|
||||
(*CodeBlock)[0] = Buf; /* Pascal strings notation (pos. 0 is len.). */
|
||||
if (READ(GifFile, &((*CodeBlock)[1]), Buf) != Buf) {
|
||||
_GifError = D_GIF_ERR_READ_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
} else {
|
||||
*CodeBlock = NULL;
|
||||
Private->Buf[0] = 0; /* Make sure the buffer is empty! */
|
||||
Private->PixelCount = 0; /* And local info. indicate image read. */
|
||||
}
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Setup the LZ decompression for this image:
|
||||
*****************************************************************************/
|
||||
static int
|
||||
DGifSetupDecompress(GifFileType * GifFile) {
|
||||
|
||||
int i, BitsPerPixel;
|
||||
GifByteType CodeSize;
|
||||
GifPrefixType *Prefix;
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
READ(GifFile, &CodeSize, 1); /* Read Code size from file. */
|
||||
BitsPerPixel = CodeSize;
|
||||
|
||||
Private->Buf[0] = 0; /* Input Buffer empty. */
|
||||
Private->BitsPerPixel = BitsPerPixel;
|
||||
Private->ClearCode = (1 << BitsPerPixel);
|
||||
Private->EOFCode = Private->ClearCode + 1;
|
||||
Private->RunningCode = Private->EOFCode + 1;
|
||||
Private->RunningBits = BitsPerPixel + 1; /* Number of bits per code. */
|
||||
Private->MaxCode1 = 1 << Private->RunningBits; /* Max. code + 1. */
|
||||
Private->StackPtr = 0; /* No pixels on the pixel stack. */
|
||||
Private->LastCode = NO_SUCH_CODE;
|
||||
Private->CrntShiftState = 0; /* No information in CrntShiftDWord. */
|
||||
Private->CrntShiftDWord = 0;
|
||||
|
||||
Prefix = Private->Prefix;
|
||||
for (i = 0; i <= LZ_MAX_CODE; i++)
|
||||
Prefix[i] = NO_SUCH_CODE;
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* The LZ decompression routine:
|
||||
* This version decompress the given gif file into Line of length LineLen.
|
||||
* This routine can be called few times (one per scan line, for example), in
|
||||
* order the complete the whole image.
|
||||
*****************************************************************************/
|
||||
static int
|
||||
DGifDecompressLine(GifFileType * GifFile,
|
||||
GifPixelType * Line,
|
||||
int LineLen) {
|
||||
|
||||
int i = 0;
|
||||
int j, CrntCode, EOFCode, ClearCode, CrntPrefix, LastCode, StackPtr;
|
||||
GifByteType *Stack, *Suffix;
|
||||
GifPrefixType *Prefix;
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
|
||||
|
||||
StackPtr = Private->StackPtr;
|
||||
Prefix = Private->Prefix;
|
||||
Suffix = Private->Suffix;
|
||||
Stack = Private->Stack;
|
||||
EOFCode = Private->EOFCode;
|
||||
ClearCode = Private->ClearCode;
|
||||
LastCode = Private->LastCode;
|
||||
|
||||
if (StackPtr != 0) {
|
||||
/* Let pop the stack off before continueing to read the gif file: */
|
||||
while (StackPtr != 0 && i < LineLen)
|
||||
Line[i++] = Stack[--StackPtr];
|
||||
}
|
||||
|
||||
while (i < LineLen) { /* Decode LineLen items. */
|
||||
if (DGifDecompressInput(GifFile, &CrntCode) == GIF_ERROR)
|
||||
return GIF_ERROR;
|
||||
|
||||
if (CrntCode == EOFCode) {
|
||||
/* Note however that usually we will not be here as we will stop
|
||||
* decoding as soon as we got all the pixel, or EOF code will
|
||||
* not be read at all, and DGifGetLine/Pixel clean everything. */
|
||||
if (i != LineLen - 1 || Private->PixelCount != 0) {
|
||||
_GifError = D_GIF_ERR_EOF_TOO_SOON;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
i++;
|
||||
} else if (CrntCode == ClearCode) {
|
||||
/* We need to start over again: */
|
||||
for (j = 0; j <= LZ_MAX_CODE; j++)
|
||||
Prefix[j] = NO_SUCH_CODE;
|
||||
Private->RunningCode = Private->EOFCode + 1;
|
||||
Private->RunningBits = Private->BitsPerPixel + 1;
|
||||
Private->MaxCode1 = 1 << Private->RunningBits;
|
||||
LastCode = Private->LastCode = NO_SUCH_CODE;
|
||||
} else {
|
||||
/* Its regular code - if in pixel range simply add it to output
|
||||
* stream, otherwise trace to codes linked list until the prefix
|
||||
* is in pixel range: */
|
||||
if (CrntCode < ClearCode) {
|
||||
/* This is simple - its pixel scalar, so add it to output: */
|
||||
Line[i++] = CrntCode;
|
||||
} else {
|
||||
/* Its a code to needed to be traced: trace the linked list
|
||||
* until the prefix is a pixel, while pushing the suffix
|
||||
* pixels on our stack. If we done, pop the stack in reverse
|
||||
* (thats what stack is good for!) order to output. */
|
||||
if (Prefix[CrntCode] == NO_SUCH_CODE) {
|
||||
/* Only allowed if CrntCode is exactly the running code:
|
||||
* In that case CrntCode = XXXCode, CrntCode or the
|
||||
* prefix code is last code and the suffix char is
|
||||
* exactly the prefix of last code! */
|
||||
if (CrntCode == Private->RunningCode - 2) {
|
||||
CrntPrefix = LastCode;
|
||||
Suffix[Private->RunningCode - 2] =
|
||||
Stack[StackPtr++] = DGifGetPrefixChar(Prefix,
|
||||
LastCode,
|
||||
ClearCode);
|
||||
} else {
|
||||
_GifError = D_GIF_ERR_IMAGE_DEFECT;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
} else
|
||||
CrntPrefix = CrntCode;
|
||||
|
||||
/* Now (if image is O.K.) we should not get an NO_SUCH_CODE
|
||||
* During the trace. As we might loop forever, in case of
|
||||
* defective image, we count the number of loops we trace
|
||||
* and stop if we got LZ_MAX_CODE. obviously we can not
|
||||
* loop more than that. */
|
||||
j = 0;
|
||||
while (j++ <= LZ_MAX_CODE &&
|
||||
CrntPrefix > ClearCode && CrntPrefix <= LZ_MAX_CODE) {
|
||||
Stack[StackPtr++] = Suffix[CrntPrefix];
|
||||
CrntPrefix = Prefix[CrntPrefix];
|
||||
}
|
||||
if (j >= LZ_MAX_CODE || CrntPrefix > LZ_MAX_CODE) {
|
||||
_GifError = D_GIF_ERR_IMAGE_DEFECT;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
/* Push the last character on stack: */
|
||||
Stack[StackPtr++] = CrntPrefix;
|
||||
|
||||
/* Now lets pop all the stack into output: */
|
||||
while (StackPtr != 0 && i < LineLen)
|
||||
Line[i++] = Stack[--StackPtr];
|
||||
}
|
||||
if (LastCode != NO_SUCH_CODE) {
|
||||
Prefix[Private->RunningCode - 2] = LastCode;
|
||||
|
||||
if (CrntCode == Private->RunningCode - 2) {
|
||||
/* Only allowed if CrntCode is exactly the running code:
|
||||
* In that case CrntCode = XXXCode, CrntCode or the
|
||||
* prefix code is last code and the suffix char is
|
||||
* exactly the prefix of last code! */
|
||||
Suffix[Private->RunningCode - 2] =
|
||||
DGifGetPrefixChar(Prefix, LastCode, ClearCode);
|
||||
} else {
|
||||
Suffix[Private->RunningCode - 2] =
|
||||
DGifGetPrefixChar(Prefix, CrntCode, ClearCode);
|
||||
}
|
||||
}
|
||||
LastCode = CrntCode;
|
||||
}
|
||||
}
|
||||
|
||||
Private->LastCode = LastCode;
|
||||
Private->StackPtr = StackPtr;
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Routine to trace the Prefixes linked list until we get a prefix which is
|
||||
* not code, but a pixel value (less than ClearCode). Returns that pixel value.
|
||||
* If image is defective, we might loop here forever, so we limit the loops to
|
||||
* the maximum possible if image O.k. - LZ_MAX_CODE times.
|
||||
*****************************************************************************/
|
||||
static int
|
||||
DGifGetPrefixChar(GifPrefixType *Prefix,
|
||||
int Code,
|
||||
int ClearCode) {
|
||||
|
||||
int i = 0;
|
||||
|
||||
while (Code > ClearCode && i++ <= LZ_MAX_CODE)
|
||||
Code = Prefix[Code];
|
||||
return Code;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Interface for accessing the LZ codes directly. Set Code to the real code
|
||||
* (12bits), or to -1 if EOF code is returned.
|
||||
*****************************************************************************/
|
||||
int
|
||||
DGifGetLZCodes(GifFileType * GifFile,
|
||||
int *Code) {
|
||||
|
||||
GifByteType *CodeBlock;
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
if (!IS_READABLE(Private)) {
|
||||
/* This file was NOT open for reading: */
|
||||
_GifError = D_GIF_ERR_NOT_READABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
if (DGifDecompressInput(GifFile, Code) == GIF_ERROR)
|
||||
return GIF_ERROR;
|
||||
|
||||
if (*Code == Private->EOFCode) {
|
||||
/* Skip rest of codes (hopefully only NULL terminating block): */
|
||||
do {
|
||||
if (DGifGetCodeNext(GifFile, &CodeBlock) == GIF_ERROR)
|
||||
return GIF_ERROR;
|
||||
} while (CodeBlock != NULL) ;
|
||||
|
||||
*Code = -1;
|
||||
} else if (*Code == Private->ClearCode) {
|
||||
/* We need to start over again: */
|
||||
Private->RunningCode = Private->EOFCode + 1;
|
||||
Private->RunningBits = Private->BitsPerPixel + 1;
|
||||
Private->MaxCode1 = 1 << Private->RunningBits;
|
||||
}
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* The LZ decompression input routine:
|
||||
* This routine is responsable for the decompression of the bit stream from
|
||||
* 8 bits (bytes) packets, into the real codes.
|
||||
* Returns GIF_OK if read succesfully.
|
||||
*****************************************************************************/
|
||||
static int
|
||||
DGifDecompressInput(GifFileType * GifFile,
|
||||
int *Code) {
|
||||
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
GifByteType NextByte;
|
||||
static unsigned short CodeMasks[] = {
|
||||
0x0000, 0x0001, 0x0003, 0x0007,
|
||||
0x000f, 0x001f, 0x003f, 0x007f,
|
||||
0x00ff, 0x01ff, 0x03ff, 0x07ff,
|
||||
0x0fff
|
||||
};
|
||||
/* The image can't contain more than LZ_BITS per code. */
|
||||
if (Private->RunningBits > LZ_BITS) {
|
||||
_GifError = D_GIF_ERR_IMAGE_DEFECT;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
while (Private->CrntShiftState < Private->RunningBits) {
|
||||
/* Needs to get more bytes from input stream for next code: */
|
||||
if (DGifBufferedInput(GifFile, Private->Buf, &NextByte) == GIF_ERROR) {
|
||||
return GIF_ERROR;
|
||||
}
|
||||
Private->CrntShiftDWord |=
|
||||
((unsigned long)NextByte) << Private->CrntShiftState;
|
||||
Private->CrntShiftState += 8;
|
||||
}
|
||||
*Code = Private->CrntShiftDWord & CodeMasks[Private->RunningBits];
|
||||
|
||||
Private->CrntShiftDWord >>= Private->RunningBits;
|
||||
Private->CrntShiftState -= Private->RunningBits;
|
||||
|
||||
/* If code cannot fit into RunningBits bits, must raise its size. Note
|
||||
* however that codes above 4095 are used for special signaling.
|
||||
* If we're using LZ_BITS bits already and we're at the max code, just
|
||||
* keep using the table as it is, don't increment Private->RunningCode.
|
||||
*/
|
||||
if (Private->RunningCode < LZ_MAX_CODE + 2 &&
|
||||
++Private->RunningCode > Private->MaxCode1 &&
|
||||
Private->RunningBits < LZ_BITS) {
|
||||
Private->MaxCode1 <<= 1;
|
||||
Private->RunningBits++;
|
||||
}
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* This routines read one gif data block at a time and buffers it internally
|
||||
* so that the decompression routine could access it.
|
||||
* The routine returns the next byte from its internal buffer (or read next
|
||||
* block in if buffer empty) and returns GIF_OK if succesful.
|
||||
*****************************************************************************/
|
||||
static int
|
||||
DGifBufferedInput(GifFileType * GifFile,
|
||||
GifByteType * Buf,
|
||||
GifByteType * NextByte) {
|
||||
|
||||
if (Buf[0] == 0) {
|
||||
/* Needs to read the next buffer - this one is empty: */
|
||||
if (READ(GifFile, Buf, 1) != 1) {
|
||||
_GifError = D_GIF_ERR_READ_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
/* There shouldn't be any empty data blocks here as the LZW spec
|
||||
* says the LZW termination code should come first. Therefore we
|
||||
* shouldn't be inside this routine at that point.
|
||||
*/
|
||||
if (Buf[0] == 0) {
|
||||
_GifError = D_GIF_ERR_IMAGE_DEFECT;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
if (READ(GifFile, &Buf[1], Buf[0]) != Buf[0]) {
|
||||
_GifError = D_GIF_ERR_READ_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
*NextByte = Buf[1];
|
||||
Buf[1] = 2; /* We use now the second place as last char read! */
|
||||
Buf[0]--;
|
||||
} else {
|
||||
*NextByte = Buf[Buf[1]++];
|
||||
Buf[0]--;
|
||||
}
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
998
oversampling/WDL/giflib/egif_lib.c
Normal file
998
oversampling/WDL/giflib/egif_lib.c
Normal file
@@ -0,0 +1,998 @@
|
||||
/******************************************************************************
|
||||
* "Gif-Lib" - Yet another gif library.
|
||||
*
|
||||
* Written by: Gershon Elber Ver 1.1, Aug. 1990
|
||||
******************************************************************************
|
||||
* The kernel of the GIF Encoding process can be found here.
|
||||
******************************************************************************
|
||||
* History:
|
||||
* 14 Jun 89 - Version 1.0 by Gershon Elber.
|
||||
* 3 Sep 90 - Version 1.1 by Gershon Elber (Support for Gif89, Unique names).
|
||||
* 26 Jun 96 - Version 3.0 by Eric S. Raymond (Full GIF89 support)
|
||||
*****************************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
/* Find a thirty-two bit int type */
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#ifdef __MSDOS__
|
||||
#include <io.h>
|
||||
#include <alloc.h>
|
||||
#include <sys\stat.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef R6000
|
||||
|
||||
/* FIXME: What is sys/mode.h? Can we substitute a check for this file rather
|
||||
* than a check based on machine type?
|
||||
*/
|
||||
#include <sys/mode.h>
|
||||
#endif
|
||||
#endif /* __MSDOS__ */
|
||||
|
||||
#ifdef HAVE_IO_H
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif /* HAVE_FCNTL_H */
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "gif_lib.h"
|
||||
#include "gif_lib_private.h"
|
||||
|
||||
/* #define DEBUG_NO_PREFIX Dump only compressed data. */
|
||||
|
||||
/* Masks given codes to BitsPerPixel, to make sure all codes are in range: */
|
||||
static GifPixelType CodeMask[] = {
|
||||
0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff
|
||||
};
|
||||
|
||||
static char GifVersionPrefix[GIF_STAMP_LEN + 1] = GIF87_STAMP;
|
||||
|
||||
#define WRITE(_gif,_buf,_len) \
|
||||
(((GifFilePrivateType*)_gif->Private)->Write ? \
|
||||
((GifFilePrivateType*)_gif->Private)->Write(_gif,_buf,_len) : \
|
||||
fwrite(_buf, 1, _len, ((GifFilePrivateType*)_gif->Private)->File))
|
||||
|
||||
static int EGifPutWord(int Word, GifFileType * GifFile);
|
||||
static int EGifSetupCompress(GifFileType * GifFile);
|
||||
static int EGifCompressLine(GifFileType * GifFile, GifPixelType * Line,
|
||||
int LineLen);
|
||||
static int EGifCompressOutput(GifFileType * GifFile, int Code);
|
||||
static int EGifBufferedOutput(GifFileType * GifFile, GifByteType * Buf,
|
||||
int c);
|
||||
|
||||
/******************************************************************************
|
||||
* Open a new gif file for write, given by its name. If TestExistance then
|
||||
* if the file exists this routines fails (returns NULL).
|
||||
* Returns GifFileType pointer dynamically allocated which serves as the gif
|
||||
* info record. _GifError is cleared if succesfull.
|
||||
*****************************************************************************/
|
||||
GifFileType *
|
||||
EGifOpenFileName(const char *FileName,
|
||||
int TestExistance) {
|
||||
|
||||
int FileHandle;
|
||||
GifFileType *GifFile;
|
||||
|
||||
if (TestExistance)
|
||||
FileHandle = open(FileName, O_WRONLY | O_CREAT | O_EXCL
|
||||
#if defined(__MSDOS__) || defined(_WIN32)
|
||||
| O_BINARY
|
||||
#endif /* __MSDOS__ */
|
||||
, 0644 );
|
||||
else
|
||||
FileHandle = open(FileName, O_WRONLY | O_CREAT | O_TRUNC
|
||||
#if defined(__MSDOS__) || defined(_WIN32)
|
||||
| O_BINARY
|
||||
#endif /* __MSDOS__ */
|
||||
, 0644 );
|
||||
|
||||
if (FileHandle == -1) {
|
||||
_GifError = E_GIF_ERR_OPEN_FAILED;
|
||||
return NULL;
|
||||
}
|
||||
GifFile = EGifOpenFileHandle(FileHandle);
|
||||
if (GifFile == (GifFileType *) NULL)
|
||||
close(FileHandle);
|
||||
return GifFile;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Update a new gif file, given its file handle, which must be opened for
|
||||
* write in binary mode.
|
||||
* Returns GifFileType pointer dynamically allocated which serves as the gif
|
||||
* info record. _GifError is cleared if succesfull.
|
||||
*****************************************************************************/
|
||||
GifFileType *
|
||||
EGifOpenFileHandle(int FileHandle) {
|
||||
|
||||
GifFileType *GifFile;
|
||||
GifFilePrivateType *Private;
|
||||
FILE *f;
|
||||
|
||||
GifFile = (GifFileType *) malloc(sizeof(GifFileType));
|
||||
if (GifFile == NULL) {
|
||||
_GifError = E_GIF_ERR_NOT_ENOUGH_MEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(GifFile, '\0', sizeof(GifFileType));
|
||||
|
||||
Private = (GifFilePrivateType *)malloc(sizeof(GifFilePrivateType));
|
||||
if (Private == NULL) {
|
||||
free(GifFile);
|
||||
_GifError = E_GIF_ERR_NOT_ENOUGH_MEM;
|
||||
return NULL;
|
||||
}
|
||||
if ((Private->HashTable = _InitHashTable()) == NULL) {
|
||||
free(GifFile);
|
||||
free(Private);
|
||||
_GifError = E_GIF_ERR_NOT_ENOUGH_MEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef __MSDOS__
|
||||
setmode(FileHandle, O_BINARY); /* Make sure it is in binary mode. */
|
||||
#endif /* __MSDOS__ */
|
||||
|
||||
f = fdopen(FileHandle, "wb"); /* Make it into a stream: */
|
||||
|
||||
#ifdef __MSDOS__
|
||||
setvbuf(f, NULL, _IOFBF, GIF_FILE_BUFFER_SIZE); /* And inc. stream
|
||||
* buffer. */
|
||||
#endif /* __MSDOS__ */
|
||||
|
||||
GifFile->Private = (VoidPtr)Private;
|
||||
Private->FileHandle = FileHandle;
|
||||
Private->File = f;
|
||||
Private->FileState = FILE_STATE_WRITE;
|
||||
|
||||
Private->Write = (OutputFunc) 0; /* No user write routine (MRB) */
|
||||
GifFile->UserData = (VoidPtr) 0; /* No user write handle (MRB) */
|
||||
|
||||
_GifError = 0;
|
||||
|
||||
return GifFile;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Output constructor that takes user supplied output function.
|
||||
* Basically just a copy of EGifOpenFileHandle. (MRB)
|
||||
*****************************************************************************/
|
||||
GifFileType *
|
||||
EGifOpen(void *userData,
|
||||
OutputFunc writeFunc) {
|
||||
|
||||
GifFileType *GifFile;
|
||||
GifFilePrivateType *Private;
|
||||
|
||||
GifFile = (GifFileType *)malloc(sizeof(GifFileType));
|
||||
if (GifFile == NULL) {
|
||||
_GifError = E_GIF_ERR_NOT_ENOUGH_MEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(GifFile, '\0', sizeof(GifFileType));
|
||||
|
||||
Private = (GifFilePrivateType *)malloc(sizeof(GifFilePrivateType));
|
||||
if (Private == NULL) {
|
||||
free(GifFile);
|
||||
_GifError = E_GIF_ERR_NOT_ENOUGH_MEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Private->HashTable = _InitHashTable();
|
||||
if (Private->HashTable == NULL) {
|
||||
free (GifFile);
|
||||
free (Private);
|
||||
_GifError = E_GIF_ERR_NOT_ENOUGH_MEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GifFile->Private = (VoidPtr) Private;
|
||||
Private->FileHandle = 0;
|
||||
Private->File = (FILE *) 0;
|
||||
Private->FileState = FILE_STATE_WRITE;
|
||||
|
||||
Private->Write = writeFunc; /* User write routine (MRB) */
|
||||
GifFile->UserData = userData; /* User write handle (MRB) */
|
||||
|
||||
_GifError = 0;
|
||||
|
||||
return GifFile;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Routine to set current GIF version. All files open for write will be
|
||||
* using this version until next call to this routine. Version consists of
|
||||
* 3 characters as "87a" or "89a". No test is made to validate the version.
|
||||
*****************************************************************************/
|
||||
void
|
||||
EGifSetGifVersion(const char *Version) {
|
||||
strncpy(GifVersionPrefix + GIF_VERSION_POS, Version, 3);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* This routine should be called before any other EGif calls, immediately
|
||||
* follows the GIF file openning.
|
||||
*****************************************************************************/
|
||||
int
|
||||
EGifPutScreenDesc(GifFileType * GifFile,
|
||||
int Width,
|
||||
int Height,
|
||||
int ColorRes,
|
||||
int BackGround,
|
||||
const ColorMapObject * ColorMap) {
|
||||
|
||||
int i;
|
||||
GifByteType Buf[3];
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
|
||||
|
||||
if (Private->FileState & FILE_STATE_SCREEN) {
|
||||
/* If already has screen descriptor - something is wrong! */
|
||||
_GifError = E_GIF_ERR_HAS_SCRN_DSCR;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
if (!IS_WRITEABLE(Private)) {
|
||||
/* This file was NOT open for writing: */
|
||||
_GifError = E_GIF_ERR_NOT_WRITEABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
/* First write the version prefix into the file. */
|
||||
#ifndef DEBUG_NO_PREFIX
|
||||
if (WRITE(GifFile, (unsigned char *)GifVersionPrefix,
|
||||
strlen(GifVersionPrefix)) != strlen(GifVersionPrefix)) {
|
||||
_GifError = E_GIF_ERR_WRITE_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
#endif /* DEBUG_NO_PREFIX */
|
||||
|
||||
GifFile->SWidth = Width;
|
||||
GifFile->SHeight = Height;
|
||||
GifFile->SColorResolution = ColorRes;
|
||||
GifFile->SBackGroundColor = BackGround;
|
||||
if (ColorMap) {
|
||||
GifFile->SColorMap = MakeMapObject(ColorMap->ColorCount,
|
||||
ColorMap->Colors);
|
||||
if (GifFile->SColorMap == NULL) {
|
||||
_GifError = E_GIF_ERR_NOT_ENOUGH_MEM;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
} else
|
||||
GifFile->SColorMap = NULL;
|
||||
|
||||
/*
|
||||
* Put the logical screen descriptor into the file:
|
||||
*/
|
||||
/* Logical Screen Descriptor: Dimensions */
|
||||
EGifPutWord(Width, GifFile);
|
||||
EGifPutWord(Height, GifFile);
|
||||
|
||||
/* Logical Screen Descriptor: Packed Fields */
|
||||
/* Note: We have actual size of the color table default to the largest
|
||||
* possible size (7+1 == 8 bits) because the decoder can use it to decide
|
||||
* how to display the files.
|
||||
*/
|
||||
Buf[0] = (ColorMap ? 0x80 : 0x00) | /* Yes/no global colormap */
|
||||
((ColorRes - 1) << 4) | /* Bits allocated to each primary color */
|
||||
(ColorMap ? ColorMap->BitsPerPixel - 1 : 0x07 ); /* Actual size of the
|
||||
color table. */
|
||||
Buf[1] = BackGround; /* Index into the ColorTable for background color */
|
||||
Buf[2] = 0; /* Pixel Aspect Ratio */
|
||||
#ifndef DEBUG_NO_PREFIX
|
||||
WRITE(GifFile, Buf, 3);
|
||||
#endif /* DEBUG_NO_PREFIX */
|
||||
|
||||
/* If we have Global color map - dump it also: */
|
||||
#ifndef DEBUG_NO_PREFIX
|
||||
if (ColorMap != NULL)
|
||||
for (i = 0; i < ColorMap->ColorCount; i++) {
|
||||
/* Put the ColorMap out also: */
|
||||
Buf[0] = ColorMap->Colors[i].Red;
|
||||
Buf[1] = ColorMap->Colors[i].Green;
|
||||
Buf[2] = ColorMap->Colors[i].Blue;
|
||||
if (WRITE(GifFile, Buf, 3) != 3) {
|
||||
_GifError = E_GIF_ERR_WRITE_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
}
|
||||
#endif /* DEBUG_NO_PREFIX */
|
||||
|
||||
/* Mark this file as has screen descriptor, and no pixel written yet: */
|
||||
Private->FileState |= FILE_STATE_SCREEN;
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* This routine should be called before any attempt to dump an image - any
|
||||
* call to any of the pixel dump routines.
|
||||
*****************************************************************************/
|
||||
int
|
||||
EGifPutImageDesc(GifFileType * GifFile,
|
||||
int Left,
|
||||
int Top,
|
||||
int Width,
|
||||
int Height,
|
||||
int Interlace,
|
||||
const ColorMapObject * ColorMap) {
|
||||
|
||||
int i;
|
||||
GifByteType Buf[3];
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
if (Private->FileState & FILE_STATE_IMAGE &&
|
||||
#if defined(__MSDOS__) || defined(__GNUC__)
|
||||
Private->PixelCount > 0xffff0000UL) {
|
||||
#else
|
||||
Private->PixelCount > 0xffff0000) {
|
||||
#endif /* __MSDOS__ */
|
||||
/* If already has active image descriptor - something is wrong! */
|
||||
_GifError = E_GIF_ERR_HAS_IMAG_DSCR;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
if (!IS_WRITEABLE(Private)) {
|
||||
/* This file was NOT open for writing: */
|
||||
_GifError = E_GIF_ERR_NOT_WRITEABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
GifFile->Image.Left = Left;
|
||||
GifFile->Image.Top = Top;
|
||||
GifFile->Image.Width = Width;
|
||||
GifFile->Image.Height = Height;
|
||||
GifFile->Image.Interlace = Interlace;
|
||||
if (ColorMap) {
|
||||
GifFile->Image.ColorMap = MakeMapObject(ColorMap->ColorCount,
|
||||
ColorMap->Colors);
|
||||
if (GifFile->Image.ColorMap == NULL) {
|
||||
_GifError = E_GIF_ERR_NOT_ENOUGH_MEM;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
} else {
|
||||
GifFile->Image.ColorMap = NULL;
|
||||
}
|
||||
|
||||
/* Put the image descriptor into the file: */
|
||||
Buf[0] = ','; /* Image seperator character. */
|
||||
#ifndef DEBUG_NO_PREFIX
|
||||
WRITE(GifFile, Buf, 1);
|
||||
#endif /* DEBUG_NO_PREFIX */
|
||||
EGifPutWord(Left, GifFile);
|
||||
EGifPutWord(Top, GifFile);
|
||||
EGifPutWord(Width, GifFile);
|
||||
EGifPutWord(Height, GifFile);
|
||||
Buf[0] = (ColorMap ? 0x80 : 0x00) |
|
||||
(Interlace ? 0x40 : 0x00) |
|
||||
(ColorMap ? ColorMap->BitsPerPixel - 1 : 0);
|
||||
#ifndef DEBUG_NO_PREFIX
|
||||
WRITE(GifFile, Buf, 1);
|
||||
#endif /* DEBUG_NO_PREFIX */
|
||||
|
||||
/* If we have Global color map - dump it also: */
|
||||
#ifndef DEBUG_NO_PREFIX
|
||||
if (ColorMap != NULL)
|
||||
for (i = 0; i < ColorMap->ColorCount; i++) {
|
||||
/* Put the ColorMap out also: */
|
||||
Buf[0] = ColorMap->Colors[i].Red;
|
||||
Buf[1] = ColorMap->Colors[i].Green;
|
||||
Buf[2] = ColorMap->Colors[i].Blue;
|
||||
if (WRITE(GifFile, Buf, 3) != 3) {
|
||||
_GifError = E_GIF_ERR_WRITE_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
}
|
||||
#endif /* DEBUG_NO_PREFIX */
|
||||
if (GifFile->SColorMap == NULL && GifFile->Image.ColorMap == NULL) {
|
||||
_GifError = E_GIF_ERR_NO_COLOR_MAP;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
/* Mark this file as has screen descriptor: */
|
||||
Private->FileState |= FILE_STATE_IMAGE;
|
||||
Private->PixelCount = (long)Width *(long)Height;
|
||||
|
||||
EGifSetupCompress(GifFile); /* Reset compress algorithm parameters. */
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Put one full scanned line (Line) of length LineLen into GIF file.
|
||||
*****************************************************************************/
|
||||
int
|
||||
EGifPutLine(GifFileType * GifFile,
|
||||
GifPixelType * Line,
|
||||
int LineLen) {
|
||||
|
||||
int i;
|
||||
GifPixelType Mask;
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
|
||||
|
||||
if (!IS_WRITEABLE(Private)) {
|
||||
/* This file was NOT open for writing: */
|
||||
_GifError = E_GIF_ERR_NOT_WRITEABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
if (!LineLen)
|
||||
LineLen = GifFile->Image.Width;
|
||||
if (Private->PixelCount < (unsigned)LineLen) {
|
||||
_GifError = E_GIF_ERR_DATA_TOO_BIG;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
Private->PixelCount -= LineLen;
|
||||
|
||||
/* Make sure the codes are not out of bit range, as we might generate
|
||||
* wrong code (because of overflow when we combine them) in this case: */
|
||||
Mask = CodeMask[Private->BitsPerPixel];
|
||||
for (i = 0; i < LineLen; i++)
|
||||
Line[i] &= Mask;
|
||||
|
||||
return EGifCompressLine(GifFile, Line, LineLen);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Put one pixel (Pixel) into GIF file.
|
||||
*****************************************************************************/
|
||||
int
|
||||
EGifPutPixel(GifFileType * GifFile,
|
||||
GifPixelType Pixel) {
|
||||
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
if (!IS_WRITEABLE(Private)) {
|
||||
/* This file was NOT open for writing: */
|
||||
_GifError = E_GIF_ERR_NOT_WRITEABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
if (Private->PixelCount == 0) {
|
||||
_GifError = E_GIF_ERR_DATA_TOO_BIG;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
--Private->PixelCount;
|
||||
|
||||
/* Make sure the code is not out of bit range, as we might generate
|
||||
* wrong code (because of overflow when we combine them) in this case: */
|
||||
Pixel &= CodeMask[Private->BitsPerPixel];
|
||||
|
||||
return EGifCompressLine(GifFile, &Pixel, 1);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Put a comment into GIF file using the GIF89 comment extension block.
|
||||
*****************************************************************************/
|
||||
int
|
||||
EGifPutComment(GifFileType * GifFile,
|
||||
const char *Comment) {
|
||||
|
||||
unsigned int length = strlen(Comment);
|
||||
char *buf;
|
||||
|
||||
length = strlen(Comment);
|
||||
if (length <= 255) {
|
||||
return EGifPutExtension(GifFile, COMMENT_EXT_FUNC_CODE,
|
||||
length, Comment);
|
||||
} else {
|
||||
buf = (char *)Comment;
|
||||
if (EGifPutExtensionFirst(GifFile, COMMENT_EXT_FUNC_CODE, 255, buf)
|
||||
== GIF_ERROR) {
|
||||
return GIF_ERROR;
|
||||
}
|
||||
length -= 255;
|
||||
buf = buf + 255;
|
||||
|
||||
/* Break the comment into 255 byte sub blocks */
|
||||
while (length > 255) {
|
||||
if (EGifPutExtensionNext(GifFile, 0, 255, buf) == GIF_ERROR) {
|
||||
return GIF_ERROR;
|
||||
}
|
||||
buf = buf + 255;
|
||||
length -= 255;
|
||||
}
|
||||
/* Output any partial block and the clear code. */
|
||||
if (length > 0) {
|
||||
if (EGifPutExtensionLast(GifFile, 0, length, buf) == GIF_ERROR) {
|
||||
return GIF_ERROR;
|
||||
}
|
||||
} else {
|
||||
if (EGifPutExtensionLast(GifFile, 0, 0, NULL) == GIF_ERROR) {
|
||||
return GIF_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Put a first extension block (see GIF manual) into gif file. Here more
|
||||
* extensions can be dumped using EGifPutExtensionNext until
|
||||
* EGifPutExtensionLast is invoked.
|
||||
*****************************************************************************/
|
||||
int
|
||||
EGifPutExtensionFirst(GifFileType * GifFile,
|
||||
int ExtCode,
|
||||
int ExtLen,
|
||||
const VoidPtr Extension) {
|
||||
|
||||
GifByteType Buf[3];
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
if (!IS_WRITEABLE(Private)) {
|
||||
/* This file was NOT open for writing: */
|
||||
_GifError = E_GIF_ERR_NOT_WRITEABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
if (ExtCode == 0) {
|
||||
WRITE(GifFile, (GifByteType *)&ExtLen, 1);
|
||||
} else {
|
||||
Buf[0] = '!';
|
||||
Buf[1] = ExtCode;
|
||||
Buf[2] = ExtLen;
|
||||
WRITE(GifFile, Buf, 3);
|
||||
}
|
||||
|
||||
WRITE(GifFile, Extension, ExtLen);
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Put a middle extension block (see GIF manual) into gif file.
|
||||
*****************************************************************************/
|
||||
int
|
||||
EGifPutExtensionNext(GifFileType * GifFile,
|
||||
int ExtCode,
|
||||
int ExtLen,
|
||||
const VoidPtr Extension) {
|
||||
|
||||
GifByteType Buf;
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
if (!IS_WRITEABLE(Private)) {
|
||||
/* This file was NOT open for writing: */
|
||||
_GifError = E_GIF_ERR_NOT_WRITEABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
Buf = ExtLen;
|
||||
WRITE(GifFile, &Buf, 1);
|
||||
WRITE(GifFile, Extension, ExtLen);
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Put a last extension block (see GIF manual) into gif file.
|
||||
*****************************************************************************/
|
||||
int
|
||||
EGifPutExtensionLast(GifFileType * GifFile,
|
||||
int ExtCode,
|
||||
int ExtLen,
|
||||
const VoidPtr Extension) {
|
||||
|
||||
GifByteType Buf;
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
if (!IS_WRITEABLE(Private)) {
|
||||
/* This file was NOT open for writing: */
|
||||
_GifError = E_GIF_ERR_NOT_WRITEABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
/* If we are given an extension sub-block output it now. */
|
||||
if (ExtLen > 0) {
|
||||
Buf = ExtLen;
|
||||
WRITE(GifFile, &Buf, 1);
|
||||
WRITE(GifFile, Extension, ExtLen);
|
||||
}
|
||||
|
||||
/* Write the block terminator */
|
||||
Buf = 0;
|
||||
WRITE(GifFile, &Buf, 1);
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Put an extension block (see GIF manual) into gif file.
|
||||
* Warning: This function is only useful for Extension blocks that have at
|
||||
* most one subblock. Extensions with more than one subblock need to use the
|
||||
* EGifPutExtension{First,Next,Last} functions instead.
|
||||
*****************************************************************************/
|
||||
int
|
||||
EGifPutExtension(GifFileType * GifFile,
|
||||
int ExtCode,
|
||||
int ExtLen,
|
||||
const VoidPtr Extension) {
|
||||
|
||||
GifByteType Buf[3];
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
if (!IS_WRITEABLE(Private)) {
|
||||
/* This file was NOT open for writing: */
|
||||
_GifError = E_GIF_ERR_NOT_WRITEABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
if (ExtCode == 0)
|
||||
WRITE(GifFile, (GifByteType *)&ExtLen, 1);
|
||||
else {
|
||||
Buf[0] = '!'; /* Extension Introducer 0x21 */
|
||||
Buf[1] = ExtCode; /* Extension Label */
|
||||
Buf[2] = ExtLen; /* Extension length */
|
||||
WRITE(GifFile, Buf, ExtCode==0xff ? 2 : 3);
|
||||
}
|
||||
WRITE(GifFile, Extension, ExtLen);
|
||||
Buf[0] = 0;
|
||||
WRITE(GifFile, Buf, 1);
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Put the image code in compressed form. This routine can be called if the
|
||||
* information needed to be piped out as is. Obviously this is much faster
|
||||
* than decoding and encoding again. This routine should be followed by calls
|
||||
* to EGifPutCodeNext, until NULL block is given.
|
||||
* The block should NOT be freed by the user (not dynamically allocated).
|
||||
*****************************************************************************/
|
||||
int
|
||||
EGifPutCode(GifFileType * GifFile,
|
||||
int CodeSize,
|
||||
const GifByteType * CodeBlock) {
|
||||
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
if (!IS_WRITEABLE(Private)) {
|
||||
/* This file was NOT open for writing: */
|
||||
_GifError = E_GIF_ERR_NOT_WRITEABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
/* No need to dump code size as Compression set up does any for us: */
|
||||
/*
|
||||
* Buf = CodeSize;
|
||||
* if (WRITE(GifFile, &Buf, 1) != 1) {
|
||||
* _GifError = E_GIF_ERR_WRITE_FAILED;
|
||||
* return GIF_ERROR;
|
||||
* }
|
||||
*/
|
||||
|
||||
return EGifPutCodeNext(GifFile, CodeBlock);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Continue to put the image code in compressed form. This routine should be
|
||||
* called with blocks of code as read via DGifGetCode/DGifGetCodeNext. If
|
||||
* given buffer pointer is NULL, empty block is written to mark end of code.
|
||||
*****************************************************************************/
|
||||
int
|
||||
EGifPutCodeNext(GifFileType * GifFile,
|
||||
const GifByteType * CodeBlock) {
|
||||
|
||||
GifByteType Buf;
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
|
||||
|
||||
if (CodeBlock != NULL) {
|
||||
if (WRITE(GifFile, CodeBlock, CodeBlock[0] + 1)
|
||||
!= (unsigned)(CodeBlock[0] + 1)) {
|
||||
_GifError = E_GIF_ERR_WRITE_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
} else {
|
||||
Buf = 0;
|
||||
if (WRITE(GifFile, &Buf, 1) != 1) {
|
||||
_GifError = E_GIF_ERR_WRITE_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
Private->PixelCount = 0; /* And local info. indicate image read. */
|
||||
}
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* This routine should be called last, to close GIF file.
|
||||
*****************************************************************************/
|
||||
int
|
||||
EGifCloseFile(GifFileType * GifFile) {
|
||||
|
||||
GifByteType Buf;
|
||||
GifFilePrivateType *Private;
|
||||
FILE *File;
|
||||
|
||||
if (GifFile == NULL)
|
||||
return GIF_ERROR;
|
||||
|
||||
Private = (GifFilePrivateType *) GifFile->Private;
|
||||
if (!IS_WRITEABLE(Private)) {
|
||||
/* This file was NOT open for writing: */
|
||||
_GifError = E_GIF_ERR_NOT_WRITEABLE;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
File = Private->File;
|
||||
|
||||
Buf = ';';
|
||||
WRITE(GifFile, &Buf, 1);
|
||||
|
||||
if (GifFile->Image.ColorMap) {
|
||||
FreeMapObject(GifFile->Image.ColorMap);
|
||||
GifFile->Image.ColorMap = NULL;
|
||||
}
|
||||
if (GifFile->SColorMap) {
|
||||
FreeMapObject(GifFile->SColorMap);
|
||||
GifFile->SColorMap = NULL;
|
||||
}
|
||||
if (Private) {
|
||||
if (Private->HashTable) {
|
||||
free((char *) Private->HashTable);
|
||||
}
|
||||
free((char *) Private);
|
||||
}
|
||||
free(GifFile);
|
||||
|
||||
if (File && fclose(File) != 0) {
|
||||
_GifError = E_GIF_ERR_CLOSE_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Put 2 bytes (word) into the given file:
|
||||
*****************************************************************************/
|
||||
static int
|
||||
EGifPutWord(int Word,
|
||||
GifFileType * GifFile) {
|
||||
|
||||
unsigned char c[2];
|
||||
|
||||
c[0] = Word & 0xff;
|
||||
c[1] = (Word >> 8) & 0xff;
|
||||
#ifndef DEBUG_NO_PREFIX
|
||||
if (WRITE(GifFile, c, 2) == 2)
|
||||
return GIF_OK;
|
||||
else
|
||||
return GIF_ERROR;
|
||||
#else
|
||||
return GIF_OK;
|
||||
#endif /* DEBUG_NO_PREFIX */
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Setup the LZ compression for this image:
|
||||
*****************************************************************************/
|
||||
static int
|
||||
EGifSetupCompress(GifFileType * GifFile) {
|
||||
|
||||
int BitsPerPixel;
|
||||
GifByteType Buf;
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
|
||||
|
||||
/* Test and see what color map to use, and from it # bits per pixel: */
|
||||
if (GifFile->Image.ColorMap)
|
||||
BitsPerPixel = GifFile->Image.ColorMap->BitsPerPixel;
|
||||
else if (GifFile->SColorMap)
|
||||
BitsPerPixel = GifFile->SColorMap->BitsPerPixel;
|
||||
else {
|
||||
_GifError = E_GIF_ERR_NO_COLOR_MAP;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
|
||||
Buf = BitsPerPixel = (BitsPerPixel < 2 ? 2 : BitsPerPixel);
|
||||
WRITE(GifFile, &Buf, 1); /* Write the Code size to file. */
|
||||
|
||||
Private->Buf[0] = 0; /* Nothing was output yet. */
|
||||
Private->BitsPerPixel = BitsPerPixel;
|
||||
Private->ClearCode = (1 << BitsPerPixel);
|
||||
Private->EOFCode = Private->ClearCode + 1;
|
||||
Private->RunningCode = Private->EOFCode + 1;
|
||||
Private->RunningBits = BitsPerPixel + 1; /* Number of bits per code. */
|
||||
Private->MaxCode1 = 1 << Private->RunningBits; /* Max. code + 1. */
|
||||
Private->CrntCode = FIRST_CODE; /* Signal that this is first one! */
|
||||
Private->CrntShiftState = 0; /* No information in CrntShiftDWord. */
|
||||
Private->CrntShiftDWord = 0;
|
||||
|
||||
/* Clear hash table and send Clear to make sure the decoder do the same. */
|
||||
_ClearHashTable(Private->HashTable);
|
||||
|
||||
if (EGifCompressOutput(GifFile, Private->ClearCode) == GIF_ERROR) {
|
||||
_GifError = E_GIF_ERR_DISK_IS_FULL;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* The LZ compression routine:
|
||||
* This version compresses the given buffer Line of length LineLen.
|
||||
* This routine can be called a few times (one per scan line, for example), in
|
||||
* order to complete the whole image.
|
||||
******************************************************************************/
|
||||
static int
|
||||
EGifCompressLine(GifFileType * GifFile,
|
||||
GifPixelType * Line,
|
||||
int LineLen) {
|
||||
|
||||
int i = 0, CrntCode, NewCode;
|
||||
unsigned long NewKey;
|
||||
GifPixelType Pixel;
|
||||
GifHashTableType *HashTable;
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
|
||||
|
||||
HashTable = Private->HashTable;
|
||||
|
||||
if (Private->CrntCode == FIRST_CODE) /* Its first time! */
|
||||
CrntCode = Line[i++];
|
||||
else
|
||||
CrntCode = Private->CrntCode; /* Get last code in compression. */
|
||||
|
||||
while (i < LineLen) { /* Decode LineLen items. */
|
||||
Pixel = Line[i++]; /* Get next pixel from stream. */
|
||||
/* Form a new unique key to search hash table for the code combines
|
||||
* CrntCode as Prefix string with Pixel as postfix char.
|
||||
*/
|
||||
NewKey = (((UINT32) CrntCode) << 8) + Pixel;
|
||||
if ((NewCode = _ExistsHashTable(HashTable, NewKey)) >= 0) {
|
||||
/* This Key is already there, or the string is old one, so
|
||||
* simple take new code as our CrntCode:
|
||||
*/
|
||||
CrntCode = NewCode;
|
||||
} else {
|
||||
/* Put it in hash table, output the prefix code, and make our
|
||||
* CrntCode equal to Pixel.
|
||||
*/
|
||||
if (EGifCompressOutput(GifFile, CrntCode) == GIF_ERROR) {
|
||||
_GifError = E_GIF_ERR_DISK_IS_FULL;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
CrntCode = Pixel;
|
||||
|
||||
/* If however the HashTable if full, we send a clear first and
|
||||
* Clear the hash table.
|
||||
*/
|
||||
if (Private->RunningCode >= LZ_MAX_CODE) {
|
||||
/* Time to do some clearance: */
|
||||
if (EGifCompressOutput(GifFile, Private->ClearCode)
|
||||
== GIF_ERROR) {
|
||||
_GifError = E_GIF_ERR_DISK_IS_FULL;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
Private->RunningCode = Private->EOFCode + 1;
|
||||
Private->RunningBits = Private->BitsPerPixel + 1;
|
||||
Private->MaxCode1 = 1 << Private->RunningBits;
|
||||
_ClearHashTable(HashTable);
|
||||
} else {
|
||||
/* Put this unique key with its relative Code in hash table: */
|
||||
_InsertHashTable(HashTable, NewKey, Private->RunningCode++);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Preserve the current state of the compression algorithm: */
|
||||
Private->CrntCode = CrntCode;
|
||||
|
||||
if (Private->PixelCount == 0) {
|
||||
/* We are done - output last Code and flush output buffers: */
|
||||
if (EGifCompressOutput(GifFile, CrntCode) == GIF_ERROR) {
|
||||
_GifError = E_GIF_ERR_DISK_IS_FULL;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
if (EGifCompressOutput(GifFile, Private->EOFCode) == GIF_ERROR) {
|
||||
_GifError = E_GIF_ERR_DISK_IS_FULL;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
if (EGifCompressOutput(GifFile, FLUSH_OUTPUT) == GIF_ERROR) {
|
||||
_GifError = E_GIF_ERR_DISK_IS_FULL;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* The LZ compression output routine:
|
||||
* This routine is responsible for the compression of the bit stream into
|
||||
* 8 bits (bytes) packets.
|
||||
* Returns GIF_OK if written succesfully.
|
||||
*****************************************************************************/
|
||||
static int
|
||||
EGifCompressOutput(GifFileType * GifFile,
|
||||
int Code) {
|
||||
|
||||
GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
|
||||
int retval = GIF_OK;
|
||||
|
||||
if (Code == FLUSH_OUTPUT) {
|
||||
while (Private->CrntShiftState > 0) {
|
||||
/* Get Rid of what is left in DWord, and flush it. */
|
||||
if (EGifBufferedOutput(GifFile, Private->Buf,
|
||||
Private->CrntShiftDWord & 0xff) == GIF_ERROR)
|
||||
retval = GIF_ERROR;
|
||||
Private->CrntShiftDWord >>= 8;
|
||||
Private->CrntShiftState -= 8;
|
||||
}
|
||||
Private->CrntShiftState = 0; /* For next time. */
|
||||
if (EGifBufferedOutput(GifFile, Private->Buf,
|
||||
FLUSH_OUTPUT) == GIF_ERROR)
|
||||
retval = GIF_ERROR;
|
||||
} else {
|
||||
Private->CrntShiftDWord |= ((long)Code) << Private->CrntShiftState;
|
||||
Private->CrntShiftState += Private->RunningBits;
|
||||
while (Private->CrntShiftState >= 8) {
|
||||
/* Dump out full bytes: */
|
||||
if (EGifBufferedOutput(GifFile, Private->Buf,
|
||||
Private->CrntShiftDWord & 0xff) == GIF_ERROR)
|
||||
retval = GIF_ERROR;
|
||||
Private->CrntShiftDWord >>= 8;
|
||||
Private->CrntShiftState -= 8;
|
||||
}
|
||||
}
|
||||
|
||||
/* If code cannt fit into RunningBits bits, must raise its size. Note */
|
||||
/* however that codes above 4095 are used for special signaling. */
|
||||
if (Private->RunningCode >= Private->MaxCode1 && Code <= 4095) {
|
||||
Private->MaxCode1 = 1 << ++Private->RunningBits;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* This routines buffers the given characters until 255 characters are ready
|
||||
* to be output. If Code is equal to -1 the buffer is flushed (EOF).
|
||||
* The buffer is Dumped with first byte as its size, as GIF format requires.
|
||||
* Returns GIF_OK if written succesfully.
|
||||
*****************************************************************************/
|
||||
static int
|
||||
EGifBufferedOutput(GifFileType * GifFile,
|
||||
GifByteType * Buf,
|
||||
int c) {
|
||||
|
||||
if (c == FLUSH_OUTPUT) {
|
||||
/* Flush everything out. */
|
||||
if (Buf[0] != 0
|
||||
&& WRITE(GifFile, Buf, Buf[0] + 1) != (unsigned)(Buf[0] + 1)) {
|
||||
_GifError = E_GIF_ERR_WRITE_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
/* Mark end of compressed data, by an empty block (see GIF doc): */
|
||||
Buf[0] = 0;
|
||||
if (WRITE(GifFile, Buf, 1) != 1) {
|
||||
_GifError = E_GIF_ERR_WRITE_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
} else {
|
||||
if (Buf[0] == 255) {
|
||||
/* Dump out this buffer - it is full: */
|
||||
if (WRITE(GifFile, Buf, Buf[0] + 1) != (unsigned)(Buf[0] + 1)) {
|
||||
_GifError = E_GIF_ERR_WRITE_FAILED;
|
||||
return GIF_ERROR;
|
||||
}
|
||||
Buf[0] = 0;
|
||||
}
|
||||
Buf[++Buf[0]] = c;
|
||||
}
|
||||
|
||||
return GIF_OK;
|
||||
}
|
||||
152
oversampling/WDL/giflib/gif_hash.c
Normal file
152
oversampling/WDL/giflib/gif_hash.c
Normal file
@@ -0,0 +1,152 @@
|
||||
/*****************************************************************************
|
||||
* "Gif-Lib" - Yet another gif library. *
|
||||
* *
|
||||
* Written by: Gershon Elber IBM PC Ver 0.1, Jun. 1989 *
|
||||
******************************************************************************
|
||||
* Module to support the following operations: *
|
||||
* *
|
||||
* 1. InitHashTable - initialize hash table. *
|
||||
* 2. ClearHashTable - clear the hash table to an empty state. *
|
||||
* 2. InsertHashTable - insert one item into data structure. *
|
||||
* 3. ExistsHashTable - test if item exists in data structure. *
|
||||
* *
|
||||
* This module is used to hash the GIF codes during encoding. *
|
||||
******************************************************************************
|
||||
* History: *
|
||||
* 14 Jun 89 - Version 1.0 by Gershon Elber. *
|
||||
*****************************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
/* Find a thirty-two bit int type */
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#ifdef __MSDOS__
|
||||
#include <io.h>
|
||||
#include <alloc.h>
|
||||
#include <sys\stat.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#endif /* __MSDOS__ */
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif /* HAVE_FCNTL_H */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "gif_lib.h"
|
||||
#include "gif_hash.h"
|
||||
#include "gif_lib_private.h"
|
||||
|
||||
/* #define DEBUG_HIT_RATE Debug number of misses per hash Insert/Exists. */
|
||||
|
||||
#ifdef DEBUG_HIT_RATE
|
||||
static long NumberOfTests = 0,
|
||||
NumberOfMisses = 0;
|
||||
#endif /* DEBUG_HIT_RATE */
|
||||
|
||||
static int KeyItem(UINT32 Item);
|
||||
|
||||
/******************************************************************************
|
||||
* Initialize HashTable - allocate the memory needed and clear it. *
|
||||
******************************************************************************/
|
||||
GifHashTableType *_InitHashTable(void)
|
||||
{
|
||||
GifHashTableType *HashTable;
|
||||
|
||||
if ((HashTable = (GifHashTableType *) malloc(sizeof(GifHashTableType)))
|
||||
== NULL)
|
||||
return NULL;
|
||||
|
||||
_ClearHashTable(HashTable);
|
||||
|
||||
return HashTable;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Routine to clear the HashTable to an empty state. *
|
||||
* This part is a little machine depended. Use the commented part otherwise. *
|
||||
******************************************************************************/
|
||||
void _ClearHashTable(GifHashTableType *HashTable)
|
||||
{
|
||||
memset(HashTable -> HTable, 0xFF, HT_SIZE * sizeof(UINT32));
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Routine to insert a new Item into the HashTable. The data is assumed to be *
|
||||
* new one. *
|
||||
******************************************************************************/
|
||||
void _InsertHashTable(GifHashTableType *HashTable, UINT32 Key, int Code)
|
||||
{
|
||||
int HKey = KeyItem(Key);
|
||||
UINT32 *HTable = HashTable -> HTable;
|
||||
|
||||
#ifdef DEBUG_HIT_RATE
|
||||
NumberOfTests++;
|
||||
NumberOfMisses++;
|
||||
#endif /* DEBUG_HIT_RATE */
|
||||
|
||||
while (HT_GET_KEY(HTable[HKey]) != 0xFFFFFL) {
|
||||
#ifdef DEBUG_HIT_RATE
|
||||
NumberOfMisses++;
|
||||
#endif /* DEBUG_HIT_RATE */
|
||||
HKey = (HKey + 1) & HT_KEY_MASK;
|
||||
}
|
||||
HTable[HKey] = HT_PUT_KEY(Key) | HT_PUT_CODE(Code);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Routine to test if given Key exists in HashTable and if so returns its code *
|
||||
* Returns the Code if key was found, -1 if not. *
|
||||
******************************************************************************/
|
||||
int _ExistsHashTable(GifHashTableType *HashTable, UINT32 Key)
|
||||
{
|
||||
int HKey = KeyItem(Key);
|
||||
UINT32 *HTable = HashTable -> HTable, HTKey;
|
||||
|
||||
#ifdef DEBUG_HIT_RATE
|
||||
NumberOfTests++;
|
||||
NumberOfMisses++;
|
||||
#endif /* DEBUG_HIT_RATE */
|
||||
|
||||
while ((HTKey = HT_GET_KEY(HTable[HKey])) != 0xFFFFFL) {
|
||||
#ifdef DEBUG_HIT_RATE
|
||||
NumberOfMisses++;
|
||||
#endif /* DEBUG_HIT_RATE */
|
||||
if (Key == HTKey) return HT_GET_CODE(HTable[HKey]);
|
||||
HKey = (HKey + 1) & HT_KEY_MASK;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Routine to generate an HKey for the hashtable out of the given unique key. *
|
||||
* The given Key is assumed to be 20 bits as follows: lower 8 bits are the *
|
||||
* new postfix character, while the upper 12 bits are the prefix code. *
|
||||
* Because the average hit ratio is only 2 (2 hash references per entry), *
|
||||
* evaluating more complex keys (such as twin prime keys) does not worth it! *
|
||||
******************************************************************************/
|
||||
static int KeyItem(UINT32 Item)
|
||||
{
|
||||
return ((Item >> 12) ^ Item) & HT_KEY_MASK;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_HIT_RATE
|
||||
/******************************************************************************
|
||||
* Debugging routine to print the hit ratio - number of times the hash table *
|
||||
* was tested per operation. This routine was used to test the KeyItem routine *
|
||||
******************************************************************************/
|
||||
void HashTablePrintHitRatio(void)
|
||||
{
|
||||
printf("Hash Table Hit Ratio is %ld/%ld = %ld%%.\n",
|
||||
NumberOfMisses, NumberOfTests,
|
||||
NumberOfMisses * 100 / NumberOfTests);
|
||||
}
|
||||
#endif /* DEBUG_HIT_RATE */
|
||||
50
oversampling/WDL/giflib/gif_hash.h
Normal file
50
oversampling/WDL/giflib/gif_hash.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/******************************************************************************
|
||||
* Declarations, global to other of the GIF-HASH.C module. *
|
||||
* *
|
||||
* Written by Gershon Elber, Jun 1989 *
|
||||
*******************************************************************************
|
||||
* History: *
|
||||
* 14 Jun 89 - Version 1.0 by Gershon Elber. *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _GIF_HASH_H_
|
||||
#define _GIF_HASH_H_
|
||||
|
||||
#include "config.h"
|
||||
|
||||
/* Find a thirty-two bit int type */
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#ifdef HAVE_BASETSD_H
|
||||
#include <basetsd.h>
|
||||
#endif
|
||||
|
||||
#define HT_SIZE 8192 /* 12bits = 4096 or twice as big! */
|
||||
#define HT_KEY_MASK 0x1FFF /* 13bits keys */
|
||||
#define HT_KEY_NUM_BITS 13 /* 13bits keys */
|
||||
#define HT_MAX_KEY 8191 /* 13bits - 1, maximal code possible */
|
||||
#define HT_MAX_CODE 4095 /* Biggest code possible in 12 bits. */
|
||||
|
||||
/* The 32 bits of the long are divided into two parts for the key & code: */
|
||||
/* 1. The code is 12 bits as our compression algorithm is limited to 12bits */
|
||||
/* 2. The key is 12 bits Prefix code + 8 bit new char or 20 bits. */
|
||||
/* The key is the upper 20 bits. The code is the lower 12. */
|
||||
#define HT_GET_KEY(l) (l >> 12)
|
||||
#define HT_GET_CODE(l) (l & 0x0FFF)
|
||||
#define HT_PUT_KEY(l) (l << 12)
|
||||
#define HT_PUT_CODE(l) (l & 0x0FFF)
|
||||
|
||||
typedef struct GifHashTableType {
|
||||
UINT32 HTable[HT_SIZE];
|
||||
} GifHashTableType;
|
||||
|
||||
GifHashTableType *_InitHashTable(void);
|
||||
void _ClearHashTable(GifHashTableType *HashTable);
|
||||
void _InsertHashTable(GifHashTableType *HashTable, UINT32 Key, int Code);
|
||||
int _ExistsHashTable(GifHashTableType *HashTable, UINT32 Key);
|
||||
|
||||
#endif /* _GIF_HASH_H_ */
|
||||
277
oversampling/WDL/giflib/gif_lib.h
Normal file
277
oversampling/WDL/giflib/gif_lib.h
Normal file
@@ -0,0 +1,277 @@
|
||||
/******************************************************************************
|
||||
* In order to make life a little bit easier when using the GIF file format,
|
||||
* this library was written, and which does all the dirty work...
|
||||
*
|
||||
* Written by Gershon Elber, Jun. 1989
|
||||
* Hacks by Eric S. Raymond, Sep. 1992
|
||||
******************************************************************************
|
||||
* History:
|
||||
* 14 Jun 89 - Version 1.0 by Gershon Elber.
|
||||
* 3 Sep 90 - Version 1.1 by Gershon Elber (Support for Gif89, Unique names)
|
||||
* 15 Sep 90 - Version 2.0 by Eric S. Raymond (Changes to suoport GIF slurp)
|
||||
* 26 Jun 96 - Version 3.0 by Eric S. Raymond (Full GIF89 support)
|
||||
* 17 Dec 98 - Version 4.0 by Toshio Kuratomi (Fix extension writing code)
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef _GIF_LIB_H_
|
||||
#define _GIF_LIB_H_ 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define GIF_LIB_VERSION " Version 4.1, "
|
||||
|
||||
#define GIF_ERROR 0
|
||||
#define GIF_OK 1
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif /* TRUE */
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif /* FALSE */
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif /* NULL */
|
||||
|
||||
#define GIF_STAMP "GIFVER" /* First chars in file - GIF stamp. */
|
||||
#define GIF_STAMP_LEN sizeof(GIF_STAMP) - 1
|
||||
#define GIF_VERSION_POS 3 /* Version first character in stamp. */
|
||||
#define GIF87_STAMP "GIF87a" /* First chars in file - GIF stamp. */
|
||||
#define GIF89_STAMP "GIF89a" /* First chars in file - GIF stamp. */
|
||||
|
||||
#define GIF_FILE_BUFFER_SIZE 16384 /* Files uses bigger buffers than usual. */
|
||||
|
||||
typedef int GifBooleanType;
|
||||
typedef unsigned char GifPixelType;
|
||||
typedef unsigned char *GifRowType;
|
||||
typedef unsigned char GifByteType;
|
||||
#ifdef _GBA_OPTMEM
|
||||
typedef unsigned short GifPrefixType;
|
||||
typedef short GifWord;
|
||||
#else
|
||||
typedef unsigned int GifPrefixType;
|
||||
typedef int GifWord;
|
||||
#endif
|
||||
|
||||
#define GIF_MESSAGE(Msg)
|
||||
#define GIF_EXIT(Msg)
|
||||
|
||||
#ifdef SYSV
|
||||
#define VoidPtr char *
|
||||
#else
|
||||
#define VoidPtr void *
|
||||
#endif /* SYSV */
|
||||
|
||||
typedef struct GifColorType {
|
||||
GifByteType Red, Green, Blue;
|
||||
} GifColorType;
|
||||
|
||||
typedef struct ColorMapObject {
|
||||
int ColorCount;
|
||||
int BitsPerPixel;
|
||||
GifColorType *Colors; /* on malloc(3) heap */
|
||||
} ColorMapObject;
|
||||
|
||||
typedef struct GifImageDesc {
|
||||
GifWord Left, Top, Width, Height, /* Current image dimensions. */
|
||||
Interlace; /* Sequential/Interlaced lines. */
|
||||
ColorMapObject *ColorMap; /* The local color map */
|
||||
} GifImageDesc;
|
||||
|
||||
typedef struct GifFileType {
|
||||
GifWord SWidth, SHeight, /* Screen dimensions. */
|
||||
SColorResolution, /* How many colors can we generate? */
|
||||
SBackGroundColor; /* I hope you understand this one... */
|
||||
ColorMapObject *SColorMap; /* NULL if not exists. */
|
||||
int ImageCount; /* Number of current image */
|
||||
GifImageDesc Image; /* Block describing current image */
|
||||
VoidPtr UserData; /* hook to attach user data (TVT) */
|
||||
VoidPtr Private; /* Don't mess with this! */
|
||||
} GifFileType;
|
||||
|
||||
typedef enum {
|
||||
UNDEFINED_RECORD_TYPE,
|
||||
SCREEN_DESC_RECORD_TYPE,
|
||||
IMAGE_DESC_RECORD_TYPE, /* Begin with ',' */
|
||||
EXTENSION_RECORD_TYPE, /* Begin with '!' */
|
||||
TERMINATE_RECORD_TYPE /* Begin with ';' */
|
||||
} GifRecordType;
|
||||
|
||||
/* DumpScreen2Gif routine constants identify type of window/screen to dump.
|
||||
* Note all values below 1000 are reserved for the IBMPC different display
|
||||
* devices (it has many!) and are compatible with the numbering TC2.0
|
||||
* (Turbo C 2.0 compiler for IBM PC) gives to these devices.
|
||||
*/
|
||||
typedef enum {
|
||||
GIF_DUMP_SGI_WINDOW = 1000,
|
||||
GIF_DUMP_X_WINDOW = 1001
|
||||
} GifScreenDumpType;
|
||||
|
||||
/* func type to read gif data from arbitrary sources (TVT) */
|
||||
typedef int (*InputFunc) (GifFileType *, GifByteType *, int);
|
||||
|
||||
/* func type to write gif data ro arbitrary targets.
|
||||
* Returns count of bytes written. (MRB)
|
||||
*/
|
||||
typedef int (*OutputFunc) (GifFileType *, const GifByteType *, int);
|
||||
|
||||
/******************************************************************************
|
||||
* GIF89 extension function codes
|
||||
******************************************************************************/
|
||||
|
||||
#define COMMENT_EXT_FUNC_CODE 0xfe /* comment */
|
||||
#define GRAPHICS_EXT_FUNC_CODE 0xf9 /* graphics control */
|
||||
#define PLAINTEXT_EXT_FUNC_CODE 0x01 /* plaintext */
|
||||
#define APPLICATION_EXT_FUNC_CODE 0xff /* application block */
|
||||
|
||||
/******************************************************************************
|
||||
* O.K., here are the routines one can access in order to encode GIF file:
|
||||
* (GIF_LIB file EGIF_LIB.C).
|
||||
******************************************************************************/
|
||||
|
||||
GifFileType *EGifOpenFileName(const char *GifFileName,
|
||||
int GifTestExistance);
|
||||
GifFileType *EGifOpenFileHandle(int GifFileHandle);
|
||||
GifFileType *EGifOpen(void *userPtr, OutputFunc writeFunc);
|
||||
|
||||
int EGifSpew(GifFileType * GifFile);
|
||||
void EGifSetGifVersion(const char *Version);
|
||||
int EGifPutScreenDesc(GifFileType * GifFile,
|
||||
int GifWidth, int GifHeight, int GifColorRes,
|
||||
int GifBackGround,
|
||||
const ColorMapObject * GifColorMap);
|
||||
int EGifPutImageDesc(GifFileType * GifFile, int GifLeft, int GifTop,
|
||||
int Width, int GifHeight, int GifInterlace,
|
||||
const ColorMapObject * GifColorMap);
|
||||
int EGifPutLine(GifFileType * GifFile, GifPixelType * GifLine,
|
||||
int GifLineLen);
|
||||
int EGifPutPixel(GifFileType * GifFile, GifPixelType GifPixel);
|
||||
int EGifPutComment(GifFileType * GifFile, const char *GifComment);
|
||||
int EGifPutExtensionFirst(GifFileType * GifFile, int GifExtCode,
|
||||
int GifExtLen, const VoidPtr GifExtension);
|
||||
int EGifPutExtensionNext(GifFileType * GifFile, int GifExtCode,
|
||||
int GifExtLen, const VoidPtr GifExtension);
|
||||
int EGifPutExtensionLast(GifFileType * GifFile, int GifExtCode,
|
||||
int GifExtLen, const VoidPtr GifExtension);
|
||||
int EGifPutExtension(GifFileType * GifFile, int GifExtCode, int GifExtLen,
|
||||
const VoidPtr GifExtension);
|
||||
int EGifPutCode(GifFileType * GifFile, int GifCodeSize,
|
||||
const GifByteType * GifCodeBlock);
|
||||
int EGifPutCodeNext(GifFileType * GifFile,
|
||||
const GifByteType * GifCodeBlock);
|
||||
int EGifCloseFile(GifFileType * GifFile);
|
||||
|
||||
#define E_GIF_ERR_OPEN_FAILED 1 /* And EGif possible errors. */
|
||||
#define E_GIF_ERR_WRITE_FAILED 2
|
||||
#define E_GIF_ERR_HAS_SCRN_DSCR 3
|
||||
#define E_GIF_ERR_HAS_IMAG_DSCR 4
|
||||
#define E_GIF_ERR_NO_COLOR_MAP 5
|
||||
#define E_GIF_ERR_DATA_TOO_BIG 6
|
||||
#define E_GIF_ERR_NOT_ENOUGH_MEM 7
|
||||
#define E_GIF_ERR_DISK_IS_FULL 8
|
||||
#define E_GIF_ERR_CLOSE_FAILED 9
|
||||
#define E_GIF_ERR_NOT_WRITEABLE 10
|
||||
|
||||
/******************************************************************************
|
||||
* O.K., here are the routines one can access in order to decode GIF file:
|
||||
* (GIF_LIB file DGIF_LIB.C).
|
||||
*****************************************************************************/
|
||||
#ifndef _GBA_NO_FILEIO
|
||||
GifFileType *DGifOpenFileName(const char *GifFileName);
|
||||
GifFileType *DGifOpenFileHandle(int GifFileHandle);
|
||||
int DGifSlurp(GifFileType * GifFile);
|
||||
#endif /* _GBA_NO_FILEIO */
|
||||
GifFileType *DGifOpen(void *userPtr, InputFunc readFunc); /* new one
|
||||
* (TVT) */
|
||||
int DGifGetScreenDesc(GifFileType * GifFile);
|
||||
int DGifGetRecordType(GifFileType * GifFile, GifRecordType * GifType);
|
||||
int DGifGetImageDesc(GifFileType * GifFile);
|
||||
int DGifGetLine(GifFileType * GifFile, GifPixelType * GifLine, int GifLineLen);
|
||||
int DGifGetPixel(GifFileType * GifFile, GifPixelType GifPixel);
|
||||
int DGifGetComment(GifFileType * GifFile, char *GifComment);
|
||||
int DGifGetExtension(GifFileType * GifFile, int *GifExtCode,
|
||||
GifByteType ** GifExtension);
|
||||
int DGifGetExtensionNext(GifFileType * GifFile, GifByteType ** GifExtension);
|
||||
int DGifGetCode(GifFileType * GifFile, int *GifCodeSize,
|
||||
GifByteType ** GifCodeBlock);
|
||||
int DGifGetCodeNext(GifFileType * GifFile, GifByteType ** GifCodeBlock);
|
||||
int DGifGetLZCodes(GifFileType * GifFile, int *GifCode);
|
||||
int DGifCloseFile(GifFileType * GifFile);
|
||||
|
||||
#define D_GIF_ERR_OPEN_FAILED 101 /* And DGif possible errors. */
|
||||
#define D_GIF_ERR_READ_FAILED 102
|
||||
#define D_GIF_ERR_NOT_GIF_FILE 103
|
||||
#define D_GIF_ERR_NO_SCRN_DSCR 104
|
||||
#define D_GIF_ERR_NO_IMAG_DSCR 105
|
||||
#define D_GIF_ERR_NO_COLOR_MAP 106
|
||||
#define D_GIF_ERR_WRONG_RECORD 107
|
||||
#define D_GIF_ERR_DATA_TOO_BIG 108
|
||||
#define D_GIF_ERR_NOT_ENOUGH_MEM 109
|
||||
#define D_GIF_ERR_CLOSE_FAILED 110
|
||||
#define D_GIF_ERR_NOT_READABLE 111
|
||||
#define D_GIF_ERR_IMAGE_DEFECT 112
|
||||
#define D_GIF_ERR_EOF_TOO_SOON 113
|
||||
|
||||
/******************************************************************************
|
||||
* O.K., here are the routines from GIF_LIB file QUANTIZE.C.
|
||||
******************************************************************************/
|
||||
int QuantizeBuffer(unsigned int Width, unsigned int Height,
|
||||
int *ColorMapSize, GifByteType * RedInput,
|
||||
GifByteType * GreenInput, GifByteType * BlueInput,
|
||||
GifByteType * OutputBuffer,
|
||||
GifColorType * OutputColorMap);
|
||||
|
||||
/******************************************************************************
|
||||
* O.K., here are the routines from GIF_LIB file QPRINTF.C.
|
||||
******************************************************************************/
|
||||
extern int GifQuietPrint;
|
||||
|
||||
#ifdef HAVE_STDARG_H
|
||||
extern void GifQprintf(char *Format, ...);
|
||||
#elif defined (HAVE_VARARGS_H)
|
||||
extern void GifQprintf();
|
||||
#endif /* HAVE_STDARG_H */
|
||||
|
||||
/******************************************************************************
|
||||
* O.K., here are the routines from GIF_LIB file GIF_ERR.C.
|
||||
******************************************************************************/
|
||||
#ifndef _GBA_NO_FILEIO
|
||||
extern void PrintGifError(void);
|
||||
#endif /* _GBA_NO_FILEIO */
|
||||
extern int GifLastError(void);
|
||||
|
||||
/******************************************************************************
|
||||
* O.K., here are the routines from GIF_LIB file DEV2GIF.C.
|
||||
******************************************************************************/
|
||||
extern int DumpScreen2Gif(const char *FileName,
|
||||
int ReqGraphDriver,
|
||||
long ReqGraphMode1,
|
||||
long ReqGraphMode2,
|
||||
long ReqGraphMode3);
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Everything below this point is new after version 1.2, supporting `slurp
|
||||
* mode' for doing I/O in two big belts with all the image-bashing in core.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Color Map handling from ALLOCGIF.C
|
||||
*****************************************************************************/
|
||||
|
||||
extern ColorMapObject *MakeMapObject(int ColorCount,
|
||||
const GifColorType * ColorMap);
|
||||
extern void FreeMapObject(ColorMapObject * Object);
|
||||
extern ColorMapObject *UnionColorMap(const ColorMapObject * ColorIn1,
|
||||
const ColorMapObject * ColorIn2,
|
||||
GifPixelType ColorTransIn2[]);
|
||||
extern int BitSize(int n);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* _GIF_LIB_H */
|
||||
59
oversampling/WDL/giflib/gif_lib_private.h
Normal file
59
oversampling/WDL/giflib/gif_lib_private.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef _GIF_LIB_PRIVATE_H
|
||||
#define _GIF_LIB_PRIVATE_H
|
||||
|
||||
#include "gif_lib.h"
|
||||
#include "gif_hash.h"
|
||||
|
||||
#define PROGRAM_NAME "GIFLIB"
|
||||
|
||||
#ifdef SYSV
|
||||
#define VersionStr "Gif library module,\t\tEric S. Raymond\n\
|
||||
(C) Copyright 1997 Eric S. Raymond\n"
|
||||
#else
|
||||
#define VersionStr PROGRAM_NAME " IBMPC " GIF_LIB_VERSION \
|
||||
" Eric S. Raymond, " __DATE__ ", " \
|
||||
__TIME__ "\n" "(C) Copyright 1997 Eric S. Raymond\n"
|
||||
#endif /* SYSV */
|
||||
|
||||
#define LZ_MAX_CODE 4095 /* Biggest code possible in 12 bits. */
|
||||
#define LZ_BITS 12
|
||||
|
||||
#define FLUSH_OUTPUT 4096 /* Impossible code, to signal flush. */
|
||||
#define FIRST_CODE 4097 /* Impossible code, to signal first. */
|
||||
#define NO_SUCH_CODE 4098 /* Impossible code, to signal empty. */
|
||||
|
||||
#define FILE_STATE_WRITE 0x01
|
||||
#define FILE_STATE_SCREEN 0x02
|
||||
#define FILE_STATE_IMAGE 0x04
|
||||
#define FILE_STATE_READ 0x08
|
||||
|
||||
#define IS_READABLE(Private) (Private->FileState & FILE_STATE_READ)
|
||||
#define IS_WRITEABLE(Private) (Private->FileState & FILE_STATE_WRITE)
|
||||
|
||||
typedef struct GifFilePrivateType {
|
||||
GifWord FileState, FileHandle, /* Where all this data goes to! */
|
||||
BitsPerPixel, /* Bits per pixel (Codes uses at least this + 1). */
|
||||
ClearCode, /* The CLEAR LZ code. */
|
||||
EOFCode, /* The EOF LZ code. */
|
||||
RunningCode, /* The next code algorithm can generate. */
|
||||
RunningBits, /* The number of bits required to represent RunningCode. */
|
||||
MaxCode1, /* 1 bigger than max. possible code, in RunningBits bits. */
|
||||
LastCode, /* The code before the current code. */
|
||||
CrntCode, /* Current algorithm code. */
|
||||
StackPtr, /* For character stack (see below). */
|
||||
CrntShiftState; /* Number of bits in CrntShiftDWord. */
|
||||
unsigned long CrntShiftDWord; /* For bytes decomposition into codes. */
|
||||
unsigned long PixelCount; /* Number of pixels in image. */
|
||||
FILE *File; /* File as stream. */
|
||||
InputFunc Read; /* function to read gif input (TVT) */
|
||||
OutputFunc Write; /* function to write gif output (MRB) */
|
||||
GifByteType Buf[256]; /* Compressed input is buffered here. */
|
||||
GifByteType Stack[LZ_MAX_CODE]; /* Decoded pixels are stacked here. */
|
||||
GifByteType Suffix[LZ_MAX_CODE + 1]; /* So we can trace the codes. */
|
||||
GifPrefixType Prefix[LZ_MAX_CODE + 1];
|
||||
GifHashTableType *HashTable;
|
||||
} GifFilePrivateType;
|
||||
|
||||
extern int _GifError;
|
||||
|
||||
#endif /* _GIF_LIB_PRIVATE_H */
|
||||
212
oversampling/WDL/giflib/gifalloc.c
Normal file
212
oversampling/WDL/giflib/gifalloc.c
Normal file
@@ -0,0 +1,212 @@
|
||||
/*****************************************************************************
|
||||
* "Gif-Lib" - Yet another gif library.
|
||||
*
|
||||
* Written by: Gershon Elber Ver 0.1, Jun. 1989
|
||||
* Extensively hacked by: Eric S. Raymond Ver 1.?, Sep 1992
|
||||
*****************************************************************************
|
||||
* GIF construction tools
|
||||
*****************************************************************************
|
||||
* History:
|
||||
* 15 Sep 92 - Version 1.0 by Eric Raymond.
|
||||
****************************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "gif_lib.h"
|
||||
|
||||
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||
|
||||
/******************************************************************************
|
||||
* Miscellaneous utility functions
|
||||
*****************************************************************************/
|
||||
|
||||
/* return smallest bitfield size n will fit in */
|
||||
int
|
||||
BitSize(int n) {
|
||||
|
||||
register int i;
|
||||
|
||||
for (i = 1; i <= 8; i++)
|
||||
if ((1 << i) >= n)
|
||||
break;
|
||||
return (i);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Color map object functions
|
||||
*****************************************************************************/
|
||||
|
||||
/*
|
||||
* Allocate a color map of given size; initialize with contents of
|
||||
* ColorMap if that pointer is non-NULL.
|
||||
*/
|
||||
ColorMapObject *
|
||||
MakeMapObject(int ColorCount,
|
||||
const GifColorType * ColorMap) {
|
||||
|
||||
ColorMapObject *Object;
|
||||
|
||||
/*** FIXME: Our ColorCount has to be a power of two. Is it necessary to
|
||||
* make the user know that or should we automatically round up instead? */
|
||||
if (ColorCount != (1 << BitSize(ColorCount))) {
|
||||
return ((ColorMapObject *) NULL);
|
||||
}
|
||||
|
||||
Object = (ColorMapObject *)malloc(sizeof(ColorMapObject));
|
||||
if (Object == (ColorMapObject *) NULL) {
|
||||
return ((ColorMapObject *) NULL);
|
||||
}
|
||||
|
||||
Object->Colors = (GifColorType *)calloc(ColorCount, sizeof(GifColorType));
|
||||
if (Object->Colors == (GifColorType *) NULL) {
|
||||
return ((ColorMapObject *) NULL);
|
||||
}
|
||||
|
||||
Object->ColorCount = ColorCount;
|
||||
Object->BitsPerPixel = BitSize(ColorCount);
|
||||
|
||||
if (ColorMap) {
|
||||
memcpy((char *)Object->Colors,
|
||||
(char *)ColorMap, ColorCount * sizeof(GifColorType));
|
||||
}
|
||||
|
||||
return (Object);
|
||||
}
|
||||
|
||||
/*
|
||||
* Free a color map object
|
||||
*/
|
||||
void
|
||||
FreeMapObject(ColorMapObject * Object) {
|
||||
|
||||
if (Object != NULL) {
|
||||
free(Object->Colors);
|
||||
free(Object);
|
||||
/*** FIXME:
|
||||
* When we are willing to break API we need to make this function
|
||||
* FreeMapObject(ColorMapObject **Object)
|
||||
* and do this assignment to NULL here:
|
||||
* *Object = NULL;
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
void
|
||||
DumpColorMap(ColorMapObject * Object,
|
||||
FILE * fp) {
|
||||
|
||||
if (Object) {
|
||||
int i, j, Len = Object->ColorCount;
|
||||
|
||||
for (i = 0; i < Len; i += 4) {
|
||||
for (j = 0; j < 4 && j < Len; j++) {
|
||||
fprintf(fp, "%3d: %02x %02x %02x ", i + j,
|
||||
Object->Colors[i + j].Red,
|
||||
Object->Colors[i + j].Green,
|
||||
Object->Colors[i + j].Blue);
|
||||
}
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* DEBUG */
|
||||
|
||||
/*
|
||||
* Compute the union of two given color maps and return it. If result can't
|
||||
* fit into 256 colors, NULL is returned, the allocated union otherwise.
|
||||
* ColorIn1 is copied as is to ColorUnion, while colors from ColorIn2 are
|
||||
* copied iff they didn't exist before. ColorTransIn2 maps the old
|
||||
* ColorIn2 into ColorUnion color map table.
|
||||
*/
|
||||
ColorMapObject *
|
||||
UnionColorMap(const ColorMapObject * ColorIn1,
|
||||
const ColorMapObject * ColorIn2,
|
||||
GifPixelType ColorTransIn2[]) {
|
||||
|
||||
int i, j, CrntSlot, RoundUpTo, NewBitSize;
|
||||
ColorMapObject *ColorUnion;
|
||||
|
||||
/*
|
||||
* Allocate table which will hold the result for sure.
|
||||
*/
|
||||
ColorUnion = MakeMapObject(MAX(ColorIn1->ColorCount,
|
||||
ColorIn2->ColorCount) * 2, NULL);
|
||||
|
||||
if (ColorUnion == NULL)
|
||||
return (NULL);
|
||||
|
||||
/* Copy ColorIn1 to ColorUnionSize; */
|
||||
/*** FIXME: What if there are duplicate entries into the colormap to begin
|
||||
* with? */
|
||||
for (i = 0; i < ColorIn1->ColorCount; i++)
|
||||
ColorUnion->Colors[i] = ColorIn1->Colors[i];
|
||||
CrntSlot = ColorIn1->ColorCount;
|
||||
|
||||
/*
|
||||
* Potentially obnoxious hack:
|
||||
*
|
||||
* Back CrntSlot down past all contiguous {0, 0, 0} slots at the end
|
||||
* of table 1. This is very useful if your display is limited to
|
||||
* 16 colors.
|
||||
*/
|
||||
while (ColorIn1->Colors[CrntSlot - 1].Red == 0
|
||||
&& ColorIn1->Colors[CrntSlot - 1].Green == 0
|
||||
&& ColorIn1->Colors[CrntSlot - 1].Blue == 0)
|
||||
CrntSlot--;
|
||||
|
||||
/* Copy ColorIn2 to ColorUnionSize (use old colors if they exist): */
|
||||
for (i = 0; i < ColorIn2->ColorCount && CrntSlot <= 256; i++) {
|
||||
/* Let's see if this color already exists: */
|
||||
/*** FIXME: Will it ever occur that ColorIn2 will contain duplicate
|
||||
* entries? So we should search from 0 to CrntSlot rather than
|
||||
* ColorIn1->ColorCount?
|
||||
*/
|
||||
for (j = 0; j < ColorIn1->ColorCount; j++)
|
||||
if (memcmp (&ColorIn1->Colors[j], &ColorIn2->Colors[i],
|
||||
sizeof(GifColorType)) == 0)
|
||||
break;
|
||||
|
||||
if (j < ColorIn1->ColorCount)
|
||||
ColorTransIn2[i] = j; /* color exists in Color1 */
|
||||
else {
|
||||
/* Color is new - copy it to a new slot: */
|
||||
ColorUnion->Colors[CrntSlot] = ColorIn2->Colors[i];
|
||||
ColorTransIn2[i] = CrntSlot++;
|
||||
}
|
||||
}
|
||||
|
||||
if (CrntSlot > 256) {
|
||||
FreeMapObject(ColorUnion);
|
||||
return ((ColorMapObject *) NULL);
|
||||
}
|
||||
|
||||
NewBitSize = BitSize(CrntSlot);
|
||||
RoundUpTo = (1 << NewBitSize);
|
||||
|
||||
if (RoundUpTo != ColorUnion->ColorCount) {
|
||||
register GifColorType *Map = ColorUnion->Colors;
|
||||
|
||||
/*
|
||||
* Zero out slots up to next power of 2.
|
||||
* We know these slots exist because of the way ColorUnion's
|
||||
* start dimension was computed.
|
||||
*/
|
||||
for (j = CrntSlot; j < RoundUpTo; j++)
|
||||
Map[j].Red = Map[j].Green = Map[j].Blue = 0;
|
||||
|
||||
/* perhaps we can shrink the map? */
|
||||
if (RoundUpTo < ColorUnion->ColorCount)
|
||||
ColorUnion->Colors = (GifColorType *)realloc(Map,
|
||||
sizeof(GifColorType) * RoundUpTo);
|
||||
}
|
||||
|
||||
ColorUnion->ColorCount = RoundUpTo;
|
||||
ColorUnion->BitsPerPixel = NewBitSize;
|
||||
|
||||
return (ColorUnion);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user