Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 79bc75f52b702b2b6fe920e7ef19e9a1562f5be6 @lantus committed Oct 21, 2011
178 CHANGES
@@ -0,0 +1,178 @@
+1.2.10:
+Sam Lantinga - Sat Nov 14 11:22:14 PST 2009
+ * Fixed bug loading multiple images
+
+1.2.9:
+Sam Lantinga - Tue Nov 10 00:29:20 PST 2009
+ * Fixed alpha premultiplication on Mac OS X and iPhone OS
+Sam Lantinga - Sun Nov 8 07:52:11 PST 2009
+ * Fixed checking for IMG_Init() return value in image loaders
+
+1.2.8:
+Sam Lantinga - Sun Oct 4 13:12:54 PDT 2009
+ * Added support for uncompressed PCX files
+Mason Wheeler - 2009-06-10 06:29:45 PDT
+ * Added IMG_Init()/IMG_Quit() to prevent constantly loading and unloading DLLs
+Couriersud - Mon, 12 Jan 2009 17:21:13 -0800
+ * Added support for ICO and CUR image files
+Eric Wing - Fri, 2 Jan 2009 02:01:16 -0800
+ * Added ImageIO loading infrastructure for Mac OS X
+ * Added UIImage loading infrastructure for iPhone / iPod Touch
+
+1.2.7:
+Sam Lantinga - Sun Nov 2 15:08:27 PST 2008
+ * Fixed buffer overflow in BMP loading code, discovered by j00ru//vx
+Sam Lantinga - Fri Dec 28 08:34:54 PST 2007
+ * Fixed buffer overflow in GIF loading code, discovered by Michael Skladnikiewicz
+
+1.2.6:
+Sam lantinga - Wed Jul 18 00:30:32 PDT 2007
+ * Improved detection of libjpeg, libpng, and libtiff at configure time
+ * PNG and TIFF images are correctly identified even if dynamic libraries
+ to load them aren't available.
+ * Fixed loading of TIFF images using libtiff 3.6
+Sam Lantinga - Thu Jul 5 07:52:35 2007
+ * Fixed static linking with libjpeg
+Michael Koch - Tue Feb 13 10:09:17 2007
+ * Fixed crash in IMG_ReadXPMFromArray()
+
+1.2.5:
+Maurizio Monge - Sun May 14 13:57:32 PDT 2006
+ * Fixed loading BMP palettes at unusual offsets
+Sam Lantinga - Thu May 11 21:51:19 PDT 2006
+ * Added support for dynamically loading libjpeg, libpng, and libtiff.
+Sam Lantinga - Sun Apr 30 01:48:40 PDT 2006
+ * Added gcc-fat.sh for generating Universal binaries on Mac OS X
+ * Updated libtool support to version 1.5.22
+Sam Lantinga - Sat Feb 4 15:17:44 PST 2006
+ * Added support for XV thumbnail images
+Gautier Portet - Fri, 19 Mar 2004 17:35:12 +0100
+ * Added support for 32-bit BMP files with alpha
+
+1.2.4:
+Pierre G. Richard - Fri, 30 Jul 2004 11:13:11 +0000 (UTC)
+ * Added support for RLE encoded BMP files
+Marc Le Douarain - Fri, 26 Dec 2003 18:23:42 +0100
+ * Added EHB and HAM mode support to the ILBM loader
+Sam Lantinga - Wed Nov 19 00:23:44 PST 2003
+ * Updated libtool support for new mingw32 DLL build process
+Holger Schemel - Mon, 04 Aug 2003 21:50:52 +0200
+ * Fixed crash loading certain PCX images
+Kyle Davenport - Sat, 19 Apr 2003 17:13:31 -0500
+ * Added .la files to the development RPM, fixing RPM build on RedHat 8
+
+1.2.3:
+Ryan C. Gordon - Sat, 8 Feb 2003 09:36:33 -0500
+ * Fixed memory leak with non-seekable SDL_RWops
+Marc Le Douarain - Sun, 22 Dec 2002 22:59:51 +0100
+ * Added 24-bit support to the ILBM format loader
+Sam Lantinga - Sun Oct 20 20:55:46 PDT 2002
+ * Added shared library support for MacOS X
+Pete Shinners - Thu Jun 20 10:05:54 PDT 2002
+ * The JPEG loader can now load EXIF format JPEG images
+Dag-Erling Smorgrav - Thu May 2 19:09:48 PDT 2002
+ * The XCF loader now ignores invisible layers and channels
+
+1.2.2:
+Sam Lantinga - Sat Apr 13 07:49:47 PDT 2002
+ * Updated autogen.sh for new versions of automake
+ * Specify the SDL API calling convention (C by default)
+Mattias Engdeg�rd - Fri Dec 28 17:54:31 PST 2001
+ * Worked around exit() in the jpeg image library
+
+1.2.1:
+Mattias Engdeg�rd - Tue Nov 20 08:08:53 PST 2001
+ * Fixed transparency in the GIF loading code
+Daniel Morais - Sun Sep 23 16:32:13 PDT 2001
+ * Added support for the IFF (LBM) image format
+Sam Lantinga - Sun Aug 19 01:51:44 PDT 2001
+ * Added Project Builder projects for building MacOS X framework
+Mattias Engdeg�rd - Tue Jul 31 04:32:29 PDT 2001
+ * Fixed transparency in 8-bit PNG files
+Mattias Engdeg�rd - Sat Apr 28 11:30:22 PDT 2001
+ * Added support for loading XPM image data directly
+Paul Jenner - Sat, 14 Apr 2001 09:20:38 -0700 (PDT)
+ * Added support for building RPM directly from tar archive
+
+1.2.0:
+Sam Lantinga - Wed Apr 4 12:42:20 PDT 2001
+ * Synchronized release version with SDL 1.2.0
+
+1.1.1:
+Berni - Wed Mar 7 09:18:02 PST 2001
+ * Added initial GIMP XCF support (disabled by default)
+Mattias Engdeg�rd - Wed Mar 7 09:01:49 PST 2001
+ * Added general PNM (PPM/PGM/PBM) support
+Mattias Engdeg�rd - Sun Mar 4 14:23:42 PST 2001
+ * Fixed bugs in PPM support, added ASCII PPM support
+Mattias Engdeg�rd - Fri Mar 2 14:48:09 PST 2001
+ * Cleaned up some compiler warnings
+Mattias Engdeg�rd - Tue Feb 27 12:44:43 PST 2001
+ * Improved the PCX loading code
+ * Modified showimage to set hardware palette for 8-bit displays
+Robert Stein - Thu, 22 Feb 2001 14:26:19 -0600
+ * Improved the PPM loading code
+Sam Lantinga - Tue Jan 30 14:24:06 PST 2001
+ * Modified showimage to accept multiple images on the command line
+Sam Lantinga - Mon Dec 18 02:49:29 PST 2000
+ * Added a Visual C++ project including JPEG and PNG loading support
+Mattias Engdeg�rd - Wed Dec 6 10:00:07 PST 2000
+ * Improved the XPM loading code
+
+1.1.0:
+Sam Lantinga - Wed Nov 29 00:46:27 PST 2000
+ * Added XPM file format support
+ Supports color, greyscale, and mono XPMs with and without transparency
+Mattias Engdeg�rd - Thu, 2 Nov 2000 23:23:17 +0100 (MET)
+ * Fixed array overrun when loading an unsupported format
+ * Minor compilation fixes for various platforms
+
+1.0.10:
+Mattias Engdeg�rd - Wed Aug 9 20:32:22 MET DST 2000
+ * Removed the alpha flipping, made IMG_InvertAlpha() a noop
+ * Fixed nonexisting PCX alpha support
+ * Some TIFF bugfixes
+ * PNG greyscale images are loaded as 8bpp with a greyscale palette
+Ray Kelm - Fri, 04 Aug 2000 20:58:00 -0400
+ * Added support for cross-compiling Windows DLL from Linux
+
+1.0.9:
+Mattias Engdeg�rd - Sat Jul 1 17:57:37 PDT 2000
+ * PNG loader properly sets the colorkey on 8-bit transparent images
+Mattias Engdeg�rd - Sat Jul 1 13:24:47 PDT 2000
+ * Fixed a bug in PCX detection
+ * Added support for TGA files
+ * showimage shows a checker background for transparent images
+
+1.0.8:
+Mark Baker - Tue May 30 12:20:00 PDT 2000
+ * Added TIFF format loading support
+
+1.0.7:
+Mattias Engdeg�rd - Sat May 27 14:18:33 PDT 2000
+ * Added fixes for loading images on big-endian systems
+
+1.0.6:
+Sam Lantinga - Sat Apr 29 10:18:32 PDT 2000
+ * showimage puts the name of the image in the title bar caption
+Sam Lantinga - Sat Apr 29 10:05:58 PDT 2000
+ * Removed pitch check, since PNG already loads to a list of row pointers
+
+1.0.5:
+Sam Lantinga - Sun Apr 23 14:41:32 PDT 2000
+ * Added support for GIF transparency
+Sam Lantinga - Wed Apr 12 14:39:20 PDT 2000
+ * Fixed memory heap crash on NT using PNG images
+Matt Campbell - Thu, 13 Apr 2000 13:29:17 -0700
+ * Fixed PNG detection on some Linux systems
+
+1.0.4:
+Sam Lantinga - Tue Feb 1 13:33:53 PST 2000
+ * Cleaned up for Visual C++
+ * Added Visual C++ project file
+
+1.0.3:
+Sam Lantinga - Wed Jan 19 22:10:52 PST 2000
+ * Added CHANGES
+ * Added rpm spec file contributed by Hakan Tandogan
+ * Changed the name of the example program from "show" to "showimage"
458 COPYING
@@ -0,0 +1,458 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
153 Demo/Makefile
@@ -0,0 +1,153 @@
+#---------------------------------------------------------------------------------
+# Clear the implicit built in rules
+#---------------------------------------------------------------------------------
+.SUFFIXES:
+#---------------------------------------------------------------------------------
+ifeq ($(strip $(DEVKITXENON)),)
+$(error "Please set DEVKITXENON in your environment. export DEVKITXENON=<path to>devkitPPC")
+endif
+
+include $(DEVKITXENON)/rules
+
+#---------------------------------------------------------------------------------
+# TARGET is the name of the output
+# BUILD is the directory where object files & intermediate files will be placed
+# SOURCES is a list of directories containing source code
+# INCLUDES is a list of directories containing extra header files
+#---------------------------------------------------------------------------------
+TARGET := $(notdir $(CURDIR))
+BUILD := build
+SOURCES := src
+DATA := data
+INCLUDES := include
+SDLINC := /usr/local/xenon/usr/include/SDL/
+
+#---------------------------------------------------------------------------------
+# options for code generation
+#---------------------------------------------------------------------------------
+
+CFLAGS = -ffunction-sections -fdata-sections -g -O2 -Wall $(MACHDEP) $(INCLUDE)
+CXXFLAGS = $(CFLAGS)
+
+LDFLAGS = -g $(MACHDEP) -Wl,--gc-sections -Wl,-Map,$(notdir $@).map
+
+#---------------------------------------------------------------------------------
+# any extra libraries we wish to link with the project
+#---------------------------------------------------------------------------------
+LIBS := -lSDL_image -lSDL -lxenon -lpng -lm -lz
+
+#---------------------------------------------------------------------------------
+# list of directories containing libraries, this must be the top level containing
+# include and lib
+#---------------------------------------------------------------------------------
+LIBDIRS := libs
+
+#---------------------------------------------------------------------------------
+# no real need to edit anything past this point unless you need to add additional
+# rules for different file extensions
+#---------------------------------------------------------------------------------
+ifneq ($(BUILD),$(notdir $(CURDIR)))
+#---------------------------------------------------------------------------------
+
+export OUTPUT := $(CURDIR)/$(TARGET)
+
+export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
+ $(foreach dir,$(DATA),$(CURDIR)/$(dir))
+
+export DEPSDIR := $(CURDIR)/$(BUILD)
+
+#---------------------------------------------------------------------------------
+# automatically build a list of object files for our project
+#---------------------------------------------------------------------------------
+SHADER := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shader)))
+PSUFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.psu)))
+VSUFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.vsu)))
+BINFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.bin)))
+PNGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.png)))
+ABCFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.abc)))
+CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
+CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
+sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
+SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
+BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
+
+#---------------------------------------------------------------------------------
+# use CXX for linking C++ projects, CC for standard C
+#---------------------------------------------------------------------------------
+ifeq ($(strip $(CPPFILES)),)
+ export LD := $(CC)
+else
+ export LD := $(CXX)
+endif
+
+export OFILES := $(addsuffix .o,$(BINFILES)) \
+ $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
+ $(sFILES:.s=.o) $(SFILES:.S=.o)
+
+#---------------------------------------------------------------------------------
+# build a list of include paths
+#---------------------------------------------------------------------------------
+export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
+ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
+ -I$(CURDIR)/$(BUILD) \
+ -I$(LIBXENON_INC) \
+ -I$(SDLINC)
+
+#---------------------------------------------------------------------------------
+# build a list of library paths
+#---------------------------------------------------------------------------------
+export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
+ -L$(LIBXENON_LIB)
+
+export OUTPUT := $(CURDIR)/$(TARGET)
+.PHONY: $(BUILD) clean
+
+#---------------------------------------------------------------------------------
+$(BUILD):
+ @[ -d $@ ] || mkdir -p $@
+ @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
+
+#---------------------------------------------------------------------------------
+clean:
+ @echo clean ...
+ @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).elf32
+
+#---------------------------------------------------------------------------------
+else
+
+DEPENDS := $(OFILES:.o=.d)
+
+#---------------------------------------------------------------------------------
+# main targets
+#---------------------------------------------------------------------------------
+$(OUTPUT).elf32: $(OUTPUT).elf
+$(OUTPUT).elf: $(OFILES)
+
+-include $(DEPENDS)
+%.vsu.o : %.vsu
+ @echo $(notdir $<)
+ @$(bin2o)
+%.psu.o : %.psu
+ @echo $(notdir $<)
+ @$(bin2o)
+%.shader.o : %.shader
+ @echo $(notdir $<)
+ @$(bin2o)
+%.bin.o : %.bin
+ @echo $(notdir $<)
+ @$(bin2o)
+%.png.o : %.png
+ @echo $(notdir $<)
+ @$(bin2o)
+%.abc.o : %.abc
+ @echo $(notdir $<)
+ @$(bin2o)
+#---------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------
+
+
+run: $(BUILD) $(OUTPUT).elf32
+ cp $(OUTPUT).elf32 xenon.elf
+ cp xenon.elf /var/lib/tftpboot/tftpboot/xenon
+ $(PREFIX)strip /var/lib/tftpboot/tftpboot/xenon
229 Demo/src/showimage.c
@@ -0,0 +1,229 @@
+/*
+ showimage: A test application for the SDL image loading library.
+ Copyright (C) 1997-2009 Sam Lantinga
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+ Sam Lantinga
+ slouken@libsdl.org
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <SDL.h>
+#include <SDL_image.h>
+
+#include <xetypes.h>
+#include <xenos/xe.h>
+#include <xenos/xenos.h>
+#include <xenos/edram.h>
+#include <xenos/xenos.h>
+#include <usb/usbmain.h>
+#include <console/console.h>
+#include <xenon_smc/xenon_smc.h>
+#include <xenon_soc/xenon_power.h>
+
+/* #define XPM_INCLUDED and supply picture.xpm to test the XPM inclusion
+ feature */
+
+
+
+/* Draw a Gimpish background pattern to show transparency in the image */
+static void draw_background(SDL_Surface *screen)
+{
+ Uint8 *dst = screen->pixels;
+ int x, y;
+ int bpp = screen->format->BytesPerPixel;
+ Uint32 col[2];
+ col[0] = SDL_MapRGB(screen->format, 0x66, 0x66, 0x66);
+ col[1] = SDL_MapRGB(screen->format, 0x99, 0x99, 0x99);
+ for(y = 0; y < screen->h; y++) {
+ for(x = 0; x < screen->w; x++) {
+ /* use an 8x8 checkerboard pattern */
+ Uint32 c = col[((x ^ y) >> 3) & 1];
+ switch(bpp) {
+ case 1:
+ dst[x] = (Uint8)c;
+ break;
+ case 2:
+ ((Uint16 *)dst)[x] = (Uint16)c;
+ break;
+ case 3:
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+ dst[x * 3] = (Uint8)(c);
+ dst[x * 3 + 1] = (Uint8)(c >> 8);
+ dst[x * 3 + 2] = (Uint8)(c >> 16);
+#else
+ dst[x * 3] = (Uint8)(c >> 16);
+ dst[x * 3 + 1] = (Uint8)(c >> 8);
+ dst[x * 3 + 2] = (Uint8)(c);
+#endif
+ break;
+ case 4:
+ ((Uint32 *)dst)[x] = c;
+ break;
+ }
+ }
+ dst += screen->pitch;
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ Uint32 flags;
+ SDL_Surface *screen, *image;
+ int i, depth, done;
+ SDL_Event event;
+#if 0
+ SDL_RWops* rw_ops;
+#endif
+
+ xenon_make_it_faster(XENON_SPEED_FULL);
+ xenos_init(VIDEO_MODE_AUTO);
+ xenon_sound_init();
+ console_init();
+ usb_init();
+ usb_do_poll();
+
+ /* Initialize the SDL library */
+ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ return(255);
+ }
+
+ flags = SDL_SWSURFACE;
+
+ SDL_ShowCursor(0);
+ flags |= SDL_FULLSCREEN;
+#if 0
+ rw_ops = SDL_RWFromFile(argv[1], "r");
+
+ fprintf(stderr, "BMP:\t%d\n", IMG_isBMP(rw_ops));
+ fprintf(stderr, "GIF:\t%d\n", IMG_isGIF(rw_ops));
+ fprintf(stderr, "JPG:\t%d\n", IMG_isJPG(rw_ops));
+ fprintf(stderr, "PNG:\t%d\n", IMG_isPNG(rw_ops));
+ fprintf(stderr, "TIF:\t%d\n", IMG_isTIF(rw_ops));
+ /* fprintf(stderr, "TGA:\t%d\n", IMG_isTGA(rw_ops)); */
+ fprintf(stderr, "PCX:\t%d\n", IMG_isPCX(rw_ops));
+#endif
+
+ /* Open the image file */
+
+ printf("About to load IMG\n");
+
+ image = IMG_Load("uda:/8bit.png");
+
+ if ( image == NULL ) {
+ fprintf(stderr, "Couldn't load : %s\n",
+ SDL_GetError());
+ return 0;
+ }
+
+ /* Create a display for the image */
+ depth = SDL_VideoModeOK(image->w, image->h, 32, flags);
+
+ printf("SDL_VideoModeOK depth = %d\n", depth);
+
+ /* Use the deepest native mode, except that we emulate 32bpp
+ for viewing non-indexed images on 8bpp screens */
+ if ( depth == 0 ) {
+ if ( image->format->BytesPerPixel > 1 ) {
+ depth = 32;
+ } else {
+ depth = 8;
+ }
+ } else
+ if ( (image->format->BytesPerPixel > 1) && (depth == 8) ) {
+ depth = 32;
+ }
+ if(depth == 8)
+ flags |= SDL_HWPALETTE;
+ screen = SDL_SetVideoMode(image->w, image->h, depth, flags);
+ if ( screen == NULL ) {
+ fprintf(stderr,"Couldn't set %dx%dx%d video mode: %s\n",
+ image->w, image->h, depth, SDL_GetError());
+ return 0;
+ }
+
+ printf("SDL_SetVideoMode depth = %d\n", depth);
+
+ /* Set the palette, if one exists */
+ if ( image->format->palette ) {
+ printf("Setting palette\n");
+ SDL_SetColors(screen, image->format->palette->colors,
+ 0, image->format->palette->ncolors);
+ }
+
+ /* Draw a background pattern if the surface has transparency */
+
+ if(image->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY))
+ draw_background(screen);
+
+ /* Display the image */
+ SDL_BlitSurface(image, NULL, screen, NULL);
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
+
+ done = 0;
+ while ( ! done ) {
+ if ( SDL_PollEvent(&event) ) {
+ switch (event.type) {
+ case SDL_KEYUP:
+ switch (event.key.keysym.sym) {
+ case SDLK_LEFT:
+ if ( i > 1 ) {
+ i -= 2;
+ done = 1;
+ }
+ break;
+ case SDLK_RIGHT:
+ if ( argv[i+1] ) {
+ done = 1;
+ }
+ break;
+ case SDLK_ESCAPE:
+ case SDLK_q:
+ argv[i+1] = NULL;
+ /* Drop through to done */
+ case SDLK_SPACE:
+ case SDLK_TAB:
+ done = 1;
+ break;
+ default:
+ break;
+ }
+ break;
+ case SDL_MOUSEBUTTONDOWN:
+ done = 1;
+ break;
+ case SDL_QUIT:
+ argv[i+1] = NULL;
+ done = 1;
+ break;
+ default:
+ break;
+ }
+ } else {
+ SDL_Delay(10);
+ }
+ }
+ SDL_FreeSurface(image);
+
+
+ /* We're done! */
+ SDL_Quit();
+ return(0);
+}
201 IMG.c
@@ -0,0 +1,201 @@
+/*
+ SDL_image: An example image loading library for use with SDL
+ Copyright (C) 1997-2009 Sam Lantinga
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+ Sam Lantinga
+ slouken@libsdl.org
+*/
+
+/* A simple library to load images of various formats as SDL surfaces */
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "SDL_image.h"
+
+#define ARRAYSIZE(a) (sizeof(a) / sizeof((a)[0]))
+
+/* Table of image detection and loading functions */
+static struct {
+ char *type;
+ int (SDLCALL *is)(SDL_RWops *src);
+ SDL_Surface *(SDLCALL *load)(SDL_RWops *src);
+} supported[] = {
+ /* keep magicless formats first */
+ { "TGA", NULL, IMG_LoadTGA_RW },
+ { "CUR", IMG_isCUR, IMG_LoadCUR_RW },
+ { "ICO", IMG_isICO, IMG_LoadICO_RW },
+ { "BMP", IMG_isBMP, IMG_LoadBMP_RW },
+ { "GIF", IMG_isGIF, IMG_LoadGIF_RW },
+ { "JPG", IMG_isJPG, IMG_LoadJPG_RW },
+ { "LBM", IMG_isLBM, IMG_LoadLBM_RW },
+ { "PCX", IMG_isPCX, IMG_LoadPCX_RW },
+ { "PNG", IMG_isPNG, IMG_LoadPNG_RW },
+ { "PNM", IMG_isPNM, IMG_LoadPNM_RW }, /* P[BGP]M share code */
+ { "TIF", IMG_isTIF, IMG_LoadTIF_RW },
+ { "XCF", IMG_isXCF, IMG_LoadXCF_RW },
+ { "XPM", IMG_isXPM, IMG_LoadXPM_RW },
+ { "XV", IMG_isXV, IMG_LoadXV_RW }
+};
+
+const SDL_version *IMG_Linked_Version(void)
+{
+ static SDL_version linked_version;
+ SDL_IMAGE_VERSION(&linked_version);
+ return(&linked_version);
+}
+
+extern int IMG_InitJPG();
+extern void IMG_QuitJPG();
+extern int IMG_InitPNG();
+extern void IMG_QuitPNG();
+extern int IMG_InitTIF();
+extern void IMG_QuitTIF();
+
+static int initialized = 0;
+
+int IMG_Init(int flags)
+{
+ int result = 0;
+
+ if (flags & IMG_INIT_JPG) {
+ if ((initialized & IMG_INIT_JPG) || IMG_InitJPG() == 0) {
+ result |= IMG_INIT_JPG;
+ }
+ }
+ if (flags & IMG_INIT_PNG) {
+ if ((initialized & IMG_INIT_PNG) || IMG_InitPNG() == 0) {
+ result |= IMG_INIT_PNG;
+ }
+ }
+ if (flags & IMG_INIT_TIF) {
+ if ((initialized & IMG_INIT_TIF) || IMG_InitTIF() == 0) {
+ result |= IMG_INIT_TIF;
+ }
+ }
+ initialized |= result;
+
+ return (result);
+}
+
+void IMG_Quit()
+{
+ if (initialized & IMG_INIT_JPG) {
+ IMG_QuitJPG();
+ }
+ if (initialized & IMG_INIT_PNG) {
+ IMG_QuitPNG();
+ }
+ if (initialized & IMG_INIT_TIF) {
+ IMG_QuitTIF();
+ }
+ initialized = 0;
+}
+
+#if !defined(__APPLE__) || defined(SDL_IMAGE_USE_COMMON_BACKEND)
+/* Load an image from a file */
+SDL_Surface *IMG_Load(const char *file)
+{
+ SDL_RWops *src = SDL_RWFromFile(file, "rb");
+ char *ext = strrchr(file, '.');
+ if(ext) {
+ ext++;
+ }
+ if(!src) {
+ /* The error message has been set in SDL_RWFromFile */
+ return NULL;
+ }
+ return IMG_LoadTyped_RW(src, 1, ext);
+}
+#endif
+
+/* Load an image from an SDL datasource (for compatibility) */
+SDL_Surface *IMG_Load_RW(SDL_RWops *src, int freesrc)
+{
+ return IMG_LoadTyped_RW(src, freesrc, NULL);
+}
+
+/* Portable case-insensitive string compare function */
+static int IMG_string_equals(const char *str1, const char *str2)
+{
+ while ( *str1 && *str2 ) {
+ if ( toupper((unsigned char)*str1) !=
+ toupper((unsigned char)*str2) )
+ break;
+ ++str1;
+ ++str2;
+ }
+ return (!*str1 && !*str2);
+}
+
+/* Load an image from an SDL datasource, optionally specifying the type */
+SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type)
+{
+ int i;
+ SDL_Surface *image;
+
+ /* Make sure there is something to do.. */
+ if ( src == NULL ) {
+ IMG_SetError("Passed a NULL data source");
+ return(NULL);
+ }
+
+ /* See whether or not this data source can handle seeking */
+ if ( SDL_RWseek(src, 0, RW_SEEK_CUR) < 0 ) {
+ IMG_SetError("Can't seek in this data source");
+ if(freesrc)
+ SDL_RWclose(src);
+ return(NULL);
+ }
+
+ /* Detect the type of image being loaded */
+ image = NULL;
+ for ( i=0; i < ARRAYSIZE(supported); ++i ) {
+ if(supported[i].is) {
+ if(!supported[i].is(src))
+ continue;
+ } else {
+ /* magicless format */
+ if(!type
+ || !IMG_string_equals(type, supported[i].type))
+ continue;
+ }
+#ifdef DEBUG_IMGLIB
+ fprintf(stderr, "IMGLIB: Loading image as %s\n",
+ supported[i].type);
+#endif
+ image = supported[i].load(src);
+ if(freesrc)
+ SDL_RWclose(src);
+ return image;
+ }
+
+ if ( freesrc ) {
+ SDL_RWclose(src);
+ }
+ IMG_SetError("Unsupported image format");
+ return NULL;
+}
+
+/* Invert the alpha of a surface for use with OpenGL
+ This function is a no-op and only kept for backwards compatibility.
+ */
+int IMG_InvertAlpha(int on)
+{
+ return 1;
+}
512 IMG_ImageIO.c
@@ -0,0 +1,512 @@
+/*
+ * IMG_ImageIO.c
+ * SDL_image
+ *
+ * Created by Eric Wing on 1/1/09.
+ * Copyright 2009 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#if defined(__APPLE__) && !defined(SDL_IMAGE_USE_COMMON_BACKEND)
+
+#include "SDL_image.h"
+
+// For ImageIO framework and also LaunchServices framework (for UTIs)
+#include <ApplicationServices/ApplicationServices.h>
+// Used because CGDataProviderCreate became deprecated in 10.5
+#include <AvailabilityMacros.h>
+
+/**************************************************************
+ ***** Begin Callback functions for block reading *************
+ **************************************************************/
+
+// This callback reads some bytes from an SDL_rwops and copies it
+// to a Quartz buffer (supplied by Apple framework).
+static size_t MyProviderGetBytesCallback(void* rwops_userdata, void* quartz_buffer, size_t the_count)
+{
+ return (size_t)SDL_RWread((struct SDL_RWops *)rwops_userdata, quartz_buffer, 1, the_count);
+}
+
+// This callback is triggered when the data provider is released
+// so you can clean up any resources.
+static void MyProviderReleaseInfoCallback(void* rwops_userdata)
+{
+ // What should I put here?
+ // I think the user and SDL_RWops controls closing, so I don't do anything.
+}
+
+static void MyProviderRewindCallback(void* rwops_userdata)
+{
+ SDL_RWseek((struct SDL_RWops *)rwops_userdata, 0, RW_SEEK_SET);
+}
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 // CGDataProviderCreateSequential was introduced in 10.5; CGDataProviderCreate is deprecated
+off_t MyProviderSkipForwardBytesCallback(void* rwops_userdata, off_t the_count)
+{
+ off_t start_position = SDL_RWtell((struct SDL_RWops *)rwops_userdata);
+ SDL_RWseek((struct SDL_RWops *)rwops_userdata, the_count, RW_SEEK_CUR);
+ off_t end_position = SDL_RWtell((struct SDL_RWops *)rwops_userdata);
+ return (end_position - start_position);
+}
+#else // CGDataProviderCreate was deprecated in 10.5
+static void MyProviderSkipBytesCallback(void* rwops_userdata, size_t the_count)
+{
+ SDL_RWseek((struct SDL_RWops *)rwops_userdata, the_count, RW_SEEK_CUR);
+}
+#endif
+
+
+/**************************************************************
+ ***** End Callback functions for block reading ***************
+ **************************************************************/
+
+// This creates a CGImageSourceRef which is a handle to an image that can be used to examine information
+// about the image or load the actual image data.
+static CGImageSourceRef CreateCGImageSourceFromRWops(SDL_RWops* rw_ops, CFDictionaryRef hints_and_options)
+{
+ CGImageSourceRef source_ref;
+
+ // Similar to SDL_RWops, Apple has their own callbacks for dealing with data streams.
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 // CGDataProviderCreateSequential was introduced in 10.5; CGDataProviderCreate is deprecated
+ CGDataProviderSequentialCallbacks provider_callbacks =
+ {
+ 0,
+ MyProviderGetBytesCallback,
+ MyProviderSkipForwardBytesCallback,
+ MyProviderRewindCallback,
+ MyProviderReleaseInfoCallback
+ };
+
+ CGDataProviderRef data_provider = CGDataProviderCreateSequential(rw_ops, &provider_callbacks);
+
+
+#else // CGDataProviderCreate was deprecated in 10.5
+
+ CGDataProviderCallbacks provider_callbacks =
+ {
+ MyProviderGetBytesCallback,
+ MyProviderSkipBytesCallback,
+ MyProviderRewindCallback,
+ MyProviderReleaseInfoCallback
+ };
+
+ CGDataProviderRef data_provider = CGDataProviderCreate(rw_ops, &provider_callbacks);
+#endif
+ // Get the CGImageSourceRef.
+ // The dictionary can be NULL or contain hints to help ImageIO figure out the image type.
+ source_ref = CGImageSourceCreateWithDataProvider(data_provider, hints_and_options);
+ return source_ref;
+}
+
+
+/* Create a CGImageSourceRef from a file. */
+/* Remember to CFRelease the created source when done. */
+static CGImageSourceRef CreateCGImageSourceFromFile(const char* the_path)
+{
+ CFURLRef the_url = NULL;
+ CGImageSourceRef source_ref = NULL;
+ CFStringRef cf_string = NULL;
+
+ /* Create a CFString from a C string */
+ cf_string = CFStringCreateWithCString(
+ NULL,
+ the_path,
+ kCFStringEncodingUTF8
+ );
+ if(!cf_string)
+ {
+ return NULL;
+ }
+
+ /* Create a CFURL from a CFString */
+ the_url = CFURLCreateWithFileSystemPath(
+ NULL,
+ cf_string,
+ kCFURLPOSIXPathStyle,
+ false
+ );
+
+ /* Don't need the CFString any more (error or not) */
+ CFRelease(cf_string);
+
+ if(!the_url)
+ {
+ return NULL;
+ }
+
+
+ source_ref = CGImageSourceCreateWithURL(the_url, NULL);
+ /* Don't need the URL any more (error or not) */
+ CFRelease(the_url);
+
+ return source_ref;
+}
+
+
+
+static CGImageRef CreateCGImageFromCGImageSource(CGImageSourceRef image_source)
+{
+ CGImageRef image_ref = NULL;
+
+ if(NULL == image_source)
+ {
+ return NULL;
+ }
+
+ // Get the first item in the image source (some image formats may
+ // contain multiple items).
+ image_ref = CGImageSourceCreateImageAtIndex(image_source, 0, NULL);
+ return image_ref;
+}
+
+static CFDictionaryRef CreateHintDictionary(CFStringRef uti_string_hint)
+{
+ CFDictionaryRef hint_dictionary = NULL;
+
+ if(uti_string_hint != NULL)
+ {
+ // Do a bunch of work to setup a CFDictionary containing the jpeg compression properties.
+ CFStringRef the_keys[1];
+ CFStringRef the_values[1];
+
+ the_keys[0] = kCGImageSourceTypeIdentifierHint;
+ the_values[0] = uti_string_hint;
+
+ // kCFTypeDictionaryKeyCallBacks or kCFCopyStringDictionaryKeyCallBacks?
+ hint_dictionary = CFDictionaryCreate(NULL, (const void**)&the_keys, (const void**)&the_values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+ }
+ return hint_dictionary;
+}
+
+
+
+
+static int Internal_isType(SDL_RWops* rw_ops, CFStringRef uti_string_to_test)
+{
+ CGImageSourceRef image_source;
+ CFStringRef uti_type;
+ Boolean is_type;
+
+ CFDictionaryRef hint_dictionary = NULL;
+
+ hint_dictionary = CreateHintDictionary(uti_string_to_test);
+ image_source = CreateCGImageSourceFromRWops(rw_ops, hint_dictionary);
+
+ if(hint_dictionary != NULL)
+ {
+ CFRelease(hint_dictionary);
+ }
+
+ if(NULL == image_source)
+ {
+ return 0;
+ }
+
+ // This will get the UTI of the container, not the image itself.
+ // Under most cases, this won't be a problem.
+ // But if a person passes an icon file which contains a bmp,
+ // the format will be of the icon file.
+ // But I think the main SDL_image codebase has this same problem so I'm not going to worry about it.
+ uti_type = CGImageSourceGetType(image_source);
+ // CFShow(uti_type);
+
+ // Unsure if we really want conformance or equality
+ is_type = UTTypeConformsTo(uti_string_to_test, uti_type);
+
+ CFRelease(image_source);
+
+ return (int)is_type;
+}
+
+// Once we have our image, we need to get it into an SDL_Surface
+static SDL_Surface* Create_SDL_Surface_From_CGImage(CGImageRef image_ref)
+{
+ /* This code is adapted from Apple's Documentation found here:
+ * http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/index.html
+ * Listing 9-4††Using a Quartz image as a texture source.
+ * Unfortunately, this guide doesn't show what to do about
+ * non-RGBA image formats so I'm making the rest up.
+ * All this code should be scrutinized.
+ */
+
+ size_t w = CGImageGetWidth(image_ref);
+ size_t h = CGImageGetHeight(image_ref);
+ CGRect rect = {{0, 0}, {w, h}};
+
+ CGImageAlphaInfo alpha = CGImageGetAlphaInfo(image_ref);
+ //size_t bits_per_pixel = CGImageGetBitsPerPixel(image_ref);
+ size_t bits_per_component = 8;
+
+ SDL_Surface* surface;
+ Uint32 Amask;
+ Uint32 Rmask;
+ Uint32 Gmask;
+ Uint32 Bmask;
+
+ CGContextRef bitmap_context;
+ CGBitmapInfo bitmap_info;
+ CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
+
+ if (alpha == kCGImageAlphaNone ||
+ alpha == kCGImageAlphaNoneSkipFirst ||
+ alpha == kCGImageAlphaNoneSkipLast) {
+ bitmap_info = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host; /* XRGB */
+ Amask = 0x00000000;
+ } else {
+ /* kCGImageAlphaFirst isn't supported */
+ //bitmap_info = kCGImageAlphaFirst | kCGBitmapByteOrder32Host; /* ARGB */
+ bitmap_info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host; /* ARGB */
+ Amask = 0xFF000000;
+ }
+
+ Rmask = 0x00FF0000;
+ Gmask = 0x0000FF00;
+ Bmask = 0x000000FF;
+
+ surface = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, Rmask, Gmask, Bmask, Amask);
+ if (surface)
+ {
+ // Sets up a context to be drawn to with surface->pixels as the area to be drawn to
+ bitmap_context = CGBitmapContextCreate(
+ surface->pixels,
+ surface->w,
+ surface->h,
+ bits_per_component,
+ surface->pitch,
+ color_space,
+ bitmap_info
+ );
+
+ // Draws the image into the context's image_data
+ CGContextDrawImage(bitmap_context, rect, image_ref);
+
+ CGContextRelease(bitmap_context);
+
+ // FIXME: Reverse the premultiplied alpha
+ if ((bitmap_info & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedFirst) {
+ int i, j;
+ Uint8 *p = (Uint8 *)surface->pixels;
+ for (i = surface->h * surface->pitch/4; i--; ) {
+#if __LITTLE_ENDIAN__
+ Uint8 A = p[3];
+ if (A) {
+ for (j = 0; j < 3; ++j) {
+ p[j] = (p[j] * 255) / A;
+ }
+ }
+#else
+ Uint8 A = p[0];
+ if (A) {
+ for (j = 1; j < 4; ++j) {
+ p[j] = (p[j] * 255) / A;
+ }
+ }
+#endif /* ENDIAN */
+ p += 4;
+ }
+ }
+ }
+
+ if (color_space)
+ {
+ CGColorSpaceRelease(color_space);
+ }
+
+ return surface;
+}
+
+
+static SDL_Surface* LoadImageFromRWops(SDL_RWops* rw_ops, CFStringRef uti_string_hint)
+{
+ SDL_Surface* sdl_surface;
+ CGImageSourceRef image_source;
+ CGImageRef image_ref = NULL;
+ CFDictionaryRef hint_dictionary = NULL;
+
+ hint_dictionary = CreateHintDictionary(uti_string_hint);
+ image_source = CreateCGImageSourceFromRWops(rw_ops, hint_dictionary);
+
+ if(hint_dictionary != NULL)
+ {
+ CFRelease(hint_dictionary);
+ }
+
+ if(NULL == image_source)
+ {
+ return NULL;
+ }
+
+ image_ref = CreateCGImageFromCGImageSource(image_source);
+ CFRelease(image_source);
+
+ if(NULL == image_ref)
+ {
+ return NULL;
+ }
+
+ sdl_surface = Create_SDL_Surface_From_CGImage(image_ref);
+ CFRelease(image_ref);
+ return sdl_surface;
+
+}
+
+
+
+static SDL_Surface* LoadImageFromFile(const char* file)
+{
+ SDL_Surface* sdl_surface = NULL;
+ CGImageSourceRef image_source = NULL;
+ CGImageRef image_ref = NULL;
+
+ // First ImageIO
+ image_source = CreateCGImageSourceFromFile(file);
+
+ if(NULL == image_source)
+ {
+ return NULL;
+ }
+
+ image_ref = CreateCGImageFromCGImageSource(image_source);
+ CFRelease(image_source);
+
+ if(NULL == image_ref)
+ {
+ return NULL;
+ }
+
+ sdl_surface = Create_SDL_Surface_From_CGImage(image_ref);
+ CFRelease(image_ref);
+ return sdl_surface;
+}
+
+int IMG_InitJPG()
+{
+ return 0;
+}
+
+void IMG_QuitJPG()
+{
+}
+
+int IMG_InitPNG()
+{
+ return 0;
+}
+
+void IMG_QuitPNG()
+{
+}
+
+int IMG_InitTIF()
+{
+ return 0;
+}
+
+void IMG_QuitTIF()
+{
+}
+
+int IMG_isCUR(SDL_RWops *src)
+{
+ /* FIXME: Is this a supported type? */
+ return Internal_isType(src, CFSTR("com.microsoft.cur"));
+}
+
+int IMG_isICO(SDL_RWops *src)
+{
+ return Internal_isType(src, kUTTypeICO);
+}
+
+int IMG_isBMP(SDL_RWops *src)
+{
+ return Internal_isType(src, kUTTypeBMP);
+}
+
+int IMG_isGIF(SDL_RWops *src)
+{
+ return Internal_isType(src, kUTTypeGIF);
+}
+
+// Note: JPEG 2000 is kUTTypeJPEG2000
+int IMG_isJPG(SDL_RWops *src)
+{
+ return Internal_isType(src, kUTTypeJPEG);
+}
+
+int IMG_isPNG(SDL_RWops *src)
+{
+ return Internal_isType(src, kUTTypePNG);
+}
+
+// This isn't a public API function. Apple seems to be able to identify tga's.
+int IMG_isTGA(SDL_RWops *src)
+{
+ return Internal_isType(src, CFSTR("com.truevision.tga-image"));
+}
+
+int IMG_isTIF(SDL_RWops *src)
+{
+ return Internal_isType(src, kUTTypeTIFF);
+}
+
+SDL_Surface* IMG_LoadCUR_RW(SDL_RWops *src)
+{
+ /* FIXME: Is this a supported type? */
+ return LoadImageFromRWops(src, CFSTR("com.microsoft.cur"));
+}
+SDL_Surface* IMG_LoadICO_RW(SDL_RWops *src)
+{
+ return LoadImageFromRWops(src, kUTTypeICO);
+}
+SDL_Surface* IMG_LoadBMP_RW(SDL_RWops *src)
+{
+ return LoadImageFromRWops(src, kUTTypeBMP);
+}
+SDL_Surface* IMG_LoadGIF_RW(SDL_RWops *src)
+{
+ return LoadImageFromRWops(src, kUTTypeGIF);
+}
+SDL_Surface* IMG_LoadJPG_RW(SDL_RWops *src)
+{
+ return LoadImageFromRWops(src, kUTTypeJPEG);
+}
+SDL_Surface* IMG_LoadPNG_RW(SDL_RWops *src)
+{
+ return LoadImageFromRWops(src, kUTTypePNG);
+}
+SDL_Surface* IMG_LoadTGA_RW(SDL_RWops *src)
+{
+ return LoadImageFromRWops(src, CFSTR("com.truevision.tga-image"));
+}
+SDL_Surface* IMG_LoadTIF_RW(SDL_RWops *src)
+{
+ return LoadImageFromRWops(src, kUTTypeTIFF);
+}
+
+// Apple provides both stream and file loading functions in ImageIO.
+// Potentially, Apple can optimize for either case.
+SDL_Surface* IMG_Load(const char *file)
+{
+ SDL_Surface* sdl_surface = NULL;
+
+ sdl_surface = LoadImageFromFile(file);
+ if(NULL == sdl_surface)
+ {
+ // Either the file doesn't exist or ImageIO doesn't understand the format.
+ // For the latter case, fallback to the native SDL_image handlers.
+ SDL_RWops *src = SDL_RWFromFile(file, "rb");
+ char *ext = strrchr(file, '.');
+ if(ext) {
+ ext++;
+ }
+ if(!src) {
+ /* The error message has been set in SDL_RWFromFile */
+ return NULL;
+ }
+ sdl_surface = IMG_LoadTyped_RW(src, 1, ext);
+ }
+ return sdl_surface;
+}
+
+#endif /* defined(__APPLE__) && !defined(SDL_IMAGE_USE_COMMON_BACKEND) */
444 IMG_UIImage.m
@@ -0,0 +1,444 @@
+/*
+ * IMG_ImageIO.c
+ * SDL_image
+ *
+ * Created by Eric Wing on 1/2/09.
+ * Copyright 2009 __MyCompanyName__. All rights reserved.
+ *
+ */
+#include "SDL_image.h"
+#import <UIKit/UIKit.h>
+#import <MobileCoreServices/MobileCoreServices.h> // for UTCoreTypes.h
+
+// Once we have our image, we need to get it into an SDL_Surface
+// (Copied straight from the ImageIO backend.)
+static SDL_Surface* Create_SDL_Surface_From_CGImage(CGImageRef image_ref)
+{
+ /* This code is adapted from Apple's Documentation found here:
+ * http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/index.html
+ * Listing 9-4††Using a Quartz image as a texture source.
+ * Unfortunately, this guide doesn't show what to do about
+ * non-RGBA image formats so I'm making the rest up.
+ * All this code should be scrutinized.
+ */
+
+ size_t w = CGImageGetWidth(image_ref);
+ size_t h = CGImageGetHeight(image_ref);
+ CGRect rect = {{0, 0}, {w, h}};
+
+ CGImageAlphaInfo alpha = CGImageGetAlphaInfo(image_ref);
+ //size_t bits_per_pixel = CGImageGetBitsPerPixel(image_ref);
+ size_t bits_per_component = 8;
+
+ SDL_Surface* surface;
+ Uint32 Amask;
+ Uint32 Rmask;
+ Uint32 Gmask;
+ Uint32 Bmask;
+
+ CGContextRef bitmap_context;
+ CGBitmapInfo bitmap_info;
+ CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
+
+ if (alpha == kCGImageAlphaNone ||
+ alpha == kCGImageAlphaNoneSkipFirst ||
+ alpha == kCGImageAlphaNoneSkipLast) {
+ bitmap_info = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host; /* XRGB */
+ Amask = 0x00000000;
+ } else {
+ /* kCGImageAlphaFirst isn't supported */
+ //bitmap_info = kCGImageAlphaFirst | kCGBitmapByteOrder32Host; /* ARGB */
+ bitmap_info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host; /* ARGB */
+ Amask = 0xFF000000;
+ }
+
+ Rmask = 0x00FF0000;
+ Gmask = 0x0000FF00;
+ Bmask = 0x000000FF;
+
+ surface = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, Rmask, Gmask, Bmask, Amask);
+ if (surface)
+ {
+ // Sets up a context to be drawn to with surface->pixels as the area to be drawn to
+ bitmap_context = CGBitmapContextCreate(
+ surface->pixels,
+ surface->w,
+ surface->h,
+ bits_per_component,
+ surface->pitch,
+ color_space,
+ bitmap_info
+ );
+
+ // Draws the image into the context's image_data
+ CGContextDrawImage(bitmap_context, rect, image_ref);
+
+ CGContextRelease(bitmap_context);
+
+ // FIXME: Reverse the premultiplied alpha
+ if ((bitmap_info & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedFirst) {
+ int i, j;
+ Uint8 *p = (Uint8 *)surface->pixels;
+ for (i = surface->h * surface->pitch/4; i--; ) {
+#if __LITTLE_ENDIAN__
+ Uint8 A = p[3];
+ if (A) {
+ for (j = 0; j < 3; ++j) {
+ p[j] = (p[j] * 255) / A;
+ }
+ }
+#else
+ Uint8 A = p[0];
+ if (A) {
+ for (j = 1; j < 4; ++j) {
+ p[j] = (p[j] * 255) / A;
+ }
+ }
+#endif /* ENDIAN */
+ p += 4;
+ }
+ }
+ }
+
+ if (color_space)
+ {
+ CGColorSpaceRelease(color_space);
+ }
+
+ return surface;
+}
+
+static SDL_Surface* LoadImageFromRWops(SDL_RWops* rw_ops, CFStringRef uti_string_hint)
+{
+ NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
+ SDL_Surface* sdl_surface;
+ UIImage* ui_image;
+
+ CGImageRef image_ref = NULL;
+ int bytes_read = 0;
+ // I don't know what a good size is.
+ // Max recommended texture size is 1024x1024 on iPhone so maybe base it on that?
+ const int block_size = 1024*4;
+ char temp_buffer[block_size];
+
+ NSMutableData* ns_data = [[NSMutableData alloc] initWithCapacity:1024*1024*4];
+
+
+ do
+ {
+ bytes_read = SDL_RWread(rw_ops, temp_buffer, 1, block_size);
+ [ns_data appendBytes:temp_buffer length:bytes_read];
+ } while(bytes_read > 0);
+
+ if(NULL == image_ref)
+ {
+ return NULL;
+ }
+
+ ui_image = [[UIImage alloc] initWithData:ns_data];
+
+ sdl_surface = Create_SDL_Surface_From_CGImage([ui_image CGImage]);
+
+ [ui_image release];
+ [ns_data release];
+
+ [autorelease_pool drain];
+
+ return sdl_surface;
+}
+
+static SDL_Surface* LoadImageFromFile(const char *file)
+{
+ NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
+ SDL_Surface* sdl_surface = NULL;
+ UIImage* ui_image;
+ NSString* ns_string;
+
+ ns_string = [[NSString alloc] initWithUTF8String:file];
+ ui_image = [[UIImage alloc] initWithContentsOfFile:ns_string];
+
+ sdl_surface = Create_SDL_Surface_From_CGImage([ui_image CGImage]);
+
+ [ui_image release];
+ [ns_string release];
+
+ [autorelease_pool drain];
+
+ return sdl_surface;
+}
+
+
+/* Since UIImage doesn't really support streams well, we should optimize for the file case. */
+SDL_Surface *IMG_Load(const char *file)
+{
+ SDL_Surface* sdl_surface = NULL;
+
+ sdl_surface = LoadImageFromFile(file);
+ if(NULL == sdl_surface)
+ {
+ // Either the file doesn't exist or ImageIO doesn't understand the format.
+ // For the latter case, fallback to the native SDL_image handlers.
+
+ SDL_RWops *src = SDL_RWFromFile(file, "rb");
+ char *ext = strrchr(file, '.');
+ if(ext) {
+ ext++;
+ }
+ if(!src) {
+ /* The error message has been set in SDL_RWFromFile */
+ return NULL;
+ }
+ sdl_surface = IMG_LoadTyped_RW(src, 1, ext);
+ }
+ return sdl_surface;
+}
+
+
+int IMG_InitJPG()
+{
+ return 0;
+}
+
+void IMG_QuitJPG()
+{
+}
+
+int IMG_InitPNG()
+{
+ return 0;
+}
+
+void IMG_QuitPNG()
+{
+}
+
+int IMG_InitTIF()
+{
+ return 0;
+}
+
+void IMG_QuitTIF()
+{
+}
+
+/* Copied straight from other files so I don't have to alter them. */
+static int IMG_isICOCUR(SDL_RWops *src, int type)
+{
+ int start;
+ int is_ICOCUR;
+
+ /* The Win32 ICO file header (14 bytes) */
+ Uint16 bfReserved;
+ Uint16 bfType;
+ Uint16 bfCount;
+
+ if ( !src )
+ return 0;
+ start = SDL_RWtell(src);
+ is_ICOCUR = 0;
+ bfReserved = SDL_ReadLE16(src);
+ bfType = SDL_ReadLE16(src);
+ bfCount = SDL_ReadLE16(src);
+ if ((bfReserved == 0) && (bfType == type) && (bfCount != 0))
+ is_ICOCUR = 1;
+ SDL_RWseek(src, start, SEEK_SET);
+
+ return (is_ICOCUR);
+}
+
+int IMG_isICO(SDL_RWops *src)
+{
+ return IMG_isICOCUR(src, 1);
+}
+
+int IMG_isCUR(SDL_RWops *src)
+{
+ return IMG_isICOCUR(src, 2);
+}
+
+int IMG_isBMP(SDL_RWops *src)
+{
+ int start;
+ int is_BMP;
+ char magic[2];
+
+ if ( !src )
+ return 0;
+ start = SDL_RWtell(src);
+ is_BMP = 0;
+ if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
+ if ( strncmp(magic, "BM", 2) == 0 ) {
+ is_BMP = 1;
+ }
+ }
+ SDL_RWseek(src, start, SEEK_SET);
+ return(is_BMP);
+}
+
+int IMG_isGIF(SDL_RWops *src)
+{
+ int start;
+ int is_GIF;
+ char magic[6];
+
+ if ( !src )
+ return 0;
+ start = SDL_RWtell(src);
+ is_GIF = 0;
+ if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
+ if ( (strncmp(magic, "GIF", 3) == 0) &&
+ ((memcmp(magic + 3, "87a", 3) == 0) ||
+ (memcmp(magic + 3, "89a", 3) == 0)) ) {
+ is_GIF = 1;
+ }
+ }
+ SDL_RWseek(src, start, SEEK_SET);
+ return(is_GIF);
+}
+
+int IMG_isJPG(SDL_RWops *src)
+{
+ int start;
+ int is_JPG;
+ int in_scan;
+ Uint8 magic[4];
+
+ /* This detection code is by Steaphan Greene <stea@cs.binghamton.edu> */
+ /* Blame me, not Sam, if this doesn't work right. */
+ /* And don't forget to report the problem to the the sdl list too! */
+
+ if ( !src )
+ return 0;
+ start = SDL_RWtell(src);
+ is_JPG = 0;
+ in_scan = 0;
+ if ( SDL_RWread(src, magic, 2, 1) ) {
+ if ( (magic[0] == 0xFF) && (magic[1] == 0xD8) ) {
+ is_JPG = 1;
+ while (is_JPG == 1) {
+ if(SDL_RWread(src, magic, 1, 2) != 2) {
+ is_JPG = 0;
+ } else if( (magic[0] != 0xFF) && (in_scan == 0) ) {
+ is_JPG = 0;
+ } else if( (magic[0] != 0xFF) || (magic[1] == 0xFF) ) {
+ /* Extra padding in JPEG (legal) */
+ /* or this is data and we are scanning */
+ SDL_RWseek(src, -1, SEEK_CUR);
+ } else if(magic[1] == 0xD9) {
+ /* Got to end of good JPEG */
+ break;
+ } else if( (in_scan == 1) && (magic[1] == 0x00) ) {
+ /* This is an encoded 0xFF within the data */
+ } else if( (magic[1] >= 0xD0) && (magic[1] < 0xD9) ) {
+ /* These have nothing else */
+ } else if(SDL_RWread(src, magic+2, 1, 2) != 2) {
+ is_JPG = 0;
+ } else {
+ /* Yes, it's big-endian */
+ Uint32 start;
+ Uint32 size;
+ Uint32 end;
+ start = SDL_RWtell(src);
+ size = (magic[2] << 8) + magic[3];
+ end = SDL_RWseek(src, size-2, SEEK_CUR);
+ if ( end != start + size - 2 ) is_JPG = 0;
+ if ( magic[1] == 0xDA ) {
+ /* Now comes the actual JPEG meat */
+#ifdef FAST_IS_JPEG
+ /* Ok, I'm convinced. It is a JPEG. */
+ break;
+#else
+ /* I'm not convinced. Prove it! */
+ in_scan = 1;
+#endif
+ }
+ }
+ }
+ }
+ }
+ SDL_RWseek(src, start, SEEK_SET);
+ return(is_JPG);
+}
+
+int IMG_isPNG(SDL_RWops *src)
+{
+ int start;
+ int is_PNG;
+ Uint8 magic[4];
+
+ if ( !src )
+ return 0;
+ start = SDL_RWtell(src);
+ is_PNG = 0;
+ if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
+ if ( magic[0] == 0x89 &&
+ magic[1] == 'P' &&
+ magic[2] == 'N' &&
+ magic[3] == 'G' ) {
+ is_PNG = 1;
+ }
+ }
+ SDL_RWseek(src, start, SEEK_SET);
+ return(is_PNG);
+}
+
+int IMG_isTIF(SDL_RWops* src)
+{
+ int start;
+ int is_TIF;
+ Uint8 magic[4];
+
+ if ( !src )
+ return 0;
+ start = SDL_RWtell(src);
+ is_TIF = 0;
+ if ( SDL_RWread(src, magic, 1, sizeof(magic)) == sizeof(magic) ) {
+ if ( (magic[0] == 'I' &&
+ magic[1] == 'I' &&
+ magic[2] == 0x2a &&
+ magic[3] == 0x00) ||
+ (magic[0] == 'M' &&
+ magic[1] == 'M' &&
+ magic[2] == 0x00 &&
+ magic[3] == 0x2a) ) {
+ is_TIF = 1;
+ }
+ }
+ SDL_RWseek(src, start, SEEK_SET);
+ return(is_TIF);
+}
+
+SDL_Surface* IMG_LoadCUR_RW(SDL_RWops *src)
+{
+ /* FIXME: Is this a supported type? */
+ return LoadImageFromRWops(src, CFSTR("com.microsoft.cur"));
+}
+SDL_Surface* IMG_LoadICO_RW(SDL_RWops *src)
+{
+ return LoadImageFromRWops(src, kUTTypeICO);
+}
+SDL_Surface* IMG_LoadBMP_RW(SDL_RWops *src)
+{
+ return LoadImageFromRWops(src, kUTTypeBMP);
+}
+SDL_Surface* IMG_LoadGIF_RW(SDL_RWops *src)
+{
+ return LoadImageFromRWops(src, kUTTypeGIF);
+}
+SDL_Surface* IMG_LoadJPG_RW(SDL_RWops *src)
+{
+ return LoadImageFromRWops(src, kUTTypeJPEG);
+}
+SDL_Surface* IMG_LoadPNG_RW(SDL_RWops *src)
+{
+ return LoadImageFromRWops(src, kUTTypePNG);
+}
+SDL_Surface* IMG_LoadTGA_RW(SDL_RWops *src)
+{
+ return LoadImageFromRWops(src, CFSTR("com.truevision.tga-image"));
+}
+SDL_Surface* IMG_LoadTIF_RW(SDL_RWops *src)
+{
+ return LoadImageFromRWops(src, kUTTypeTIFF);
+}
+
845 IMG_bmp.c
@@ -0,0 +1,845 @@
+/*
+ SDL_image: An example image loading library for use with SDL
+ Copyright (C) 1997-2009 Sam Lantinga
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+ Sam Lantinga
+ slouken@libsdl.org
+*/
+
+#if !defined(__APPLE__) || defined(SDL_IMAGE_USE_COMMON_BACKEND)
+
+/* This is a BMP image file loading framework */
+/* ICO/CUR file support is here as well since it uses similar internal
+ * representation */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "SDL_image.h"
+
+#ifdef LOAD_BMP
+
+/* See if an image is contained in a data source */
+int IMG_isBMP(SDL_RWops *src)
+{
+ int start;
+ int is_BMP;
+ char magic[2];
+
+ if ( !src )
+ return 0;
+ start = SDL_RWtell(src);
+ is_BMP = 0;
+ if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
+ if ( strncmp(magic, "BM", 2) == 0 ) {
+ is_BMP = 1;
+ }
+ }
+ SDL_RWseek(src, start, RW_SEEK_SET);
+ return(is_BMP);
+}
+
+static int IMG_isICOCUR(SDL_RWops *src, int type)
+{
+ int start;
+ int is_ICOCUR;
+
+ /* The Win32 ICO file header (14 bytes) */
+ Uint16 bfReserved;
+ Uint16 bfType;
+ Uint16 bfCount;
+
+ if ( !src )
+ return 0;
+ start = SDL_RWtell(src);
+ is_ICOCUR = 0;
+ bfReserved = SDL_ReadLE16(src);
+ bfType = SDL_ReadLE16(src);
+ bfCount = SDL_ReadLE16(src);
+ if ((bfReserved == 0) && (bfType == type) && (bfCount != 0))
+ is_ICOCUR = 1;
+ SDL_RWseek(src, start, RW_SEEK_SET);
+
+ return (is_ICOCUR);
+}
+
+int IMG_isICO(SDL_RWops *src)
+{
+ return IMG_isICOCUR(src, 1);
+}
+
+int IMG_isCUR(SDL_RWops *src)
+{
+ return IMG_isICOCUR(src, 2);
+}
+
+#include "SDL_error.h"
+#include "SDL_video.h"
+#include "SDL_endian.h"
+
+/* Compression encodings for BMP files */
+#ifndef BI_RGB
+#define BI_RGB 0
+#define BI_RLE8 1
+#define BI_RLE4 2
+#define BI_BITFIELDS 3
+#endif
+
+static int readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8)
+{
+ /*
+ | Sets the surface pixels from src. A bmp image is upside down.
+ */
+ int pitch = surface->pitch;
+ int height = surface->h;
+ Uint8 *start = (Uint8 *)surface->pixels;
+ Uint8 *end = start + (height*pitch);
+ Uint8 *bits = end-pitch, *spot;
+ int ofs = 0;
+ Uint8 ch;
+ Uint8 needsPad;
+
+#define COPY_PIXEL(x) spot = &bits[ofs++]; if(spot >= start && spot < end) *spot = (x)
+
+ for (;;) {
+ if ( !SDL_RWread(src, &ch, 1, 1) ) return 1;
+ /*
+ | encoded mode starts with a run length, and then a byte
+ | with two colour indexes to alternate between for the run
+ */
+ if ( ch ) {
+ Uint8 pixel;
+ if ( !SDL_RWread(src, &pixel, 1, 1) ) return 1;
+ if ( isRle8 ) { /* 256-color bitmap, compressed */
+ do {
+ COPY_PIXEL(pixel);
+ } while (--ch);
+ } else { /* 16-color bitmap, compressed */
+ Uint8 pixel0 = pixel >> 4;
+ Uint8 pixel1 = pixel & 0x0F;
+ for (;;) {
+ COPY_PIXEL(pixel0); /* even count, high nibble */
+ if (!--ch) break;
+ COPY_PIXEL(pixel1); /* odd count, low nibble */
+ if (!--ch) break;
+ }
+ }
+ } else {
+ /*
+ | A leading zero is an escape; it may signal the end of the bitmap,
+ | a cursor move, or some absolute data.
+ | zero tag may be absolute mode or an escape
+ */
+ if ( !SDL_RWread(src, &ch, 1, 1) ) return 1;
+ switch (ch) {
+ case 0: /* end of line */
+ ofs = 0;
+ bits -= pitch; /* go to previous */
+ break;
+ case 1: /* end of bitmap */
+ return 0; /* success! */
+ case 2: /* delta */
+ if ( !SDL_RWread(src, &ch, 1, 1) ) return 1;
+ ofs += ch;
+ if ( !SDL_RWread(src, &ch, 1, 1) ) return 1;
+ bits -= (ch * pitch);
+ break;
+ default: /* no compression */
+ if (isRle8) {
+ needsPad = ( ch & 1 );
+ do {
+ Uint8 pixel;
+ if ( !SDL_RWread(src, &pixel, 1, 1) ) return 1;
+ COPY_PIXEL(pixel);
+ } while (--ch);
+ } else {
+ needsPad = ( ((ch+1)>>1) & 1 ); /* (ch+1)>>1: bytes size */
+ for (;;) {
+ Uint8 pixel;
+ if ( !SDL_RWread(src, &pixel, 1, 1) ) return 1;
+ COPY_PIXEL(pixel >> 4);
+ if (!--ch) break;
+ COPY_PIXEL(pixel & 0x0F);
+ if (!--ch) break;
+ }
+ }
+ /* pad at even boundary */
+ if ( needsPad && !SDL_RWread(src, &ch, 1, 1) ) return 1;
+ break;
+ }
+ }
+ }
+}
+
+static SDL_Surface *LoadBMP_RW (SDL_RWops *src, int freesrc)
+{
+ SDL_bool was_error;
+ long fp_offset;
+ int bmpPitch;
+ int i, pad;
+ SDL_Surface *surface;
+ Uint32 Rmask;
+ Uint32 Gmask;
+ Uint32 Bmask;
+ Uint32 Amask;
+ SDL_Palette *palette;
+ Uint8 *bits;
+ Uint8 *top, *end;
+ SDL_bool topDown;
+ int ExpandBMP;
+
+ /* The Win32 BMP file header (14 bytes) */
+ char magic[2];
+ Uint32 bfSize;
+ Uint16 bfReserved1;
+ Uint16 bfReserved2;
+ Uint32 bfOffBits;
+
+ /* The Win32 BITMAPINFOHEADER struct (40 bytes) */
+ Uint32 biSize;
+ Sint32 biWidth;
+ Sint32 biHeight;
+ Uint16 biPlanes;
+ Uint16 biBitCount;
+ Uint32 biCompression;
+ Uint32 biSizeImage;
+ Sint32 biXPelsPerMeter;
+ Sint32 biYPelsPerMeter;
+ Uint32 biClrUsed;
+ Uint32 biClrImportant;
+
+ /* Make sure we are passed a valid data source */
+ surface = NULL;
+ was_error = SDL_FALSE;
+ if ( src == NULL ) {
+ was_error = SDL_TRUE;
+ goto done;
+ }
+
+ /* Read in the BMP file header */
+ fp_offset = SDL_RWtell(src);
+ SDL_ClearError();
+ if ( SDL_RWread(src, magic, 1, 2) != 2 ) {
+ SDL_Error(SDL_EFREAD);
+ was_error = SDL_TRUE;
+ goto done;
+ }
+ if ( strncmp(magic, "BM", 2) != 0 ) {
+ SDL_SetError("File is not a Windows BMP file");
+ was_error = SDL_TRUE;
+ goto done;
+ }
+ bfSize = SDL_ReadLE32(src);
+ bfReserved1 = SDL_ReadLE16(src);
+ bfReserved2 = SDL_ReadLE16(src);
+ bfOffBits = SDL_ReadLE32(src);
+
+ /* Read the Win32 BITMAPINFOHEADER */
+ biSize = SDL_ReadLE32(src);
+ if ( biSize == 12 ) {
+ biWidth = (Uint32)SDL_ReadLE16(src);
+ biHeight = (Uint32)SDL_ReadLE16(src);
+ biPlanes = SDL_ReadLE16(src);
+ biBitCount = SDL_ReadLE16(src);
+ biCompression = BI_RGB;
+ biSizeImage = 0;
+ biXPelsPerMeter = 0;
+ biYPelsPerMeter = 0;
+ biClrUsed = 0;
+ biClrImportant = 0;
+ } else {
+ biWidth = SDL_ReadLE32(src);
+ biHeight = SDL_ReadLE32(src);
+ biPlanes = SDL_ReadLE16(src);
+ biBitCount = SDL_ReadLE16(src);
+ biCompression = SDL_ReadLE32(src);
+ biSizeImage = SDL_ReadLE32(src);
+ biXPelsPerMeter = SDL_ReadLE32(src);
+ biYPelsPerMeter = SDL_ReadLE32(src);
+ biClrUsed = SDL_ReadLE32(src);
+ biClrImportant = SDL_ReadLE32(src);
+ }
+ if (biHeight < 0) {
+ topDown = SDL_TRUE;
+ biHeight = -biHeight;
+ } else {
+ topDown = SDL_FALSE;
+ }
+
+ /* Check for read error */
+ if ( strcmp(SDL_GetError(), "") != 0 ) {
+ was_error = SDL_TRUE;
+ goto done;
+ }
+
+ /* Expand 1 and 4 bit bitmaps to 8 bits per pixel */
+ switch (biBitCount) {
+ case 1:
+ case 4:
+ ExpandBMP = biBitCount;
+ biBitCount = 8;
+ break;
+ default:
+ ExpandBMP = 0;
+ break;
+ }
+
+ /* RLE4 and RLE8 BMP compression is supported */
+ Rmask = Gmask = Bmask = Amask = 0;
+ switch (biCompression) {
+ case BI_RGB:
+ /* If there are no masks, use the defaults */
+ if ( bfOffBits == (14+biSize) ) {
+ /* Default values for the BMP format */
+ switch (biBitCount) {
+ case 15:
+ case 16:
+ Rmask = 0x7C00;
+ Gmask = 0x03E0;
+ Bmask = 0x001F;
+ break;
+ case 24:
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ Rmask = 0x000000FF;
+ Gmask = 0x0000FF00;
+ Bmask = 0x00FF0000;
+#else
+ Rmask = 0x00FF0000;
+ Gmask = 0x0000FF00;
+ Bmask = 0x000000FF;
+#endif
+ break;
+ case 32:
+ Amask = 0xFF000000;
+ Rmask = 0x00FF0000;
+ Gmask = 0x0000FF00;
+ Bmask = 0x000000FF;
+ break;
+ default:
+ break;
+ }
+ break;
+ }
+ /* Fall through -- read the RGB masks */