# for TIZEN-maru board
-$(call set-vpath, $(SRC_PATH):$(TARGET_PATH):$(SRC_PATH)/hw:$(SRC_PATH)/tizen/src:$(SRC_PATH)/tizen/src/hw:$(SRC_PATH)/tizen/src/skin)
+$(call set-vpath, $(SRC_PATH):$(TARGET_PATH):$(SRC_PATH)/hw:$(SRC_PATH)/tizen/src:$(SRC_PATH)/tizen/src/hw:$(SRC_PATH)/tizen/src/skin:$(SRC_PATH)/tizen/src/SDL_gfx)
QEMU_CFLAGS += -I$(SRC_PATH)/hw -I$(SRC_PATH)/tizen/src
QEMU_CFLAGS += -I$(SRC_PATH)/tizen/distrib/libav/$(ARCH)/include
--- /dev/null
+Andreas Schiffler <aschiffler@ferzkopp.net>
--- /dev/null
+(C) A. Schiffler, ZLIB - see file LICENSE
--- /dev/null
+/*
+
+Copyright (C) 2001-2011 Andreas Schiffler
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+
+Andreas Schiffler -- aschiffler at ferzkopp dot net
+
+*/
\ No newline at end of file
--- /dev/null
+/*!\r
+\r
+\r
+\mainpage SDL_gfx - SDL-1.2 graphics drawing primitives, rotozoom and other supporting functions\r
+\r
+\r
+\section contact_sec Contact and License\r
+\r
+Email aschiffler at ferzkopp dot net to contact the author or better check\r
+author's homepage at http://www.ferzkopp.net for the most up-to-date\r
+contact information.\r
+\r
+This library is licenced under the zlib License, see the file LICENSE for details. \r
+\r
+\r
+\section intro_sec Introduction\r
+\r
+The SDL_gfx library evolved out of the SDL_gfxPrimitives code which\r
+provided basic drawing routines such as lines, circles or polygons for \r
+SDL Surfaces and adding a couple other useful functions for zooming \r
+images for example and doing basic image processing on byte arrays.\r
+\r
+Note that SDL_gfx is compatible with SDL version 1.2 (not SDL2).\r
+\r
+The current components of the SDL_gfx library are:\r
+- Graphic Primitives (SDL_gfxPrimitives.h, SDL_gfxPrimitives.c)\r
+- Rotozoomer (SDL_rotozoom.h, SDL_rotozoom.c)\r
+- Framerate control (SDL_framerate.h, SDL_framerate.c)\r
+- MMX image filters (SDL_imageFilter.h, SDL_imageFilter.c)\r
+- Custom Blit functions (SDL_gfxBlitFunc.h, SDL_gfxBlitFunc.c)\r
+- Build-in 8x8 Font (SDL_gfxPrimitives_font.h)\r
+\r
+\r
+\r
+\subsection notes_gfx Notes on Graphics Primitives\r
+\r
+Care has been taken so that all routines are fully alpha-aware and can \r
+blend any primitive onto the target surface if ALPHA<255. Surface depths \r
+supported are 1,2,3 and 4 bytes per pixel. Surface locking is implemented\r
+in each routine and the library should work well with hardware \r
+accelerated surfaces. \r
+\r
+\htmlonly\r
+<a href="../Screenshots/SDL_gfxPrimitives.jpg" target="_blank" title="SDL_gfxPrimitives Screenshot"><img src="../Screenshots/SDL_gfxPrimitives-thumb.jpg" border="0" hspace="5"></a><br />\r
+\endhtmlonly\r
+\r
+Currently, The following Anti-Aliased drawing primitives are available:\r
+- AA-line\r
+- AA-polygon\r
+- AA-circle\r
+- AA-ellipse\r
+\r
+Note: All ___Color routines expect the color to be in the format 0xRRGGBBAA.\r
+\r
+\subsection notes_roto Notes on Rotozoomer\r
+\r
+The rotozoom code is not ASM-speed quality, but it should be fast enough \r
+even for some realtime effects if the CPU is good or bitmaps small.\r
+With interpolation the routines are typically used for pre-rendering stuff \r
+in higher quality (i.e. smoothing) - that's also the reason why the API differs \r
+from SDL_BlitRect() - as they create a new target surface each time rotozoom \r
+is called. The final rendering speed is dependent on the target surface\r
+size as it is beeing xy-scanned when rendering the new surface.\r
+\r
+\htmlonly\r
+<a href="../Screenshots/SDL_rotozoom.jpg" target="_blank" title="SDL_rotozoom Screenshot"><img src="../Screenshots/SDL_rotozoom-thumb.jpg" border="0" hspace="5"></a><br />\r
+\endhtmlonly\r
+\r
+Note also that the smoothing toggle is dependent on the input surface bit \r
+depth. 8bit surfaces will \b never be smoothed - only 32bit surfaces will.\r
+\r
+Note that surfaces of other bit depth then 8 and 32 will be converted \r
+on the fly to a 32bit surface using a blit into a temporary surface. This \r
+impacts performance somewhat.\r
+\r
+Smoothing (interpolation) flags work only on 32bit surfaces:\r
+\verbatim\r
+ #define SMOOTHING_OFF 0\r
+ #define SMOOTHING_ON 1\r
+\endverbatim\r
+ \r
+\subsection notes_rate Notes on Framerate Manager\r
+\r
+The framerate functions are used to insert delays into the graphics loop\r
+to maintain a constant framerate.\r
+\r
+The implementation is more sophisticated that the usual\r
+\verbatim\r
+ SDL_Delay(1000/FPS); \r
+\endverbatim\r
+call since these functions keep track of the desired game time per frame \r
+for a linearly interpolated sequence of future timing points of each frame. \r
+This is done to avoid rounding errors from the inherent instability in the \r
+delay generation and application.\r
+\r
+\htmlonly\r
+<a href="../framerate.png" target="_blank" title="Framerate Diagram"><img src="../framerate-thumb.png" border="0"></a><br />\r
+\endhtmlonly\r
+\r
+i.e. the 100th frame of a game running at 50Hz will be accurately\r
+2.00sec after the 1st frame (if the machine can keep up with the drawing).\r
+\r
+The functions return 0 or 'value' for sucess and -1 for error. All functions\r
+use a pointer to a framerate-manager variable to operate.\r
+\r
+\r
+\subsection notes_filter Notes on ImageFilters\r
+\r
+The imagefilter functions are a collection of MMX optimized routines that\r
+operate on continuous buffers of bytes - typically greyscale images from \r
+framegrabbers and such - performing functions such as image addition and \r
+binarization. All functions (almost ... not the the convolution routines) \r
+have a C implementation that is automatically used on systems without MMX \r
+capabilities.\r
+\r
+The compiler flag -DUSE_MMX toggles the conditional compile of MMX assembly.\r
+An assembler must be installed (i.e. "nasm").\r
+\r
+\r
+\subsection notes_blitters Notes on Custom Blitters\r
+\r
+The custom blitter functions provide (limited) support for surface\r
+compositing - that is surfaces can be blitted together, and then\r
+still blitted to the screen with transparency intact.\r
+\r
+\subsection platforms Supported Platforms\r
+\r
+\subsubsection platformlinux Unix/Linux\r
+\r
+The library compiles and is tested for a Linux target (gcc compiler) via the\r
+the usual configure;make;make install sequence.\r
+\r
+\subsubsection platformwindows Windows\r
+ \r
+A Win32 target is available (VisualC6/7/8/9, mingw32, xmingw32 cross-compiler).\r
+The SDL_gfx.sln will open VS2010 (the old VS2008 .sln is also still included) \r
+including express versions. \r
+\r
+See "Other Builds" for additional makefiles (may be out of date).\r
+\r
+When using the cross-compiler (available on the author's homepage, very\r
+out of date), the build process generates .DLLs. You can use the command \r
+line 'LIB.EXE' tool to generate VC6 compatible .LIB files for linking \r
+purposes. \r
+\r
+\subsubsection platformosx Mac OSX \r
+\r
+The usual autotools build chain should be used. MacPorts or fink may \r
+be required (that's what the author uses).\r
+\r
+Xcode is supported via templates. See "Other Builds" folder Xcode3+.zip -\r
+this template only supports SDL_gfx and not the tests. For this template, the\r
+Deployment Target (the lowest version to run on) is set to 10.5 and expects\r
+the SDL.framework preinstalled in some default location\r
+(either /Library/Frameworks, or ~/Library/Frameworks). \r
+\r
+Older targets are also reported to work (10.3+ native and Project Builder). \r
+\r
+\subsubsection platformqnx QNX\r
+\r
+QNX was reported to build (see .diff in "Other Builds").\r
+\r
+\subsubsection platformzune Zune\r
+\r
+ZuneHD (WinCE 6 ARM) is reported to build (see OpenZDK in "Other Builds").\r
+Note that between rendering on the Zune's ARM CPU and constantly uploading\r
+textures to the GPU, SDL_gfx is going to be slow. Also, the libc math \r
+functions all use software FP emulation even when VFP floating point\r
+support is turned on in the compiler, so there's extra overhead due to that\r
+as well.\r
+\r
+\subsubsection platformothers Others\r
+\r
+Other platforms might work but have not been tested by the author.\r
+Please check the file "INSTALL" as well as the folder "Other Builds".\r
+\r
+See also section "Installation" below for more build instructions.\r
+\r
+\section install_sec Installation\r
+\r
+\subsection unix Unix/Linux\r
+\r
+To compile the library your need the SDL 1.2 installed from source or \r
+installed with the 'devel' RPM package. For example on Mandriva, run:\r
+\verbatim\r
+ urpmi libSDL1.2-devel\r
+\endverbatim\r
+\r
+Then run\r
+\verbatim\r
+ ./autogen.sh # (optional, recommended)\r
+ ./configure\r
+ make\r
+ make install\r
+ ldconfig\r
+\endverbatim\r
+\r
+to compile and install the library. The default location for the \r
+installation is /usr/local/lib and /usr/local/include. The libary \r
+path might need to be added to the file:\r
+ /etc/ld.so.conf\r
+\r
+Run the shell script 'nodebug.sh' before make, to patch the makefile \r
+for optimized compilation:\r
+\verbatim\r
+ ./autogen.sh # (optional, recommended)\r
+ ./configure\r
+ ./nodebug.sh\r
+ make\r
+ make install\r
+ ldconfig\r
+\endverbatim\r
+\r
+Check the folder "Other Builds" for alternative makefiles.\r
+\r
+\subsection prep Build Prep\r
+\r
+Run autogen.sh or manually:\r
+\verbatim\r
+ aclocal --force\r
+ libtoolize --force --copy\r
+ autoreconf -fvi\r
+\endverbatim\r
+\r
+\subsection nommx No-MMX\r
+\r
+To build without MMX code enabled (i.e. PPC or for AMD64 architecture\r
+which is missing pusha/popa):\r
+\verbatim\r
+ ./configure --disable-mmx\r
+ make\r
+ make install\r
+\endverbatim\r
+i.e. to build on MacOSX 10.3+ use:\r
+\verbatim\r
+ ./configure --disable-mmx && make\r
+\endverbatim\r
+\r
+\subsection vs9 Windows (VC9, VS2010)\r
+\r
+Open SDL_gfx.sln solution file and review README.\r
+\r
+\subsection vs8 Windows (VC8, VS2008)\r
+\r
+Open SDL_gfx_VS2008.sln solution file and review README.\r
+\r
+\r
+\subsection vc6 Windows (VC6/7)\r
+\r
+See folder Other Builds.\r
+\r
+To create a Windows DLL using VisualC6:\r
+\verbatim\r
+ unzip -a VisualC6.zip\r
+ vcvars32.bat\r
+ copy VisualC/makefile\r
+ nmake\r
+\endverbatim\r
+or\r
+\verbatim\r
+ unzip -a VisualC7.zip\r
+\endverbatim\r
+and open the project file.\r
+\r
+\r
+\subsection wince WindowsCE\r
+\r
+See folder Other Builds.\r
+\r
+May need workaround for missing lrint.\r
+\r
+\r
+\subsection cross Cross-Compilation\r
+\r
+To build using mingw32 on Win32, check the makefile contained in mingw.zip\r
+\r
+To create a Windows DLL using the xmingw32 cross-compiler:\r
+\verbatim\r
+ cross-configure\r
+ cross-make\r
+ cross-make install\r
+\endverbatim\r
+\r
+Make sure the -DBUILD_DLL is used (and only then) when creating the DLLs.\r
+Make sure -DWIN32 is used when compiling the sources (creating or using\r
+the DLLs.\r
+\r
+Specify the path to your cross-compiled 'sdl-config', and invoke\r
+'./configure' with the '--host' and '--build' arguments. For example,\r
+to cross-compile a .DLL from GNU/Linux:\r
+\verbatim\r
+ SDL_CONFIG=/usr/local/cross-tools/i386-mingw32msvc/bin/sdl-config \\r
+ ./configure --host=i586-mingw32msvc --build=i686-pc-linux-gnu\r
+ make\r
+ make install\r
+\endverbatim\r
+\r
+\subsection qnx QNX\r
+\r
+To build on QNX6, patch first using:\r
+\verbatim\r
+ patch -p0 <QNX.diff\r
+\endverbatim\r
+\r
+\subsection osx OSX\r
+\r
+Use standard unix build sequence.\r
+\r
+To build on MacOS X with Project Builder, follow these steps:\r
+- Update your developer tools to the lastest version.\r
+- Install the SDL Developers framework for Mac OS X.\r
+- Download the latest SDL_gfx source distribution and extract the\r
+ archive in a convenient location.\r
+- Extract the included OSX-PB.tgz archive into the\r
+ top directory of the SDL_gfx distribution (from step 3). This will create a\r
+ PB that contains the project files.\r
+- The project has targets for the SDL_gfx framework and the four test\r
+ programs. All can be built using the 'deployment' or 'development' build\r
+ styles. \r
+\r
+A newer version for MaxOS X is included in the OSX-PB-XCode.zip archive. The \r
+updated version uses relative pathnames where appropriate, and pointers to \r
+the standard installation location of SDL. However, it may require XCode in \r
+order to be used.\r
+\r
+\section interfaces_sec Language Interfaces\r
+\r
+SDL_gfx has been integrated with the following language interfaces:\r
+- Pascal: http://www.freepascal-meets-sdl.net\r
+- Perl: http://sdl.perl.org\r
+- Python: http://www.pygame.org\r
+- C#: http://cs-sdl.sourceforge.net\r
+- Lua: http://www.egsl.retrogamecoding.org/\r
+- Oberon: http://sourceforge.net/projects/sdl-for-oberon/\r
+\r
+\section test_sec Test Programs\r
+\r
+Change to the ./Test directory and run\r
+\verbatim\r
+ ./autogen.sh\r
+ ./configure\r
+ make\r
+\endverbatim\r
+to create several test programs for the libraries functions. This requires\r
+the library to be previously compiled and installed.\r
+\r
+\r
+See the source code .c files for some sample code and implementation hints.\r
+\r
+\r
+\section contrib_sec Contributors\r
+\r
+- Fix for filledbox by Ingo van Lil, inguin at gmx.de - thanks Ingo.\r
+\r
+- Non-alpha line drawing code adapted from routine \r
+ by Pete Shinners, pete at shinners.org - thanks Pete.\r
+\r
+- More fixes by Karl Bartel, karlb at gmx.net - thanks Karl.\r
+\r
+- Much testing and suggestions for fixes from Danny van Bruggen,\r
+ danny at froukepc.dhs.org - thanks Danny.\r
+\r
+- Original AA-circle/-ellipse code idea from Stephane Magnenat, \r
+ nct at wg0.ysagoon.com - thanks Stephane.\r
+\r
+- Faster blending routines contributed by Anders Lindstroem,\r
+ cal at swipnet.se - thanks Anders.\r
+\r
+- New AA-circle/-ellipse code based on ideas from Anders Lindstroem - \r
+ thanks Anders.\r
+\r
+- VisualC makefile contributed by Danny van Bruggen, \r
+ danny at froukepc.dhs.org - thanks Danny.\r
+\r
+- VisualC7 project file contributed by James Turk, \r
+ jturk at conceptofzero.com - thanks James.\r
+\r
+- Project Builder package contributed by Thomas Tongue, \r
+ TTongue at imagiware.com - Thanks Thomas.\r
+\r
+- Fix for filledPolygon contributed by Kentaro Fukuchi \r
+ fukuchi at is.titech.ac.jp - Thanks Kentaro.\r
+\r
+- QNX6 patch contributed by Mike Gorchak,\r
+ mike at malva.ua - Thanks Mike.\r
+\r
+- Pie idea contributed by Eike Lange,\r
+ eike.lange at uni-essen.de - Thanks Eike.\r
+\r
+- Dynamic font setup by Todor Prokopov,\r
+ koprok at dir.bg - Thanks Todor.\r
+\r
+- Horizontal/Vertical flipping code by Victor (Haypo) \r
+ Stinner, victor.stinner at haypocalc.com - Thanks Victor.\r
+\r
+- OSX build fixes by Michael Wybrow, \r
+ mjwybrow at cs.mu.oz.au - Thanks Michael.\r
+\r
+- gcc3.4 build fixes by Dries Verachtert, \r
+ dries at ulyssis.org - Thanks Dries.\r
+\r
+- Updated OSX build by Brian Rice,\r
+ water451 at gmail.com - Thanks Brian.\r
+\r
+- aaellipse issues pointed out by Marco Wertz,\r
+ marco.wertz at gmx.de - Thanks Marco.\r
+\r
+- texturedPolygon idea and code by Kees Jongenburger,\r
+ kees.jongenburger at gmail.com - Thanks Kees.\r
+ \r
+- Several bugfixes contributed by Sigborn Skjaeret, \r
+ cisc at broadpark.no - Thanks CISC.\r
+\r
+- Syntax error for C++ found by Olivier Boudeville,\r
+ olivier.boudeville at online.fr - Thanks Olivier.\r
+\r
+- hline/vline clipping fixes found by Daniel Roggen,\r
+ droggen at gmail.com and Mikael Thieme, \r
+ mikael.thieme at his.se - Thanks Daniel+Mikael.\r
+\r
+- rotozoom fix for big-endian machines (i.e. PPC)\r
+ by Julian Mayer, julianmayer at mac.com - Thanks\r
+ Julian.\r
+\r
+- Cross-compilation notes contributed by Sylvain\r
+ Beucler, beuc at beuc.net - Thanks Sylvain.\r
+\r
+- Fix duplicate pixel renders in circleColor contributed\r
+ by David Raber, lotharstar at gmail.com - Thanks David.\r
+\r
+- New arcColor (and arcRGBA) routine contributed\r
+ by David Raber, lotharstar at gmail.com - Thanks David.\r
+\r
+- Idea for polygonColorMT and texturePolygonMT routines for\r
+ multithreaded operation contributed by "unknown" -\r
+ Thank you.\r
+\r
+- Multiple patches applied and repackaged version 2.0.18\r
+ by Paul, sweetlilmre at gmail.com - Thanks Paul and\r
+ other contributors of patches.\r
+\r
+- Change to avoid gcc4 compiler warnings contributed by Thien-Thi\r
+ nguyen, ttn at gnuvola.org - thanks Thi. \r
+\r
+- hline 1bpp off-by-one patch contributed by Manuel Lausch\r
+ mail at manuellausch.de - Thanks Manuel.\r
+\r
+- pkg-config support contributed by Luca Bigliardi, shammash\r
+ at artha.org - thanks Luca.\r
+\r
+- Updated mingw Makefile contributed by Jan Leike, jan dot leike \r
+ at gmx dot net - thanks Jan.\r
+\r
+- Rotozoom debugging help by Jeff Wilges, heff at ifup dot us -\r
+ thanks Jeff.\r
+\r
+- Build updates provided by Barry deFreese, bdefreese at debian \r
+ dot org - thanks Barry.\r
+\r
+- Fix for 1-pixel postponement with 8bit scaling by Sylvain Beucler, \r
+ beuc at beuc dot net - thanks Sylvain.\r
+\r
+- Updates to headers and configure to allow for cross-compiling \r
+ to DLL (not just static .a) and fixes for compiling on Windows \r
+ using autotools by Sylvain Beucler, beuc at beuc dot net - thanks Sylvain.\r
+\r
+- Added Visual CE Project to Builds. Contributed by vrichomme at smartmobili\r
+ dot com - thanks.\r
+\r
+- Added Symbian and Windows 64bit fix with lrint function by Rene \r
+ Dudfield, renesd at gmail dot com - thanks Rene.\r
+\r
+- Fixes for Rotate90 0-degree case by Chris Allport, chris dot allport\r
+ at gmail dot com - thanks Chris.\r
+\r
+- Fixed for Win32 build support defines by tigerfishdaisy (SF) - thanks\r
+ Tiger Tiger.\r
+\r
+- Patch for OpenSDK contributed by itsnotabigtruck at ovi dot com - thanks\r
+ IsNotABigTruck.\r
+\r
+- OSX Xcode 3+ template ZIP contributed by marabus at meta dot ua - thanks\r
+ Vasyl.\r
+\r
+- Memory leak/error check patch for zoomSurface contributed by \r
+ RodolfoRG - thanks Rodolfo.\r
+\r
+- Zoom scaling factor rounding bugfix patch contributed by WanderWander\r
+ Lairson Costa - thanks Wander.\r
+\r
+- Suggestions for speed improvements contributed by inkyankes - thanks.\r
+\r
+- Pixel blend routine patches contributed by mitja at lxnav dot com -\r
+ thanks Mitja.\r
+\r
+\section changelog_sec Change Log\r
+\r
+\verbinclude ChangeLog\r
+\r
+*/
\ No newline at end of file
--- /dev/null
+/*
+
+SDL_rotozoom.c: rotozoomer, zoomer and shrinker for 32bit or 8bit surfaces
+
+Copyright (C) 2001-2012 Andreas Schiffler
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not
+claim that you wrote the original software. If you use this software
+in a product, an acknowledgment in the product documentation would be
+appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and must not be
+misrepresented as being the original software.
+
+3. This notice may not be removed or altered from any source
+distribution.
+
+Andreas Schiffler -- aschiffler at ferzkopp dot net
+
+*/
+
+#ifdef WIN32
+#include <windows.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "SDL_rotozoom.h"
+
+/* ---- Internally used structures */
+
+/*!
+\brief A 32 bit RGBA pixel.
+*/
+typedef struct tColorRGBA {
+ Uint8 r;
+ Uint8 g;
+ Uint8 b;
+ Uint8 a;
+} tColorRGBA;
+
+/*!
+\brief A 8bit Y/palette pixel.
+*/
+typedef struct tColorY {
+ Uint8 y;
+} tColorY;
+
+/*!
+\brief Returns maximum of two numbers a and b.
+*/
+#define MAX(a,b) (((a) > (b)) ? (a) : (b))
+
+/*!
+\brief Number of guard rows added to destination surfaces.
+
+This is a simple but effective workaround for observed issues.
+These rows allocate extra memory and are then hidden from the surface.
+Rows are added to the end of destination surfaces when they are allocated.
+This catches any potential overflows which seem to happen with
+just the right src image dimensions and scale/rotation and can lead
+to a situation where the program can segfault.
+*/
+#define GUARD_ROWS (2)
+
+/*!
+\brief Lower limit of absolute zoom factor or rotation degrees.
+*/
+#define VALUE_LIMIT 0.001
+
+/*!
+\brief Returns colorkey info for a surface
+*/
+static Uint32 _colorkey(SDL_Surface *src)
+{
+ Uint32 key = 0;
+#if (SDL_MINOR_VERSION == 3)
+ SDL_GetColorKey(src, &key);
+#else
+ if (src)
+ {
+ key = src->format->colorkey;
+ }
+#endif
+ return key;
+}
+
+
+/*!
+\brief Internal 32 bit integer-factor averaging Shrinker.
+
+Shrinks 32 bit RGBA/ABGR 'src' surface to 'dst' surface.
+Averages color and alpha values values of src pixels to calculate dst pixels.
+Assumes src and dst surfaces are of 32 bit depth.
+Assumes dst surface was allocated with the correct dimensions.
+
+\param src The surface to shrink (input).
+\param dst The shrunken surface (output).
+\param factorx The horizontal shrinking ratio.
+\param factory The vertical shrinking ratio.
+
+\return 0 for success or -1 for error.
+*/
+static int _shrinkSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int factorx, int factory)
+{
+ int x, y, dx, dy, sgap, dgap, ra, ga, ba, aa;
+ int n_average;
+ tColorRGBA *sp, *osp, *oosp;
+ tColorRGBA *dp;
+
+ /*
+ * Averaging integer shrink
+ */
+
+ /* Precalculate division factor */
+ n_average = factorx*factory;
+
+ /*
+ * Scan destination
+ */
+ sp = (tColorRGBA *) src->pixels;
+ sgap = src->pitch - src->w * 4;
+
+ dp = (tColorRGBA *) dst->pixels;
+ dgap = dst->pitch - dst->w * 4;
+
+ for (y = 0; y < dst->h; y++) {
+
+ osp=sp;
+ for (x = 0; x < dst->w; x++) {
+
+ /* Trace out source box and accumulate */
+ oosp=sp;
+ ra=ga=ba=aa=0;
+ for (dy=0; dy < factory; dy++) {
+ for (dx=0; dx < factorx; dx++) {
+ ra += sp->r;
+ ga += sp->g;
+ ba += sp->b;
+ aa += sp->a;
+
+ sp++;
+ }
+ /* src dx loop */
+ sp = (tColorRGBA *)((Uint8*)sp + (src->pitch - 4*factorx)); // next y
+ }
+ /* src dy loop */
+
+ /* next box-x */
+ sp = (tColorRGBA *)((Uint8*)oosp + 4*factorx);
+
+ /* Store result in destination */
+ dp->r = ra/n_average;
+ dp->g = ga/n_average;
+ dp->b = ba/n_average;
+ dp->a = aa/n_average;
+
+ /*
+ * Advance destination pointer
+ */
+ dp++;
+ }
+ /* dst x loop */
+
+ /* next box-y */
+ sp = (tColorRGBA *)((Uint8*)osp + src->pitch*factory);
+
+ /*
+ * Advance destination pointers
+ */
+ dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
+ }
+ /* dst y loop */
+
+ return (0);
+}
+
+/*!
+\brief Internal 8 bit integer-factor averaging shrinker.
+
+Shrinks 8bit Y 'src' surface to 'dst' surface.
+Averages color (brightness) values values of src pixels to calculate dst pixels.
+Assumes src and dst surfaces are of 8 bit depth.
+Assumes dst surface was allocated with the correct dimensions.
+
+\param src The surface to shrink (input).
+\param dst The shrunken surface (output).
+\param factorx The horizontal shrinking ratio.
+\param factory The vertical shrinking ratio.
+
+\return 0 for success or -1 for error.
+*/
+static int _shrinkSurfaceY(SDL_Surface * src, SDL_Surface * dst, int factorx, int factory)
+{
+ int x, y, dx, dy, sgap, dgap, a;
+ int n_average;
+ Uint8 *sp, *osp, *oosp;
+ Uint8 *dp;
+
+ /*
+ * Averaging integer shrink
+ */
+
+ /* Precalculate division factor */
+ n_average = factorx*factory;
+
+ /*
+ * Scan destination
+ */
+ sp = (Uint8 *) src->pixels;
+ sgap = src->pitch - src->w;
+
+ dp = (Uint8 *) dst->pixels;
+ dgap = dst->pitch - dst->w;
+
+ for (y = 0; y < dst->h; y++) {
+
+ osp=sp;
+ for (x = 0; x < dst->w; x++) {
+
+ /* Trace out source box and accumulate */
+ oosp=sp;
+ a=0;
+ for (dy=0; dy < factory; dy++) {
+ for (dx=0; dx < factorx; dx++) {
+ a += (*sp);
+ /* next x */
+ sp++;
+ }
+ /* end src dx loop */
+ /* next y */
+ sp = (Uint8 *)((Uint8*)sp + (src->pitch - factorx));
+ }
+ /* end src dy loop */
+
+ /* next box-x */
+ sp = (Uint8 *)((Uint8*)oosp + factorx);
+
+ /* Store result in destination */
+ *dp = a/n_average;
+
+ /*
+ * Advance destination pointer
+ */
+ dp++;
+ }
+ /* end dst x loop */
+
+ /* next box-y */
+ sp = (Uint8 *)((Uint8*)osp + src->pitch*factory);
+
+ /*
+ * Advance destination pointers
+ */
+ dp = (Uint8 *)((Uint8 *)dp + dgap);
+ }
+ /* end dst y loop */
+
+ return (0);
+}
+
+/*!
+\brief Internal 32 bit Zoomer with optional anti-aliasing by bilinear interpolation.
+
+Zooms 32 bit RGBA/ABGR 'src' surface to 'dst' surface.
+Assumes src and dst surfaces are of 32 bit depth.
+Assumes dst surface was allocated with the correct dimensions.
+
+\param src The surface to zoom (input).
+\param dst The zoomed surface (output).
+\param flipx Flag indicating if the image should be horizontally flipped.
+\param flipy Flag indicating if the image should be vertically flipped.
+\param smooth Antialiasing flag; set to SMOOTHING_ON to enable.
+
+\return 0 for success or -1 for error.
+*/
+static int _zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy, int smooth)
+{
+ int x, y, sx, sy, ssx, ssy, *sax, *say, *csax, *csay, *salast, csx, csy, ex, ey, cx, cy, sstep, sstepx, sstepy;
+ tColorRGBA *c00, *c01, *c10, *c11;
+ tColorRGBA *sp, *csp, *dp;
+ int spixelgap, spixelw, spixelh, dgap, t1, t2;
+
+ /*
+ * Allocate memory for row/column 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
+ */
+ spixelw = (src->w - 1);
+ spixelh = (src->h - 1);
+ if (smooth) {
+ sx = (int) (65536.0 * (float) spixelw / (float) (dst->w - 1));
+ sy = (int) (65536.0 * (float) spixelh / (float) (dst->h - 1));
+ } else {
+ sx = (int) (65536.0 * (float) (src->w) / (float) (dst->w));
+ sy = (int) (65536.0 * (float) (src->h) / (float) (dst->h));
+ }
+
+ /* Maximum scaled source size */
+ ssx = (src->w << 16) - 1;
+ ssy = (src->h << 16) - 1;
+
+ /* Precalculate horizontal row increments */
+ csx = 0;
+ csax = sax;
+ for (x = 0; x <= dst->w; x++) {
+ *csax = csx;
+ csax++;
+ csx += sx;
+
+ /* Guard from overflows */
+ if (csx > ssx) {
+ csx = ssx;
+ }
+ }
+
+ /* Precalculate vertical row increments */
+ csy = 0;
+ csay = say;
+ for (y = 0; y <= dst->h; y++) {
+ *csay = csy;
+ csay++;
+ csy += sy;
+
+ /* Guard from overflows */
+ if (csy > ssy) {
+ csy = ssy;
+ }
+ }
+
+ sp = (tColorRGBA *) src->pixels;
+ dp = (tColorRGBA *) dst->pixels;
+ dgap = dst->pitch - dst->w * 4;
+ spixelgap = src->pitch/4;
+
+ if (flipx) sp += spixelw;
+ if (flipy) sp += (spixelgap * spixelh);
+
+ /*
+ * Switch between interpolating and non-interpolating code
+ */
+ if (smooth) {
+
+ /*
+ * Interpolating Zoom
+ */
+ csay = say;
+ for (y = 0; y < dst->h; y++) {
+ csp = sp;
+ csax = sax;
+ for (x = 0; x < dst->w; x++) {
+ /*
+ * Setup color source pointers
+ */
+ ex = (*csax & 0xffff);
+ ey = (*csay & 0xffff);
+ cx = (*csax >> 16);
+ cy = (*csay >> 16);
+ sstepx = cx < spixelw;
+ sstepy = cy < spixelh;
+ c00 = sp;
+ c01 = sp;
+ c10 = sp;
+ if (sstepy) {
+ if (flipy) {
+ c10 -= spixelgap;
+ } else {
+ c10 += spixelgap;
+ }
+ }
+ c11 = c10;
+ if (sstepx) {
+ if (flipx) {
+ c01--;
+ c11--;
+ } else {
+ c01++;
+ c11++;
+ }
+ }
+
+ /*
+ * Draw and interpolate colors
+ */
+ 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 pointer x
+ */
+ salast = csax;
+ csax++;
+ sstep = (*csax >> 16) - (*salast >> 16);
+ if (flipx) {
+ sp -= sstep;
+ } else {
+ sp += sstep;
+ }
+
+ /*
+ * Advance destination pointer x
+ */
+ dp++;
+ }
+ /*
+ * Advance source pointer y
+ */
+ salast = csay;
+ csay++;
+ sstep = (*csay >> 16) - (*salast >> 16);
+ sstep *= spixelgap;
+ if (flipy) {
+ sp = csp - sstep;
+ } else {
+ sp = csp + sstep;
+ }
+
+ /*
+ * Advance destination pointer y
+ */
+ dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
+ }
+ } else {
+ /*
+ * Non-Interpolating Zoom
+ */
+ csay = say;
+ for (y = 0; y < dst->h; y++) {
+ csp = sp;
+ csax = sax;
+ for (x = 0; x < dst->w; x++) {
+ /*
+ * Draw
+ */
+ *dp = *sp;
+
+ /*
+ * Advance source pointer x
+ */
+ salast = csax;
+ csax++;
+ sstep = (*csax >> 16) - (*salast >> 16);
+ if (flipx) sstep = -sstep;
+ sp += sstep;
+
+ /*
+ * Advance destination pointer x
+ */
+ dp++;
+ }
+ /*
+ * Advance source pointer y
+ */
+ salast = csay;
+ csay++;
+ sstep = (*csay >> 16) - (*salast >> 16);
+ sstep *= spixelgap;
+ if (flipy) sstep = -sstep;
+ sp = csp + sstep;
+
+ /*
+ * Advance destination pointer y
+ */
+ dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
+ }
+ }
+
+ /*
+ * Remove temp arrays
+ */
+ free(sax);
+ free(say);
+
+ return (0);
+}
+
+/*!
+
+\brief Internal 8 bit Zoomer without smoothing.
+
+Zooms 8bit palette/Y 'src' surface to 'dst' surface.
+Assumes src and dst surfaces are of 8 bit depth.
+Assumes dst surface was allocated with the correct dimensions.
+
+\param src The surface to zoom (input).
+\param dst The zoomed surface (output).
+\param flipx Flag indicating if the image should be horizontally flipped.
+\param flipy Flag indicating if the image should be vertically flipped.
+
+\return 0 for success or -1 for error.
+*/
+static int _zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy)
+{
+ int x, y;
+ Uint32 *sax, *say, *csax, *csay;
+ int csx, csy;
+ Uint8 *sp, *dp, *csp;
+ int dgap;
+
+ /*
+ * Allocate memory for row increments
+ */
+ if ((sax = (Uint32 *) malloc((dst->w + 1) * sizeof(Uint32))) == NULL) {
+ return (-1);
+ }
+ if ((say = (Uint32 *) malloc((dst->h + 1) * sizeof(Uint32))) == NULL) {
+ free(sax);
+ return (-1);
+ }
+
+ /*
+ * Pointer setup
+ */
+ sp = csp = (Uint8 *) src->pixels;
+ dp = (Uint8 *) dst->pixels;
+ dgap = dst->pitch - dst->w;
+
+ if (flipx) csp += (src->w-1);
+ if (flipy) csp = ( (Uint8*)csp + src->pitch*(src->h-1) );
+
+ /*
+ * Precalculate row increments
+ */
+ csx = 0;
+ csax = sax;
+ for (x = 0; x < dst->w; x++) {
+ csx += src->w;
+ *csax = 0;
+ while (csx >= dst->w) {
+ csx -= dst->w;
+ (*csax)++;
+ }
+ (*csax) = (*csax) * (flipx ? -1 : 1);
+ csax++;
+ }
+ csy = 0;
+ csay = say;
+ for (y = 0; y < dst->h; y++) {
+ csy += src->h;
+ *csay = 0;
+ while (csy >= dst->h) {
+ csy -= dst->h;
+ (*csay)++;
+ }
+ (*csay) = (*csay) * (flipy ? -1 : 1);
+ csay++;
+ }
+
+ /*
+ * 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);
+}
+
+/*!
+\brief Internal 32 bit rotozoomer with optional anti-aliasing.
+
+Rotates and zooms 32 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control
+parameters by scanning the destination surface and applying optionally anti-aliasing
+by bilinear interpolation.
+Assumes src and dst surfaces are of 32 bit depth.
+Assumes dst surface was allocated with the correct dimensions.
+
+\param src Source surface.
+\param dst Destination surface.
+\param cx Horizontal center coordinate.
+\param cy Vertical center coordinate.
+\param isin Integer version of sine of angle.
+\param icos Integer version of cosine of angle.
+\param flipx Flag indicating horizontal mirroring should be applied.
+\param flipy Flag indicating vertical mirroring should be applied.
+\param smooth Flag indicating anti-aliasing should be used.
+*/
+static void _transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy, int smooth)
+{
+ int x, y, t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh;
+ tColorRGBA c00, c01, c10, c11, cswap;
+ tColorRGBA *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 = (tColorRGBA*) 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 (flipx) dx = sw - dx;
+ if (flipy) dy = sh - dy;
+ if ((dx > -1) && (dy > -1) && (dx < (src->w-1)) && (dy < (src->h-1))) {
+ sp = (tColorRGBA *)src->pixels;;
+ sp += ((src->pitch/4) * dy);
+ sp += dx;
+ c00 = *sp;
+ sp += 1;
+ c01 = *sp;
+ sp += (src->pitch/4);
+ c11 = *sp;
+ sp -= 1;
+ c10 = *sp;
+ if (flipx) {
+ cswap = c00; c00=c01; c01=cswap;
+ cswap = c10; c10=c11; c11=cswap;
+ }
+ if (flipy) {
+ cswap = c00; c00=c10; c10=cswap;
+ cswap = c01; c01=c11; c11=cswap;
+ }
+ /*
+ * 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 (flipx) dx = (src->w-1)-dx;
+ if (flipy) dy = (src->h-1)-dy;
+ 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);
+ }
+ }
+}
+
+/*!
+
+\brief Rotates and zooms 8 bit palette/Y 'src' surface to 'dst' surface without smoothing.
+
+Rotates and zooms 8 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control
+parameters by scanning the destination surface.
+Assumes src and dst surfaces are of 8 bit depth.
+Assumes dst surface was allocated with the correct dimensions.
+
+\param src Source surface.
+\param dst Destination surface.
+\param cx Horizontal center coordinate.
+\param cy Vertical center coordinate.
+\param isin Integer version of sine of angle.
+\param icos Integer version of cosine of angle.
+\param flipx Flag indicating horizontal mirroring should be applied.
+\param flipy Flag indicating vertical mirroring should be applied.
+*/
+static void transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy)
+{
+ 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 = (tColorY*) dst->pixels;
+ gap = dst->pitch - dst->w;
+ /*
+ * Clear surface to colorkey
+ */
+ memset(pc, (int)(_colorkey(src) & 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 (flipx) dx = (src->w-1)-dx;
+ if (flipy) dy = (src->h-1)-dy;
+ 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;
+ }
+}
+
+/*!
+\brief Rotates a 32 bit surface in increments of 90 degrees.
+
+Specialized 90 degree rotator which rotates a 'src' surface in 90 degree
+increments clockwise returning a new surface. Faster than rotozoomer since
+not scanning or interpolation takes place. Input surface must be 32 bit.
+(code contributed by J. Schiller, improved by C. Allport and A. Schiffler)
+
+\param src Source surface to rotate.
+\param numClockwiseTurns Number of clockwise 90 degree turns to apply to the source.
+
+\returns The new, rotated surface; or NULL for surfaces with incorrect input format.
+*/
+SDL_Surface* rotateSurface90Degrees(SDL_Surface* src, int numClockwiseTurns)
+{
+ int row, col, newWidth, newHeight;
+ int bpp, src_ipr, dst_ipr;
+ SDL_Surface* dst;
+ Uint32* srcBuf;
+ Uint32* dstBuf;
+
+ /* Has to be a valid surface pointer and only 32-bit surfaces (for now) */
+ if (!src || src->format->BitsPerPixel != 32) { return NULL; }
+
+ /* normalize numClockwiseTurns */
+ while(numClockwiseTurns < 0) { numClockwiseTurns += 4; }
+ numClockwiseTurns = (numClockwiseTurns % 4);
+
+ /* if it's even, our new width will be the same as the source surface */
+ newWidth = (numClockwiseTurns % 2) ? (src->h) : (src->w);
+ newHeight = (numClockwiseTurns % 2) ? (src->w) : (src->h);
+ dst = SDL_CreateRGBSurface( src->flags, newWidth, newHeight, src->format->BitsPerPixel,
+ src->format->Rmask,
+ src->format->Gmask,
+ src->format->Bmask,
+ src->format->Amask);
+ if(!dst) {
+ return NULL;
+ }
+
+ if (SDL_MUSTLOCK(dst)) {
+ SDL_LockSurface(dst);
+ }
+ if (SDL_MUSTLOCK(dst)) {
+ SDL_LockSurface(dst);
+ }
+
+ /* Calculate int-per-row */
+ bpp = src->format->BitsPerPixel / 8;
+ src_ipr = src->pitch / bpp;
+ dst_ipr = dst->pitch / bpp;
+
+ switch(numClockwiseTurns) {
+ case 0: /* Make a copy of the surface */
+ {
+ /* Unfortunately SDL_BlitSurface cannot be used to make a copy of the surface
+ since it does not preserve alpha. */
+
+ if (src->pitch == dst->pitch) {
+ /* If the pitch is the same for both surfaces, the memory can be copied all at once. */
+ memcpy(dst->pixels, src->pixels, (src->h * src->pitch));
+ }
+ else
+ {
+ /* If the pitch differs, copy each row separately */
+ srcBuf = (Uint32*)(src->pixels);
+ dstBuf = (Uint32*)(dst->pixels);
+ for (row = 0; row < src->h; row++) {
+ memcpy(dstBuf, srcBuf, dst->w * bpp);
+ srcBuf += src_ipr;
+ dstBuf += dst_ipr;
+ } /* end for(col) */
+ } /* end for(row) */
+ }
+ break;
+
+ /* rotate clockwise */
+ case 1: /* rotated 90 degrees clockwise */
+ {
+ for (row = 0; row < src->h; ++row) {
+ srcBuf = (Uint32*)(src->pixels) + (row * src_ipr);
+ dstBuf = (Uint32*)(dst->pixels) + (dst->w - row - 1);
+ for (col = 0; col < src->w; ++col) {
+ *dstBuf = *srcBuf;
+ ++srcBuf;
+ dstBuf += dst_ipr;
+ }
+ /* end for(col) */
+ }
+ /* end for(row) */
+ }
+ break;
+
+ case 2: /* rotated 180 degrees clockwise */
+ {
+ for (row = 0; row < src->h; ++row) {
+ srcBuf = (Uint32*)(src->pixels) + (row * src_ipr);
+ dstBuf = (Uint32*)(dst->pixels) + ((dst->h - row - 1) * dst_ipr) + (dst->w - 1);
+ for (col = 0; col < src->w; ++col) {
+ *dstBuf = *srcBuf;
+ ++srcBuf;
+ --dstBuf;
+ }
+ }
+ }
+ break;
+
+ case 3:
+ {
+ for (row = 0; row < src->h; ++row) {
+ srcBuf = (Uint32*)(src->pixels) + (row * src_ipr);
+ dstBuf = (Uint32*)(dst->pixels) + row + ((dst->h - 1) * dst_ipr);
+ for (col = 0; col < src->w; ++col) {
+ *dstBuf = *srcBuf;
+ ++srcBuf;
+ dstBuf -= dst_ipr;
+ }
+ }
+ }
+ break;
+ }
+ /* end switch */
+
+ if (SDL_MUSTLOCK(src)) {
+ SDL_UnlockSurface(src);
+ }
+ if (SDL_MUSTLOCK(dst)) {
+ SDL_UnlockSurface(dst);
+ }
+
+ return dst;
+}
+
+
+/*!
+\brief Internal target surface sizing function for rotozooms with trig result return.
+
+\param width The source surface width.
+\param height The source surface height.
+\param angle The angle to rotate in degrees.
+\param zoomx The horizontal scaling factor.
+\param zoomy The vertical scaling factor.
+\param dstwidth The calculated width of the destination surface.
+\param dstheight The calculated height of the destination surface.
+\param canglezoom The sine of the angle adjusted by the zoom factor.
+\param sanglezoom The cosine of the angle adjusted by the zoom factor.
+
+*/
+static void _rotozoomSurfaceSizeTrig(int width, int height, double angle, double zoomx, double zoomy,
+ 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 *= zoomx;
+ *canglezoom *= zoomx;
+ x = (double)(width / 2);
+ y = (double)(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;
+}
+
+/*!
+\brief Returns the size of the resulting target surface for a rotozoomSurfaceXY() call.
+
+\param width The source surface width.
+\param height The source surface height.
+\param angle The angle to rotate in degrees.
+\param zoomx The horizontal scaling factor.
+\param zoomy The vertical scaling factor.
+\param dstwidth The calculated width of the rotozoomed destination surface.
+\param dstheight The calculated height of the rotozoomed destination surface.
+*/
+void rotozoomSurfaceSizeXY(int width, int height, double angle, double zoomx, double zoomy, int *dstwidth, int *dstheight)
+{
+ double dummy_sanglezoom, dummy_canglezoom;
+
+ _rotozoomSurfaceSizeTrig(width, height, angle, zoomx, zoomy, dstwidth, dstheight, &dummy_sanglezoom, &dummy_canglezoom);
+}
+
+/*!
+\brief Returns the size of the resulting target surface for a rotozoomSurface() call.
+
+\param width The source surface width.
+\param height The source surface height.
+\param angle The angle to rotate in degrees.
+\param zoom The scaling factor.
+\param dstwidth The calculated width of the rotozoomed destination surface.
+\param dstheight The calculated height of the rotozoomed destination surface.
+*/
+void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth, int *dstheight)
+{
+ double dummy_sanglezoom, dummy_canglezoom;
+
+ _rotozoomSurfaceSizeTrig(width, height, angle, zoom, zoom, dstwidth, dstheight, &dummy_sanglezoom, &dummy_canglezoom);
+}
+
+/*!
+\brief Rotates and zooms a surface and optional anti-aliasing.
+
+Rotates and zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface.
+'angle' is the rotation in degrees and 'zoom' a scaling factor. If 'smooth' is set
+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.
+
+\param src The surface to rotozoom.
+\param angle The angle to rotate in degrees.
+\param zoom The scaling factor.
+\param smooth Antialiasing flag; set to SMOOTHING_ON to enable.
+
+\return The new rotozoomed surface.
+*/
+SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth)
+{
+ return rotozoomSurfaceXY(src, angle, zoom, zoom, smooth);
+}
+
+/*!
+\brief Rotates and zooms a surface with different horizontal and vertival scaling factors and optional anti-aliasing.
+
+Rotates and zooms a 32bit or 8bit 'src' surface to newly created 'dst' surface.
+'angle' is the rotation in degrees, 'zoomx and 'zoomy' scaling factors. If 'smooth' is set
+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.
+
+\param src The surface to rotozoom.
+\param angle The angle to rotate in degrees.
+\param zoomx The horizontal scaling factor.
+\param zoomy The vertical scaling factor.
+\param smooth Antialiasing flag; set to SMOOTHING_ON to enable.
+
+\return The new rotozoomed surface.
+*/
+SDL_Surface *rotozoomSurfaceXY(SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth)
+{
+ SDL_Surface *rz_src;
+ SDL_Surface *rz_dst;
+ double zoominv;
+ double sanglezoom, canglezoom, sanglezoominv, canglezoominv;
+ int dstwidthhalf, dstwidth, dstheighthalf, dstheight;
+ int is32bit;
+ int i, src_converted;
+ int flipx,flipy;
+ Uint8 r,g,b;
+ Uint32 colorkey = 0;
+ int colorKeyAvailable = 0;
+
+ /*
+ * Sanity check
+ */
+ if (src == NULL)
+ return (NULL);
+
+ if (src->flags & SDL_SRCCOLORKEY)
+ {
+ colorkey = _colorkey(src);
+ SDL_GetRGB(colorkey, src->format, &r, &g, &b);
+ colorKeyAvailable = 1;
+ }
+ /*
+ * 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,
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+ 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
+#else
+ 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff
+#endif
+ );
+ if(colorKeyAvailable)
+ SDL_SetColorKey(src, 0, 0);
+
+ SDL_BlitSurface(src, NULL, rz_src, NULL);
+
+ if(colorKeyAvailable)
+ SDL_SetColorKey(src, SDL_SRCCOLORKEY, colorkey);
+ src_converted = 1;
+ is32bit = 1;
+ }
+
+ /*
+ * Sanity check zoom factor
+ */
+ flipx = (zoomx<0.0);
+ if (flipx) zoomx=-zoomx;
+ flipy = (zoomy<0.0);
+ if (flipy) zoomy=-zoomy;
+ if (zoomx < VALUE_LIMIT) zoomx = VALUE_LIMIT;
+ if (zoomy < VALUE_LIMIT) zoomy = VALUE_LIMIT;
+ zoominv = 65536.0 / (zoomx * zoomx);
+
+ /*
+ * 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, zoomx, zoomy, &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 + GUARD_ROWS, 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 + GUARD_ROWS, 8, 0, 0, 0, 0);
+ }
+
+ /* Check target */
+ if (rz_dst == NULL)
+ return NULL;
+
+ /* Adjust for guard rows */
+ rz_dst->h = dstheight;
+
+ if (colorKeyAvailable == 1){
+ colorkey = SDL_MapRGB(rz_dst->format, r, g, b);
+
+ SDL_FillRect(rz_dst, NULL, colorkey );
+ }
+
+ /*
+ * Lock source surface
+ */
+ if (SDL_MUSTLOCK(rz_src)) {
+ 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),
+ flipx, flipy,
+ smooth);
+ /*
+ * Turn on source-alpha support
+ */
+ SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255);
+ SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, _colorkey(rz_src));
+ } 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),
+ flipx, flipy);
+ SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, _colorkey(rz_src));
+ }
+ /*
+ * Unlock source surface
+ */
+ if (SDL_MUSTLOCK(rz_src)) {
+ SDL_UnlockSurface(rz_src);
+ }
+
+ } else {
+
+ /*
+ * Angle=0: Just a zoom
+ */
+ /*
+ * --------------------
+ */
+
+ /*
+ * Calculate target size
+ */
+ 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 + GUARD_ROWS, 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 + GUARD_ROWS, 8, 0, 0, 0, 0);
+ }
+
+ /* Check target */
+ if (rz_dst == NULL)
+ return NULL;
+
+ /* Adjust for guard rows */
+ rz_dst->h = dstheight;
+
+ if (colorKeyAvailable == 1){
+ colorkey = SDL_MapRGB(rz_dst->format, r, g, b);
+
+ SDL_FillRect(rz_dst, NULL, colorkey );
+ }
+
+ /*
+ * Lock source surface
+ */
+ if (SDL_MUSTLOCK(rz_src)) {
+ 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, flipx, flipy, smooth);
+
+ /*
+ * Turn on source-alpha support
+ */
+ SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255);
+ SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, _colorkey(rz_src));
+ } 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, flipx, flipy);
+ SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, _colorkey(rz_src));
+ }
+
+ /*
+ * Unlock source surface
+ */
+ if (SDL_MUSTLOCK(rz_src)) {
+ SDL_UnlockSurface(rz_src);
+ }
+ }
+
+ /*
+ * Cleanup temp surface
+ */
+ if (src_converted) {
+ SDL_FreeSurface(rz_src);
+ }
+
+ /*
+ * Return destination surface
+ */
+ return (rz_dst);
+}
+
+/*!
+\brief Calculates the size of the target surface for a zoomSurface() call.
+
+The minimum size of the target surface is 1. The input factors can be positive or negative.
+
+\param width The width of the source surface to zoom.
+\param height The height of the source surface to zoom.
+\param zoomx The horizontal zoom factor.
+\param zoomy The vertical zoom factor.
+\param dstwidth Pointer to an integer to store the calculated width of the zoomed target surface.
+\param dstheight Pointer to an integer to store the calculated height of the zoomed target surface.
+*/
+void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight)
+{
+ /*
+ * Make zoom factors positive
+ */
+ int flipx, flipy;
+ flipx = (zoomx<0.0);
+ if (flipx) zoomx = -zoomx;
+ flipy = (zoomy<0.0);
+ if (flipy) zoomy = -zoomy;
+
+ /*
+ * Sanity check zoom factors
+ */
+ if (zoomx < VALUE_LIMIT) {
+ zoomx = VALUE_LIMIT;
+ }
+ if (zoomy < VALUE_LIMIT) {
+ zoomy = VALUE_LIMIT;
+ }
+
+ /*
+ * Calculate target size
+ */
+ *dstwidth = (int) floor(((double) width * zoomx) + 0.5);
+ *dstheight = (int) floor(((double) height * zoomy) + 0.5);
+ if (*dstwidth < 1) {
+ *dstwidth = 1;
+ }
+ if (*dstheight < 1) {
+ *dstheight = 1;
+ }
+}
+
+/*!
+\brief Zoom a surface by independent horizontal and vertical factors with optional smoothing.
+
+Zooms a 32bit or 8bit 'src' surface to newly created 'dst' surface.
+'zoomx' and 'zoomy' are scaling factors for width and height. If 'smooth' is on
+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.
+If zoom factors are negative, the image is flipped on the axes.
+
+\param src The surface to zoom.
+\param zoomx The horizontal zoom factor.
+\param zoomy The vertical zoom factor.
+\param smooth Antialiasing flag; set to SMOOTHING_ON to enable.
+
+\return The new, zoomed surface.
+*/
+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;
+ int flipx, flipy;
+
+ /*
+ * 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,
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+ 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
+#else
+ 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff
+#endif
+ );
+ if (rz_src == NULL) {
+ return NULL;
+ }
+ SDL_BlitSurface(src, NULL, rz_src, NULL);
+ src_converted = 1;
+ is32bit = 1;
+ }
+
+ flipx = (zoomx<0.0);
+ if (flipx) zoomx = -zoomx;
+ flipy = (zoomy<0.0);
+ if (flipy) zoomy = -zoomy;
+
+ /* 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 + GUARD_ROWS, 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 + GUARD_ROWS, 8, 0, 0, 0, 0);
+ }
+
+ /* Check target */
+ if (rz_dst == NULL) {
+ /*
+ * Cleanup temp surface
+ */
+ if (src_converted) {
+ SDL_FreeSurface(rz_src);
+ }
+ return NULL;
+ }
+
+ /* Adjust for guard rows */
+ rz_dst->h = dstheight;
+
+ /*
+ * Lock source surface
+ */
+ if (SDL_MUSTLOCK(rz_src)) {
+ 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, flipx, flipy, 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, flipx, flipy);
+ SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, _colorkey(rz_src));
+ }
+ /*
+ * Unlock source surface
+ */
+ if (SDL_MUSTLOCK(rz_src)) {
+ SDL_UnlockSurface(rz_src);
+ }
+
+ /*
+ * Cleanup temp surface
+ */
+ if (src_converted) {
+ SDL_FreeSurface(rz_src);
+ }
+
+ /*
+ * Return destination surface
+ */
+ return (rz_dst);
+}
+
+/*!
+\brief Shrink a surface by an integer ratio using averaging.
+
+Shrinks a 32bit or 8bit 'src' surface to a newly created 'dst' surface.
+'factorx' and 'factory' are the shrinking ratios (i.e. 2=1/2 the size,
+3=1/3 the size, etc.) The destination surface is antialiased by averaging
+the source box RGBA or Y information. If the surface is not 8bit
+or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
+The input surface is not modified. The output surface is newly allocated.
+
+\param src The surface to shrink.
+\param factorx The horizontal shrinking ratio.
+\param factory The vertical shrinking ratio.
+
+\return The new, shrunken surface.
+*/
+/*@null@*/
+SDL_Surface *shrinkSurface(SDL_Surface *src, int factorx, int factory)
+{
+ int result;
+ SDL_Surface *rz_src;
+ SDL_Surface *rz_dst = NULL;
+ int dstwidth, dstheight;
+ int is32bit;
+ int i, src_converted;
+ int haveError = 0;
+
+ /*
+ * 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,
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+ 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
+#else
+ 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff
+#endif
+ );
+ if (rz_src==NULL) {
+ haveError = 1;
+ goto exitShrinkSurface;
+ }
+
+ SDL_BlitSurface(src, NULL, rz_src, NULL);
+ src_converted = 1;
+ is32bit = 1;
+ }
+
+ /*
+ * Lock the surface
+ */
+ if (SDL_MUSTLOCK(rz_src)) {
+ if (SDL_LockSurface(rz_src) < 0) {
+ haveError = 1;
+ goto exitShrinkSurface;
+ }
+ }
+
+ /* Get size for target */
+ dstwidth=rz_src->w/factorx;
+ while (dstwidth*factorx>rz_src->w) { dstwidth--; }
+ dstheight=rz_src->h/factory;
+ while (dstheight*factory>rz_src->h) { dstheight--; }
+
+ /*
+ * Alloc space to completely contain the shrunken surface
+ * (with added guard rows)
+ */
+ if (is32bit==1) {
+ /*
+ * Target surface is 32bit with source RGBA/ABGR ordering
+ */
+ rz_dst =
+ SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 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 + GUARD_ROWS, 8, 0, 0, 0, 0);
+ }
+
+ /* Check target */
+ if (rz_dst == NULL) {
+ haveError = 1;
+ goto exitShrinkSurface;
+ }
+
+ /* Adjust for guard rows */
+ rz_dst->h = dstheight;
+
+ /*
+ * Check which kind of surface we have
+ */
+ if (is32bit==1) {
+ /*
+ * Call the 32bit transformation routine to do the shrinking (using alpha)
+ */
+ result = _shrinkSurfaceRGBA(rz_src, rz_dst, factorx, factory);
+ if ((result!=0) || (rz_dst==NULL)) {
+ haveError = 1;
+ goto exitShrinkSurface;
+ }
+
+ /*
+ * Turn on source-alpha support
+ */
+ result = SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255);
+ if (result!=0) {
+ haveError = 1;
+ goto exitShrinkSurface;
+ }
+ } 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 shrinking
+ */
+ result = _shrinkSurfaceY(rz_src, rz_dst, factorx, factory);
+ if (result!=0) {
+ haveError = 1;
+ goto exitShrinkSurface;
+ }
+
+ /*
+ * Set colorkey on target
+ */
+ result = SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, _colorkey(rz_src));
+ if (result!=0) {
+ haveError = 1;
+ goto exitShrinkSurface;
+ }
+ }
+
+exitShrinkSurface:
+ if (rz_src!=NULL) {
+ /*
+ * Unlock source surface
+ */
+ if (SDL_MUSTLOCK(rz_src)) {
+ SDL_UnlockSurface(rz_src);
+ }
+
+ /*
+ * Cleanup temp surface
+ */
+ if (src_converted==1) {
+ SDL_FreeSurface(rz_src);
+ }
+ }
+
+ /* Check error state; maybe need to cleanup destination */
+ if (haveError==1) {
+ if (rz_dst!=NULL) {
+ SDL_FreeSurface(rz_dst);
+ }
+ rz_dst=NULL;
+ }
+
+ /*
+ * Return destination surface
+ */
+ return (rz_dst);
+}
--- /dev/null
+/*
+
+SDL_rotozoom.c: rotozoomer, zoomer and shrinker for 32bit or 8bit surfaces
+
+Copyright (C) 2001-2012 Andreas Schiffler
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not
+claim that you wrote the original software. If you use this software
+in a product, an acknowledgment in the product documentation would be
+appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and must not be
+misrepresented as being the original software.
+
+3. This notice may not be removed or altered from any source
+distribution.
+
+Andreas Schiffler -- aschiffler at ferzkopp dot net
+
+*/
+
+#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 */
+
+ /*!
+ \brief Disable anti-aliasing (no smoothing).
+ */
+#define SMOOTHING_OFF 0
+
+ /*!
+ \brief Enable anti-aliasing (smoothing).
+ */
+#define SMOOTHING_ON 1
+
+ /* ---- Function Prototypes */
+
+#ifdef _MSC_VER
+# if defined(DLL_EXPORT) && !defined(LIBSDL_GFX_DLL_IMPORT)
+# define SDL_ROTOZOOM_SCOPE __declspec(dllexport)
+# else
+# ifdef LIBSDL_GFX_DLL_IMPORT
+# define SDL_ROTOZOOM_SCOPE __declspec(dllimport)
+# endif
+# endif
+#endif
+#ifndef SDL_ROTOZOOM_SCOPE
+# define SDL_ROTOZOOM_SCOPE extern
+#endif
+
+ /*
+
+ Rotozoom functions
+
+ */
+
+ SDL_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth);
+
+ SDL_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurfaceXY
+ (SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth);
+
+
+ SDL_ROTOZOOM_SCOPE void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth,
+ int *dstheight);
+
+ SDL_ROTOZOOM_SCOPE void rotozoomSurfaceSizeXY
+ (int width, int height, double angle, double zoomx, double zoomy,
+ int *dstwidth, int *dstheight);
+
+ /*
+
+ Zooming functions
+
+ */
+
+ SDL_ROTOZOOM_SCOPE SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth);
+
+ SDL_ROTOZOOM_SCOPE void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight);
+
+ /*
+
+ Shrinking functions
+
+ */
+
+ SDL_ROTOZOOM_SCOPE SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory);
+
+ /*
+
+ Specialized rotation functions
+
+ */
+
+ SDL_ROTOZOOM_SCOPE SDL_Surface* rotateSurface90Degrees(SDL_Surface* src, int numClockwiseTurns);
+
+ /* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SDL_rotozoom_h */
+++ /dev/null
-/*
-
-SDL_rotozoom.c: rotozoomer, zoomer and shrinker for 32bit or 8bit surfaces
-
-Copyright (C) 2001-2012 Andreas Schiffler
-
-This software is provided 'as-is', without any express or implied
-warranty. In no event will the authors be held liable for any damages
-arising from the use of this software.
-
-Permission is granted to anyone to use this software for any purpose,
-including commercial applications, and to alter it and redistribute it
-freely, subject to the following restrictions:
-
-1. The origin of this software must not be misrepresented; you must not
-claim that you wrote the original software. If you use this software
-in a product, an acknowledgment in the product documentation would be
-appreciated but is not required.
-
-2. Altered source versions must be plainly marked as such, and must not be
-misrepresented as being the original software.
-
-3. This notice may not be removed or altered from any source
-distribution.
-
-Andreas Schiffler -- aschiffler at ferzkopp dot net
-
-*/
-
-#ifdef WIN32
-#include <windows.h>
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "SDL_rotozoom.h"
-
-/* ---- Internally used structures */
-
-/*!
-\brief A 32 bit RGBA pixel.
-*/
-typedef struct tColorRGBA {
- Uint8 r;
- Uint8 g;
- Uint8 b;
- Uint8 a;
-} tColorRGBA;
-
-/*!
-\brief A 8bit Y/palette pixel.
-*/
-typedef struct tColorY {
- Uint8 y;
-} tColorY;
-
-/*!
-\brief Returns maximum of two numbers a and b.
-*/
-#define MAX(a,b) (((a) > (b)) ? (a) : (b))
-
-/*!
-\brief Number of guard rows added to destination surfaces.
-
-This is a simple but effective workaround for observed issues.
-These rows allocate extra memory and are then hidden from the surface.
-Rows are added to the end of destination surfaces when they are allocated.
-This catches any potential overflows which seem to happen with
-just the right src image dimensions and scale/rotation and can lead
-to a situation where the program can segfault.
-*/
-#define GUARD_ROWS (2)
-
-/*!
-\brief Lower limit of absolute zoom factor or rotation degrees.
-*/
-#define VALUE_LIMIT 0.001
-
-/*!
-\brief Returns colorkey info for a surface
-*/
-static Uint32 _colorkey(SDL_Surface *src)
-{
- Uint32 key = 0;
-#if (SDL_MINOR_VERSION == 3)
- SDL_GetColorKey(src, &key);
-#else
- if (src)
- {
- key = src->format->colorkey;
- }
-#endif
- return key;
-}
-
-
-/*!
-\brief Internal 32 bit integer-factor averaging Shrinker.
-
-Shrinks 32 bit RGBA/ABGR 'src' surface to 'dst' surface.
-Averages color and alpha values values of src pixels to calculate dst pixels.
-Assumes src and dst surfaces are of 32 bit depth.
-Assumes dst surface was allocated with the correct dimensions.
-
-\param src The surface to shrink (input).
-\param dst The shrunken surface (output).
-\param factorx The horizontal shrinking ratio.
-\param factory The vertical shrinking ratio.
-
-\return 0 for success or -1 for error.
-*/
-static int _shrinkSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int factorx, int factory)
-{
- int x, y, dx, dy, sgap, dgap, ra, ga, ba, aa;
- int n_average;
- tColorRGBA *sp, *osp, *oosp;
- tColorRGBA *dp;
-
- /*
- * Averaging integer shrink
- */
-
- /* Precalculate division factor */
- n_average = factorx*factory;
-
- /*
- * Scan destination
- */
- sp = (tColorRGBA *) src->pixels;
- sgap = src->pitch - src->w * 4;
-
- dp = (tColorRGBA *) dst->pixels;
- dgap = dst->pitch - dst->w * 4;
-
- for (y = 0; y < dst->h; y++) {
-
- osp=sp;
- for (x = 0; x < dst->w; x++) {
-
- /* Trace out source box and accumulate */
- oosp=sp;
- ra=ga=ba=aa=0;
- for (dy=0; dy < factory; dy++) {
- for (dx=0; dx < factorx; dx++) {
- ra += sp->r;
- ga += sp->g;
- ba += sp->b;
- aa += sp->a;
-
- sp++;
- }
- /* src dx loop */
- sp = (tColorRGBA *)((Uint8*)sp + (src->pitch - 4*factorx)); // next y
- }
- /* src dy loop */
-
- /* next box-x */
- sp = (tColorRGBA *)((Uint8*)oosp + 4*factorx);
-
- /* Store result in destination */
- dp->r = ra/n_average;
- dp->g = ga/n_average;
- dp->b = ba/n_average;
- dp->a = aa/n_average;
-
- /*
- * Advance destination pointer
- */
- dp++;
- }
- /* dst x loop */
-
- /* next box-y */
- sp = (tColorRGBA *)((Uint8*)osp + src->pitch*factory);
-
- /*
- * Advance destination pointers
- */
- dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
- }
- /* dst y loop */
-
- return (0);
-}
-
-/*!
-\brief Internal 8 bit integer-factor averaging shrinker.
-
-Shrinks 8bit Y 'src' surface to 'dst' surface.
-Averages color (brightness) values values of src pixels to calculate dst pixels.
-Assumes src and dst surfaces are of 8 bit depth.
-Assumes dst surface was allocated with the correct dimensions.
-
-\param src The surface to shrink (input).
-\param dst The shrunken surface (output).
-\param factorx The horizontal shrinking ratio.
-\param factory The vertical shrinking ratio.
-
-\return 0 for success or -1 for error.
-*/
-static int _shrinkSurfaceY(SDL_Surface * src, SDL_Surface * dst, int factorx, int factory)
-{
- int x, y, dx, dy, sgap, dgap, a;
- int n_average;
- Uint8 *sp, *osp, *oosp;
- Uint8 *dp;
-
- /*
- * Averaging integer shrink
- */
-
- /* Precalculate division factor */
- n_average = factorx*factory;
-
- /*
- * Scan destination
- */
- sp = (Uint8 *) src->pixels;
- sgap = src->pitch - src->w;
-
- dp = (Uint8 *) dst->pixels;
- dgap = dst->pitch - dst->w;
-
- for (y = 0; y < dst->h; y++) {
-
- osp=sp;
- for (x = 0; x < dst->w; x++) {
-
- /* Trace out source box and accumulate */
- oosp=sp;
- a=0;
- for (dy=0; dy < factory; dy++) {
- for (dx=0; dx < factorx; dx++) {
- a += (*sp);
- /* next x */
- sp++;
- }
- /* end src dx loop */
- /* next y */
- sp = (Uint8 *)((Uint8*)sp + (src->pitch - factorx));
- }
- /* end src dy loop */
-
- /* next box-x */
- sp = (Uint8 *)((Uint8*)oosp + factorx);
-
- /* Store result in destination */
- *dp = a/n_average;
-
- /*
- * Advance destination pointer
- */
- dp++;
- }
- /* end dst x loop */
-
- /* next box-y */
- sp = (Uint8 *)((Uint8*)osp + src->pitch*factory);
-
- /*
- * Advance destination pointers
- */
- dp = (Uint8 *)((Uint8 *)dp + dgap);
- }
- /* end dst y loop */
-
- return (0);
-}
-
-/*!
-\brief Internal 32 bit Zoomer with optional anti-aliasing by bilinear interpolation.
-
-Zooms 32 bit RGBA/ABGR 'src' surface to 'dst' surface.
-Assumes src and dst surfaces are of 32 bit depth.
-Assumes dst surface was allocated with the correct dimensions.
-
-\param src The surface to zoom (input).
-\param dst The zoomed surface (output).
-\param flipx Flag indicating if the image should be horizontally flipped.
-\param flipy Flag indicating if the image should be vertically flipped.
-\param smooth Antialiasing flag; set to SMOOTHING_ON to enable.
-
-\return 0 for success or -1 for error.
-*/
-static int _zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy, int smooth)
-{
- int x, y, sx, sy, ssx, ssy, *sax, *say, *csax, *csay, *salast, csx, csy, ex, ey, cx, cy, sstep, sstepx, sstepy;
- tColorRGBA *c00, *c01, *c10, *c11;
- tColorRGBA *sp, *csp, *dp;
- int spixelgap, spixelw, spixelh, dgap, t1, t2;
-
- /*
- * Allocate memory for row/column 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
- */
- spixelw = (src->w - 1);
- spixelh = (src->h - 1);
- if (smooth) {
- sx = (int) (65536.0 * (float) spixelw / (float) (dst->w - 1));
- sy = (int) (65536.0 * (float) spixelh / (float) (dst->h - 1));
- } else {
- sx = (int) (65536.0 * (float) (src->w) / (float) (dst->w));
- sy = (int) (65536.0 * (float) (src->h) / (float) (dst->h));
- }
-
- /* Maximum scaled source size */
- ssx = (src->w << 16) - 1;
- ssy = (src->h << 16) - 1;
-
- /* Precalculate horizontal row increments */
- csx = 0;
- csax = sax;
- for (x = 0; x <= dst->w; x++) {
- *csax = csx;
- csax++;
- csx += sx;
-
- /* Guard from overflows */
- if (csx > ssx) {
- csx = ssx;
- }
- }
-
- /* Precalculate vertical row increments */
- csy = 0;
- csay = say;
- for (y = 0; y <= dst->h; y++) {
- *csay = csy;
- csay++;
- csy += sy;
-
- /* Guard from overflows */
- if (csy > ssy) {
- csy = ssy;
- }
- }
-
- sp = (tColorRGBA *) src->pixels;
- dp = (tColorRGBA *) dst->pixels;
- dgap = dst->pitch - dst->w * 4;
- spixelgap = src->pitch/4;
-
- if (flipx) sp += spixelw;
- if (flipy) sp += (spixelgap * spixelh);
-
- /*
- * Switch between interpolating and non-interpolating code
- */
- if (smooth) {
-
- /*
- * Interpolating Zoom
- */
- csay = say;
- for (y = 0; y < dst->h; y++) {
- csp = sp;
- csax = sax;
- for (x = 0; x < dst->w; x++) {
- /*
- * Setup color source pointers
- */
- ex = (*csax & 0xffff);
- ey = (*csay & 0xffff);
- cx = (*csax >> 16);
- cy = (*csay >> 16);
- sstepx = cx < spixelw;
- sstepy = cy < spixelh;
- c00 = sp;
- c01 = sp;
- c10 = sp;
- if (sstepy) {
- if (flipy) {
- c10 -= spixelgap;
- } else {
- c10 += spixelgap;
- }
- }
- c11 = c10;
- if (sstepx) {
- if (flipx) {
- c01--;
- c11--;
- } else {
- c01++;
- c11++;
- }
- }
-
- /*
- * Draw and interpolate colors
- */
- 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 pointer x
- */
- salast = csax;
- csax++;
- sstep = (*csax >> 16) - (*salast >> 16);
- if (flipx) {
- sp -= sstep;
- } else {
- sp += sstep;
- }
-
- /*
- * Advance destination pointer x
- */
- dp++;
- }
- /*
- * Advance source pointer y
- */
- salast = csay;
- csay++;
- sstep = (*csay >> 16) - (*salast >> 16);
- sstep *= spixelgap;
- if (flipy) {
- sp = csp - sstep;
- } else {
- sp = csp + sstep;
- }
-
- /*
- * Advance destination pointer y
- */
- dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
- }
- } else {
- /*
- * Non-Interpolating Zoom
- */
- csay = say;
- for (y = 0; y < dst->h; y++) {
- csp = sp;
- csax = sax;
- for (x = 0; x < dst->w; x++) {
- /*
- * Draw
- */
- *dp = *sp;
-
- /*
- * Advance source pointer x
- */
- salast = csax;
- csax++;
- sstep = (*csax >> 16) - (*salast >> 16);
- if (flipx) sstep = -sstep;
- sp += sstep;
-
- /*
- * Advance destination pointer x
- */
- dp++;
- }
- /*
- * Advance source pointer y
- */
- salast = csay;
- csay++;
- sstep = (*csay >> 16) - (*salast >> 16);
- sstep *= spixelgap;
- if (flipy) sstep = -sstep;
- sp = csp + sstep;
-
- /*
- * Advance destination pointer y
- */
- dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
- }
- }
-
- /*
- * Remove temp arrays
- */
- free(sax);
- free(say);
-
- return (0);
-}
-
-/*!
-
-\brief Internal 8 bit Zoomer without smoothing.
-
-Zooms 8bit palette/Y 'src' surface to 'dst' surface.
-Assumes src and dst surfaces are of 8 bit depth.
-Assumes dst surface was allocated with the correct dimensions.
-
-\param src The surface to zoom (input).
-\param dst The zoomed surface (output).
-\param flipx Flag indicating if the image should be horizontally flipped.
-\param flipy Flag indicating if the image should be vertically flipped.
-
-\return 0 for success or -1 for error.
-*/
-static int _zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy)
-{
- int x, y;
- Uint32 *sax, *say, *csax, *csay;
- int csx, csy;
- Uint8 *sp, *dp, *csp;
- int dgap;
-
- /*
- * Allocate memory for row increments
- */
- if ((sax = (Uint32 *) malloc((dst->w + 1) * sizeof(Uint32))) == NULL) {
- return (-1);
- }
- if ((say = (Uint32 *) malloc((dst->h + 1) * sizeof(Uint32))) == NULL) {
- free(sax);
- return (-1);
- }
-
- /*
- * Pointer setup
- */
- sp = csp = (Uint8 *) src->pixels;
- dp = (Uint8 *) dst->pixels;
- dgap = dst->pitch - dst->w;
-
- if (flipx) csp += (src->w-1);
- if (flipy) csp = ( (Uint8*)csp + src->pitch*(src->h-1) );
-
- /*
- * Precalculate row increments
- */
- csx = 0;
- csax = sax;
- for (x = 0; x < dst->w; x++) {
- csx += src->w;
- *csax = 0;
- while (csx >= dst->w) {
- csx -= dst->w;
- (*csax)++;
- }
- (*csax) = (*csax) * (flipx ? -1 : 1);
- csax++;
- }
- csy = 0;
- csay = say;
- for (y = 0; y < dst->h; y++) {
- csy += src->h;
- *csay = 0;
- while (csy >= dst->h) {
- csy -= dst->h;
- (*csay)++;
- }
- (*csay) = (*csay) * (flipy ? -1 : 1);
- csay++;
- }
-
- /*
- * 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);
-}
-
-/*!
-\brief Internal 32 bit rotozoomer with optional anti-aliasing.
-
-Rotates and zooms 32 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control
-parameters by scanning the destination surface and applying optionally anti-aliasing
-by bilinear interpolation.
-Assumes src and dst surfaces are of 32 bit depth.
-Assumes dst surface was allocated with the correct dimensions.
-
-\param src Source surface.
-\param dst Destination surface.
-\param cx Horizontal center coordinate.
-\param cy Vertical center coordinate.
-\param isin Integer version of sine of angle.
-\param icos Integer version of cosine of angle.
-\param flipx Flag indicating horizontal mirroring should be applied.
-\param flipy Flag indicating vertical mirroring should be applied.
-\param smooth Flag indicating anti-aliasing should be used.
-*/
-static void _transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy, int smooth)
-{
- int x, y, t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh;
- tColorRGBA c00, c01, c10, c11, cswap;
- tColorRGBA *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 = (tColorRGBA*) 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 (flipx) dx = sw - dx;
- if (flipy) dy = sh - dy;
- if ((dx > -1) && (dy > -1) && (dx < (src->w-1)) && (dy < (src->h-1))) {
- sp = (tColorRGBA *)src->pixels;;
- sp += ((src->pitch/4) * dy);
- sp += dx;
- c00 = *sp;
- sp += 1;
- c01 = *sp;
- sp += (src->pitch/4);
- c11 = *sp;
- sp -= 1;
- c10 = *sp;
- if (flipx) {
- cswap = c00; c00=c01; c01=cswap;
- cswap = c10; c10=c11; c11=cswap;
- }
- if (flipy) {
- cswap = c00; c00=c10; c10=cswap;
- cswap = c01; c01=c11; c11=cswap;
- }
- /*
- * 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 (flipx) dx = (src->w-1)-dx;
- if (flipy) dy = (src->h-1)-dy;
- 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);
- }
- }
-}
-
-/*!
-
-\brief Rotates and zooms 8 bit palette/Y 'src' surface to 'dst' surface without smoothing.
-
-Rotates and zooms 8 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control
-parameters by scanning the destination surface.
-Assumes src and dst surfaces are of 8 bit depth.
-Assumes dst surface was allocated with the correct dimensions.
-
-\param src Source surface.
-\param dst Destination surface.
-\param cx Horizontal center coordinate.
-\param cy Vertical center coordinate.
-\param isin Integer version of sine of angle.
-\param icos Integer version of cosine of angle.
-\param flipx Flag indicating horizontal mirroring should be applied.
-\param flipy Flag indicating vertical mirroring should be applied.
-*/
-static void transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy)
-{
- 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 = (tColorY*) dst->pixels;
- gap = dst->pitch - dst->w;
- /*
- * Clear surface to colorkey
- */
- memset(pc, (int)(_colorkey(src) & 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 (flipx) dx = (src->w-1)-dx;
- if (flipy) dy = (src->h-1)-dy;
- 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;
- }
-}
-
-/*!
-\brief Rotates a 32 bit surface in increments of 90 degrees.
-
-Specialized 90 degree rotator which rotates a 'src' surface in 90 degree
-increments clockwise returning a new surface. Faster than rotozoomer since
-not scanning or interpolation takes place. Input surface must be 32 bit.
-(code contributed by J. Schiller, improved by C. Allport and A. Schiffler)
-
-\param src Source surface to rotate.
-\param numClockwiseTurns Number of clockwise 90 degree turns to apply to the source.
-
-\returns The new, rotated surface; or NULL for surfaces with incorrect input format.
-*/
-SDL_Surface* rotateSurface90Degrees(SDL_Surface* src, int numClockwiseTurns)
-{
- int row, col, newWidth, newHeight;
- int bpp, src_ipr, dst_ipr;
- SDL_Surface* dst;
- Uint32* srcBuf;
- Uint32* dstBuf;
-
- /* Has to be a valid surface pointer and only 32-bit surfaces (for now) */
- if (!src || src->format->BitsPerPixel != 32) { return NULL; }
-
- /* normalize numClockwiseTurns */
- while(numClockwiseTurns < 0) { numClockwiseTurns += 4; }
- numClockwiseTurns = (numClockwiseTurns % 4);
-
- /* if it's even, our new width will be the same as the source surface */
- newWidth = (numClockwiseTurns % 2) ? (src->h) : (src->w);
- newHeight = (numClockwiseTurns % 2) ? (src->w) : (src->h);
- dst = SDL_CreateRGBSurface( src->flags, newWidth, newHeight, src->format->BitsPerPixel,
- src->format->Rmask,
- src->format->Gmask,
- src->format->Bmask,
- src->format->Amask);
- if(!dst) {
- return NULL;
- }
-
- if (SDL_MUSTLOCK(dst)) {
- SDL_LockSurface(dst);
- }
- if (SDL_MUSTLOCK(dst)) {
- SDL_LockSurface(dst);
- }
-
- /* Calculate int-per-row */
- bpp = src->format->BitsPerPixel / 8;
- src_ipr = src->pitch / bpp;
- dst_ipr = dst->pitch / bpp;
-
- switch(numClockwiseTurns) {
- case 0: /* Make a copy of the surface */
- {
- /* Unfortunately SDL_BlitSurface cannot be used to make a copy of the surface
- since it does not preserve alpha. */
-
- if (src->pitch == dst->pitch) {
- /* If the pitch is the same for both surfaces, the memory can be copied all at once. */
- memcpy(dst->pixels, src->pixels, (src->h * src->pitch));
- }
- else
- {
- /* If the pitch differs, copy each row separately */
- srcBuf = (Uint32*)(src->pixels);
- dstBuf = (Uint32*)(dst->pixels);
- for (row = 0; row < src->h; row++) {
- memcpy(dstBuf, srcBuf, dst->w * bpp);
- srcBuf += src_ipr;
- dstBuf += dst_ipr;
- } /* end for(col) */
- } /* end for(row) */
- }
- break;
-
- /* rotate clockwise */
- case 1: /* rotated 90 degrees clockwise */
- {
- for (row = 0; row < src->h; ++row) {
- srcBuf = (Uint32*)(src->pixels) + (row * src_ipr);
- dstBuf = (Uint32*)(dst->pixels) + (dst->w - row - 1);
- for (col = 0; col < src->w; ++col) {
- *dstBuf = *srcBuf;
- ++srcBuf;
- dstBuf += dst_ipr;
- }
- /* end for(col) */
- }
- /* end for(row) */
- }
- break;
-
- case 2: /* rotated 180 degrees clockwise */
- {
- for (row = 0; row < src->h; ++row) {
- srcBuf = (Uint32*)(src->pixels) + (row * src_ipr);
- dstBuf = (Uint32*)(dst->pixels) + ((dst->h - row - 1) * dst_ipr) + (dst->w - 1);
- for (col = 0; col < src->w; ++col) {
- *dstBuf = *srcBuf;
- ++srcBuf;
- --dstBuf;
- }
- }
- }
- break;
-
- case 3:
- {
- for (row = 0; row < src->h; ++row) {
- srcBuf = (Uint32*)(src->pixels) + (row * src_ipr);
- dstBuf = (Uint32*)(dst->pixels) + row + ((dst->h - 1) * dst_ipr);
- for (col = 0; col < src->w; ++col) {
- *dstBuf = *srcBuf;
- ++srcBuf;
- dstBuf -= dst_ipr;
- }
- }
- }
- break;
- }
- /* end switch */
-
- if (SDL_MUSTLOCK(src)) {
- SDL_UnlockSurface(src);
- }
- if (SDL_MUSTLOCK(dst)) {
- SDL_UnlockSurface(dst);
- }
-
- return dst;
-}
-
-
-/*!
-\brief Internal target surface sizing function for rotozooms with trig result return.
-
-\param width The source surface width.
-\param height The source surface height.
-\param angle The angle to rotate in degrees.
-\param zoomx The horizontal scaling factor.
-\param zoomy The vertical scaling factor.
-\param dstwidth The calculated width of the destination surface.
-\param dstheight The calculated height of the destination surface.
-\param canglezoom The sine of the angle adjusted by the zoom factor.
-\param sanglezoom The cosine of the angle adjusted by the zoom factor.
-
-*/
-static void _rotozoomSurfaceSizeTrig(int width, int height, double angle, double zoomx, double zoomy,
- 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 *= zoomx;
- *canglezoom *= zoomx;
- x = (double)(width / 2);
- y = (double)(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;
-}
-
-/*!
-\brief Returns the size of the resulting target surface for a rotozoomSurfaceXY() call.
-
-\param width The source surface width.
-\param height The source surface height.
-\param angle The angle to rotate in degrees.
-\param zoomx The horizontal scaling factor.
-\param zoomy The vertical scaling factor.
-\param dstwidth The calculated width of the rotozoomed destination surface.
-\param dstheight The calculated height of the rotozoomed destination surface.
-*/
-void rotozoomSurfaceSizeXY(int width, int height, double angle, double zoomx, double zoomy, int *dstwidth, int *dstheight)
-{
- double dummy_sanglezoom, dummy_canglezoom;
-
- _rotozoomSurfaceSizeTrig(width, height, angle, zoomx, zoomy, dstwidth, dstheight, &dummy_sanglezoom, &dummy_canglezoom);
-}
-
-/*!
-\brief Returns the size of the resulting target surface for a rotozoomSurface() call.
-
-\param width The source surface width.
-\param height The source surface height.
-\param angle The angle to rotate in degrees.
-\param zoom The scaling factor.
-\param dstwidth The calculated width of the rotozoomed destination surface.
-\param dstheight The calculated height of the rotozoomed destination surface.
-*/
-void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth, int *dstheight)
-{
- double dummy_sanglezoom, dummy_canglezoom;
-
- _rotozoomSurfaceSizeTrig(width, height, angle, zoom, zoom, dstwidth, dstheight, &dummy_sanglezoom, &dummy_canglezoom);
-}
-
-/*!
-\brief Rotates and zooms a surface and optional anti-aliasing.
-
-Rotates and zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface.
-'angle' is the rotation in degrees and 'zoom' a scaling factor. If 'smooth' is set
-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.
-
-\param src The surface to rotozoom.
-\param angle The angle to rotate in degrees.
-\param zoom The scaling factor.
-\param smooth Antialiasing flag; set to SMOOTHING_ON to enable.
-
-\return The new rotozoomed surface.
-*/
-SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth)
-{
- return rotozoomSurfaceXY(src, angle, zoom, zoom, smooth);
-}
-
-/*!
-\brief Rotates and zooms a surface with different horizontal and vertival scaling factors and optional anti-aliasing.
-
-Rotates and zooms a 32bit or 8bit 'src' surface to newly created 'dst' surface.
-'angle' is the rotation in degrees, 'zoomx and 'zoomy' scaling factors. If 'smooth' is set
-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.
-
-\param src The surface to rotozoom.
-\param angle The angle to rotate in degrees.
-\param zoomx The horizontal scaling factor.
-\param zoomy The vertical scaling factor.
-\param smooth Antialiasing flag; set to SMOOTHING_ON to enable.
-
-\return The new rotozoomed surface.
-*/
-SDL_Surface *rotozoomSurfaceXY(SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth)
-{
- SDL_Surface *rz_src;
- SDL_Surface *rz_dst;
- double zoominv;
- double sanglezoom, canglezoom, sanglezoominv, canglezoominv;
- int dstwidthhalf, dstwidth, dstheighthalf, dstheight;
- int is32bit;
- int i, src_converted;
- int flipx,flipy;
- Uint8 r,g,b;
- Uint32 colorkey = 0;
- int colorKeyAvailable = 0;
-
- /*
- * Sanity check
- */
- if (src == NULL)
- return (NULL);
-
- if (src->flags & SDL_SRCCOLORKEY)
- {
- colorkey = _colorkey(src);
- SDL_GetRGB(colorkey, src->format, &r, &g, &b);
- colorKeyAvailable = 1;
- }
- /*
- * 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,
-#if SDL_BYTEORDER == SDL_LIL_ENDIAN
- 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
-#else
- 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff
-#endif
- );
- if(colorKeyAvailable)
- SDL_SetColorKey(src, 0, 0);
-
- SDL_BlitSurface(src, NULL, rz_src, NULL);
-
- if(colorKeyAvailable)
- SDL_SetColorKey(src, SDL_SRCCOLORKEY, colorkey);
- src_converted = 1;
- is32bit = 1;
- }
-
- /*
- * Sanity check zoom factor
- */
- flipx = (zoomx<0.0);
- if (flipx) zoomx=-zoomx;
- flipy = (zoomy<0.0);
- if (flipy) zoomy=-zoomy;
- if (zoomx < VALUE_LIMIT) zoomx = VALUE_LIMIT;
- if (zoomy < VALUE_LIMIT) zoomy = VALUE_LIMIT;
- zoominv = 65536.0 / (zoomx * zoomx);
-
- /*
- * 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, zoomx, zoomy, &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 + GUARD_ROWS, 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 + GUARD_ROWS, 8, 0, 0, 0, 0);
- }
-
- /* Check target */
- if (rz_dst == NULL)
- return NULL;
-
- /* Adjust for guard rows */
- rz_dst->h = dstheight;
-
- if (colorKeyAvailable == 1){
- colorkey = SDL_MapRGB(rz_dst->format, r, g, b);
-
- SDL_FillRect(rz_dst, NULL, colorkey );
- }
-
- /*
- * Lock source surface
- */
- if (SDL_MUSTLOCK(rz_src)) {
- 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),
- flipx, flipy,
- smooth);
- /*
- * Turn on source-alpha support
- */
- SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255);
- SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, _colorkey(rz_src));
- } 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),
- flipx, flipy);
- SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, _colorkey(rz_src));
- }
- /*
- * Unlock source surface
- */
- if (SDL_MUSTLOCK(rz_src)) {
- SDL_UnlockSurface(rz_src);
- }
-
- } else {
-
- /*
- * Angle=0: Just a zoom
- */
- /*
- * --------------------
- */
-
- /*
- * Calculate target size
- */
- 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 + GUARD_ROWS, 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 + GUARD_ROWS, 8, 0, 0, 0, 0);
- }
-
- /* Check target */
- if (rz_dst == NULL)
- return NULL;
-
- /* Adjust for guard rows */
- rz_dst->h = dstheight;
-
- if (colorKeyAvailable == 1){
- colorkey = SDL_MapRGB(rz_dst->format, r, g, b);
-
- SDL_FillRect(rz_dst, NULL, colorkey );
- }
-
- /*
- * Lock source surface
- */
- if (SDL_MUSTLOCK(rz_src)) {
- 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, flipx, flipy, smooth);
-
- /*
- * Turn on source-alpha support
- */
- SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255);
- SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, _colorkey(rz_src));
- } 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, flipx, flipy);
- SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, _colorkey(rz_src));
- }
-
- /*
- * Unlock source surface
- */
- if (SDL_MUSTLOCK(rz_src)) {
- SDL_UnlockSurface(rz_src);
- }
- }
-
- /*
- * Cleanup temp surface
- */
- if (src_converted) {
- SDL_FreeSurface(rz_src);
- }
-
- /*
- * Return destination surface
- */
- return (rz_dst);
-}
-
-/*!
-\brief Calculates the size of the target surface for a zoomSurface() call.
-
-The minimum size of the target surface is 1. The input factors can be positive or negative.
-
-\param width The width of the source surface to zoom.
-\param height The height of the source surface to zoom.
-\param zoomx The horizontal zoom factor.
-\param zoomy The vertical zoom factor.
-\param dstwidth Pointer to an integer to store the calculated width of the zoomed target surface.
-\param dstheight Pointer to an integer to store the calculated height of the zoomed target surface.
-*/
-void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight)
-{
- /*
- * Make zoom factors positive
- */
- int flipx, flipy;
- flipx = (zoomx<0.0);
- if (flipx) zoomx = -zoomx;
- flipy = (zoomy<0.0);
- if (flipy) zoomy = -zoomy;
-
- /*
- * Sanity check zoom factors
- */
- if (zoomx < VALUE_LIMIT) {
- zoomx = VALUE_LIMIT;
- }
- if (zoomy < VALUE_LIMIT) {
- zoomy = VALUE_LIMIT;
- }
-
- /*
- * Calculate target size
- */
- *dstwidth = (int) floor(((double) width * zoomx) + 0.5);
- *dstheight = (int) floor(((double) height * zoomy) + 0.5);
- if (*dstwidth < 1) {
- *dstwidth = 1;
- }
- if (*dstheight < 1) {
- *dstheight = 1;
- }
-}
-
-/*!
-\brief Zoom a surface by independent horizontal and vertical factors with optional smoothing.
-
-Zooms a 32bit or 8bit 'src' surface to newly created 'dst' surface.
-'zoomx' and 'zoomy' are scaling factors for width and height. If 'smooth' is on
-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.
-If zoom factors are negative, the image is flipped on the axes.
-
-\param src The surface to zoom.
-\param zoomx The horizontal zoom factor.
-\param zoomy The vertical zoom factor.
-\param smooth Antialiasing flag; set to SMOOTHING_ON to enable.
-
-\return The new, zoomed surface.
-*/
-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;
- int flipx, flipy;
-
- /*
- * 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,
-#if SDL_BYTEORDER == SDL_LIL_ENDIAN
- 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
-#else
- 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff
-#endif
- );
- if (rz_src == NULL) {
- return NULL;
- }
- SDL_BlitSurface(src, NULL, rz_src, NULL);
- src_converted = 1;
- is32bit = 1;
- }
-
- flipx = (zoomx<0.0);
- if (flipx) zoomx = -zoomx;
- flipy = (zoomy<0.0);
- if (flipy) zoomy = -zoomy;
-
- /* 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 + GUARD_ROWS, 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 + GUARD_ROWS, 8, 0, 0, 0, 0);
- }
-
- /* Check target */
- if (rz_dst == NULL) {
- /*
- * Cleanup temp surface
- */
- if (src_converted) {
- SDL_FreeSurface(rz_src);
- }
- return NULL;
- }
-
- /* Adjust for guard rows */
- rz_dst->h = dstheight;
-
- /*
- * Lock source surface
- */
- if (SDL_MUSTLOCK(rz_src)) {
- 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, flipx, flipy, 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, flipx, flipy);
- SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, _colorkey(rz_src));
- }
- /*
- * Unlock source surface
- */
- if (SDL_MUSTLOCK(rz_src)) {
- SDL_UnlockSurface(rz_src);
- }
-
- /*
- * Cleanup temp surface
- */
- if (src_converted) {
- SDL_FreeSurface(rz_src);
- }
-
- /*
- * Return destination surface
- */
- return (rz_dst);
-}
-
-/*!
-\brief Shrink a surface by an integer ratio using averaging.
-
-Shrinks a 32bit or 8bit 'src' surface to a newly created 'dst' surface.
-'factorx' and 'factory' are the shrinking ratios (i.e. 2=1/2 the size,
-3=1/3 the size, etc.) The destination surface is antialiased by averaging
-the source box RGBA or Y information. If the surface is not 8bit
-or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
-The input surface is not modified. The output surface is newly allocated.
-
-\param src The surface to shrink.
-\param factorx The horizontal shrinking ratio.
-\param factory The vertical shrinking ratio.
-
-\return The new, shrunken surface.
-*/
-/*@null@*/
-SDL_Surface *shrinkSurface(SDL_Surface *src, int factorx, int factory)
-{
- int result;
- SDL_Surface *rz_src;
- SDL_Surface *rz_dst = NULL;
- int dstwidth, dstheight;
- int is32bit;
- int i, src_converted;
- int haveError = 0;
-
- /*
- * 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,
-#if SDL_BYTEORDER == SDL_LIL_ENDIAN
- 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
-#else
- 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff
-#endif
- );
- if (rz_src==NULL) {
- haveError = 1;
- goto exitShrinkSurface;
- }
-
- SDL_BlitSurface(src, NULL, rz_src, NULL);
- src_converted = 1;
- is32bit = 1;
- }
-
- /*
- * Lock the surface
- */
- if (SDL_MUSTLOCK(rz_src)) {
- if (SDL_LockSurface(rz_src) < 0) {
- haveError = 1;
- goto exitShrinkSurface;
- }
- }
-
- /* Get size for target */
- dstwidth=rz_src->w/factorx;
- while (dstwidth*factorx>rz_src->w) { dstwidth--; }
- dstheight=rz_src->h/factory;
- while (dstheight*factory>rz_src->h) { dstheight--; }
-
- /*
- * Alloc space to completely contain the shrunken surface
- * (with added guard rows)
- */
- if (is32bit==1) {
- /*
- * Target surface is 32bit with source RGBA/ABGR ordering
- */
- rz_dst =
- SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 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 + GUARD_ROWS, 8, 0, 0, 0, 0);
- }
-
- /* Check target */
- if (rz_dst == NULL) {
- haveError = 1;
- goto exitShrinkSurface;
- }
-
- /* Adjust for guard rows */
- rz_dst->h = dstheight;
-
- /*
- * Check which kind of surface we have
- */
- if (is32bit==1) {
- /*
- * Call the 32bit transformation routine to do the shrinking (using alpha)
- */
- result = _shrinkSurfaceRGBA(rz_src, rz_dst, factorx, factory);
- if ((result!=0) || (rz_dst==NULL)) {
- haveError = 1;
- goto exitShrinkSurface;
- }
-
- /*
- * Turn on source-alpha support
- */
- result = SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255);
- if (result!=0) {
- haveError = 1;
- goto exitShrinkSurface;
- }
- } 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 shrinking
- */
- result = _shrinkSurfaceY(rz_src, rz_dst, factorx, factory);
- if (result!=0) {
- haveError = 1;
- goto exitShrinkSurface;
- }
-
- /*
- * Set colorkey on target
- */
- result = SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, _colorkey(rz_src));
- if (result!=0) {
- haveError = 1;
- goto exitShrinkSurface;
- }
- }
-
-exitShrinkSurface:
- if (rz_src!=NULL) {
- /*
- * Unlock source surface
- */
- if (SDL_MUSTLOCK(rz_src)) {
- SDL_UnlockSurface(rz_src);
- }
-
- /*
- * Cleanup temp surface
- */
- if (src_converted==1) {
- SDL_FreeSurface(rz_src);
- }
- }
-
- /* Check error state; maybe need to cleanup destination */
- if (haveError==1) {
- if (rz_dst!=NULL) {
- SDL_FreeSurface(rz_dst);
- }
- rz_dst=NULL;
- }
-
- /*
- * Return destination surface
- */
- return (rz_dst);
-}
+++ /dev/null
-/*
-
-SDL_rotozoom.c: rotozoomer, zoomer and shrinker for 32bit or 8bit surfaces
-
-Copyright (C) 2001-2012 Andreas Schiffler
-
-This software is provided 'as-is', without any express or implied
-warranty. In no event will the authors be held liable for any damages
-arising from the use of this software.
-
-Permission is granted to anyone to use this software for any purpose,
-including commercial applications, and to alter it and redistribute it
-freely, subject to the following restrictions:
-
-1. The origin of this software must not be misrepresented; you must not
-claim that you wrote the original software. If you use this software
-in a product, an acknowledgment in the product documentation would be
-appreciated but is not required.
-
-2. Altered source versions must be plainly marked as such, and must not be
-misrepresented as being the original software.
-
-3. This notice may not be removed or altered from any source
-distribution.
-
-Andreas Schiffler -- aschiffler at ferzkopp dot net
-
-*/
-
-#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 */
-
- /*!
- \brief Disable anti-aliasing (no smoothing).
- */
-#define SMOOTHING_OFF 0
-
- /*!
- \brief Enable anti-aliasing (smoothing).
- */
-#define SMOOTHING_ON 1
-
- /* ---- Function Prototypes */
-
-#ifdef _MSC_VER
-# if defined(DLL_EXPORT) && !defined(LIBSDL_GFX_DLL_IMPORT)
-# define SDL_ROTOZOOM_SCOPE __declspec(dllexport)
-# else
-# ifdef LIBSDL_GFX_DLL_IMPORT
-# define SDL_ROTOZOOM_SCOPE __declspec(dllimport)
-# endif
-# endif
-#endif
-#ifndef SDL_ROTOZOOM_SCOPE
-# define SDL_ROTOZOOM_SCOPE extern
-#endif
-
- /*
-
- Rotozoom functions
-
- */
-
- SDL_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth);
-
- SDL_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurfaceXY
- (SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth);
-
-
- SDL_ROTOZOOM_SCOPE void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth,
- int *dstheight);
-
- SDL_ROTOZOOM_SCOPE void rotozoomSurfaceSizeXY
- (int width, int height, double angle, double zoomx, double zoomy,
- int *dstwidth, int *dstheight);
-
- /*
-
- Zooming functions
-
- */
-
- SDL_ROTOZOOM_SCOPE SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth);
-
- SDL_ROTOZOOM_SCOPE void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight);
-
- /*
-
- Shrinking functions
-
- */
-
- SDL_ROTOZOOM_SCOPE SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory);
-
- /*
-
- Specialized rotation functions
-
- */
-
- SDL_ROTOZOOM_SCOPE SDL_Surface* rotateSurface90Degrees(SDL_Surface* src, int numClockwiseTurns);
-
- /* Ends C function definitions when using C++ */
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _SDL_rotozoom_h */