se me habia olvidao añadir esto :P
This commit is contained in:
parent
c63da7af35
commit
edc0478664
456
util/cosas utiles/SDL_gfx/LICENSE
Normal file
456
util/cosas utiles/SDL_gfx/LICENSE
Normal file
|
@ -0,0 +1,456 @@
|
||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
Version 2.1, February 1999
|
||||||
|
|
||||||
|
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||||
|
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
277
util/cosas utiles/SDL_gfx/README
Normal file
277
util/cosas utiles/SDL_gfx/README
Normal file
|
@ -0,0 +1,277 @@
|
||||||
|
|
||||||
|
SDL_gfx - SDL graphics drawing primitives and other support functions
|
||||||
|
=============================================================================
|
||||||
|
|
||||||
|
Email aschiffler@appwares.ca to contact the author or better check
|
||||||
|
author's homepage at http://www.ferzkopp.net for the most up-to-date
|
||||||
|
contact information.
|
||||||
|
|
||||||
|
This library is licenced under the LGPL, see the file LICENSE for details.
|
||||||
|
|
||||||
|
|
||||||
|
Intro
|
||||||
|
-----
|
||||||
|
|
||||||
|
The SDL_gfx library evolved out of the SDL_gfxPrimitives code which
|
||||||
|
provided basic drawing routines such as lines, circles or polygons for
|
||||||
|
SDL Surfaces and adding a couple other useful functions for zooming
|
||||||
|
images for example and doing basic image processing on byte arrays.
|
||||||
|
|
||||||
|
The current components of the SDL_gfx library are:
|
||||||
|
- Graphic Primitives (SDL_gfxPrimitves.h)
|
||||||
|
- Rotozoomer (SDL_rotozoom.h)
|
||||||
|
- Framerate control (SDL_framerate.h)
|
||||||
|
- MMX image filters (SDL_imageFilter.h)
|
||||||
|
|
||||||
|
See ./Docs directory for a longer HTML version of this document.
|
||||||
|
|
||||||
|
|
||||||
|
Supported Platforms
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
The library compiles and is tested for a Linux target (gcc compiler) and
|
||||||
|
a Win32 target (VisualC6/7, xmingw32 cross-compiler). MacOS X target is
|
||||||
|
reported to work (Project Builder).
|
||||||
|
|
||||||
|
When using the cross-compiler (available on the author's homepage),
|
||||||
|
the build process generates .DLLs. You can use the command line 'LIB.EXE'
|
||||||
|
tool to generate VC6 compatible .LIB files for linking purposes.
|
||||||
|
|
||||||
|
Other platforms might work but have not been tested by the author.
|
||||||
|
|
||||||
|
|
||||||
|
Notes on Graphics Primitives
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
Care has been taken so that all routines are fully alpha-aware and can
|
||||||
|
blend any primitive onto the target surface if ALPHA<255. Surface depths
|
||||||
|
supported are 1,2,3 and 4 bytes per pixel. Surface locking is implemented
|
||||||
|
in each routine and the library should work well with hardware
|
||||||
|
accelerated surfaces.
|
||||||
|
|
||||||
|
Currently, The following Anti-Aliased drawing primitives are available:
|
||||||
|
- AA-line
|
||||||
|
- AA-polygon
|
||||||
|
- AA-circle
|
||||||
|
- AA-ellipse
|
||||||
|
|
||||||
|
[[[ Interface ]]]
|
||||||
|
|
||||||
|
See SDL_gfxPrimitives.h for all the drawing functions.
|
||||||
|
|
||||||
|
|
||||||
|
Notes on Rotozoomer
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
The rotozoom code is not ASSEMBLY quality - but it should be fast enough
|
||||||
|
even for some realtime effects if the CPU is good or bitmaps small.
|
||||||
|
With interpolation the routines are typically used for pre-rendering stuff
|
||||||
|
in higher quality (i.e. smoothing) - that's also a reason why the API differs
|
||||||
|
from SDL_BlitRect() and creates a new target surface each time rotozoom
|
||||||
|
is called. The final rendering speed is dependent on the target surface
|
||||||
|
size as it is beeing xy-scanned when rendering the new surface.
|
||||||
|
|
||||||
|
Note also that the smoothing toggle is dependent on the input surface bit
|
||||||
|
depth. 8bit surfaces will never be smoothed - only 32bit surfaces will.
|
||||||
|
|
||||||
|
Note that surfaces of other bit depth then 8 and 32 will be converted
|
||||||
|
on the fly to a 32bit surface using a blit into a temporary surface. This
|
||||||
|
impacts performance somewhat.
|
||||||
|
|
||||||
|
|
||||||
|
[[[ Interface ]]]
|
||||||
|
|
||||||
|
SDL_Surface * rotozoomSurface (SDL_Surface *src, double angle, double zoom, int smooth);
|
||||||
|
|
||||||
|
Rotates and zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface.
|
||||||
|
'angle' is the rotation in degrees. 'zoom' a scaling factor. If 'smooth' is 1
|
||||||
|
then the destination 32bit surface is anti-aliased. If the surface is not 8bit
|
||||||
|
or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SDL_Surface * zoomSurface (SDL_Surface *src, double zoomx, double zoomy, int smooth);
|
||||||
|
|
||||||
|
Zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface.
|
||||||
|
'zoomx' and 'zoomy' are scaling factors for width and height. If 'smooth' is 1
|
||||||
|
then the destination 32bit surface is anti-aliased. If the surface is not 8bit
|
||||||
|
or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
|
||||||
|
|
||||||
|
|
||||||
|
Smoothing (interpolation) flags work only on 32bit surfaces:
|
||||||
|
|
||||||
|
#define SMOOTHING_OFF 0
|
||||||
|
#define SMOOTHING_ON 1
|
||||||
|
|
||||||
|
|
||||||
|
Notes on framerate functions
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
The framerate functions are used to insert delays into the graphics loop
|
||||||
|
to maintain a constant framerate.
|
||||||
|
|
||||||
|
The implementation is more sophisticated that the usual
|
||||||
|
SDL_Delay(1000/FPS);
|
||||||
|
call since these functions keep track of the desired game time per frame
|
||||||
|
for a linearly interpolated sequence of future timing points of each frame.
|
||||||
|
This is done to avoid rounding errors from the inherent instability in the
|
||||||
|
delay generation and application.
|
||||||
|
|
||||||
|
i.e. the 100th frame of a game running at 50Hz will be accurately
|
||||||
|
2.00sec after the 1st frame (if the machine can keep up with the drawing).
|
||||||
|
|
||||||
|
|
||||||
|
[[[ Interface ]]]
|
||||||
|
|
||||||
|
The functions return 0 or 'value' for sucess and -1 for error. All functions
|
||||||
|
use a pointer to a framerate-manager variable to operate.
|
||||||
|
|
||||||
|
void SDL_initFramerate(FPSmanager * manager);
|
||||||
|
|
||||||
|
Initialize the framerate manager, set default framerate of 30Hz and
|
||||||
|
reset delay interpolation.
|
||||||
|
|
||||||
|
|
||||||
|
int SDL_setFramerate(FPSmanager * manager, int rate);
|
||||||
|
|
||||||
|
Set a new framerate for the manager and reset delay interpolation.
|
||||||
|
|
||||||
|
|
||||||
|
int SDL_getFramerate(FPSmanager * manager);
|
||||||
|
|
||||||
|
Get the currently set framerate of the manager.
|
||||||
|
|
||||||
|
|
||||||
|
void SDL_framerateDelay(FPSmanager * manager);
|
||||||
|
|
||||||
|
Generate a delay to accomodate currently set framerate. Call once in the
|
||||||
|
graphics/rendering loop. If the computer cannot keep up with the rate (i.e.
|
||||||
|
drawing too slow), the delay is zero and the delay interpolation is reset.
|
||||||
|
|
||||||
|
|
||||||
|
Notes on imageFilter functions
|
||||||
|
------------------------------
|
||||||
|
|
||||||
|
The imagefilter functions are a collection of MMX optimized routines that
|
||||||
|
operate on continuous buffers of bytes - typically greyscale images from
|
||||||
|
framegrabbers and such - performing functions such as image addition and
|
||||||
|
binarization. All functions (almost .. not the the convolution routines)
|
||||||
|
have a C implementation that is automatically used on systems without MMX
|
||||||
|
capabilities.
|
||||||
|
|
||||||
|
|
||||||
|
[[[ Interface ]]]
|
||||||
|
|
||||||
|
See the extensive list of routines in SDL_imageFilters.h for info.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Installation and Test
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
To compile the library your need the SDL 1.2 installed from source or
|
||||||
|
with the 'devel' RPM package.
|
||||||
|
|
||||||
|
Run
|
||||||
|
./autogen.sh (optional)
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
make install
|
||||||
|
ldconfig
|
||||||
|
|
||||||
|
to compile and install the library. The default location for the
|
||||||
|
installation is /usr/local/lib and /usr/local/include.
|
||||||
|
|
||||||
|
Run the shell script 'nodebug.sh' before make, to patch the makefile
|
||||||
|
for optimized compilation:
|
||||||
|
./autogen.sh (optional)
|
||||||
|
./configure
|
||||||
|
./nodebug.sh
|
||||||
|
make
|
||||||
|
make install
|
||||||
|
ldconfig
|
||||||
|
|
||||||
|
To create a Windows DLL using VisualC:
|
||||||
|
unzip -a VisualC6.zip
|
||||||
|
vcvars32.bat
|
||||||
|
copy VisualC/makefile
|
||||||
|
nmake
|
||||||
|
or
|
||||||
|
unzip -a VisualC7.zip
|
||||||
|
and open the project file.
|
||||||
|
|
||||||
|
|
||||||
|
To create a Windows DLL using the xmingw32 cross-compiler:
|
||||||
|
cross-configure
|
||||||
|
cross-make
|
||||||
|
cross-make install
|
||||||
|
|
||||||
|
|
||||||
|
To build without MMX code enabled (i.e. PPC architecture):
|
||||||
|
./configure --disable-mmx
|
||||||
|
make
|
||||||
|
make install
|
||||||
|
|
||||||
|
To build on MacOS X with Project Builder, follow these steps:
|
||||||
|
* Update your developer tools to the lastest version (December 2002 as
|
||||||
|
of this revision).
|
||||||
|
* Install the SDL Developers framework for Mac OS X.
|
||||||
|
* Download the latest SDL_gfx source distribution and extract the
|
||||||
|
archive in a convenient location.
|
||||||
|
* Extract the included OSX-PB.tgz archive into the
|
||||||
|
top directory of the SDL_gfx distribution (from step 3). This will create a
|
||||||
|
PB that contains the project files.
|
||||||
|
* The project has targets for the SDL_gfx framework and the four test
|
||||||
|
programs. All can be built using the 'deployment' or 'development' build
|
||||||
|
styles.
|
||||||
|
|
||||||
|
|
||||||
|
Test Programs
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Change to the ./Test directory and run
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
to create several test programs for the libraries functions. This requires
|
||||||
|
the library to be compiled and installed.
|
||||||
|
|
||||||
|
|
||||||
|
See the source code .c files for sample code.
|
||||||
|
|
||||||
|
|
||||||
|
Thanks
|
||||||
|
------
|
||||||
|
|
||||||
|
Thanks to 'AppWares Development Group' for supporting this project - please
|
||||||
|
visit http://www.appwares.com for more information.
|
||||||
|
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Non-alpha line drawing code adapted from routine
|
||||||
|
by Pete Shinners, pete@shinners.org - thanks Pete.
|
||||||
|
|
||||||
|
* More fixes by Karl Bartel, karlb@gmx.net - thanks Karl.
|
||||||
|
|
||||||
|
* Much testing and suggestions for fixes from Danny van Bruggen,
|
||||||
|
danny@froukepc.dhs.org - thanks Danny.
|
||||||
|
|
||||||
|
* Original AA-circle/-ellipse code idea from Stephane Magnenat,
|
||||||
|
nct@wg0.ysagoon.com - thanks Stephane.
|
||||||
|
|
||||||
|
* Faster blending routines contributed by Anders Lindström,
|
||||||
|
cal@swipnet.se - thanks Anders.
|
||||||
|
|
||||||
|
* New AA-circle/-ellipse code based on ideas from Anders Lindström -
|
||||||
|
thanks Anders.
|
||||||
|
|
||||||
|
* VisualC makefile contributed by Danny van Bruggen,
|
||||||
|
danny@froukepc.dhs.org - thanks Danny.
|
||||||
|
|
||||||
|
* VisualC7 project file contributed by James Turk,
|
||||||
|
jturk@conceptofzero.com - thanks James.
|
||||||
|
|
||||||
|
* Project Builder package contributed by Thomas Tongue,
|
||||||
|
TTongue@imagiware.com - Thanks Thomas.
|
||||||
|
|
84
util/cosas utiles/SDL_gfx/SDL_framerate.c
Normal file
84
util/cosas utiles/SDL_gfx/SDL_framerate.c
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
SDL_framerate: framerate manager
|
||||||
|
|
||||||
|
LGPL (c) A. Schiffler
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "SDL_framerate.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
Initialize the framerate manager
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SDL_initFramerate(FPSmanager * manager)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Store some sane values
|
||||||
|
*/
|
||||||
|
manager->framecount = 0;
|
||||||
|
manager->rate = FPS_DEFAULT;
|
||||||
|
manager->rateticks = (1000.0 / (float) FPS_DEFAULT);
|
||||||
|
manager->lastticks = SDL_GetTicks();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Set the framerate in Hz
|
||||||
|
*/
|
||||||
|
|
||||||
|
int SDL_setFramerate(FPSmanager * manager, int rate)
|
||||||
|
{
|
||||||
|
if ((rate >= FPS_LOWER_LIMIT) && (rate <= FPS_UPPER_LIMIT)) {
|
||||||
|
manager->framecount = 0;
|
||||||
|
manager->rate = rate;
|
||||||
|
manager->rateticks = (1000.0 / (float) rate);
|
||||||
|
return (0);
|
||||||
|
} else {
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Return the current target framerate in Hz
|
||||||
|
*/
|
||||||
|
|
||||||
|
int SDL_getFramerate(FPSmanager * manager)
|
||||||
|
{
|
||||||
|
if (manager == NULL) {
|
||||||
|
return (-1);
|
||||||
|
} else {
|
||||||
|
return (manager->rate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Delay execution to maintain a constant framerate. Calculate fps.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SDL_framerateDelay(FPSmanager * manager)
|
||||||
|
{
|
||||||
|
Uint32 current_ticks;
|
||||||
|
Uint32 target_ticks;
|
||||||
|
Uint32 the_delay;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Next frame
|
||||||
|
*/
|
||||||
|
manager->framecount++;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get/calc ticks
|
||||||
|
*/
|
||||||
|
current_ticks = SDL_GetTicks();
|
||||||
|
target_ticks = manager->lastticks + (Uint32) ((float) manager->framecount * manager->rateticks);
|
||||||
|
|
||||||
|
if (current_ticks <= target_ticks) {
|
||||||
|
the_delay = target_ticks - current_ticks;
|
||||||
|
SDL_Delay(the_delay);
|
||||||
|
} else {
|
||||||
|
manager->framecount = 0;
|
||||||
|
manager->lastticks = SDL_GetTicks();
|
||||||
|
}
|
||||||
|
}
|
65
util/cosas utiles/SDL_gfx/SDL_framerate.h
Normal file
65
util/cosas utiles/SDL_gfx/SDL_framerate.h
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
SDL_framerate: framerate manager
|
||||||
|
|
||||||
|
LGPL (c) A. Schiffler
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SDL_framerate_h
|
||||||
|
#define _SDL_framerate_h
|
||||||
|
|
||||||
|
/* Set up for C function definitions, even when using C++ */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* --- */
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
/* --------- Definitions */
|
||||||
|
|
||||||
|
/* Some rates in Hz */
|
||||||
|
|
||||||
|
#define FPS_UPPER_LIMIT 200
|
||||||
|
#define FPS_LOWER_LIMIT 1
|
||||||
|
#define FPS_DEFAULT 30
|
||||||
|
|
||||||
|
/* --------- Structure variables */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Uint32 framecount;
|
||||||
|
float rateticks;
|
||||||
|
Uint32 lastticks;
|
||||||
|
Uint32 rate;
|
||||||
|
} FPSmanager;
|
||||||
|
|
||||||
|
/* --------- Function prototypes */
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#ifdef BUILD_DLL
|
||||||
|
#define DLLINTERFACE __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define DLLINTERFACE __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define DLLINTERFACE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Functions return 0 or value for sucess and -1 for error */
|
||||||
|
|
||||||
|
DLLINTERFACE void SDL_initFramerate(FPSmanager * manager);
|
||||||
|
DLLINTERFACE int SDL_setFramerate(FPSmanager * manager, int rate);
|
||||||
|
DLLINTERFACE int SDL_getFramerate(FPSmanager * manager);
|
||||||
|
DLLINTERFACE void SDL_framerateDelay(FPSmanager * manager);
|
||||||
|
|
||||||
|
/* --- */
|
||||||
|
|
||||||
|
/* Ends C function definitions when using C++ */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _SDL_framerate_h */
|
3660
util/cosas utiles/SDL_gfx/SDL_gfxPrimitives.c
Normal file
3660
util/cosas utiles/SDL_gfx/SDL_gfxPrimitives.c
Normal file
File diff suppressed because it is too large
Load diff
181
util/cosas utiles/SDL_gfx/SDL_gfxPrimitives.h
Normal file
181
util/cosas utiles/SDL_gfx/SDL_gfxPrimitives.h
Normal file
|
@ -0,0 +1,181 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
SDL_gfxPrimitives: graphics primitives for SDL
|
||||||
|
|
||||||
|
LGPL (c) A. Schiffler
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SDL_gfxPrimitives_h
|
||||||
|
#define _SDL_gfxPrimitives_h
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#ifndef M_PI
|
||||||
|
#define M_PI 3.141592654
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
/* Set up for C function definitions, even when using C++ */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ----- Versioning */
|
||||||
|
|
||||||
|
#define SDL_GFXPRIMITIVES_MAJOR 1
|
||||||
|
#define SDL_GFXPRIMITIVES_MINOR 5
|
||||||
|
|
||||||
|
/* ----- W32 DLL interface */
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#ifdef BUILD_DLL
|
||||||
|
#define DLLINTERFACE __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define DLLINTERFACE __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define DLLINTERFACE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ----- Prototypes */
|
||||||
|
|
||||||
|
/* Note: all ___Color routines expect the color to be in format 0xRRGGBBAA */
|
||||||
|
|
||||||
|
/* Pixel */
|
||||||
|
|
||||||
|
DLLINTERFACE int pixelColor(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color);
|
||||||
|
DLLINTERFACE int pixelRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Horizontal line */
|
||||||
|
|
||||||
|
DLLINTERFACE int hlineColor(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, Uint32 color);
|
||||||
|
DLLINTERFACE int hlineRGBA(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Vertical line */
|
||||||
|
|
||||||
|
DLLINTERFACE int vlineColor(SDL_Surface * dst, Sint16 x, Sint16 y1, Sint16 y2, Uint32 color);
|
||||||
|
DLLINTERFACE int vlineRGBA(SDL_Surface * dst, Sint16 x, Sint16 y1, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Rectangle */
|
||||||
|
|
||||||
|
DLLINTERFACE int rectangleColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
|
||||||
|
DLLINTERFACE int rectangleRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1,
|
||||||
|
Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Filled rectangle (Box) */
|
||||||
|
|
||||||
|
DLLINTERFACE int boxColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
|
||||||
|
DLLINTERFACE int boxRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2,
|
||||||
|
Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Line */
|
||||||
|
|
||||||
|
DLLINTERFACE int lineColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
|
||||||
|
DLLINTERFACE int lineRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1,
|
||||||
|
Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* AA Line */
|
||||||
|
DLLINTERFACE int aalineColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
|
||||||
|
DLLINTERFACE int aalineRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1,
|
||||||
|
Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Circle */
|
||||||
|
|
||||||
|
DLLINTERFACE int circleColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 r, Uint32 color);
|
||||||
|
DLLINTERFACE int circleRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* AA Circle */
|
||||||
|
|
||||||
|
DLLINTERFACE int aacircleColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 r, Uint32 color);
|
||||||
|
DLLINTERFACE int aacircleRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
|
||||||
|
Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Filled Circle */
|
||||||
|
|
||||||
|
DLLINTERFACE int filledCircleColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 r, Uint32 color);
|
||||||
|
DLLINTERFACE int filledCircleRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
|
||||||
|
Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Ellipse */
|
||||||
|
|
||||||
|
DLLINTERFACE int ellipseColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color);
|
||||||
|
DLLINTERFACE int ellipseRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
|
||||||
|
Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* AA Ellipse */
|
||||||
|
|
||||||
|
DLLINTERFACE int aaellipseColor(SDL_Surface * dst, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint32 color);
|
||||||
|
DLLINTERFACE int aaellipseRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
|
||||||
|
Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Filled Ellipse */
|
||||||
|
|
||||||
|
DLLINTERFACE int filledEllipseColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color);
|
||||||
|
DLLINTERFACE int filledEllipseRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
|
||||||
|
Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
/* Filled Pie */
|
||||||
|
|
||||||
|
DLLINTERFACE int filledpieColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad,
|
||||||
|
Sint16 start, Sint16 end, Uint32 color);
|
||||||
|
DLLINTERFACE int filledpieRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad,
|
||||||
|
Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Trigon */
|
||||||
|
|
||||||
|
DLLINTERFACE int trigonColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
|
||||||
|
DLLINTERFACE int trigonRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
|
||||||
|
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* AA-Trigon */
|
||||||
|
|
||||||
|
DLLINTERFACE int aatrigonColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
|
||||||
|
DLLINTERFACE int aatrigonRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
|
||||||
|
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Filled Trigon */
|
||||||
|
|
||||||
|
DLLINTERFACE int filledTrigonColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, int color);
|
||||||
|
DLLINTERFACE int filledTrigonRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
|
||||||
|
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Polygon */
|
||||||
|
|
||||||
|
DLLINTERFACE int polygonColor(SDL_Surface * dst, Sint16 * vx, Sint16 * vy, int n, Uint32 color);
|
||||||
|
DLLINTERFACE int polygonRGBA(SDL_Surface * dst, Sint16 * vx, Sint16 * vy,
|
||||||
|
int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* AA-Polygon */
|
||||||
|
|
||||||
|
DLLINTERFACE int aapolygonColor(SDL_Surface * dst, Sint16 * vx, Sint16 * vy, int n, Uint32 color);
|
||||||
|
DLLINTERFACE int aapolygonRGBA(SDL_Surface * dst, Sint16 * vx, Sint16 * vy,
|
||||||
|
int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Filled Polygon */
|
||||||
|
|
||||||
|
DLLINTERFACE int filledPolygonColor(SDL_Surface * dst, Sint16 * vx, Sint16 * vy, int n, int color);
|
||||||
|
DLLINTERFACE int filledPolygonRGBA(SDL_Surface * dst, Sint16 * vx,
|
||||||
|
Sint16 * vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Bezier */
|
||||||
|
/* s = number of steps */
|
||||||
|
|
||||||
|
DLLINTERFACE int bezierColor(SDL_Surface * dst, Sint16 * vx, Sint16 * vy, int n, int s, Uint32 color);
|
||||||
|
DLLINTERFACE int bezierRGBA(SDL_Surface * dst, Sint16 * vx, Sint16 * vy,
|
||||||
|
int n, int s, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
|
||||||
|
/* 8x8 Characters/Strings */
|
||||||
|
|
||||||
|
DLLINTERFACE int characterColor(SDL_Surface * dst, Sint16 x, Sint16 y, char c, Uint32 color);
|
||||||
|
DLLINTERFACE int characterRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, char c, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
DLLINTERFACE int stringColor(SDL_Surface * dst, Sint16 x, Sint16 y, char *c, Uint32 color);
|
||||||
|
DLLINTERFACE int stringRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, char *c, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
|
|
||||||
|
/* Ends C function definitions when using C++ */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _SDL_gfxPrimitives_h */
|
939
util/cosas utiles/SDL_gfx/SDL_rotozoom.c
Normal file
939
util/cosas utiles/SDL_gfx/SDL_rotozoom.c
Normal file
|
@ -0,0 +1,939 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
SDL_rotozoom.c - rotozoomer for 32bit or 8bit surfaces
|
||||||
|
|
||||||
|
LGPL (c) A. Schiffler
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "SDL_rotozoom.h"
|
||||||
|
|
||||||
|
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
32bit Zoomer with optional anti-aliasing by bilinear interpolation.
|
||||||
|
|
||||||
|
Zoomes 32bit RGBA/ABGR 'src' surface to 'dst' surface.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
int zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int smooth)
|
||||||
|
{
|
||||||
|
int x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy, ex, ey, t1, t2, sstep;
|
||||||
|
tColorRGBA *c00, *c01, *c10, *c11;
|
||||||
|
tColorRGBA *sp, *csp, *dp;
|
||||||
|
int sgap, dgap;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Variable setup
|
||||||
|
*/
|
||||||
|
if (smooth) {
|
||||||
|
/*
|
||||||
|
* For interpolation: assume source dimension is one pixel
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* smaller to avoid overflow on right and bottom edge.
|
||||||
|
*/
|
||||||
|
sx = (int) (65536.0 * (float) (src->w - 1) / (float) dst->w);
|
||||||
|
sy = (int) (65536.0 * (float) (src->h - 1) / (float) dst->h);
|
||||||
|
} else {
|
||||||
|
sx = (int) (65536.0 * (float) src->w / (float) dst->w);
|
||||||
|
sy = (int) (65536.0 * (float) src->h / (float) dst->h);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate memory for row increments
|
||||||
|
*/
|
||||||
|
if ((sax = (int *) malloc((dst->w + 1) * sizeof(Uint32))) == NULL) {
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if ((say = (int *) malloc((dst->h + 1) * sizeof(Uint32))) == NULL) {
|
||||||
|
free(sax);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Precalculate row increments
|
||||||
|
*/
|
||||||
|
csx = 0;
|
||||||
|
csax = sax;
|
||||||
|
for (x = 0; x <= dst->w; x++) {
|
||||||
|
*csax = csx;
|
||||||
|
csax++;
|
||||||
|
csx &= 0xffff;
|
||||||
|
csx += sx;
|
||||||
|
}
|
||||||
|
csy = 0;
|
||||||
|
csay = say;
|
||||||
|
for (y = 0; y <= dst->h; y++) {
|
||||||
|
*csay = csy;
|
||||||
|
csay++;
|
||||||
|
csy &= 0xffff;
|
||||||
|
csy += sy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Pointer setup
|
||||||
|
*/
|
||||||
|
sp = csp = (tColorRGBA *) src->pixels;
|
||||||
|
dp = (tColorRGBA *) dst->pixels;
|
||||||
|
sgap = src->pitch - src->w * 4;
|
||||||
|
dgap = dst->pitch - dst->w * 4;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Switch between interpolating and non-interpolating code
|
||||||
|
*/
|
||||||
|
if (smooth) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Interpolating Zoom
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Scan destination
|
||||||
|
*/
|
||||||
|
csay = say;
|
||||||
|
for (y = 0; y < dst->h; y++) {
|
||||||
|
/*
|
||||||
|
* Setup color source pointers
|
||||||
|
*/
|
||||||
|
c00 = csp;
|
||||||
|
c01 = csp;
|
||||||
|
c01++;
|
||||||
|
c10 = (tColorRGBA *) ((Uint8 *) csp + src->pitch);
|
||||||
|
c11 = c10;
|
||||||
|
c11++;
|
||||||
|
csax = sax;
|
||||||
|
for (x = 0; x < dst->w; x++) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Interpolate colors
|
||||||
|
*/
|
||||||
|
ex = (*csax & 0xffff);
|
||||||
|
ey = (*csay & 0xffff);
|
||||||
|
t1 = ((((c01->r - c00->r) * ex) >> 16) + c00->r) & 0xff;
|
||||||
|
t2 = ((((c11->r - c10->r) * ex) >> 16) + c10->r) & 0xff;
|
||||||
|
dp->r = (((t2 - t1) * ey) >> 16) + t1;
|
||||||
|
t1 = ((((c01->g - c00->g) * ex) >> 16) + c00->g) & 0xff;
|
||||||
|
t2 = ((((c11->g - c10->g) * ex) >> 16) + c10->g) & 0xff;
|
||||||
|
dp->g = (((t2 - t1) * ey) >> 16) + t1;
|
||||||
|
t1 = ((((c01->b - c00->b) * ex) >> 16) + c00->b) & 0xff;
|
||||||
|
t2 = ((((c11->b - c10->b) * ex) >> 16) + c10->b) & 0xff;
|
||||||
|
dp->b = (((t2 - t1) * ey) >> 16) + t1;
|
||||||
|
t1 = ((((c01->a - c00->a) * ex) >> 16) + c00->a) & 0xff;
|
||||||
|
t2 = ((((c11->a - c10->a) * ex) >> 16) + c10->a) & 0xff;
|
||||||
|
dp->a = (((t2 - t1) * ey) >> 16) + t1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Advance source pointers
|
||||||
|
*/
|
||||||
|
csax++;
|
||||||
|
sstep = (*csax >> 16);
|
||||||
|
c00 += sstep;
|
||||||
|
c01 += sstep;
|
||||||
|
c10 += sstep;
|
||||||
|
c11 += sstep;
|
||||||
|
/*
|
||||||
|
* Advance destination pointer
|
||||||
|
*/
|
||||||
|
dp++;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Advance source pointer
|
||||||
|
*/
|
||||||
|
csay++;
|
||||||
|
csp = (tColorRGBA *) ((Uint8 *) csp + (*csay >> 16) * src->pitch);
|
||||||
|
/*
|
||||||
|
* Advance destination pointers
|
||||||
|
*/
|
||||||
|
dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Non-Interpolating Zoom
|
||||||
|
*/
|
||||||
|
|
||||||
|
csay = say;
|
||||||
|
for (y = 0; y < dst->h; y++) {
|
||||||
|
sp = csp;
|
||||||
|
csax = sax;
|
||||||
|
for (x = 0; x < dst->w; x++) {
|
||||||
|
/*
|
||||||
|
* Draw
|
||||||
|
*/
|
||||||
|
*dp = *sp;
|
||||||
|
/*
|
||||||
|
* Advance source pointers
|
||||||
|
*/
|
||||||
|
csax++;
|
||||||
|
sp += (*csax >> 16);
|
||||||
|
/*
|
||||||
|
* Advance destination pointer
|
||||||
|
*/
|
||||||
|
dp++;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Advance source pointer
|
||||||
|
*/
|
||||||
|
csay++;
|
||||||
|
csp = (tColorRGBA *) ((Uint8 *) csp + (*csay >> 16) * src->pitch);
|
||||||
|
/*
|
||||||
|
* Advance destination pointers
|
||||||
|
*/
|
||||||
|
dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Remove temp arrays
|
||||||
|
*/
|
||||||
|
free(sax);
|
||||||
|
free(say);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
8bit Zoomer without smoothing.
|
||||||
|
|
||||||
|
Zoomes 8bit palette/Y 'src' surface to 'dst' surface.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst)
|
||||||
|
{
|
||||||
|
Uint32 x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy;
|
||||||
|
Uint8 *sp, *dp, *csp;
|
||||||
|
int dgap;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Variable setup
|
||||||
|
*/
|
||||||
|
sx = (Uint32) (65536.0 * (float) src->w / (float) dst->w);
|
||||||
|
sy = (Uint32) (65536.0 * (float) src->h / (float) dst->h);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate memory for row increments
|
||||||
|
*/
|
||||||
|
if ((sax = (Uint32 *) malloc(dst->w * sizeof(Uint32))) == NULL) {
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if ((say = (Uint32 *) malloc(dst->h * sizeof(Uint32))) == NULL) {
|
||||||
|
if (sax != NULL) {
|
||||||
|
free(sax);
|
||||||
|
}
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Precalculate row increments
|
||||||
|
*/
|
||||||
|
csx = 0;
|
||||||
|
csax = sax;
|
||||||
|
for (x = 0; x < dst->w; x++) {
|
||||||
|
csx += sx;
|
||||||
|
*csax = (csx >> 16);
|
||||||
|
csx &= 0xffff;
|
||||||
|
csax++;
|
||||||
|
}
|
||||||
|
csy = 0;
|
||||||
|
csay = say;
|
||||||
|
for (y = 0; y < dst->h; y++) {
|
||||||
|
csy += sy;
|
||||||
|
*csay = (csy >> 16);
|
||||||
|
csy &= 0xffff;
|
||||||
|
csay++;
|
||||||
|
}
|
||||||
|
|
||||||
|
csx = 0;
|
||||||
|
csax = sax;
|
||||||
|
for (x = 0; x < dst->w; x++) {
|
||||||
|
csx += (*csax);
|
||||||
|
csax++;
|
||||||
|
}
|
||||||
|
csy = 0;
|
||||||
|
csay = say;
|
||||||
|
for (y = 0; y < dst->h; y++) {
|
||||||
|
csy += (*csay);
|
||||||
|
csay++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Pointer setup
|
||||||
|
*/
|
||||||
|
sp = csp = (Uint8 *) src->pixels;
|
||||||
|
dp = (Uint8 *) dst->pixels;
|
||||||
|
dgap = dst->pitch - dst->w;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Draw
|
||||||
|
*/
|
||||||
|
csay = say;
|
||||||
|
for (y = 0; y < dst->h; y++) {
|
||||||
|
csax = sax;
|
||||||
|
sp = csp;
|
||||||
|
for (x = 0; x < dst->w; x++) {
|
||||||
|
/*
|
||||||
|
* Draw
|
||||||
|
*/
|
||||||
|
*dp = *sp;
|
||||||
|
/*
|
||||||
|
* Advance source pointers
|
||||||
|
*/
|
||||||
|
sp += (*csax);
|
||||||
|
csax++;
|
||||||
|
/*
|
||||||
|
* Advance destination pointer
|
||||||
|
*/
|
||||||
|
dp++;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Advance source pointer (for row)
|
||||||
|
*/
|
||||||
|
csp += ((*csay) * src->pitch);
|
||||||
|
csay++;
|
||||||
|
/*
|
||||||
|
* Advance destination pointers
|
||||||
|
*/
|
||||||
|
dp += dgap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Remove temp arrays
|
||||||
|
*/
|
||||||
|
free(sax);
|
||||||
|
free(say);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
32bit Rotozoomer with optional anti-aliasing by bilinear interpolation.
|
||||||
|
|
||||||
|
Rotates and zoomes 32bit RGBA/ABGR 'src' surface to 'dst' surface.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
void transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int smooth)
|
||||||
|
{
|
||||||
|
int x, y, t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh;
|
||||||
|
tColorRGBA c00, c01, c10, c11;
|
||||||
|
tColorRGBA *pc, *sp; // *spb;
|
||||||
|
int gap;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Variable setup
|
||||||
|
*/
|
||||||
|
xd = ((src->w - dst->w) << 15);
|
||||||
|
yd = ((src->h - dst->h) << 15);
|
||||||
|
ax = (cx << 16) - (icos * cx);
|
||||||
|
ay = (cy << 16) - (isin * cx);
|
||||||
|
sw = src->w - 1;
|
||||||
|
sh = src->h - 1;
|
||||||
|
pc = dst->pixels;
|
||||||
|
gap = dst->pitch - dst->w * 4;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Switch between interpolating and non-interpolating code
|
||||||
|
*/
|
||||||
|
if (smooth) {
|
||||||
|
for (y = 0; y < dst->h; y++) {
|
||||||
|
dy = cy - y;
|
||||||
|
sdx = (ax + (isin * dy)) + xd;
|
||||||
|
sdy = (ay - (icos * dy)) + yd;
|
||||||
|
for (x = 0; x < dst->w; x++) {
|
||||||
|
dx = (sdx >> 16);
|
||||||
|
dy = (sdy >> 16);
|
||||||
|
if ((dx >= -1) && (dy >= -1) && (dx < src->w) && (dy < src->h)) {
|
||||||
|
if ((dx >= 0) && (dy >= 0) && (dx < sw) && (dy < sh)) {
|
||||||
|
sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy);
|
||||||
|
sp += dx;
|
||||||
|
c00 = *sp;
|
||||||
|
sp += 1;
|
||||||
|
c01 = *sp;
|
||||||
|
sp = (tColorRGBA *) ((Uint8 *) sp + src->pitch);
|
||||||
|
sp -= 1;
|
||||||
|
c10 = *sp;
|
||||||
|
sp += 1;
|
||||||
|
c11 = *sp;
|
||||||
|
} else if ((dx == sw) && (dy == sh)) {
|
||||||
|
sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy);
|
||||||
|
sp += dx;
|
||||||
|
c00 = *sp;
|
||||||
|
c01 = *sp;
|
||||||
|
c10 = *sp;
|
||||||
|
c11 = *sp;
|
||||||
|
} else if ((dx == -1) && (dy == -1)) {
|
||||||
|
sp = (tColorRGBA *) (src->pixels);
|
||||||
|
c00 = *sp;
|
||||||
|
c01 = *sp;
|
||||||
|
c10 = *sp;
|
||||||
|
c11 = *sp;
|
||||||
|
} else if ((dx == -1) && (dy == sh)) {
|
||||||
|
sp = (tColorRGBA *) (src->pixels);
|
||||||
|
sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy);
|
||||||
|
c00 = *sp;
|
||||||
|
c01 = *sp;
|
||||||
|
c10 = *sp;
|
||||||
|
c11 = *sp;
|
||||||
|
} else if ((dx == sw) && (dy == -1)) {
|
||||||
|
sp = (tColorRGBA *) (src->pixels);
|
||||||
|
sp += dx;
|
||||||
|
c00 = *sp;
|
||||||
|
c01 = *sp;
|
||||||
|
c10 = *sp;
|
||||||
|
c11 = *sp;
|
||||||
|
} else if (dx == -1) {
|
||||||
|
sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy);
|
||||||
|
c00 = *sp;
|
||||||
|
c01 = *sp;
|
||||||
|
c10 = *sp;
|
||||||
|
sp = (tColorRGBA *) ((Uint8 *) sp + src->pitch);
|
||||||
|
c11 = *sp;
|
||||||
|
} else if (dy == -1) {
|
||||||
|
sp = (tColorRGBA *) (src->pixels);
|
||||||
|
sp += dx;
|
||||||
|
c00 = *sp;
|
||||||
|
c01 = *sp;
|
||||||
|
c10 = *sp;
|
||||||
|
sp += 1;
|
||||||
|
c11 = *sp;
|
||||||
|
} else if (dx == sw) {
|
||||||
|
sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy);
|
||||||
|
sp += dx;
|
||||||
|
c00 = *sp;
|
||||||
|
c01 = *sp;
|
||||||
|
sp = (tColorRGBA *) ((Uint8 *) sp + src->pitch);
|
||||||
|
c10 = *sp;
|
||||||
|
c11 = *sp;
|
||||||
|
} else if (dy == sh) {
|
||||||
|
sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy);
|
||||||
|
sp += dx;
|
||||||
|
c00 = *sp;
|
||||||
|
sp += 1;
|
||||||
|
c01 = *sp;
|
||||||
|
c10 = *sp;
|
||||||
|
c11 = *sp;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Interpolate colors
|
||||||
|
*/
|
||||||
|
ex = (sdx & 0xffff);
|
||||||
|
ey = (sdy & 0xffff);
|
||||||
|
t1 = ((((c01.r - c00.r) * ex) >> 16) + c00.r) & 0xff;
|
||||||
|
t2 = ((((c11.r - c10.r) * ex) >> 16) + c10.r) & 0xff;
|
||||||
|
pc->r = (((t2 - t1) * ey) >> 16) + t1;
|
||||||
|
t1 = ((((c01.g - c00.g) * ex) >> 16) + c00.g) & 0xff;
|
||||||
|
t2 = ((((c11.g - c10.g) * ex) >> 16) + c10.g) & 0xff;
|
||||||
|
pc->g = (((t2 - t1) * ey) >> 16) + t1;
|
||||||
|
t1 = ((((c01.b - c00.b) * ex) >> 16) + c00.b) & 0xff;
|
||||||
|
t2 = ((((c11.b - c10.b) * ex) >> 16) + c10.b) & 0xff;
|
||||||
|
pc->b = (((t2 - t1) * ey) >> 16) + t1;
|
||||||
|
t1 = ((((c01.a - c00.a) * ex) >> 16) + c00.a) & 0xff;
|
||||||
|
t2 = ((((c11.a - c10.a) * ex) >> 16) + c10.a) & 0xff;
|
||||||
|
pc->a = (((t2 - t1) * ey) >> 16) + t1;
|
||||||
|
}
|
||||||
|
sdx += icos;
|
||||||
|
sdy += isin;
|
||||||
|
pc++;
|
||||||
|
}
|
||||||
|
pc = (tColorRGBA *) ((Uint8 *) pc + gap);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (y = 0; y < dst->h; y++) {
|
||||||
|
dy = cy - y;
|
||||||
|
sdx = (ax + (isin * dy)) + xd;
|
||||||
|
sdy = (ay - (icos * dy)) + yd;
|
||||||
|
for (x = 0; x < dst->w; x++) {
|
||||||
|
dx = (short) (sdx >> 16);
|
||||||
|
dy = (short) (sdy >> 16);
|
||||||
|
if ((dx >= 0) && (dy >= 0) && (dx < src->w) && (dy < src->h)) {
|
||||||
|
sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy);
|
||||||
|
sp += dx;
|
||||||
|
*pc = *sp;
|
||||||
|
}
|
||||||
|
sdx += icos;
|
||||||
|
sdy += isin;
|
||||||
|
pc++;
|
||||||
|
}
|
||||||
|
pc = (tColorRGBA *) ((Uint8 *) pc + gap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
8bit Rotozoomer without smoothing
|
||||||
|
|
||||||
|
Rotates and zoomes 8bit palette/Y 'src' surface to 'dst' surface.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
void transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos)
|
||||||
|
{
|
||||||
|
int x, y, dx, dy, xd, yd, sdx, sdy, ax, ay, sw, sh;
|
||||||
|
tColorY *pc, *sp;
|
||||||
|
int gap;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Variable setup
|
||||||
|
*/
|
||||||
|
xd = ((src->w - dst->w) << 15);
|
||||||
|
yd = ((src->h - dst->h) << 15);
|
||||||
|
ax = (cx << 16) - (icos * cx);
|
||||||
|
ay = (cy << 16) - (isin * cx);
|
||||||
|
sw = src->w - 1;
|
||||||
|
sh = src->h - 1;
|
||||||
|
pc = dst->pixels;
|
||||||
|
gap = dst->pitch - dst->w;
|
||||||
|
/*
|
||||||
|
* Clear surface to colorkey
|
||||||
|
*/
|
||||||
|
memset(pc, (unsigned char) (src->format->colorkey & 0xff), dst->pitch * dst->h);
|
||||||
|
/*
|
||||||
|
* Iterate through destination surface
|
||||||
|
*/
|
||||||
|
for (y = 0; y < dst->h; y++) {
|
||||||
|
dy = cy - y;
|
||||||
|
sdx = (ax + (isin * dy)) + xd;
|
||||||
|
sdy = (ay - (icos * dy)) + yd;
|
||||||
|
for (x = 0; x < dst->w; x++) {
|
||||||
|
dx = (short) (sdx >> 16);
|
||||||
|
dy = (short) (sdy >> 16);
|
||||||
|
if ((dx >= 0) && (dy >= 0) && (dx < src->w) && (dy < src->h)) {
|
||||||
|
sp = (tColorY *) (src->pixels);
|
||||||
|
sp += (src->pitch * dy + dx);
|
||||||
|
*pc = *sp;
|
||||||
|
}
|
||||||
|
sdx += icos;
|
||||||
|
sdy += isin;
|
||||||
|
pc++;
|
||||||
|
}
|
||||||
|
pc += gap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
rotozoomSurface()
|
||||||
|
|
||||||
|
Rotates and zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface.
|
||||||
|
'angle' is the rotation in degrees. 'zoom' a scaling factor. If 'smooth' is 1
|
||||||
|
then the destination 32bit surface is anti-aliased. If the surface is not 8bit
|
||||||
|
or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define VALUE_LIMIT 0.001
|
||||||
|
|
||||||
|
|
||||||
|
/* Local rotozoom-size function with trig result return */
|
||||||
|
|
||||||
|
void rotozoomSurfaceSizeTrig(int width, int height, double angle, double zoom, int *dstwidth, int *dstheight,
|
||||||
|
double *canglezoom, double *sanglezoom)
|
||||||
|
{
|
||||||
|
double x, y, cx, cy, sx, sy;
|
||||||
|
double radangle;
|
||||||
|
int dstwidthhalf, dstheighthalf;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Determine destination width and height by rotating a centered source box
|
||||||
|
*/
|
||||||
|
radangle = angle * (M_PI / 180.0);
|
||||||
|
*sanglezoom = sin(radangle);
|
||||||
|
*canglezoom = cos(radangle);
|
||||||
|
*sanglezoom *= zoom;
|
||||||
|
*canglezoom *= zoom;
|
||||||
|
x = width / 2;
|
||||||
|
y = height / 2;
|
||||||
|
cx = *canglezoom * x;
|
||||||
|
cy = *canglezoom * y;
|
||||||
|
sx = *sanglezoom * x;
|
||||||
|
sy = *sanglezoom * y;
|
||||||
|
dstwidthhalf = MAX((int)
|
||||||
|
ceil(MAX(MAX(MAX(fabs(cx + sy), fabs(cx - sy)), fabs(-cx + sy)), fabs(-cx - sy))), 1);
|
||||||
|
dstheighthalf = MAX((int)
|
||||||
|
ceil(MAX(MAX(MAX(fabs(sx + cy), fabs(sx - cy)), fabs(-sx + cy)), fabs(-sx - cy))), 1);
|
||||||
|
*dstwidth = 2 * dstwidthhalf;
|
||||||
|
*dstheight = 2 * dstheighthalf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Publically available rotozoom-size function */
|
||||||
|
|
||||||
|
void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth, int *dstheight)
|
||||||
|
{
|
||||||
|
double dummy_sanglezoom, dummy_canglezoom;
|
||||||
|
|
||||||
|
rotozoomSurfaceSizeTrig(width, height, angle, zoom, dstwidth, dstheight, &dummy_sanglezoom, &dummy_canglezoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Publically available rotozoom function */
|
||||||
|
|
||||||
|
SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth)
|
||||||
|
{
|
||||||
|
SDL_Surface *rz_src;
|
||||||
|
SDL_Surface *rz_dst;
|
||||||
|
double zoominv;
|
||||||
|
double sanglezoom, canglezoom, sanglezoominv, canglezoominv;
|
||||||
|
int dstwidthhalf, dstwidth, dstheighthalf, dstheight;
|
||||||
|
//double x, y, cx, cy, sx, sy;
|
||||||
|
int is32bit;
|
||||||
|
int i, src_converted;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sanity check
|
||||||
|
*/
|
||||||
|
if (src == NULL)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Determine if source surface is 32bit or 8bit
|
||||||
|
*/
|
||||||
|
is32bit = (src->format->BitsPerPixel == 32);
|
||||||
|
if ((is32bit) || (src->format->BitsPerPixel == 8)) {
|
||||||
|
/*
|
||||||
|
* Use source surface 'as is'
|
||||||
|
*/
|
||||||
|
rz_src = src;
|
||||||
|
src_converted = 0;
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* New source surface is 32bit with a defined RGBA ordering
|
||||||
|
*/
|
||||||
|
rz_src =
|
||||||
|
SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
|
||||||
|
SDL_BlitSurface(src, NULL, rz_src, NULL);
|
||||||
|
src_converted = 1;
|
||||||
|
is32bit = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sanity check zoom factor
|
||||||
|
*/
|
||||||
|
if (zoom < VALUE_LIMIT) {
|
||||||
|
zoom = VALUE_LIMIT;
|
||||||
|
}
|
||||||
|
zoominv = 65536.0 / (zoom * zoom);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if we have a rotozoom or just a zoom
|
||||||
|
*/
|
||||||
|
if (fabs(angle) > VALUE_LIMIT) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Angle!=0: full rotozoom
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* -----------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Determine target size */
|
||||||
|
rotozoomSurfaceSizeTrig(rz_src->w, rz_src->h, angle, zoom, &dstwidth, &dstheight, &canglezoom, &sanglezoom);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate target factors from sin/cos and zoom
|
||||||
|
*/
|
||||||
|
sanglezoominv = sanglezoom;
|
||||||
|
canglezoominv = canglezoom;
|
||||||
|
sanglezoominv *= zoominv;
|
||||||
|
canglezoominv *= zoominv;
|
||||||
|
|
||||||
|
/* Calculate half size */
|
||||||
|
dstwidthhalf = dstwidth / 2;
|
||||||
|
dstheighthalf = dstheight / 2;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Alloc space to completely contain the rotated surface
|
||||||
|
*/
|
||||||
|
rz_dst = NULL;
|
||||||
|
if (is32bit) {
|
||||||
|
/*
|
||||||
|
* Target surface is 32bit with source RGBA/ABGR ordering
|
||||||
|
*/
|
||||||
|
rz_dst =
|
||||||
|
SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 32,
|
||||||
|
rz_src->format->Rmask, rz_src->format->Gmask,
|
||||||
|
rz_src->format->Bmask, rz_src->format->Amask);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Target surface is 8bit
|
||||||
|
*/
|
||||||
|
rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Lock source surface
|
||||||
|
*/
|
||||||
|
SDL_LockSurface(rz_src);
|
||||||
|
/*
|
||||||
|
* Check which kind of surface we have
|
||||||
|
*/
|
||||||
|
if (is32bit) {
|
||||||
|
/*
|
||||||
|
* Call the 32bit transformation routine to do the rotation (using alpha)
|
||||||
|
*/
|
||||||
|
transformSurfaceRGBA(rz_src, rz_dst, dstwidthhalf, dstheighthalf,
|
||||||
|
(int) (sanglezoominv), (int) (canglezoominv), smooth);
|
||||||
|
/*
|
||||||
|
* Turn on source-alpha support
|
||||||
|
*/
|
||||||
|
SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Copy palette and colorkey info
|
||||||
|
*/
|
||||||
|
for (i = 0; i < rz_src->format->palette->ncolors; i++) {
|
||||||
|
rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i];
|
||||||
|
}
|
||||||
|
rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors;
|
||||||
|
/*
|
||||||
|
* Call the 8bit transformation routine to do the rotation
|
||||||
|
*/
|
||||||
|
transformSurfaceY(rz_src, rz_dst, dstwidthhalf, dstheighthalf,
|
||||||
|
(int) (sanglezoominv), (int) (canglezoominv));
|
||||||
|
SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, rz_src->format->colorkey);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Unlock source surface
|
||||||
|
*/
|
||||||
|
SDL_UnlockSurface(rz_src);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Angle=0: Just a zoom
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* --------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate target size
|
||||||
|
*/
|
||||||
|
zoomSurfaceSize(rz_src->w, rz_src->h, zoom, zoom, &dstwidth, &dstheight);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Alloc space to completely contain the zoomed surface
|
||||||
|
*/
|
||||||
|
rz_dst = NULL;
|
||||||
|
if (is32bit) {
|
||||||
|
/*
|
||||||
|
* Target surface is 32bit with source RGBA/ABGR ordering
|
||||||
|
*/
|
||||||
|
rz_dst =
|
||||||
|
SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 32,
|
||||||
|
rz_src->format->Rmask, rz_src->format->Gmask,
|
||||||
|
rz_src->format->Bmask, rz_src->format->Amask);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Target surface is 8bit
|
||||||
|
*/
|
||||||
|
rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Lock source surface
|
||||||
|
*/
|
||||||
|
SDL_LockSurface(rz_src);
|
||||||
|
/*
|
||||||
|
* Check which kind of surface we have
|
||||||
|
*/
|
||||||
|
if (is32bit) {
|
||||||
|
/*
|
||||||
|
* Call the 32bit transformation routine to do the zooming (using alpha)
|
||||||
|
*/
|
||||||
|
zoomSurfaceRGBA(rz_src, rz_dst, smooth);
|
||||||
|
/*
|
||||||
|
* Turn on source-alpha support
|
||||||
|
*/
|
||||||
|
SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Copy palette and colorkey info
|
||||||
|
*/
|
||||||
|
for (i = 0; i < rz_src->format->palette->ncolors; i++) {
|
||||||
|
rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i];
|
||||||
|
}
|
||||||
|
rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors;
|
||||||
|
/*
|
||||||
|
* Call the 8bit transformation routine to do the zooming
|
||||||
|
*/
|
||||||
|
zoomSurfaceY(rz_src, rz_dst);
|
||||||
|
SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, rz_src->format->colorkey);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Unlock source surface
|
||||||
|
*/
|
||||||
|
SDL_UnlockSurface(rz_src);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Cleanup temp surface
|
||||||
|
*/
|
||||||
|
if (src_converted) {
|
||||||
|
SDL_FreeSurface(rz_src);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return destination surface
|
||||||
|
*/
|
||||||
|
return (rz_dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
zoomSurface()
|
||||||
|
|
||||||
|
Zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface.
|
||||||
|
'zoomx' and 'zoomy' are scaling factors for width and height. If 'smooth' is 1
|
||||||
|
then the destination 32bit surface is anti-aliased. If the surface is not 8bit
|
||||||
|
or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define VALUE_LIMIT 0.001
|
||||||
|
|
||||||
|
void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Sanity check zoom factors
|
||||||
|
*/
|
||||||
|
if (zoomx < VALUE_LIMIT) {
|
||||||
|
zoomx = VALUE_LIMIT;
|
||||||
|
}
|
||||||
|
if (zoomy < VALUE_LIMIT) {
|
||||||
|
zoomy = VALUE_LIMIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate target size
|
||||||
|
*/
|
||||||
|
*dstwidth = (int) ((double) width * zoomx);
|
||||||
|
*dstheight = (int) ((double) height * zoomy);
|
||||||
|
if (*dstwidth < 1) {
|
||||||
|
*dstwidth = 1;
|
||||||
|
}
|
||||||
|
if (*dstheight < 1) {
|
||||||
|
*dstheight = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth)
|
||||||
|
{
|
||||||
|
SDL_Surface *rz_src;
|
||||||
|
SDL_Surface *rz_dst;
|
||||||
|
int dstwidth, dstheight;
|
||||||
|
int is32bit;
|
||||||
|
int i, src_converted;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sanity check
|
||||||
|
*/
|
||||||
|
if (src == NULL)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Determine if source surface is 32bit or 8bit
|
||||||
|
*/
|
||||||
|
is32bit = (src->format->BitsPerPixel == 32);
|
||||||
|
if ((is32bit) || (src->format->BitsPerPixel == 8)) {
|
||||||
|
/*
|
||||||
|
* Use source surface 'as is'
|
||||||
|
*/
|
||||||
|
rz_src = src;
|
||||||
|
src_converted = 0;
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* New source surface is 32bit with a defined RGBA ordering
|
||||||
|
*/
|
||||||
|
rz_src =
|
||||||
|
SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
|
||||||
|
SDL_BlitSurface(src, NULL, rz_src, NULL);
|
||||||
|
src_converted = 1;
|
||||||
|
is32bit = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get size if target */
|
||||||
|
zoomSurfaceSize(rz_src->w, rz_src->h, zoomx, zoomy, &dstwidth, &dstheight);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Alloc space to completely contain the zoomed surface
|
||||||
|
*/
|
||||||
|
rz_dst = NULL;
|
||||||
|
if (is32bit) {
|
||||||
|
/*
|
||||||
|
* Target surface is 32bit with source RGBA/ABGR ordering
|
||||||
|
*/
|
||||||
|
rz_dst =
|
||||||
|
SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 32,
|
||||||
|
rz_src->format->Rmask, rz_src->format->Gmask,
|
||||||
|
rz_src->format->Bmask, rz_src->format->Amask);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Target surface is 8bit
|
||||||
|
*/
|
||||||
|
rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Lock source surface
|
||||||
|
*/
|
||||||
|
SDL_LockSurface(rz_src);
|
||||||
|
/*
|
||||||
|
* Check which kind of surface we have
|
||||||
|
*/
|
||||||
|
if (is32bit) {
|
||||||
|
/*
|
||||||
|
* Call the 32bit transformation routine to do the zooming (using alpha)
|
||||||
|
*/
|
||||||
|
zoomSurfaceRGBA(rz_src, rz_dst, smooth);
|
||||||
|
/*
|
||||||
|
* Turn on source-alpha support
|
||||||
|
*/
|
||||||
|
SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Copy palette and colorkey info
|
||||||
|
*/
|
||||||
|
for (i = 0; i < rz_src->format->palette->ncolors; i++) {
|
||||||
|
rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i];
|
||||||
|
}
|
||||||
|
rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors;
|
||||||
|
/*
|
||||||
|
* Call the 8bit transformation routine to do the zooming
|
||||||
|
*/
|
||||||
|
zoomSurfaceY(rz_src, rz_dst);
|
||||||
|
SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, rz_src->format->colorkey);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Unlock source surface
|
||||||
|
*/
|
||||||
|
SDL_UnlockSurface(rz_src);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Cleanup temp surface
|
||||||
|
*/
|
||||||
|
if (src_converted) {
|
||||||
|
SDL_FreeSurface(rz_src);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return destination surface
|
||||||
|
*/
|
||||||
|
return (rz_dst);
|
||||||
|
}
|
99
util/cosas utiles/SDL_gfx/SDL_rotozoom.h
Normal file
99
util/cosas utiles/SDL_gfx/SDL_rotozoom.h
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
SDL_rotozoom - rotozoomer
|
||||||
|
|
||||||
|
LGPL (c) A. Schiffler
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SDL_rotozoom_h
|
||||||
|
#define _SDL_rotozoom_h
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/* Set up for C function definitions, even when using C++ */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef M_PI
|
||||||
|
#define M_PI 3.141592654
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
/* ---- Defines */
|
||||||
|
|
||||||
|
#define SMOOTHING_OFF 0
|
||||||
|
#define SMOOTHING_ON 1
|
||||||
|
|
||||||
|
/* ---- Structures */
|
||||||
|
|
||||||
|
typedef struct tColorRGBA {
|
||||||
|
Uint8 r;
|
||||||
|
Uint8 g;
|
||||||
|
Uint8 b;
|
||||||
|
Uint8 a;
|
||||||
|
} tColorRGBA;
|
||||||
|
|
||||||
|
typedef struct tColorY {
|
||||||
|
Uint8 y;
|
||||||
|
} tColorY;
|
||||||
|
|
||||||
|
|
||||||
|
/* ---- Prototypes */
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#ifdef BUILD_DLL
|
||||||
|
#define DLLINTERFACE __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define DLLINTERFACE __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define DLLINTERFACE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
rotozoomSurface()
|
||||||
|
|
||||||
|
Rotates and zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface.
|
||||||
|
'angle' is the rotation in degrees. 'zoom' a scaling factor. If 'smooth' is 1
|
||||||
|
then the destination 32bit surface is anti-aliased. If the surface is not 8bit
|
||||||
|
or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
DLLINTERFACE SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth);
|
||||||
|
|
||||||
|
|
||||||
|
/* Returns the size of the target surface for a rotozoomSurface() call */
|
||||||
|
|
||||||
|
DLLINTERFACE void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth,
|
||||||
|
int *dstheight);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
zoomSurface()
|
||||||
|
|
||||||
|
Zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface.
|
||||||
|
'zoomx' and 'zoomy' are scaling factors for width and height. If 'smooth' is 1
|
||||||
|
then the destination 32bit surface is anti-aliased. If the surface is not 8bit
|
||||||
|
or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
DLLINTERFACE SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth);
|
||||||
|
|
||||||
|
/* Returns the size of the target surface for a zoomSurface() call */
|
||||||
|
|
||||||
|
DLLINTERFACE void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight);
|
||||||
|
|
||||||
|
|
||||||
|
/* Ends C function definitions when using C++ */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _SDL_rotozoom_h */
|
2889
util/cosas utiles/kplib/kplib.c
Normal file
2889
util/cosas utiles/kplib/kplib.c
Normal file
File diff suppressed because it is too large
Load diff
31
util/cosas utiles/kplib/kplib.h
Normal file
31
util/cosas utiles/kplib/kplib.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
KPLIB.H: Ken's Picture LIBrary written by Ken Silverman
|
||||||
|
Copyright (c) 1998-2004 Ken Silverman
|
||||||
|
Ken Silverman's official web site: http://www.advsys.net/ken
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __KPLIB_H__
|
||||||
|
#define __KPLIB_H__
|
||||||
|
|
||||||
|
//High-level (easy) picture loading function:
|
||||||
|
extern void kpzload (const char *, long *, long *, long *, long *);
|
||||||
|
//Low-level PNG/JPG functions:
|
||||||
|
extern void kpgetdim (const char *, long, long *, long *);
|
||||||
|
extern long kprender (const char *, long, long, long, long, long, long, long);
|
||||||
|
|
||||||
|
//ZIP functions:
|
||||||
|
extern void kzaddstack (const char *);
|
||||||
|
extern void kzuninit ();
|
||||||
|
extern long kzopen (const char *);
|
||||||
|
extern long kzread (void *, long);
|
||||||
|
extern long kzfilelength ();
|
||||||
|
extern void kzseek (long, long);
|
||||||
|
extern long kztell ();
|
||||||
|
extern long kzgetc ();
|
||||||
|
extern long kzeof ();
|
||||||
|
extern void kzclose ();
|
||||||
|
|
||||||
|
extern void kzfindfilestart (const char *); //pass wildcard string
|
||||||
|
extern long kzfindfile (char *); //you alloc buf, returns 1:found,0:~found
|
||||||
|
|
||||||
|
#endif //__KPLIB_H__
|
8
util/cosas utiles/kplib/leeme.txt
Normal file
8
util/cosas utiles/kplib/leeme.txt
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
Ésta es la librería KPLIB, escrita por Ken Silverman (el ke hizo el motor del Duke3D).
|
||||||
|
Lo he sacado de su librería Voxlap. El .h es un cacho sacado de voxlap5.h
|
||||||
|
Puede abrir BMP,JPG,PNG,GIF,PCX,TGA,CEL y ZIP (y puede ke algún otro formato). Funciona en Windows y Linux. Está muy bien porke además es pequeña y simple (normalmente necesitaríamos varias librerías para abrir tantos formatos). Además, puede cargar cualquiera de los mencionados formatos directamente desde un archivo ZIP, lo cual permite usarlos como sistema de ficheros virtual (PAK's). Y por cierto, Silverman hizo varias mejoras al formato PNG, por lo que ésta es una de las mejores librerías que hay para cargar PNG.
|
||||||
|
Creo que no infringimos ninguna licencia incluyendo esto en eDIV. en el .C no pone nada, pero quizás utilice la licencia BUILD, que básicamente dice que le demos crédito al autor y que no lo utilicemos con fines comerciales sin darle su parte X) no sé a vosotros, pero a mí a estas alturas me importan bastante poco las posibles (o mejor dicho, improbables) aplicaciones comerciales de eDIV.
|
||||||
|
|
||||||
|
+ info en la página de Silverman: http://www.advsys.net/ken
|
||||||
|
|
||||||
|
Er_Makina
|
Loading…
Reference in a new issue