diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-08-21 12:31:51 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-08-24 21:08:13 +0300 |
commit | 8d4af08b165e10d7e82380074ce733ee9d068c6a (patch) | |
tree | dfc3454ef8085af0200d3b7f7446cb0db5545379 | |
parent | 1acca8b48a4e1b55e897fc09f18ff325efc18412 (diff) | |
download | manaverse-8d4af08b165e10d7e82380074ce733ee9d068c6a.tar.gz manaverse-8d4af08b165e10d7e82380074ce733ee9d068c6a.tar.bz2 manaverse-8d4af08b165e10d7e82380074ce733ee9d068c6a.tar.xz manaverse-8d4af08b165e10d7e82380074ce733ee9d068c6a.zip |
embed SDL2gfx.
-rwxr-xr-x | build/bmake | 3 | ||||
-rw-r--r-- | src/Makefile.am | 7 | ||||
-rw-r--r-- | src/sdl2gfx/SDL_framerate.c | 189 | ||||
-rw-r--r-- | src/sdl2gfx/SDL_framerate.h | 100 | ||||
-rw-r--r-- | src/sdl2gfx/SDL_gfxPrimitives.c | 4295 | ||||
-rw-r--r-- | src/sdl2gfx/SDL_gfxPrimitives.h | 241 | ||||
-rw-r--r-- | src/sdl2gfx/SDL_gfxPrimitives_font.h | 3082 | ||||
-rw-r--r-- | src/sdl2gfx/SDL_rotozoom.c | 1651 | ||||
-rw-r--r-- | src/sdl2gfx/SDL_rotozoom.h | 123 |
9 files changed, 9690 insertions, 1 deletions
diff --git a/build/bmake b/build/bmake index 7e5076655..e095494c9 100755 --- a/build/bmake +++ b/build/bmake @@ -45,7 +45,8 @@ autoreconf -i --with-internalguichan=yes \ --enable-tcmalloc=no \ --enable-googleprofiler=no \ ---enable-eathena=yes +--enable-eathena=yes \ +--with-sdl2 cd po make -j5 update-gmo 2>../build/make1.log diff --git a/src/Makefile.am b/src/Makefile.am index 72f3edae3..685b8f63b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -27,6 +27,13 @@ endif if USE_SDL2 manaplus_CXXFLAGS += -DUSE_SDL2 +manaplus_SOURCES += sdl2gfx/SDL_framerate.c \ + sdl2gfx/SDL_framerate.h \ + sdl2gfx/SDL_gfxPrimitives.c \ + sdl2gfx/SDL_gfxPrimitives.h \ + sdl2gfx/SDL_gfxPrimitives_font.h \ + sdl2gfx/SDL_rotozoom.c \ + sdl2gfx/SDL_rotozoom.h endif if USE_INTERNALGUICHAN diff --git a/src/sdl2gfx/SDL_framerate.c b/src/sdl2gfx/SDL_framerate.c new file mode 100644 index 000000000..6735f6355 --- /dev/null +++ b/src/sdl2gfx/SDL_framerate.c @@ -0,0 +1,189 @@ +/* + +SDL_framerate.c: framerate manager + +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 + +*/ + +#include "SDL_framerate.h" + +/*! +\brief Internal wrapper to SDL_GetTicks that ensures a non-zero return value. + +\return The tick count. +*/ +Uint32 _getTicks() +{ + Uint32 ticks = SDL_GetTicks(); + + /* + * Since baseticks!=0 is used to track initialization + * we need to ensure that the tick count is always >0 + * since SDL_GetTicks may not have incremented yet and + * return 0 depending on the timing of the calls. + */ + if (ticks == 0) { + return 1; + } else { + return ticks; + } +} + +/*! +\brief Initialize the framerate manager. + +Initialize the framerate manager, set default framerate of 30Hz and +reset delay interpolation. + +\param manager Pointer to the framerate manager. +*/ +void SDL_initFramerate(FPSmanager * manager) +{ + /* + * Store some sane values + */ + manager->framecount = 0; + manager->rate = FPS_DEFAULT; + manager->rateticks = (1000.0f / (float) FPS_DEFAULT); + manager->baseticks = _getTicks(); + manager->lastticks = manager->baseticks; + +} + +/*! +\brief Set the framerate in Hz + +Sets a new framerate for the manager and reset delay interpolation. +Rate values must be between FPS_LOWER_LIMIT and FPS_UPPER_LIMIT inclusive to be accepted. + +\param manager Pointer to the framerate manager. +\param rate The new framerate in Hz (frames per second). + +\return 0 for sucess and -1 for error. +*/ +int SDL_setFramerate(FPSmanager * manager, Uint32 rate) +{ + if ((rate >= FPS_LOWER_LIMIT) && (rate <= FPS_UPPER_LIMIT)) { + manager->framecount = 0; + manager->rate = rate; + manager->rateticks = (1000.0f / (float) rate); + return (0); + } else { + return (-1); + } +} + +/*! +\brief Return the current target framerate in Hz + +Get the currently set framerate of the manager. + +\param manager Pointer to the framerate manager. + +\return Current framerate in Hz or -1 for error. +*/ +int SDL_getFramerate(FPSmanager * manager) +{ + if (manager == NULL) { + return (-1); + } else { + return ((int)manager->rate); + } +} + +/*! +\brief Return the current framecount. + +Get the current framecount from the framerate manager. +A frame is counted each time SDL_framerateDelay is called. + +\param manager Pointer to the framerate manager. + +\return Current frame count or -1 for error. +*/ +int SDL_getFramecount(FPSmanager * manager) +{ + if (manager == NULL) { + return (-1); + } else { + return ((int)manager->framecount); + } +} + +/*! +\brief Delay execution to maintain a constant framerate and calculate fps. + +Generate a delay to accomodate currently set framerate. Call once in the +graphics/rendering loop. If the computer cannot keep up with the rate (i.e. +drawing too slow), the delay is zero and the delay interpolation is reset. + +\param manager Pointer to the framerate manager. + +\return The time that passed since the last call to the function in ms. May return 0. +*/ +Uint32 SDL_framerateDelay(FPSmanager * manager) +{ + Uint32 current_ticks; + Uint32 target_ticks; + Uint32 the_delay; + Uint32 time_passed = 0; + + /* + * No manager, no delay + */ + if (manager == NULL) { + return 0; + } + + /* + * Initialize uninitialized manager + */ + if (manager->baseticks == 0) { + SDL_initFramerate(manager); + } + + /* + * Next frame + */ + manager->framecount++; + + /* + * Get/calc ticks + */ + current_ticks = _getTicks(); + time_passed = current_ticks - manager->lastticks; + manager->lastticks = current_ticks; + target_ticks = manager->baseticks + (Uint32) ((float) manager->framecount * manager->rateticks); + + if (current_ticks <= target_ticks) { + the_delay = target_ticks - current_ticks; + SDL_Delay(the_delay); + } else { + manager->framecount = 0; + manager->baseticks = _getTicks(); + } + + return time_passed; +} diff --git a/src/sdl2gfx/SDL_framerate.h b/src/sdl2gfx/SDL_framerate.h new file mode 100644 index 000000000..b4e7ab8e8 --- /dev/null +++ b/src/sdl2gfx/SDL_framerate.h @@ -0,0 +1,100 @@ +/* + +SDL2_framerate.h: framerate manager + +Copyright (C) 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 _SDL2_framerate_h +#define _SDL2_framerate_h + +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + + /* --- */ + +#include "SDL.h" + + /* --------- Definitions */ + + /*! + \brief Highest possible rate supported by framerate controller in Hz (1/s). + */ +#define FPS_UPPER_LIMIT 200 + + /*! + \brief Lowest possible rate supported by framerate controller in Hz (1/s). + */ +#define FPS_LOWER_LIMIT 1 + + /*! + \brief Default rate of framerate controller in Hz (1/s). + */ +#define FPS_DEFAULT 30 + + /*! + \brief Structure holding the state and timing information of the framerate controller. + */ + typedef struct { + Uint32 framecount; + float rateticks; + Uint32 baseticks; + Uint32 lastticks; + Uint32 rate; + } FPSmanager; + + /* ---- Function Prototypes */ + +#ifdef _MSC_VER +# if defined(DLL_EXPORT) && !defined(LIBSDL2_GFX_DLL_IMPORT) +# define SDL2_FRAMERATE_SCOPE __declspec(dllexport) +# else +# ifdef LIBSDL2_GFX_DLL_IMPORT +# define SDL2_FRAMERATE_SCOPE __declspec(dllimport) +# endif +# endif +#endif +#ifndef SDL2_FRAMERATE_SCOPE +# define SDL2_FRAMERATE_SCOPE extern +#endif + + /* Functions return 0 or value for sucess and -1 for error */ + + SDL2_FRAMERATE_SCOPE void SDL_initFramerate(FPSmanager * manager); + SDL2_FRAMERATE_SCOPE int SDL_setFramerate(FPSmanager * manager, Uint32 rate); + SDL2_FRAMERATE_SCOPE int SDL_getFramerate(FPSmanager * manager); + SDL2_FRAMERATE_SCOPE int SDL_getFramecount(FPSmanager * manager); + SDL2_FRAMERATE_SCOPE Uint32 SDL_framerateDelay(FPSmanager * manager); + + /* --- */ + + /* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif + +#endif /* _SDL2_framerate_h */ diff --git a/src/sdl2gfx/SDL_gfxPrimitives.c b/src/sdl2gfx/SDL_gfxPrimitives.c new file mode 100644 index 000000000..f2115ce99 --- /dev/null +++ b/src/sdl2gfx/SDL_gfxPrimitives.c @@ -0,0 +1,4295 @@ +/* + +SDL2_gfxPrimitives.c: graphics primitives for SDL2 renderers + +Copyright (C) 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 + +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> + +#include "SDL_gfxPrimitives.h" +#include "SDL_rotozoom.h" +#include "SDL_gfxPrimitives_font.h" + +/* ---- Structures */
+
+/*!
+\brief The structure passed to the internal Bresenham iterator.
+*/
+typedef struct {
+ Sint16 x, y;
+ int dx, dy, s1, s2, swapdir, error;
+ Uint32 count;
+} SDL2_gfxBresenhamIterator;
+
+/*!
+\brief The structure passed to the internal Murphy iterator.
+*/
+typedef struct {
+ SDL_Renderer *renderer;
+ int u, v; /* delta x , delta y */
+ int ku, kt, kv, kd; /* loop constants */
+ int oct2;
+ int quad4;
+ Sint16 last1x, last1y, last2x, last2y, first1x, first1y, first2x, first2y, tempx, tempy;
+} SDL2_gfxMurphyIterator; + +/* ---- Pixel */ + +/*! +\brief Draw pixel in currently set color. + +\param renderer The renderer to draw on. +\param x X (horizontal) coordinate of the pixel. +\param y Y (vertical) coordinate of the pixel. + +\returns Returns 0 on success, -1 on failure. +*/ +int pixel(SDL_Renderer *renderer, Sint16 x, Sint16 y) +{ + return SDL_RenderDrawPoint(renderer, x, y); +} + +/*! +\brief Draw pixel with blending enabled if a<255. + +\param renderer The renderer to draw on. +\param x X (horizontal) coordinate of the pixel. +\param y Y (vertical) coordinate of the pixel. +\param color The color value of the pixel to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int pixelColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return pixelRGBA(renderer, x, y, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Draw pixel with blending enabled if a<255. + +\param renderer The renderer to draw on. +\param x X (horizontal) coordinate of the pixel. +\param y Y (vertical) coordinate of the pixel. +\param r The red color value of the pixel to draw. +\param g The green color value of the pixel to draw. +\param b The blue color value of the pixel to draw. +\param a The alpha value of the pixel to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int pixelRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + int result = 0; + result |= SDL_SetRenderDrawBlendMode(renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND); + result |= SDL_SetRenderDrawColor(renderer, r, g, b, a); + result |= SDL_RenderDrawPoint(renderer, x, y); + return result; +} + +/*!
+\brief Draw pixel with blending enabled and using alpha weight on color.
+
+\param renderer The renderer to draw on. +\param x The horizontal coordinate of the pixel.
+\param y The vertical position of the pixel.
+\param r The red color value of the pixel to draw. +\param g The green color value of the pixel to draw. +\param b The blue color value of the pixel to draw. +\param a The alpha value of the pixel to draw. +\param weight The weight multiplied into the alpha value of the pixel.
+
+\returns Returns 0 on success, -1 on failure.
+*/
+int pixelRGBAWeight(SDL_Renderer * renderer, Sint16 x, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a, Uint32 weight)
+{
+ /*
+ * Modify Alpha by weight
+ */
+ Uint32 ax = a;
+ ax = ((ax * weight) >> 8);
+ if (ax > 255) {
+ a = 255;
+ } else {
+ a = (Uint8)(ax & 0x000000ff);
+ }
+
+ return pixelRGBA(renderer, x, y, r, g, b, a);
+} + +/* ---- Hline */ + +/*! +\brief Draw horizontal line in currently set color + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point (i.e. left) of the line. +\param x2 X coordinate of the second point (i.e. right) of the line. +\param y Y coordinate of the points of the line. + +\returns Returns 0 on success, -1 on failure. +*/ +int hline(SDL_Renderer * renderer, Sint16 x1, Sint16 x2, Sint16 y) +{ + return SDL_RenderDrawLine(renderer, x1, y, x2, y);; +} + + +/*! +\brief Draw horizontal line with blending. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point (i.e. left) of the line. +\param x2 X coordinate of the second point (i.e. right) of the line. +\param y Y coordinate of the points of the line. +\param color The color value of the line to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int hlineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 x2, Sint16 y, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return hlineRGBA(renderer, x1, x2, y, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Draw horizontal line with blending. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point (i.e. left) of the line. +\param x2 X coordinate of the second point (i.e. right) of the line. +\param y Y coordinate of the points of the line. +\param r The red value of the line to draw. +\param g The green value of the line to draw. +\param b The blue value of the line to draw. +\param a The alpha value of the line to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int hlineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 x2, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + int result = 0; + result |= SDL_SetRenderDrawBlendMode(renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND); + result |= SDL_SetRenderDrawColor(renderer, r, g, b, a); + result |= SDL_RenderDrawLine(renderer, x1, y, x2, y); + return result; +} + +/* ---- Vline */ + +/*! +\brief Draw vertical line with blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the points of the line. +\param y1 Y coordinate of the first point (i.e. top) of the line. +\param y2 Y coordinate of the second point (i.e. bottom) of the line. +\param color The color value of the line to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int vlineColor(SDL_Renderer * renderer, Sint16 x, Sint16 y1, Sint16 y2, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return vlineRGBA(renderer, x, y1, y2, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Draw vertical line with blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the points of the line. +\param y1 Y coordinate of the first point (i.e. top) of the line. +\param y2 Y coordinate of the second point (i.e. bottom) of the line. +\param r The red value of the line to draw. +\param g The green value of the line to draw. +\param b The blue value of the line to draw. +\param a The alpha value of the line to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int vlineRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y1, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + int result = 0; + result |= SDL_SetRenderDrawBlendMode(renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND); + result |= SDL_SetRenderDrawColor(renderer, r, g, b, a); + result |= SDL_RenderDrawLine(renderer, x, y1, x, y2); + return result; +} + +/* ---- Rectangle */ + +/*! +\brief Draw rectangle with blending. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point (i.e. top right) of the rectangle. +\param y1 Y coordinate of the first point (i.e. top right) of the rectangle. +\param x2 X coordinate of the second point (i.e. bottom left) of the rectangle. +\param y2 Y coordinate of the second point (i.e. bottom left) of the rectangle. +\param color The color value of the rectangle to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int rectangleColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return rectangleRGBA(renderer, x1, y1, x2, y2, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Draw rectangle with blending. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point (i.e. top right) of the rectangle. +\param y1 Y coordinate of the first point (i.e. top right) of the rectangle. +\param x2 X coordinate of the second point (i.e. bottom left) of the rectangle. +\param y2 Y coordinate of the second point (i.e. bottom left) of the rectangle. +\param r The red value of the rectangle to draw. +\param g The green value of the rectangle to draw. +\param b The blue value of the rectangle to draw. +\param a The alpha value of the rectangle to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int rectangleRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + int result; + Sint16 tmp; + SDL_Rect rect; + + /* + * Test for special cases of straight lines or single point + */ + if (x1 == x2) { + if (y1 == y2) { + return (pixelRGBA(renderer, x1, y1, r, g, b, a)); + } else { + return (vlineRGBA(renderer, x1, y1, y2, r, g, b, a)); + } + } else { + if (y1 == y2) { + return (hlineRGBA(renderer, x1, x2, y1, r, g, b, a)); + } + } + + /* + * Swap x1, x2 if required + */ + if (x1 > x2) { + tmp = x1; + x1 = x2; + x2 = tmp; + } + + /* + * Swap y1, y2 if required + */ + if (y1 > y2) { + tmp = y1; + y1 = y2; + y2 = tmp; + } + + /* + * Create destination rect + */ + rect.x = x1; + rect.y = y1; + rect.w = x2 - x1; + rect.h = y2 - y1; + + /* + * Draw + */ + result = 0; + result |= SDL_SetRenderDrawBlendMode(renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND); + result |= SDL_SetRenderDrawColor(renderer, r, g, b, a); + result |= SDL_RenderDrawRect(renderer, &rect); + return result; +} + +/* ---- Rounded Rectangle */ + +/*! +\brief Draw rounded-corner rectangle with blending. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point (i.e. top right) of the rectangle. +\param y1 Y coordinate of the first point (i.e. top right) of the rectangle. +\param x2 X coordinate of the second point (i.e. bottom left) of the rectangle. +\param y2 Y coordinate of the second point (i.e. bottom left) of the rectangle. +\param rad The radius of the corner arc. +\param color The color value of the rectangle to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int roundedRectangleColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 rad, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return roundedRectangleRGBA(renderer, x1, y1, x2, y2, rad, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Draw rounded-corner rectangle with blending. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point (i.e. top right) of the rectangle. +\param y1 Y coordinate of the first point (i.e. top right) of the rectangle. +\param x2 X coordinate of the second point (i.e. bottom left) of the rectangle. +\param y2 Y coordinate of the second point (i.e. bottom left) of the rectangle. +\param rad The radius of the corner arc. +\param r The red value of the rectangle to draw. +\param g The green value of the rectangle to draw. +\param b The blue value of the rectangle to draw. +\param a The alpha value of the rectangle to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int roundedRectangleRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + int result = 0; + Sint16 tmp; + Sint16 w, h; + Sint16 xx1, xx2; + Sint16 yy1, yy2; + + /* + * Check renderer + */ + if (renderer == NULL) + { + return -1; + } + + /* + * Check radius vor valid range + */ + if (rad < 0) { + return -1; + } + + /* + * Special case - no rounding + */ + if (rad == 0) { + return rectangleRGBA(renderer, x1, y1, x2, y2, r, g, b, a); + } + + /* + * Test for special cases of straight lines or single point + */ + if (x1 == x2) { + if (y1 == y2) { + return (pixelRGBA(renderer, x1, y1, r, g, b, a)); + } else { + return (vlineRGBA(renderer, x1, y1, y2, r, g, b, a)); + } + } else { + if (y1 == y2) { + return (hlineRGBA(renderer, x1, x2, y1, r, g, b, a)); + } + } + + /* + * Swap x1, x2 if required + */ + if (x1 > x2) { + tmp = x1; + x1 = x2; + x2 = tmp; + } + + /* + * Swap y1, y2 if required + */ + if (y1 > y2) { + tmp = y1; + y1 = y2; + y2 = tmp; + } + + /* + * Calculate width&height + */ + w = x2 - x1; + h = y2 - y1; + + /* + * Maybe adjust radius + */ + if ((rad * 2) > w) + { + rad = w / 2; + } + if ((rad * 2) > h) + { + rad = h / 2; + } + + /* + * Draw corners + */ + xx1 = x1 + rad; + xx2 = x2 - rad; + yy1 = y1 + rad; + yy2 = y2 - rad; + result |= arcRGBA(renderer, xx1, yy1, rad, 180, 270, r, g, b, a); + result |= arcRGBA(renderer, xx2, yy1, rad, 270, 360, r, g, b, a); + result |= arcRGBA(renderer, xx1, yy2, rad, 90, 180, r, g, b, a); + result |= arcRGBA(renderer, xx2, yy2, rad, 0, 90, r, g, b, a); + + /* + * Draw lines + */ + if (xx1 <= xx2) { + result |= hlineRGBA(renderer, xx1, xx2, y1, r, g, b, a); + result |= hlineRGBA(renderer, xx1, xx2, y2, r, g, b, a); + } + if (yy1 <= yy2) { + result |= vlineRGBA(renderer, x1, yy1, yy2, r, g, b, a); + result |= vlineRGBA(renderer, x2, yy1, yy2, r, g, b, a); + } + + return result; +} + +/* ---- Rounded Box */ + +/*! +\brief Draw rounded-corner box (filled rectangle) with blending. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point (i.e. top right) of the box. +\param y1 Y coordinate of the first point (i.e. top right) of the box. +\param x2 X coordinate of the second point (i.e. bottom left) of the box. +\param y2 Y coordinate of the second point (i.e. bottom left) of the box. +\param rad The radius of the corner arcs of the box. +\param color The color value of the box to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int roundedBoxColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 rad, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return roundedBoxRGBA(renderer, x1, y1, x2, y2, rad, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Draw rounded-corner box (filled rectangle) with blending. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point (i.e. top right) of the box. +\param y1 Y coordinate of the first point (i.e. top right) of the box. +\param x2 X coordinate of the second point (i.e. bottom left) of the box. +\param y2 Y coordinate of the second point (i.e. bottom left) of the box. +\param rad The radius of the corner arcs of the box. +\param r The red value of the box to draw. +\param g The green value of the box to draw. +\param b The blue value of the box to draw. +\param a The alpha value of the box to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int roundedBoxRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, + Sint16 y2, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + int result = 0; + Sint16 w, h, tmp; + Sint16 xx1, xx2, yy1, yy2; + + /* + * Check destination renderer + */ + if (renderer == NULL) + { + return -1; + } + + /* + * Check radius vor valid range + */ + if (rad < 0) { + return -1; + } + + /* + * Special case - no rounding + */ + if (rad == 0) { + return rectangleRGBA(renderer, x1, y1, x2, y2, r, g, b, a); + } + + /* + * Test for special cases of straight lines or single point + */ + if (x1 == x2) { + if (y1 == y2) { + return (pixelRGBA(renderer, x1, y1, r, g, b, a)); + } else { + return (vlineRGBA(renderer, x1, y1, y2, r, g, b, a)); + } + } else { + if (y1 == y2) { + return (hlineRGBA(renderer, x1, x2, y1, r, g, b, a)); + } + } + + /* + * Swap x1, x2 if required + */ + if (x1 > x2) { + tmp = x1; + x1 = x2; + x2 = tmp; + } + + /* + * Swap y1, y2 if required + */ + if (y1 > y2) { + tmp = y1; + y1 = y2; + y2 = tmp; + } + + /* + * Calculate width&height + */ + w = x2 - x1; + h = y2 - y1; + + /* + * Maybe adjust radius + */ + if ((rad * 2) > w) + { + rad = w / 2; + } + if ((rad * 2) > h) + { + rad = h / 2; + } + + /* + * Draw corners + */ + xx1 = x1 + rad; + xx2 = x2 - rad; + yy1 = y1 + rad; + yy2 = y2 - rad; + result |= filledPieRGBA(renderer, xx1, yy1, rad, 180, 270, r, g, b, a); + result |= filledPieRGBA(renderer, xx2, yy1, rad, 270, 360, r, g, b, a); + result |= filledPieRGBA(renderer, xx1, yy2, rad, 90, 180, r, g, b, a); + result |= filledPieRGBA(renderer, xx2, yy2, rad, 0, 90, r, g, b, a); + + /* + * Draw body + */ + xx1++; + xx2--; + yy1++; + yy2--; + if (xx1 <= xx2) { + result |= boxRGBA(renderer, xx1, y1, xx2, y2, r, g, b, a); + } + if (yy1 <= yy2) { + result |= boxRGBA(renderer, x1, yy1, xx1-1, yy2, r, g, b, a); + result |= boxRGBA(renderer, xx2+1, yy1, x2, yy2, r, g, b, a); + } + + return result; +} + +/* ---- Box */ + +/*! +\brief Draw box (filled rectangle) with blending. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point (i.e. top right) of the box. +\param y1 Y coordinate of the first point (i.e. top right) of the box. +\param x2 X coordinate of the second point (i.e. bottom left) of the box. +\param y2 Y coordinate of the second point (i.e. bottom left) of the box. +\param color The color value of the box to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int boxColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return boxRGBA(renderer, x1, y1, x2, y2, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Draw box (filled rectangle) with blending. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point (i.e. top right) of the box. +\param y1 Y coordinate of the first point (i.e. top right) of the box. +\param x2 X coordinate of the second point (i.e. bottom left) of the box. +\param y2 Y coordinate of the second point (i.e. bottom left) of the box. +\param r The red value of the box to draw. +\param g The green value of the box to draw. +\param b The blue value of the box to draw. +\param a The alpha value of the box to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int boxRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + int result; + Sint16 tmp; + SDL_Rect rect; + + /* + * Test for special cases of straight lines or single point + */ + if (x1 == x2) { + if (y1 == y2) { + return (pixelRGBA(renderer, x1, y1, r, g, b, a)); + } else { + return (vlineRGBA(renderer, x1, y1, y2, r, g, b, a)); + } + } else { + if (y1 == y2) { + return (hlineRGBA(renderer, x1, x2, y1, r, g, b, a)); + } + } + + /* + * Swap x1, x2 if required + */ + if (x1 > x2) { + tmp = x1; + x1 = x2; + x2 = tmp; + } + + /* + * Swap y1, y2 if required + */ + if (y1 > y2) { + tmp = y1; + y1 = y2; + y2 = tmp; + } + + /* + * Create destination rect + */ + rect.x = x1; + rect.y = y1; + rect.w = x2 - x1; + rect.h = y2 - y1; + + /* + * Draw + */ + result = 0; + result |= SDL_SetRenderDrawBlendMode(renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND); + result |= SDL_SetRenderDrawColor(renderer, r, g, b, a); + result |= SDL_RenderFillRect(renderer, &rect); + return result; +} + +/* ----- Line */ + +/*! +\brief Draw line with alpha blending using the currently set color. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point of the line. +\param y1 Y coordinate of the first point of the line. +\param x2 X coordinate of the second point of the line. +\param y2 Y coordinate of the second point of the line. + +\returns Returns 0 on success, -1 on failure. +*/ +int line(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2) +{ + /* + * Draw + */ + return SDL_RenderDrawLine(renderer, x1, y1, x2, y2); +} + +/*! +\brief Draw line with alpha blending. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point of the line. +\param y1 Y coordinate of the first point of the line. +\param x2 X coordinate of the second point of the line. +\param y2 Y coordinate of the seond point of the line. +\param color The color value of the line to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int lineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return lineRGBA(renderer, x1, y1, x2, y2, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Draw line with alpha blending. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point of the line. +\param y1 Y coordinate of the first point of the line. +\param x2 X coordinate of the second point of the line. +\param y2 Y coordinate of the second point of the line. +\param r The red value of the line to draw. +\param g The green value of the line to draw. +\param b The blue value of the line to draw. +\param a The alpha value of the line to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int lineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + /* + * Draw + */ + int result = 0; + result |= SDL_SetRenderDrawBlendMode(renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND); + result |= SDL_SetRenderDrawColor(renderer, r, g, b, a); + result |= SDL_RenderDrawLine(renderer, x1, y1, x2, y2); + return result; +} + +/* ---- AA Line */ + +#define AAlevels 256
+#define AAbits 8
+
+/*!
+\brief Internal function to draw anti-aliased line with alpha blending and endpoint control.
+
+This implementation of the Wu antialiasing code is based on Mike Abrash's
+DDJ article which was reprinted as Chapter 42 of his Graphics Programming
+Black Book, but has been optimized to work with SDL and utilizes 32-bit
+fixed-point arithmetic by A. Schiffler. The endpoint control allows the
+supression to draw the last pixel useful for rendering continous aa-lines
+with alpha<255.
+
+\param dst The surface to draw on.
+\param x1 X coordinate of the first point of the aa-line.
+\param y1 Y coordinate of the first point of the aa-line.
+\param x2 X coordinate of the second point of the aa-line.
+\param y2 Y coordinate of the second point of the aa-line.
+\param r The red value of the aa-line to draw. +\param g The green value of the aa-line to draw. +\param b The blue value of the aa-line to draw. +\param a The alpha value of the aa-line to draw. +\param draw_endpoint Flag indicating if the endpoint should be drawn; draw if non-zero.
+
+\returns Returns 0 on success, -1 on failure.
+*/
+int _aalineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a, int draw_endpoint)
+{
+ Sint32 xx0, yy0, xx1, yy1;
+ int result;
+ Uint32 intshift, erracc, erradj;
+ Uint32 erracctmp, wgt, wgtcompmask;
+ int dx, dy, tmp, xdir, y0p1, x0pxdir;
+
+ /*
+ * Keep on working with 32bit numbers
+ */
+ xx0 = x1;
+ yy0 = y1;
+ xx1 = x2;
+ yy1 = y2;
+
+ /*
+ * Reorder points if required
+ */
+ if (yy0 > yy1) {
+ tmp = yy0;
+ yy0 = yy1;
+ yy1 = tmp;
+ tmp = xx0;
+ xx0 = xx1;
+ xx1 = tmp;
+ }
+
+ /*
+ * Calculate distance
+ */
+ dx = xx1 - xx0;
+ dy = yy1 - yy0;
+
+ /*
+ * Check for special cases
+ */
+ if (dx == 0) {
+ /*
+ * Vertical line
+ */
+ if (draw_endpoint)
+ {
+ return (vlineRGBA(renderer, x1, y1, y2, r, g, b, a));
+ } else {
+ if (dy>0) {
+ return (vlineRGBA(renderer, x1, yy0, yy0+dy, r, g, b, a));
+ } else {
+ return (pixelRGBA(renderer, x1, y1, r, g, b, a));
+ }
+ }
+ } else if (dy == 0) {
+ /*
+ * Horizontal line
+ */
+ if (draw_endpoint)
+ {
+ return (hlineRGBA(renderer, x1, x2, y1, r, g, b, a));
+ } else {
+ if (dx>0) {
+ return (hlineRGBA(renderer, xx0, xx0+dx, y1, r, g, b, a));
+ } else {
+ return (pixelRGBA(renderer, x1, y1, r, g, b, a));
+ }
+ }
+ } else if ((dx == dy) && (draw_endpoint)) {
+ /*
+ * Diagonal line (with endpoint)
+ */
+ return (lineRGBA(renderer, x1, y1, x2, y2, r, g, b, a));
+ }
+
+ /*
+ * Adjust for negative dx and set xdir
+ */
+ if (dx >= 0) {
+ xdir = 1;
+ } else {
+ xdir = -1;
+ dx = (-dx);
+ }
+
+ /*
+ * Line is not horizontal, vertical or diagonal (with endpoint)
+ */
+ result = 0;
+
+ /*
+ * Zero accumulator
+ */
+ erracc = 0;
+
+ /*
+ * # of bits by which to shift erracc to get intensity level
+ */
+ intshift = 32 - AAbits;
+
+ /*
+ * Mask used to flip all bits in an intensity weighting
+ */
+ wgtcompmask = AAlevels - 1;
+
+ /*
+ * Draw the initial pixel in the foreground color
+ */
+ result |= pixelRGBA(renderer, x1, y1, r, g, b, a);
+
+ /*
+ * x-major or y-major?
+ */
+ if (dy > dx) {
+
+ /*
+ * y-major. Calculate 16-bit fixed point fractional part of a pixel that
+ * X advances every time Y advances 1 pixel, truncating the result so that
+ * we won't overrun the endpoint along the X axis
+ */
+ /*
+ * Not-so-portable version: erradj = ((Uint64)dx << 32) / (Uint64)dy;
+ */
+ erradj = ((dx << 16) / dy) << 16;
+
+ /*
+ * draw all pixels other than the first and last
+ */
+ x0pxdir = xx0 + xdir;
+ while (--dy) {
+ erracctmp = erracc;
+ erracc += erradj;
+ if (erracc <= erracctmp) {
+ /*
+ * rollover in error accumulator, x coord advances
+ */
+ xx0 = x0pxdir;
+ x0pxdir += xdir;
+ }
+ yy0++; /* y-major so always advance Y */
+
+ /*
+ * the AAbits most significant bits of erracc give us the intensity
+ * weighting for this pixel, and the complement of the weighting for
+ * the paired pixel.
+ */
+ wgt = (erracc >> intshift) & 255;
+ result |= pixelRGBAWeight (renderer, xx0, yy0, r, g, b, a, 255 - wgt);
+ result |= pixelRGBAWeight (renderer, x0pxdir, yy0, r, g, b, a, wgt);
+ }
+
+ } else {
+
+ /*
+ * x-major line. Calculate 16-bit fixed-point fractional part of a pixel
+ * that Y advances each time X advances 1 pixel, truncating the result so
+ * that we won't overrun the endpoint along the X axis.
+ */
+ /*
+ * Not-so-portable version: erradj = ((Uint64)dy << 32) / (Uint64)dx;
+ */
+ erradj = ((dy << 16) / dx) << 16;
+
+ /*
+ * draw all pixels other than the first and last
+ */
+ y0p1 = yy0 + 1;
+ while (--dx) {
+
+ erracctmp = erracc;
+ erracc += erradj;
+ if (erracc <= erracctmp) {
+ /*
+ * Accumulator turned over, advance y
+ */
+ yy0 = y0p1;
+ y0p1++;
+ }
+ xx0 += xdir; /* x-major so always advance X */
+ /*
+ * the AAbits most significant bits of erracc give us the intensity
+ * weighting for this pixel, and the complement of the weighting for
+ * the paired pixel.
+ */
+ wgt = (erracc >> intshift) & 255;
+ result |= pixelRGBAWeight (renderer, xx0, yy0, r, g, b, a, 255 - wgt);
+ result |= pixelRGBAWeight (renderer, xx0, y0p1, r, g, b, a, wgt);
+ }
+ }
+
+ /*
+ * Do we have to draw the endpoint
+ */
+ if (draw_endpoint) {
+ /*
+ * Draw final pixel, always exactly intersected by the line and doesn't
+ * need to be weighted.
+ */
+ result |= pixelRGBA (renderer, x2, y2, r, g, b, a);
+ }
+
+ return (result);
+} + +/*! +\brief Draw anti-aliased line with alpha blending. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point of the aa-line. +\param y1 Y coordinate of the first point of the aa-line. +\param x2 X coordinate of the second point of the aa-line. +\param y2 Y coordinate of the second point of the aa-line. +\param color The color value of the aa-line to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int aalineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return _aalineRGBA(renderer, x1, y1, x2, y2, c[0], c[1], c[2], c[3], 1); +} + +/*! +\brief Draw anti-aliased line with alpha blending. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point of the aa-line. +\param y1 Y coordinate of the first point of the aa-line. +\param x2 X coordinate of the second point of the aa-line. +\param y2 Y coordinate of the second point of the aa-line. +\param r The red value of the aa-line to draw. +\param g The green value of the aa-line to draw. +\param b The blue value of the aa-line to draw. +\param a The alpha value of the aa-line to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int aalineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + return _aalineRGBA(renderer, x1, y1, x2, y2, r, g, b, a, 1); +} + +/* ----- Circle */ + +/*! +\brief Draw circle with blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the circle. +\param y Y coordinate of the center of the circle. +\param rad Radius in pixels of the circle. +\param color The color value of the circle to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int circleColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return ellipseRGBA(renderer, x, y, rad, rad, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Draw circle with blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the circle. +\param y Y coordinate of the center of the circle. +\param rad Radius in pixels of the circle. +\param r The red value of the circle to draw. +\param g The green value of the circle to draw. +\param b The blue value of the circle to draw. +\param a The alpha value of the circle to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int circleRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + return ellipseRGBA(renderer, x, y, rad, rad, r, g, b, a); +} + +/* ----- Arc */ + +/*! +\brief Arc with blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the arc. +\param y Y coordinate of the center of the arc. +\param rad Radius in pixels of the arc. +\param start Starting radius in degrees of the arc. 0 degrees is down, increasing counterclockwise. +\param end Ending radius in degrees of the arc. 0 degrees is down, increasing counterclockwise. +\param color The color value of the arc to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int arcColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return arcRGBA(renderer, x, y, rad, start, end, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Arc with blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the arc. +\param y Y coordinate of the center of the arc. +\param rad Radius in pixels of the arc. +\param start Starting radius in degrees of the arc. 0 degrees is down, increasing counterclockwise. +\param end Ending radius in degrees of the arc. 0 degrees is down, increasing counterclockwise. +\param r The red value of the arc to draw. +\param g The green value of the arc to draw. +\param b The blue value of the arc to draw. +\param a The alpha value of the arc to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int arcRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + int result;
+ Sint16 cx = 0;
+ Sint16 cy = rad;
+ Sint16 df = 1 - rad;
+ Sint16 d_e = 3;
+ Sint16 d_se = -2 * rad + 5;
+ Sint16 xpcx, xmcx, xpcy, xmcy;
+ Sint16 ypcy, ymcy, ypcx, ymcx;
+ Uint8 drawoct;
+ int startoct, endoct, oct, stopval_start = 0, stopval_end = 0;
+ double dstart, dend, temp = 0.;
+
+ /*
+ * Sanity check radius
+ */
+ if (rad < 0) {
+ return (-1);
+ }
+
+ /*
+ * Special case for rad=0 - draw a point
+ */
+ if (rad == 0) {
+ return (pixelRGBA(renderer, x, y, r, g, b, a));
+ }
+
+ // Octant labelling
+ //
+ // \ 5 | 6 /
+ // \ | /
+ // 4 \ | / 7
+ // \|/
+ //------+------ +x
+ // /|\
+ // 3 / | \ 0
+ // / | \
+ // / 2 | 1 \
+ // +y
+
+ // Initially reset bitmask to 0x00000000
+ // the set whether or not to keep drawing a given octant.
+ // For example: 0x00111100 means we're drawing in octants 2-5
+ drawoct = 0;
+
+ /*
+ * Fixup angles
+ */
+ start %= 360;
+ end %= 360;
+ // 0 <= start & end < 360; note that sometimes start > end - if so, arc goes back through 0.
+ while (start < 0) start += 360;
+ while (end < 0) end += 360;
+ start %= 360;
+ end %= 360;
+
+ // now, we find which octants we're drawing in.
+ startoct = start / 45;
+ endoct = end / 45;
+ oct = startoct - 1; // we increment as first step in loop
+
+ // stopval_start, stopval_end;
+ // what values of cx to stop at.
+ do {
+ oct = (oct + 1) % 8;
+
+ if (oct == startoct) {
+ // need to compute stopval_start for this octant. Look at picture above if this is unclear
+ dstart = (double)start;
+ switch (oct)
+ {
+ case 0:
+ case 3:
+ temp = sin(dstart * M_PI / 180.);
+ break;
+ case 1:
+ case 6:
+ temp = cos(dstart * M_PI / 180.);
+ break;
+ case 2:
+ case 5:
+ temp = -cos(dstart * M_PI / 180.);
+ break;
+ case 4:
+ case 7:
+ temp = -sin(dstart * M_PI / 180.);
+ break;
+ }
+ temp *= rad;
+ stopval_start = (int)temp; // always round down.
+
+ // This isn't arbitrary, but requires graph paper to explain well.
+ // The basic idea is that we're always changing drawoct after we draw, so we
+ // stop immediately after we render the last sensible pixel at x = ((int)temp).
+
+ // and whether to draw in this octant initially
+ if (oct % 2) drawoct |= (1 << oct); // this is basically like saying drawoct[oct] = true, if drawoct were a bool array
+ else drawoct &= 255 - (1 << oct); // this is basically like saying drawoct[oct] = false
+ }
+ if (oct == endoct) {
+ // need to compute stopval_end for this octant
+ dend = (double)end;
+ switch (oct)
+ {
+ case 0:
+ case 3:
+ temp = sin(dend * M_PI / 180);
+ break;
+ case 1:
+ case 6:
+ temp = cos(dend * M_PI / 180);
+ break;
+ case 2:
+ case 5:
+ temp = -cos(dend * M_PI / 180);
+ break;
+ case 4:
+ case 7:
+ temp = -sin(dend * M_PI / 180);
+ break;
+ }
+ temp *= rad;
+ stopval_end = (int)temp;
+
+ // and whether to draw in this octant initially
+ if (startoct == endoct) {
+ // note: we start drawing, stop, then start again in this case
+ // otherwise: we only draw in this octant, so initialize it to false, it will get set back to true
+ if (start > end) {
+ // unfortunately, if we're in the same octant and need to draw over the whole circle,
+ // we need to set the rest to true, because the while loop will end at the bottom.
+ drawoct = 255;
+ } else {
+ drawoct &= 255 - (1 << oct);
+ }
+ }
+ else if (oct % 2) drawoct &= 255 - (1 << oct);
+ else drawoct |= (1 << oct);
+ } else if (oct != startoct) { // already verified that it's != endoct
+ drawoct |= (1 << oct); // draw this entire segment
+ }
+ } while (oct != endoct);
+
+ // so now we have what octants to draw and when to draw them. all that's left is the actual raster code.
+
+ /*
+ * Set color
+ */
+ result = 0; + result |= SDL_SetRenderDrawBlendMode(renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND); + result |= SDL_SetRenderDrawColor(renderer, r, g, b, a); +
+ /*
+ * Draw arc
+ */
+ do {
+ ypcy = y + cy;
+ ymcy = y - cy;
+ if (cx > 0) {
+ xpcx = x + cx;
+ xmcx = x - cx;
+
+ // always check if we're drawing a certain octant before adding a pixel to that octant.
+ if (drawoct & 4) result |= pixel(renderer, xmcx, ypcy);
+ if (drawoct & 2) result |= pixel(renderer, xpcx, ypcy);
+ if (drawoct & 32) result |= pixel(renderer, xmcx, ymcy);
+ if (drawoct & 64) result |= pixel(renderer, xpcx, ymcy);
+ } else {
+ if (drawoct & 96) result |= pixel(renderer, x, ymcy);
+ if (drawoct & 6) result |= pixel(renderer, x, ypcy);
+ }
+
+ xpcy = x + cy;
+ xmcy = x - cy;
+ if (cx > 0 && cx != cy) {
+ ypcx = y + cx;
+ ymcx = y - cx;
+ if (drawoct & 8) result |= pixel(renderer, xmcy, ypcx);
+ if (drawoct & 1) result |= pixel(renderer, xpcy, ypcx);
+ if (drawoct & 16) result |= pixel(renderer, xmcy, ymcx);
+ if (drawoct & 128) result |= pixel(renderer, xpcy, ymcx);
+ } else if (cx == 0) {
+ if (drawoct & 24) result |= pixel(renderer, xmcy, y);
+ if (drawoct & 129) result |= pixel(renderer, xpcy, y);
+ }
+
+ /*
+ * Update whether we're drawing an octant
+ */
+ if (stopval_start == cx) {
+ // works like an on-off switch.
+ // This is just in case start & end are in the same octant.
+ if (drawoct & (1 << startoct)) drawoct &= 255 - (1 << startoct);
+ else drawoct |= (1 << startoct);
+ }
+ if (stopval_end == cx) {
+ if (drawoct & (1 << endoct)) drawoct &= 255 - (1 << endoct);
+ else drawoct |= (1 << endoct);
+ }
+
+ /*
+ * Update pixels
+ */
+ if (df < 0) {
+ df += d_e;
+ d_e += 2;
+ d_se += 2;
+ } else {
+ df += d_se;
+ d_e += 2;
+ d_se += 4;
+ cy--;
+ }
+ cx++;
+ } while (cx <= cy);
+
+ return (result); +} + +/* ----- AA Circle */ + +/*! +\brief Draw anti-aliased circle with blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the aa-circle. +\param y Y coordinate of the center of the aa-circle. +\param rad Radius in pixels of the aa-circle. +\param color The color value of the aa-circle to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int aacircleColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return aaellipseRGBA(renderer, x, y, rad, rad, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Draw anti-aliased circle with blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the aa-circle. +\param y Y coordinate of the center of the aa-circle. +\param rad Radius in pixels of the aa-circle. +\param r The red value of the aa-circle to draw. +\param g The green value of the aa-circle to draw. +\param b The blue value of the aa-circle to draw. +\param a The alpha value of the aa-circle to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int aacircleRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + /* + * Draw + */ + return aaellipseRGBA(renderer, x, y, rad, rad, r, g, b, a); +} + +/* ----- Filled Circle */ + +/*! +\brief Draw filled circle with blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the filled circle. +\param y Y coordinate of the center of the filled circle. +\param rad Radius in pixels of the filled circle. +\param color The color value of the filled circle to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int filledCircleColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return filledEllipseRGBA(renderer, x, y, rad, rad, c[0], c[1], c[2], c[3]); +}
+ +/*! +\brief Draw filled circle with blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the filled circle. +\param y Y coordinate of the center of the filled circle. +\param rad Radius in pixels of the filled circle. +\param r The red value of the filled circle to draw. +\param g The green value of the filled circle to draw. +\param b The blue value of the filled circle to draw. +\param a The alpha value of the filled circle to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int filledCircleRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + int result;
+ Sint16 cx = 0;
+ Sint16 cy = rad;
+ Sint16 ocx = (Sint16) 0xffff;
+ Sint16 ocy = (Sint16) 0xffff;
+ Sint16 df = 1 - rad;
+ Sint16 d_e = 3;
+ Sint16 d_se = -2 * rad + 5;
+ Sint16 xpcx, xmcx, xpcy, xmcy;
+ Sint16 ypcy, ymcy, ypcx, ymcx;
+
+ /*
+ * Sanity check radius
+ */
+ if (rad < 0) {
+ return (-1);
+ }
+
+ /*
+ * Special case for rad=0 - draw a point
+ */
+ if (rad == 0) {
+ return (pixelRGBA(renderer, x, y, r, g, b, a));
+ }
+
+ /*
+ * Set color
+ */
+ result = 0;
+ result |= SDL_SetRenderDrawBlendMode(renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND); + result |= SDL_SetRenderDrawColor(renderer, r, g, b, a); +
+ /*
+ * Draw
+ */
+ do {
+ xpcx = x + cx;
+ xmcx = x - cx;
+ xpcy = x + cy;
+ xmcy = x - cy;
+ if (ocy != cy) {
+ if (cy > 0) {
+ ypcy = y + cy;
+ ymcy = y - cy;
+ result |= hline(renderer, xmcx, xpcx, ypcy);
+ result |= hline(renderer, xmcx, xpcx, ymcy);
+ } else {
+ result |= hline(renderer, xmcx, xpcx, y);
+ }
+ ocy = cy;
+ }
+ if (ocx != cx) {
+ if (cx != cy) {
+ if (cx > 0) {
+ ypcx = y + cx;
+ ymcx = y - cx;
+ result |= hline(renderer, xmcy, xpcy, ymcx);
+ result |= hline(renderer, xmcy, xpcy, ypcx);
+ } else {
+ result |= hline(renderer, xmcy, xpcy, y);
+ }
+ }
+ ocx = cx;
+ }
+
+ /*
+ * Update
+ */
+ if (df < 0) {
+ df += d_e;
+ d_e += 2;
+ d_se += 2;
+ } else {
+ df += d_se;
+ d_e += 2;
+ d_se += 4;
+ cy--;
+ }
+ cx++;
+ } while (cx <= cy);
+
+ return (result); +} + +/* ----- Ellipse */ + +/*! +\brief Draw ellipse with blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the ellipse. +\param y Y coordinate of the center of the ellipse. +\param rx Horizontal radius in pixels of the ellipse. +\param ry Vertical radius in pixels of the ellipse. +\param color The color value of the ellipse to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int ellipseColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color) +{
+ Uint8 *c = (Uint8 *)&color; + return ellipseRGBA(renderer, x, y, rx, ry, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Draw ellipse with blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the ellipse. +\param y Y coordinate of the center of the ellipse. +\param rx Horizontal radius in pixels of the ellipse. +\param ry Vertical radius in pixels of the ellipse. +\param r The red value of the ellipse to draw. +\param g The green value of the ellipse to draw. +\param b The blue value of the ellipse to draw. +\param a The alpha value of the ellipse to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int ellipseRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + int result;
+ int ix, iy;
+ int h, i, j, k;
+ int oh, oi, oj, ok;
+ int xmh, xph, ypk, ymk;
+ int xmi, xpi, ymj, ypj;
+ int xmj, xpj, ymi, ypi;
+ int xmk, xpk, ymh, yph;
+
+ /*
+ * Sanity check radii
+ */
+ if ((rx < 0) || (ry < 0)) {
+ return (-1);
+ }
+
+ /*
+ * Special case for rx=0 - draw a vline
+ */
+ if (rx == 0) {
+ return (vlineRGBA(renderer, x, y - ry, y + ry, r, g, b, a));
+ }
+ /*
+ * Special case for ry=0 - draw a hline
+ */
+ if (ry == 0) {
+ return (hlineRGBA(renderer, x - rx, x + rx, y, r, g, b, a));
+ }
+
+ /*
+ * Set color
+ */
+ result = 0;
+ result |= SDL_SetRenderDrawBlendMode(renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND); + result |= SDL_SetRenderDrawColor(renderer, r, g, b, a); +
+ /*
+ * Init vars
+ */
+ oh = oi = oj = ok = 0xFFFF;
+
+ /*
+ * Draw
+ */
+ if (rx > ry) {
+ ix = 0;
+ iy = rx * 64;
+
+ do {
+ h = (ix + 32) >> 6;
+ i = (iy + 32) >> 6;
+ j = (h * ry) / rx;
+ k = (i * ry) / rx;
+
+ if (((ok != k) && (oj != k)) || ((oj != j) && (ok != j)) || (k != j)) {
+ xph = x + h;
+ xmh = x - h;
+ if (k > 0) {
+ ypk = y + k;
+ ymk = y - k;
+ result |= pixel(renderer, xmh, ypk);
+ result |= pixel(renderer, xph, ypk);
+ result |= pixel(renderer, xmh, ymk);
+ result |= pixel(renderer, xph, ymk);
+ } else {
+ result |= pixel(renderer, xmh, y);
+ result |= pixel(renderer, xph, y);
+ }
+ ok = k;
+ xpi = x + i;
+ xmi = x - i;
+ if (j > 0) {
+ ypj = y + j;
+ ymj = y - j;
+ result |= pixel(renderer, xmi, ypj);
+ result |= pixel(renderer, xpi, ypj);
+ result |= pixel(renderer, xmi, ymj);
+ result |= pixel(renderer, xpi, ymj);
+ } else {
+ result |= pixel(renderer, xmi, y);
+ result |= pixel(renderer, xpi, y);
+ }
+ oj = j;
+ }
+
+ ix = ix + iy / rx;
+ iy = iy - ix / rx;
+
+ } while (i > h);
+ } else {
+ ix = 0;
+ iy = ry * 64;
+
+ do {
+ h = (ix + 32) >> 6;
+ i = (iy + 32) >> 6;
+ j = (h * rx) / ry;
+ k = (i * rx) / ry;
+
+ if (((oi != i) && (oh != i)) || ((oh != h) && (oi != h) && (i != h))) {
+ xmj = x - j;
+ xpj = x + j;
+ if (i > 0) {
+ ypi = y + i;
+ ymi = y - i;
+ result |= pixel(renderer, xmj, ypi);
+ result |= pixel(renderer, xpj, ypi);
+ result |= pixel(renderer, xmj, ymi);
+ result |= pixel(renderer, xpj, ymi);
+ } else {
+ result |= pixel(renderer, xmj, y);
+ result |= pixel(renderer, xpj, y);
+ }
+ oi = i;
+ xmk = x - k;
+ xpk = x + k;
+ if (h > 0) {
+ yph = y + h;
+ ymh = y - h;
+ result |= pixel(renderer, xmk, yph);
+ result |= pixel(renderer, xpk, yph);
+ result |= pixel(renderer, xmk, ymh);
+ result |= pixel(renderer, xpk, ymh);
+ } else {
+ result |= pixel(renderer, xmk, y);
+ result |= pixel(renderer, xpk, y);
+ }
+ oh = h;
+ }
+
+ ix = ix + iy / ry;
+ iy = iy - ix / ry;
+
+ } while (i > h);
+ }
+
+ return (result);
+} + +/* ----- AA Ellipse */ + +/* Windows targets do not have lrint, so provide a local inline version */
+#if defined(_MSC_VER)
+/* Detect 64bit and use intrinsic version */
+#ifdef _M_X64
+#include <emmintrin.h>
+static __inline long
+ lrint(float f)
+{
+ return _mm_cvtss_si32(_mm_load_ss(&f));
+}
+#elif defined(_M_IX86)
+__inline long int
+ lrint (double flt)
+{
+ int intgr;
+ _asm
+ {
+ fld flt
+ fistp intgr
+ };
+ return intgr;
+}
+#elif defined(_M_ARM)
+#include <armintr.h>
+#pragma warning(push)
+#pragma warning(disable: 4716)
+__declspec(naked) long int
+ lrint (double flt)
+{
+ __emit(0xEC410B10); // fmdrr d0, r0, r1
+ __emit(0xEEBD0B40); // ftosid s0, d0
+ __emit(0xEE100A10); // fmrs r0, s0
+ __emit(0xE12FFF1E); // bx lr
+}
+#pragma warning(pop)
+#else
+#error lrint needed for MSVC on non X86/AMD64/ARM targets.
+#endif
+#endif + +/*! +\brief Draw anti-aliased ellipse with blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the aa-ellipse. +\param y Y coordinate of the center of the aa-ellipse. +\param rx Horizontal radius in pixels of the aa-ellipse. +\param ry Vertical radius in pixels of the aa-ellipse. +\param color The color value of the aa-ellipse to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int aaellipseColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return aaellipseRGBA(renderer, x, y, rx, ry, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Draw anti-aliased ellipse with blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the aa-ellipse. +\param y Y coordinate of the center of the aa-ellipse. +\param rx Horizontal radius in pixels of the aa-ellipse. +\param ry Vertical radius in pixels of the aa-ellipse. +\param r The red value of the aa-ellipse to draw. +\param g The green value of the aa-ellipse to draw. +\param b The blue value of the aa-ellipse to draw. +\param a The alpha value of the aa-ellipse to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int aaellipseRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + int result;
+ int i;
+ int a2, b2, ds, dt, dxt, t, s, d;
+ Sint16 xp, yp, xs, ys, dyt, od, xx, yy, xc2, yc2;
+ float cp;
+ double sab;
+ Uint8 weight, iweight;
+
+ /*
+ * Sanity check radii
+ */
+ if ((rx < 0) || (ry < 0)) {
+ return (-1);
+ }
+
+ /*
+ * Special case for rx=0 - draw a vline
+ */
+ if (rx == 0) {
+ return (vlineRGBA(renderer, x, y - ry, y + ry, r, g, b, a));
+ }
+ /*
+ * Special case for ry=0 - draw an hline
+ */
+ if (ry == 0) {
+ return (hlineRGBA(renderer, x - rx, x + rx, y, r, g, b, a));
+ }
+
+ /* Variable setup */
+ a2 = rx * rx;
+ b2 = ry * ry;
+
+ ds = 2 * a2;
+ dt = 2 * b2;
+
+ xc2 = 2 * x;
+ yc2 = 2 * y;
+
+ sab = sqrt((double)(a2 + b2));
+ od = (Sint16)lrint(sab*0.01) + 1; /* introduce some overdraw */
+ dxt = (Sint16)lrint((double)a2 / sab) + od;
+
+ t = 0;
+ s = -2 * a2 * ry;
+ d = 0;
+
+ xp = x;
+ yp = y - ry;
+
+ /* Draw */
+ result = 0;
+ result |= SDL_SetRenderDrawBlendMode(renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND); +
+ /* "End points" */
+ result |= pixelRGBA(renderer, xp, yp, r, g, b, a);
+ result |= pixelRGBA(renderer, xc2 - xp, yp, r, g, b, a);
+ result |= pixelRGBA(renderer, xp, yc2 - yp, r, g, b, a);
+ result |= pixelRGBA(renderer, xc2 - xp, yc2 - yp, r, g, b, a);
+
+ for (i = 1; i <= dxt; i++) {
+ xp--;
+ d += t - b2;
+
+ if (d >= 0)
+ ys = yp - 1;
+ else if ((d - s - a2) > 0) {
+ if ((2 * d - s - a2) >= 0)
+ ys = yp + 1;
+ else {
+ ys = yp;
+ yp++;
+ d -= s + a2;
+ s += ds;
+ }
+ } else {
+ yp++;
+ ys = yp + 1;
+ d -= s + a2;
+ s += ds;
+ }
+
+ t -= dt;
+
+ /* Calculate alpha */
+ if (s != 0) {
+ cp = (float) abs(d) / (float) abs(s);
+ if (cp > 1.0) {
+ cp = 1.0;
+ }
+ } else {
+ cp = 1.0;
+ }
+
+ /* Calculate weights */
+ weight = (Uint8) (cp * 255);
+ iweight = 255 - weight;
+
+ /* Upper half */
+ xx = xc2 - xp;
+ result |= pixelRGBAWeight(renderer, xp, yp, r, g, b, a, iweight);
+ result |= pixelRGBAWeight(renderer, xx, yp, r, g, b, a, iweight);
+
+ result |= pixelRGBAWeight(renderer, xp, ys, r, g, b, a, weight);
+ result |= pixelRGBAWeight(renderer, xx, ys, r, g, b, a, weight);
+
+ /* Lower half */
+ yy = yc2 - yp;
+ result |= pixelRGBAWeight(renderer, xp, yy, r, g, b, a, iweight);
+ result |= pixelRGBAWeight(renderer, xx, yy, r, g, b, a, iweight);
+
+ yy = yc2 - ys;
+ result |= pixelRGBAWeight(renderer, xp, yy, r, g, b, a, weight);
+ result |= pixelRGBAWeight(renderer, xx, yy, r, g, b, a, weight);
+ }
+
+ /* Replaces original approximation code dyt = abs(yp - yc); */
+ dyt = (Sint16)lrint((double)b2 / sab ) + od;
+
+ for (i = 1; i <= dyt; i++) {
+ yp++;
+ d -= s + a2;
+
+ if (d <= 0)
+ xs = xp + 1;
+ else if ((d + t - b2) < 0) {
+ if ((2 * d + t - b2) <= 0)
+ xs = xp - 1;
+ else {
+ xs = xp;
+ xp--;
+ d += t - b2;
+ t -= dt;
+ }
+ } else {
+ xp--;
+ xs = xp - 1;
+ d += t - b2;
+ t -= dt;
+ }
+
+ s += ds;
+
+ /* Calculate alpha */
+ if (t != 0) {
+ cp = (float) abs(d) / (float) abs(t);
+ if (cp > 1.0) {
+ cp = 1.0;
+ }
+ } else {
+ cp = 1.0;
+ }
+
+ /* Calculate weight */
+ weight = (Uint8) (cp * 255);
+ iweight = 255 - weight;
+
+ /* Left half */
+ xx = xc2 - xp;
+ yy = yc2 - yp;
+ result |= pixelRGBAWeight(renderer, xp, yp, r, g, b, a, iweight);
+ result |= pixelRGBAWeight(renderer, xx, yp, r, g, b, a, iweight);
+
+ result |= pixelRGBAWeight(renderer, xp, yy, r, g, b, a, iweight);
+ result |= pixelRGBAWeight(renderer, xx, yy, r, g, b, a, iweight);
+
+ /* Right half */
+ xx = xc2 - xs;
+ result |= pixelRGBAWeight(renderer, xs, yp, r, g, b, a, weight);
+ result |= pixelRGBAWeight(renderer, xx, yp, r, g, b, a, weight);
+
+ result |= pixelRGBAWeight(renderer, xs, yy, r, g, b, a, weight);
+ result |= pixelRGBAWeight(renderer, xx, yy, r, g, b, a, weight);
+ }
+
+ return (result); +} + +/* ---- Filled Ellipse */ + +/*! +\brief Draw filled ellipse with blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the filled ellipse. +\param y Y coordinate of the center of the filled ellipse. +\param rx Horizontal radius in pixels of the filled ellipse. +\param ry Vertical radius in pixels of the filled ellipse. +\param color The color value of the filled ellipse to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int filledEllipseColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return filledEllipseRGBA(renderer, x, y, rx, ry, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Draw filled ellipse with blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the filled ellipse. +\param y Y coordinate of the center of the filled ellipse. +\param rx Horizontal radius in pixels of the filled ellipse. +\param ry Vertical radius in pixels of the filled ellipse. +\param r The red value of the filled ellipse to draw. +\param g The green value of the filled ellipse to draw. +\param b The blue value of the filled ellipse to draw. +\param a The alpha value of the filled ellipse to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int filledEllipseRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + int result;
+ int ix, iy;
+ int h, i, j, k;
+ int oh, oi, oj, ok;
+ int xmh, xph;
+ int xmi, xpi;
+ int xmj, xpj;
+ int xmk, xpk;
+
+ /*
+ * Sanity check radii
+ */
+ if ((rx < 0) || (ry < 0)) {
+ return (-1);
+ }
+
+ /*
+ * Special case for rx=0 - draw a vline
+ */
+ if (rx == 0) {
+ return (vlineRGBA(renderer, x, y - ry, y + ry, r, g, b, a));
+ }
+ /*
+ * Special case for ry=0 - draw a hline
+ */
+ if (ry == 0) {
+ return (hlineRGBA(renderer, x - rx, x + rx, y, r, g, b, a));
+ }
+
+ /*
+ * Set color
+ */
+ result = 0;
+ result |= SDL_SetRenderDrawBlendMode(renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND); + result |= SDL_SetRenderDrawColor(renderer, r, g, b, a);
+
+ /*
+ * Init vars
+ */
+ oh = oi = oj = ok = 0xFFFF;
+
+ /*
+ * Draw
+ */
+ if (rx > ry) {
+ ix = 0;
+ iy = rx * 64;
+
+ do {
+ h = (ix + 32) >> 6;
+ i = (iy + 32) >> 6;
+ j = (h * ry) / rx;
+ k = (i * ry) / rx;
+
+ if ((ok != k) && (oj != k)) {
+ xph = x + h;
+ xmh = x - h;
+ if (k > 0) {
+ result |= hline(renderer, xmh, xph, y + k);
+ result |= hline(renderer, xmh, xph, y - k);
+ } else {
+ result |= hline(renderer, xmh, xph, y);
+ }
+ ok = k;
+ }
+ if ((oj != j) && (ok != j) && (k != j)) {
+ xmi = x - i;
+ xpi = x + i;
+ if (j > 0) {
+ result |= hline(renderer, xmi, xpi, y + j);
+ result |= hline(renderer, xmi, xpi, y - j);
+ } else {
+ result |= hline(renderer, xmi, xpi, y);
+ }
+ oj = j;
+ }
+
+ ix = ix + iy / rx;
+ iy = iy - ix / rx;
+
+ } while (i > h);
+ } else {
+ ix = 0;
+ iy = ry * 64;
+
+ do {
+ h = (ix + 32) >> 6;
+ i = (iy + 32) >> 6;
+ j = (h * rx) / ry;
+ k = (i * rx) / ry;
+
+ if ((oi != i) && (oh != i)) {
+ xmj = x - j;
+ xpj = x + j;
+ if (i > 0) {
+ result |= hline(renderer, xmj, xpj, y + i);
+ result |= hline(renderer, xmj, xpj, y - i);
+ } else {
+ result |= hline(renderer, xmj, xpj, y);
+ }
+ oi = i;
+ }
+ if ((oh != h) && (oi != h) && (i != h)) {
+ xmk = x - k;
+ xpk = x + k;
+ if (h > 0) {
+ result |= hline(renderer, xmk, xpk, y + h);
+ result |= hline(renderer, xmk, xpk, y - h);
+ } else {
+ result |= hline(renderer, xmk, xpk, y);
+ }
+ oh = h;
+ }
+
+ ix = ix + iy / ry;
+ iy = iy - ix / ry;
+
+ } while (i > h);
+ }
+
+ return (result); +} + +/* ----- Pie */ + +/*! +\brief Internal float (low-speed) pie-calc implementation by drawing polygons. + +Note: Determines vertex array and uses polygon or filledPolygon drawing routines to render. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the pie. +\param y Y coordinate of the center of the pie. +\param rad Radius in pixels of the pie. +\param start Starting radius in degrees of the pie. +\param end Ending radius in degrees of the pie. +\param color The color value of the pie to draw (0xRRGGBBAA). +\param filled Flag indicating if the pie should be filled (=1) or not (=0). + +\returns Returns 0 on success, -1 on failure. +*/ +int _pieRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a, Uint8 filled) +{ + int result; + double angle, start_angle, end_angle; + double deltaAngle; + double dr; + int numpoints, i; + Sint16 *vx, *vy; + + /* + * Sanity check radii + */ + if (rad < 0) { + return (-1); + } + + /* + * Fixup angles + */ + start = start % 360; + end = end % 360; + + /* + * Special case for rad=0 - draw a point + */ + if (rad == 0) { + return (pixelRGBA(renderer, x, y, r, g, b, a)); + } + + /* + * Variable setup + */ + dr = (double) rad; + deltaAngle = 3.0 / dr; + start_angle = (double) start *(2.0 * M_PI / 360.0); + end_angle = (double) end *(2.0 * M_PI / 360.0); + if (start > end) { + end_angle += (2.0 * M_PI); + } + + /* We will always have at least 2 points */ + numpoints = 2; + + /* Count points (rather than calculating it) */ + angle = start_angle; + while (angle < end_angle) { + angle += deltaAngle; + numpoints++; + } + + /* Allocate combined vertex array */ + vx = vy = (Sint16 *) malloc(2 * sizeof(Uint16) * numpoints); + if (vx == NULL) { + return (-1); + } + + /* Update point to start of vy */ + vy += numpoints; + + /* Center */ + vx[0] = x; + vy[0] = y; + + /* First vertex */ + angle = start_angle; + vx[1] = x + (int) (dr * cos(angle)); + vy[1] = y + (int) (dr * sin(angle)); + + if (numpoints<3) + { + result = lineRGBA(renderer, vx[0], vy[0], vx[1], vy[1], r, g, b, a); + } + else + { + /* Calculate other vertices */ + i = 2; + angle = start_angle; + while (angle < end_angle) { + angle += deltaAngle; + if (angle>end_angle) + { + angle = end_angle; + } + vx[i] = x + (int) (dr * cos(angle)); + vy[i] = y + (int) (dr * sin(angle)); + i++; + } + + /* Draw */ + if (filled) { + result = filledPolygonRGBA(renderer, vx, vy, numpoints, r, g, b, a); + } else { + result = polygonRGBA(renderer, vx, vy, numpoints, r, g, b, a); + } + } + + /* Free combined vertex array */ + free(vx); + + return (result); +} + +/*! +\brief Draw pie (outline) with alpha blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the pie. +\param y Y coordinate of the center of the pie. +\param rad Radius in pixels of the pie. +\param start Starting radius in degrees of the pie. +\param end Ending radius in degrees of the pie. +\param color The color value of the pie to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int pieColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, + Sint16 start, Sint16 end, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return _pieRGBA(renderer, x, y, rad, start, end, c[0], c[1], c[2], c[3], 0); +} + +/*! +\brief Draw pie (outline) with alpha blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the pie. +\param y Y coordinate of the center of the pie. +\param rad Radius in pixels of the pie. +\param start Starting radius in degrees of the pie. +\param end Ending radius in degrees of the pie. +\param r The red value of the pie to draw. +\param g The green value of the pie to draw. +\param b The blue value of the pie to draw. +\param a The alpha value of the pie to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int pieRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, + Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + return _pieRGBA(renderer, x, y, rad, start, end, r, g, b, a, 0); +} + +/*! +\brief Draw filled pie with alpha blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the filled pie. +\param y Y coordinate of the center of the filled pie. +\param rad Radius in pixels of the filled pie. +\param start Starting radius in degrees of the filled pie. +\param end Ending radius in degrees of the filled pie. +\param color The color value of the filled pie to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int filledPieColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return _pieRGBA(renderer, x, y, rad, start, end, c[0], c[1], c[2], c[3], 1); +} + +/*! +\brief Draw filled pie with alpha blending. + +\param renderer The renderer to draw on. +\param x X coordinate of the center of the filled pie. +\param y Y coordinate of the center of the filled pie. +\param rad Radius in pixels of the filled pie. +\param start Starting radius in degrees of the filled pie. +\param end Ending radius in degrees of the filled pie. +\param r The red value of the filled pie to draw. +\param g The green value of the filled pie to draw. +\param b The blue value of the filled pie to draw. +\param a The alpha value of the filled pie to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int filledPieRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, + Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + return _pieRGBA(renderer, x, y, rad, start, end, r, g, b, a, 1); +} + +/* ------ Trigon */ + +/*! +\brief Draw trigon (triangle outline) with alpha blending. + +Note: Creates vertex array and uses polygon routine to render. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point of the trigon. +\param y1 Y coordinate of the first point of the trigon. +\param x2 X coordinate of the second point of the trigon. +\param y2 Y coordinate of the second point of the trigon. +\param x3 X coordinate of the third point of the trigon. +\param y3 Y coordinate of the third point of the trigon. +\param color The color value of the trigon to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int trigonColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color) +{ + Sint16 vx[3]; + Sint16 vy[3]; + + vx[0]=x1; + vx[1]=x2; + vx[2]=x3; + vy[0]=y1; + vy[1]=y2; + vy[2]=y3; + + return(polygonColor(renderer,vx,vy,3,color)); +} + +/*! +\brief Draw trigon (triangle outline) with alpha blending. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point of the trigon. +\param y1 Y coordinate of the first point of the trigon. +\param x2 X coordinate of the second point of the trigon. +\param y2 Y coordinate of the second point of the trigon. +\param x3 X coordinate of the third point of the trigon. +\param y3 Y coordinate of the third point of the trigon. +\param r The red value of the trigon to draw. +\param g The green value of the trigon to draw. +\param b The blue value of the trigon to draw. +\param a The alpha value of the trigon to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int trigonRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, + Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + Sint16 vx[3]; + Sint16 vy[3]; + + vx[0]=x1; + vx[1]=x2; + vx[2]=x3; + vy[0]=y1; + vy[1]=y2; + vy[2]=y3; + + return(polygonRGBA(renderer,vx,vy,3,r,g,b,a)); +} + +/* ------ AA-Trigon */ + +/*! +\brief Draw anti-aliased trigon (triangle outline) with alpha blending. + +Note: Creates vertex array and uses aapolygon routine to render. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point of the aa-trigon. +\param y1 Y coordinate of the first point of the aa-trigon. +\param x2 X coordinate of the second point of the aa-trigon. +\param y2 Y coordinate of the second point of the aa-trigon. +\param x3 X coordinate of the third point of the aa-trigon. +\param y3 Y coordinate of the third point of the aa-trigon. +\param color The color value of the aa-trigon to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int aatrigonColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color) +{ + Sint16 vx[3]; + Sint16 vy[3]; + + vx[0]=x1; + vx[1]=x2; + vx[2]=x3; + vy[0]=y1; + vy[1]=y2; + vy[2]=y3; + + return(aapolygonColor(renderer,vx,vy,3,color)); +} + +/*! +\brief Draw anti-aliased trigon (triangle outline) with alpha blending. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point of the aa-trigon. +\param y1 Y coordinate of the first point of the aa-trigon. +\param x2 X coordinate of the second point of the aa-trigon. +\param y2 Y coordinate of the second point of the aa-trigon. +\param x3 X coordinate of the third point of the aa-trigon. +\param y3 Y coordinate of the third point of the aa-trigon. +\param r The red value of the aa-trigon to draw. +\param g The green value of the aa-trigon to draw. +\param b The blue value of the aa-trigon to draw. +\param a The alpha value of the aa-trigon to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int aatrigonRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, + Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + Sint16 vx[3]; + Sint16 vy[3]; + + vx[0]=x1; + vx[1]=x2; + vx[2]=x3; + vy[0]=y1; + vy[1]=y2; + vy[2]=y3; + + return(aapolygonRGBA(renderer,vx,vy,3,r,g,b,a)); +} + +/* ------ Filled Trigon */ + +/*! +\brief Draw filled trigon (triangle) with alpha blending. + +Note: Creates vertex array and uses aapolygon routine to render. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point of the filled trigon. +\param y1 Y coordinate of the first point of the filled trigon. +\param x2 X coordinate of the second point of the filled trigon. +\param y2 Y coordinate of the second point of the filled trigon. +\param x3 X coordinate of the third point of the filled trigon. +\param y3 Y coordinate of the third point of the filled trigon. +\param color The color value of the filled trigon to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int filledTrigonColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color) +{ + Sint16 vx[3]; + Sint16 vy[3]; + + vx[0]=x1; + vx[1]=x2; + vx[2]=x3; + vy[0]=y1; + vy[1]=y2; + vy[2]=y3; + + return(filledPolygonColor(renderer,vx,vy,3,color)); +} + +/*! +\brief Draw filled trigon (triangle) with alpha blending. + +Note: Creates vertex array and uses aapolygon routine to render. + +\param renderer The renderer to draw on. +\param x1 X coordinate of the first point of the filled trigon. +\param y1 Y coordinate of the first point of the filled trigon. +\param x2 X coordinate of the second point of the filled trigon. +\param y2 Y coordinate of the second point of the filled trigon. +\param x3 X coordinate of the third point of the filled trigon. +\param y3 Y coordinate of the third point of the filled trigon. +\param r The red value of the filled trigon to draw. +\param g The green value of the filled trigon to draw. +\param b The blue value of the filled trigon to draw. +\param a The alpha value of the filled trigon to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int filledTrigonRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, + Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + Sint16 vx[3]; + Sint16 vy[3]; + + vx[0]=x1; + vx[1]=x2; + vx[2]=x3; + vy[0]=y1; + vy[1]=y2; + vy[2]=y3; + + return(filledPolygonRGBA(renderer,vx,vy,3,r,g,b,a)); +} + +/* ---- Polygon */ + +/*! +\brief Draw polygon with alpha blending. + +\param renderer The renderer to draw on. +\param vx Vertex array containing X coordinates of the points of the polygon. +\param vy Vertex array containing Y coordinates of the points of the polygon. +\param n Number of points in the vertex array. Minimum number is 3. +\param color The color value of the polygon to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int polygonColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return polygonRGBA(renderer, vx, vy, n, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Draw polygon with the currently set color and blend mode. + +\param renderer The renderer to draw on. +\param vx Vertex array containing X coordinates of the points of the polygon. +\param vy Vertex array containing Y coordinates of the points of the polygon. +\param n Number of points in the vertex array. Minimum number is 3. +\param r The red value of the polygon to draw. +\param g The green value of the polygon to draw. +\param b The blue value of the polygon to draw. +\param a The alpha value of the polygon to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int polygon(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n) +{ + /* + * Draw + */ + int result; + int i, nn; + SDL_Point* points; + + /* + * Vertex array NULL check + */ + if (vx == NULL) { + return (-1); + } + if (vy == NULL) { + return (-1); + } + + /* + * Sanity check + */ + if (n < 3) { + return (-1); + } + + /* + * Create array of points + */ + nn = n + 1; + points = (SDL_Point*)malloc(sizeof(SDL_Point) * nn); + if (points == NULL) + { + return -1; + } + for (i=0; i<n; i++) + { + points[i].x = vx[i]; + points[i].y = vy[i]; + } + points[n].x = vx[0]; + points[n].y = vy[0]; + + /* + * Draw + */ + result |= SDL_RenderDrawLines(renderer, points, nn); + free(points); + + return (result); +} + +/*! +\brief Draw polygon with alpha blending. + +\param renderer The renderer to draw on. +\param vx Vertex array containing X coordinates of the points of the polygon. +\param vy Vertex array containing Y coordinates of the points of the polygon. +\param n Number of points in the vertex array. Minimum number is 3. +\param r The red value of the polygon to draw. +\param g The green value of the polygon to draw. +\param b The blue value of the polygon to draw. +\param a The alpha value of the polygon to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int polygonRGBA(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + /* + * Draw + */ + int result; + const Sint16 *x1, *y1, *x2, *y2; + + /* + * Vertex array NULL check + */ + if (vx == NULL) { + return (-1); + } + if (vy == NULL) { + return (-1); + } + + /* + * Sanity check + */ + if (n < 3) { + return (-1); + } + + /* + * Pointer setup + */ + x1 = x2 = vx; + y1 = y2 = vy; + x2++; + y2++; + + /* + * Set color + */ + result = 0; + result |= SDL_SetRenderDrawBlendMode(renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND); + result |= SDL_SetRenderDrawColor(renderer, r, g, b, a); + + /* + * Draw + */ + result |= polygon(renderer, vx, vy, n); + + return (result); +} + +/* ---- AA-Polygon */ + +/*! +\brief Draw anti-aliased polygon with alpha blending. + +\param renderer The renderer to draw on. +\param vx Vertex array containing X coordinates of the points of the aa-polygon. +\param vy Vertex array containing Y coordinates of the points of the aa-polygon. +\param n Number of points in the vertex array. Minimum number is 3. +\param color The color value of the aa-polygon to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int aapolygonColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return aapolygonRGBA(renderer, vx, vy, n, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Draw anti-aliased polygon with alpha blending. + +\param renderer The renderer to draw on. +\param vx Vertex array containing X coordinates of the points of the aa-polygon. +\param vy Vertex array containing Y coordinates of the points of the aa-polygon. +\param n Number of points in the vertex array. Minimum number is 3. +\param r The red value of the aa-polygon to draw. +\param g The green value of the aa-polygon to draw. +\param b The blue value of the aa-polygon to draw. +\param a The alpha value of the aa-polygon to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int aapolygonRGBA(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + int result; + int i; + const Sint16 *x1, *y1, *x2, *y2; + + /* + * Vertex array NULL check + */ + if (vx == NULL) { + return (-1); + } + if (vy == NULL) { + return (-1); + } + + /* + * Sanity check + */ + if (n < 3) { + return (-1); + } + + /* + * Pointer setup + */ + x1 = x2 = vx; + y1 = y2 = vy; + x2++; + y2++; + + /* + * Draw + */ + result = 0; + for (i = 1; i < n; i++) { + result |= _aalineRGBA(renderer, *x1, *y1, *x2, *y2, r, g, b, a, 0); + x1 = x2; + y1 = y2; + x2++; + y2++; + } + + result |= _aalineRGBA(renderer, *x1, *y1, *vx, *vy, r, g, b, a, 0); + + return (result); +} + +/* ---- Filled Polygon */ +
+/*!
+\brief Internal helper qsort callback functions used in filled polygon drawing.
+
+\param a The surface to draw on.
+\param b Vertex array containing X coordinates of the points of the polygon.
+
+\returns Returns 0 if a==b, a negative number if a<b or a positive number if a>b.
+*/
+int _gfxPrimitivesCompareInt(const void *a, const void *b)
+{
+ return (*(const int *) a) - (*(const int *) b);
+}
+
+/*!
+\brief Global vertex array to use if optional parameters are not given in filledPolygonMT calls.
+
+Note: Used for non-multithreaded (default) operation of filledPolygonMT.
+*/
+static int *gfxPrimitivesPolyIntsGlobal = NULL;
+
+/*!
+\brief Flag indicating if global vertex array was already allocated.
+
+Note: Used for non-multithreaded (default) operation of filledPolygonMT.
+*/
+static int gfxPrimitivesPolyAllocatedGlobal = 0;
+
+/*!
+\brief Draw filled polygon with alpha blending (multi-threaded capable).
+
+Note: The last two parameters are optional; but are required for multithreaded operation.
+
+\param dst The surface to draw on.
+\param vx Vertex array containing X coordinates of the points of the filled polygon.
+\param vy Vertex array containing Y coordinates of the points of the filled polygon.
+\param n Number of points in the vertex array. Minimum number is 3.
+\param r The red value of the filled polygon to draw. +\param g The green value of the filled polygon to draw. +\param b The blue value of the filled polygon to draw. +\param a The alpha value of the filled polygon to draw. +\param polyInts Preallocated, temporary vertex array used for sorting vertices. Required for multithreaded operation; set to NULL otherwise.
+\param polyAllocated Flag indicating if temporary vertex array was allocated. Required for multithreaded operation; set to NULL otherwise.
+
+\returns Returns 0 on success, -1 on failure.
+*/
+int filledPolygonRGBAMT(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a, int **polyInts, int *polyAllocated)
+{
+ int result;
+ int i;
+ int y, xa, xb;
+ int miny, maxy;
+ int x1, y1;
+ int x2, y2;
+ int ind1, ind2;
+ int ints;
+ int *gfxPrimitivesPolyInts = NULL;
+ int *gfxPrimitivesPolyIntsNew = NULL;
+ int gfxPrimitivesPolyAllocated = 0;
+
+ /*
+ * Vertex array NULL check
+ */
+ if (vx == NULL) {
+ return (-1);
+ }
+ if (vy == NULL) {
+ return (-1);
+ }
+
+ /*
+ * Sanity check number of edges
+ */
+ if (n < 3) {
+ return -1;
+ }
+
+ /*
+ * Map polygon cache
+ */
+ if ((polyInts==NULL) || (polyAllocated==NULL)) {
+ /* Use global cache */
+ gfxPrimitivesPolyInts = gfxPrimitivesPolyIntsGlobal;
+ gfxPrimitivesPolyAllocated = gfxPrimitivesPolyAllocatedGlobal;
+ } else {
+ /* Use local cache */
+ gfxPrimitivesPolyInts = *polyInts;
+ gfxPrimitivesPolyAllocated = *polyAllocated;
+ }
+
+ /*
+ * Allocate temp array, only grow array
+ */
+ if (!gfxPrimitivesPolyAllocated) {
+ gfxPrimitivesPolyInts = (int *) malloc(sizeof(int) * n);
+ gfxPrimitivesPolyAllocated = n;
+ } else {
+ if (gfxPrimitivesPolyAllocated < n) {
+ gfxPrimitivesPolyIntsNew = (int *) realloc(gfxPrimitivesPolyInts, sizeof(int) * n);
+ if (!gfxPrimitivesPolyIntsNew) {
+ if (!gfxPrimitivesPolyInts) {
+ free(gfxPrimitivesPolyInts);
+ gfxPrimitivesPolyInts = NULL;
+ }
+ gfxPrimitivesPolyAllocated = 0;
+ } else {
+ gfxPrimitivesPolyInts = gfxPrimitivesPolyIntsNew;
+ gfxPrimitivesPolyAllocated = n;
+ }
+ }
+ }
+
+ /*
+ * Check temp array
+ */
+ if (gfxPrimitivesPolyInts==NULL) {
+ gfxPrimitivesPolyAllocated = 0;
+ }
+
+ /*
+ * Update cache variables
+ */
+ if ((polyInts==NULL) || (polyAllocated==NULL)) {
+ gfxPrimitivesPolyIntsGlobal = gfxPrimitivesPolyInts;
+ gfxPrimitivesPolyAllocatedGlobal = gfxPrimitivesPolyAllocated;
+ } else {
+ *polyInts = gfxPrimitivesPolyInts;
+ *polyAllocated = gfxPrimitivesPolyAllocated;
+ }
+
+ /*
+ * Check temp array again
+ */
+ if (gfxPrimitivesPolyInts==NULL) {
+ return(-1);
+ }
+
+ /*
+ * Determine Y maxima
+ */
+ miny = vy[0];
+ maxy = vy[0];
+ for (i = 1; (i < n); i++) {
+ if (vy[i] < miny) {
+ miny = vy[i];
+ } else if (vy[i] > maxy) {
+ maxy = vy[i];
+ }
+ }
+
+ /*
+ * Draw, scanning y
+ */
+ result = 0;
+ for (y = miny; (y <= maxy); y++) {
+ ints = 0;
+ for (i = 0; (i < n); i++) {
+ if (!i) {
+ ind1 = n - 1;
+ ind2 = 0;
+ } else {
+ ind1 = i - 1;
+ ind2 = i;
+ }
+ y1 = vy[ind1];
+ y2 = vy[ind2];
+ if (y1 < y2) {
+ x1 = vx[ind1];
+ x2 = vx[ind2];
+ } else if (y1 > y2) {
+ y2 = vy[ind1];
+ y1 = vy[ind2];
+ x2 = vx[ind1];
+ x1 = vx[ind2];
+ } else {
+ continue;
+ }
+ if ( ((y >= y1) && (y < y2)) || ((y == maxy) && (y > y1) && (y <= y2)) ) {
+ gfxPrimitivesPolyInts[ints++] = ((65536 * (y - y1)) / (y2 - y1)) * (x2 - x1) + (65536 * x1);
+ }
+ }
+
+ qsort(gfxPrimitivesPolyInts, ints, sizeof(int), _gfxPrimitivesCompareInt);
+
+ /* + * Set color + */ + result = 0; + result |= SDL_SetRenderDrawBlendMode(renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND); + result |= SDL_SetRenderDrawColor(renderer, r, g, b, a); +
+ for (i = 0; (i < ints); i += 2) {
+ xa = gfxPrimitivesPolyInts[i] + 1;
+ xa = (xa >> 16) + ((xa & 32768) >> 15);
+ xb = gfxPrimitivesPolyInts[i+1] - 1;
+ xb = (xb >> 16) + ((xb & 32768) >> 15);
+ result |= hline(renderer, xa, xb, y);
+ }
+ }
+
+ return (result);
+}
+ +/*! +\brief Draw filled polygon with alpha blending. + +\param renderer The renderer to draw on. +\param vx Vertex array containing X coordinates of the points of the filled polygon. +\param vy Vertex array containing Y coordinates of the points of the filled polygon. +\param n Number of points in the vertex array. Minimum number is 3. +\param color The color value of the filled polygon to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int filledPolygonColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return filledPolygonRGBAMT(renderer, vx, vy, n, c[0], c[1], c[2], c[3], NULL, NULL); +} + +/*! +\brief Draw filled polygon with alpha blending. + +\param renderer The renderer to draw on. +\param vx Vertex array containing X coordinates of the points of the filled polygon. +\param vy Vertex array containing Y coordinates of the points of the filled polygon. +\param n Number of points in the vertex array. Minimum number is 3. +\param r The red value of the filled polygon to draw. +\param g The green value of the filled polygon to draw. +\param b The blue value of the filed polygon to draw. +\param a The alpha value of the filled polygon to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int filledPolygonRGBA(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + return filledPolygonRGBAMT(renderer, vx, vy, n, r, g, b, a, NULL, NULL); +} + +/* ---- Textured Polygon */
+ +/*!
+\brief Internal function to draw a textured horizontal line.
+
+\param renderer The renderer to draw on. +\param x1 X coordinate of the first point (i.e. left) of the line.
+\param x2 X coordinate of the second point (i.e. right) of the line.
+\param y Y coordinate of the points of the line.
+\param texture The texture to retrieve color information from.
+\param texture_w The width of the texture.
+\param texture_h The height of the texture.
+\param texture_dx The X offset for the texture lookup.
+\param texture_dy The Y offset for the textured lookup.
+
+\returns Returns 0 on success, -1 on failure.
+*/
+int _HLineTextured(SDL_Renderer *renderer, Sint16 x1, Sint16 x2, Sint16 y, SDL_Texture *texture, int texture_w, int texture_h, int texture_dx, int texture_dy)
+{
+ Sint16 w;
+ Sint16 xtmp;
+ int result = 0;
+ int texture_x_walker;
+ int texture_y_start;
+ SDL_Rect source_rect,dst_rect;
+ int pixels_written,write_width;
+
+ /*
+ * Swap x1, x2 if required to ensure x1<=x2
+ */
+ if (x1 > x2) {
+ xtmp = x1;
+ x1 = x2;
+ x2 = xtmp;
+ }
+
+ /*
+ * Calculate width to draw
+ */
+ w = x2 - x1 + 1;
+
+ /*
+ * Determine where in the texture we start drawing
+ */
+ texture_x_walker = (x1 - texture_dx) % texture_w;
+ if (texture_x_walker < 0){
+ texture_x_walker = texture_w + texture_x_walker ;
+ }
+
+ texture_y_start = (y + texture_dy) % texture_h;
+ if (texture_y_start < 0){
+ texture_y_start = texture_h + texture_y_start;
+ }
+
+ // setup the source rectangle; we are only drawing one horizontal line
+ source_rect.y = texture_y_start;
+ source_rect.x = texture_x_walker;
+ source_rect.h = 1;
+
+ // we will draw to the current y
+ dst_rect.y = y;
+
+ // if there are enough pixels left in the current row of the texture
+ // draw it all at once
+ if (w <= texture_w -texture_x_walker){
+ source_rect.w = w;
+ source_rect.x = texture_x_walker;
+ dst_rect.x= x1;
+ result = (SDL_RenderCopy(renderer, texture, &source_rect ,&dst_rect) == 0);
+ } else { // we need to draw multiple times
+ // draw the first segment
+ pixels_written = texture_w - texture_x_walker;
+ source_rect.w = pixels_written;
+ source_rect.x = texture_x_walker;
+ dst_rect.x= x1;
+ result |= (SDL_RenderCopy(renderer, texture, &source_rect , &dst_rect) == 0);
+ write_width = texture_w;
+
+ // now draw the rest
+ // set the source x to 0
+ source_rect.x = 0;
+ while (pixels_written < w){
+ if (write_width >= w - pixels_written) {
+ write_width = w - pixels_written;
+ }
+ source_rect.w = write_width;
+ dst_rect.x = x1 + pixels_written;
+ result |= (SDL_RenderCopy(renderer,texture,&source_rect , &dst_rect) == 0);
+ pixels_written += write_width;
+ }
+ }
+
+ return result;
+}
+
+/*!
+\brief Draws a polygon filled with the given texture (Multi-Threading Capable).
+
+\param renderer The renderer to draw on. +\param vx array of x vector components
+\param vy array of x vector components
+\param n the amount of vectors in the vx and vy array
+\param texture the sdl surface to use to fill the polygon
+\param texture_dx the offset of the texture relative to the screeen. If you move the polygon 10 pixels
+to the left and want the texture to apear the same you need to increase the texture_dx value
+\param texture_dy see texture_dx
+\param polyInts Preallocated temp array storage for vertex sorting (used for multi-threaded operation)
+\param polyAllocated Flag indicating oif the temp array was allocated (used for multi-threaded operation)
+
+\returns Returns 0 on success, -1 on failure.
+*/
+int texturedPolygonMT(SDL_Renderer *renderer, const Sint16 * vx, const Sint16 * vy, int n,
+ SDL_Surface * texture, int texture_dx, int texture_dy, int **polyInts, int *polyAllocated)
+{
+ int result;
+ int i;
+ int y, xa, xb;
+ int minx,maxx,miny, maxy;
+ int x1, y1;
+ int x2, y2;
+ int ind1, ind2;
+ int ints;
+ int *gfxPrimitivesPolyInts = NULL;
+ int gfxPrimitivesPolyAllocated = 0;
+ SDL_Texture *textureAsTexture;
+
+ /*
+ * Sanity check number of edges
+ */
+ if (n < 3) {
+ return -1;
+ }
+
+ /*
+ * Map polygon cache
+ */
+ if ((polyInts==NULL) || (polyAllocated==NULL)) {
+ /* Use global cache */
+ gfxPrimitivesPolyInts = gfxPrimitivesPolyIntsGlobal;
+ gfxPrimitivesPolyAllocated = gfxPrimitivesPolyAllocatedGlobal;
+ } else {
+ /* Use local cache */
+ gfxPrimitivesPolyInts = *polyInts;
+ gfxPrimitivesPolyAllocated = *polyAllocated;
+ }
+
+ /*
+ * Allocate temp array, only grow array
+ */
+ if (!gfxPrimitivesPolyAllocated) {
+ gfxPrimitivesPolyInts = (int *) malloc(sizeof(int) * n);
+ gfxPrimitivesPolyAllocated = n;
+ } else {
+ if (gfxPrimitivesPolyAllocated < n) {
+ gfxPrimitivesPolyInts = (int *) realloc(gfxPrimitivesPolyInts, sizeof(int) * n);
+ gfxPrimitivesPolyAllocated = n;
+ }
+ }
+
+ /*
+ * Check temp array
+ */
+ if (gfxPrimitivesPolyInts==NULL) {
+ gfxPrimitivesPolyAllocated = 0;
+ }
+
+ /*
+ * Update cache variables
+ */
+ if ((polyInts==NULL) || (polyAllocated==NULL)) {
+ gfxPrimitivesPolyIntsGlobal = gfxPrimitivesPolyInts;
+ gfxPrimitivesPolyAllocatedGlobal = gfxPrimitivesPolyAllocated;
+ } else {
+ *polyInts = gfxPrimitivesPolyInts;
+ *polyAllocated = gfxPrimitivesPolyAllocated;
+ }
+
+ /*
+ * Check temp array again
+ */
+ if (gfxPrimitivesPolyInts==NULL) {
+ return(-1);
+ }
+
+ /*
+ * Determine X,Y minima,maxima
+ */
+ miny = vy[0];
+ maxy = vy[0];
+ minx = vx[0];
+ maxx = vx[0];
+ for (i = 1; (i < n); i++) {
+ if (vy[i] < miny) {
+ miny = vy[i];
+ } else if (vy[i] > maxy) {
+ maxy = vy[i];
+ }
+ if (vx[i] < minx) {
+ minx = vx[i];
+ } else if (vx[i] > maxx) {
+ maxx = vx[i];
+ }
+ }
+
+ /*
+ * Draw, scanning y
+ */
+ result = 0;
+ for (y = miny; (y <= maxy); y++) {
+ ints = 0;
+ for (i = 0; (i < n); i++) {
+ if (!i) {
+ ind1 = n - 1;
+ ind2 = 0;
+ } else {
+ ind1 = i - 1;
+ ind2 = i;
+ }
+ y1 = vy[ind1];
+ y2 = vy[ind2];
+ if (y1 < y2) {
+ x1 = vx[ind1];
+ x2 = vx[ind2];
+ } else if (y1 > y2) {
+ y2 = vy[ind1];
+ y1 = vy[ind2];
+ x2 = vx[ind1];
+ x1 = vx[ind2];
+ } else {
+ continue;
+ }
+ if ( ((y >= y1) && (y < y2)) || ((y == maxy) && (y > y1) && (y <= y2)) ) {
+ gfxPrimitivesPolyInts[ints++] = ((65536 * (y - y1)) / (y2 - y1)) * (x2 - x1) + (65536 * x1);
+ }
+ }
+
+ qsort(gfxPrimitivesPolyInts, ints, sizeof(int), _gfxPrimitivesCompareInt);
+
+ textureAsTexture = SDL_CreateTextureFromSurface(renderer, texture);
+ if (textureAsTexture == NULL)
+ {
+ return (-1);
+ }
+
+ for (i = 0; (i < ints); i += 2) {
+ xa = gfxPrimitivesPolyInts[i] + 1;
+ xa = (xa >> 16) + ((xa & 32768) >> 15);
+ xb = gfxPrimitivesPolyInts[i+1] - 1;
+ xb = (xb >> 16) + ((xb & 32768) >> 15);
+ result |= _HLineTextured(renderer, xa, xb, y, textureAsTexture, texture->w, texture->h, texture_dx, texture_dy);
+ }
+ SDL_DestroyTexture(textureAsTexture);
+ }
+
+ return (result);
+}
+
+/*!
+\brief Draws a polygon filled with the given texture.
+
+This standard version is calling multithreaded versions with NULL cache parameters.
+
+\param renderer The renderer to draw on. +\param vx array of x vector components
+\param vy array of x vector components
+\param n the amount of vectors in the vx and vy array
+\param texture the sdl surface to use to fill the polygon
+\param texture_dx the offset of the texture relative to the screeen. if you move the polygon 10 pixels
+to the left and want the texture to apear the same you need to increase the texture_dx value
+\param texture_dy see texture_dx
+
+\returns Returns 0 on success, -1 on failure.
+*/
+int texturedPolygon(SDL_Renderer *renderer, const Sint16 * vx, const Sint16 * vy, int n, SDL_Surface *texture, int texture_dx, int texture_dy)
+{
+ /*
+ * Draw
+ */
+ return (texturedPolygonMT(renderer, vx, vy, n, texture, texture_dx, texture_dy, NULL, NULL));
+} + +/* ---- Character */
+
+/*!
+\brief Global cache for NxM pixel font textures created at runtime.
+*/
+static SDL_Texture *gfxPrimitivesFont[256];
+
+/*!
+\brief Pointer to the current font data. Default is a 8x8 pixel internal font.
+*/
+static const unsigned char *currentFontdata = gfxPrimitivesFontdata;
+
+/*!
+\brief Width of the current font. Default is 8.
+*/
+static Uint32 charWidth = 8;
+
+/*!
+\brief Height of the current font. Default is 8.
+*/
+static Uint32 charHeight = 8;
+
+/*!
+\brief Width for rendering. Autocalculated.
+*/
+static Uint32 charWidthLocal = 8;
+
+/*!
+\brief Height for rendering. Autocalculated.
+*/
+static Uint32 charHeightLocal = 8;
+
+/*!
+\brief Pitch of the current font in bytes. Default is 1.
+*/
+static Uint32 charPitch = 1;
+
+/*!
+\brief Characters 90deg clockwise rotations. Default is 0. Max is 3.
+*/
+static Uint32 charRotation = 0;
+
+/*!
+\brief Character data size in bytes of the current font. Default is 8.
+*/
+static Uint32 charSize = 8;
+
+/*!
+\brief Sets or resets the current global font data.
+
+The font data array is organized in follows:
+[fontdata] = [character 0][character 1]...[character 255] where
+[character n] = [byte 1 row 1][byte 2 row 1]...[byte {pitch} row 1][byte 1 row 2] ...[byte {pitch} row height] where
+[byte n] = [bit 0]...[bit 7] where
+[bit n] = [0 for transparent pixel|1 for colored pixel]
+
+\param fontdata Pointer to array of font data. Set to NULL, to reset global font to the default 8x8 font.
+\param cw Width of character in bytes. Ignored if fontdata==NULL.
+\param ch Height of character in bytes. Ignored if fontdata==NULL.
+*/
+void gfxPrimitivesSetFont(const void *fontdata, Uint32 cw, Uint32 ch)
+{
+ int i;
+
+ if ((fontdata) && (cw) && (ch)) {
+ currentFontdata = (unsigned char *)fontdata;
+ charWidth = cw;
+ charHeight = ch;
+ } else {
+ currentFontdata = gfxPrimitivesFontdata;
+ charWidth = 8;
+ charHeight = 8;
+ }
+
+ charPitch = (charWidth+7)/8;
+ charSize = charPitch * charHeight;
+
+ /* Maybe flip width/height for rendering */
+ if ((charRotation==1) || (charRotation==3))
+ {
+ charWidthLocal = charHeight;
+ charHeightLocal = charWidth;
+ }
+ else
+ {
+ charWidthLocal = charWidth;
+ charHeightLocal = charHeight;
+ }
+
+ /* Clear character cache */
+ for (i = 0; i < 256; i++) {
+ if (gfxPrimitivesFont[i]) {
+ SDL_DestroyTexture(gfxPrimitivesFont[i]);
+ gfxPrimitivesFont[i] = NULL;
+ }
+ }
+}
+
+/*!
+\brief Sets current global font character rotation steps.
+
+Default is 0 (no rotation). 1 = 90deg clockwise. 2 = 180deg clockwise. 3 = 270deg clockwise.
+Changing the rotation, will reset the character cache.
+
+\param rotation Number of 90deg clockwise steps to rotate
+*/
+void gfxPrimitivesSetFontRotation(Uint32 rotation)
+{
+ int i;
+
+ rotation = rotation & 3;
+ if (charRotation != rotation)
+ {
+ /* Store rotation */
+ charRotation = rotation;
+
+ /* Maybe flip width/height for rendering */
+ if ((charRotation==1) || (charRotation==3))
+ {
+ charWidthLocal = charHeight;
+ charHeightLocal = charWidth;
+ }
+ else
+ {
+ charWidthLocal = charWidth;
+ charHeightLocal = charHeight;
+ }
+
+ /* Clear character cache */
+ for (i = 0; i < 256; i++) {
+ if (gfxPrimitivesFont[i]) {
+ SDL_DestroyTexture(gfxPrimitivesFont[i]);
+ gfxPrimitivesFont[i] = NULL;
+ }
+ }
+ }
+}
+
+/*!
+\brief Draw a character of the currently set font.
+
+\param dst The surface to draw on.
+\param x X (horizontal) coordinate of the upper left corner of the character.
+\param y Y (vertical) coordinate of the upper left corner of the character.
+\param c The character to draw.
+\param r The red value of the character to draw.
+\param g The green value of the character to draw.
+\param b The blue value of the character to draw.
+\param a The alpha value of the character to draw.
+
+\returns Returns 0 on success, -1 on failure.
+*/
+int characterRGBA(SDL_Renderer *renderer, Sint16 x, Sint16 y, char c, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ SDL_Rect srect;
+ SDL_Rect drect;
+ int result;
+ Uint32 ix, iy;
+ const unsigned char *charpos;
+ Uint8 *curpos;
+ Uint8 patt, mask;
+ Uint8 *linepos;
+ Uint32 pitch;
+ SDL_Surface *character;
+ SDL_Surface *rotatedCharacter;
+ Uint32 ci;
+
+ /*
+ * Setup source rectangle
+ */
+ srect.x = 0;
+ srect.y = 0;
+ srect.w = charWidthLocal;
+ srect.h = charHeightLocal;
+
+ /*
+ * Setup destination rectangle
+ */
+ drect.x = x;
+ drect.y = y;
+ drect.w = charWidthLocal;
+ drect.h = charHeightLocal;
+
+ /* Character index in cache */
+ ci = (unsigned char) c;
+
+ /*
+ * Create new charWidth x charHeight bitmap surface if not already present.
+ * Might get rotated later.
+ */
+ if (gfxPrimitivesFont[ci] == NULL) {
+ /*
+ * Redraw character into surface
+ */
+ character = SDL_CreateRGBSurface(SDL_SWSURFACE,
+ charWidth, charHeight, 32,
+ 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
+ if (character == NULL) {
+ return (-1);
+ }
+
+ charpos = currentFontdata + ci * charSize;
+ linepos = (Uint8 *)character->pixels;
+ pitch = character->pitch;
+
+ /*
+ * Drawing loop
+ */
+ patt = 0;
+ for (iy = 0; iy < charHeight; iy++) {
+ mask = 0x00;
+ curpos = linepos;
+ for (ix = 0; ix < charWidth; ix++) {
+ if (!(mask >>= 1)) {
+ patt = *charpos++;
+ mask = 0x80;
+ }
+ if (patt & mask) {
+ *(Uint32 *)curpos = 0xffffffff;
+ } else {
+ *(Uint32 *)curpos = 0;
+ }
+ curpos += 4;
+ }
+ linepos += pitch;
+ }
+
+ /* Maybe rotate and replace cached image */
+ if (charRotation>0)
+ {
+ rotatedCharacter = rotateSurface90Degrees(character, charRotation);
+ SDL_FreeSurface(character);
+ character = rotatedCharacter;
+ }
+
+ /* Convert temp surface into texture */
+ gfxPrimitivesFont[ci] = SDL_CreateTextureFromSurface(renderer, character);
+ SDL_FreeSurface(character);
+
+ /*
+ * Check pointer
+ */
+ if (gfxPrimitivesFont[ci] == NULL) {
+ return (-1);
+ }
+ }
+
+ /* + * Set color + */ + result = 0; + result |= SDL_SetTextureColorMod(gfxPrimitivesFont[ci], r, g, b); + result |= SDL_SetTextureAlphaMod(gfxPrimitivesFont[ci], a); +
+ /*
+ * Draw texture onto destination
+ */
+ result |= SDL_RenderCopy(renderer, gfxPrimitivesFont[ci], &srect, &drect);
+
+ return (result);
+}
+ + +/*! +\brief Draw a character of the currently set font. + +\param renderer The renderer to draw on. +\param x X (horizontal) coordinate of the upper left corner of the character. +\param y Y (vertical) coordinate of the upper left corner of the character. +\param c The character to draw. +\param color The color value of the character to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int characterColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, char c, Uint32 color) +{ + Uint8 *co = (Uint8 *)&color; + return characterRGBA(renderer, x, y, c, co[0], co[1], co[2], co[3]); +} + + +/*! +\brief Draw a string in the currently set font. + +The spacing between consequtive characters in the string is the fixed number of pixels +of the character width of the current global font. + +\param renderer The renderer to draw on. +\param x X (horizontal) coordinate of the upper left corner of the string. +\param y Y (vertical) coordinate of the upper left corner of the string. +\param s The string to draw. +\param color The color value of the string to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int stringColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, const char *s, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return stringRGBA(renderer, x, y, s, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Draw a string in the currently set font. + +\param renderer The renderer to draw on. +\param x X (horizontal) coordinate of the upper left corner of the string. +\param y Y (vertical) coordinate of the upper left corner of the string. +\param s The string to draw. +\param r The red value of the string to draw. +\param g The green value of the string to draw. +\param b The blue value of the string to draw. +\param a The alpha value of the string to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int stringRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, const char *s, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + int result = 0; + Sint16 curx = x; + Sint16 cury = y; + const char *curchar = s; + + while (*curchar && !result) { + result |= characterRGBA(renderer, curx, cury, *curchar, r, g, b, a); + switch (charRotation) + { + case 0: + curx += charWidthLocal; + break; + case 2: + curx -= charWidthLocal; + break; + case 1: + cury += charHeightLocal; + break; + case 3: + cury -= charHeightLocal; + break; + } + curchar++; + } + + return (result); +} + +/* ---- Bezier curve */ + +/*! +\brief Internal function to calculate bezier interpolator of data array with ndata values at position 't'. + +\param data Array of values. +\param ndata Size of array. +\param t Position for which to calculate interpolated value. t should be between [0, ndata]. + +\returns Interpolated value at position t, value[0] when t<0, value[n-1] when t>n. +*/ +double _evaluateBezier (double *data, int ndata, double t) +{ + double mu, result; + int n,k,kn,nn,nkn; + double blend,muk,munk; + + /* Sanity check bounds */ + if (t<0.0) { + return(data[0]); + } + if (t>=(double)ndata) { + return(data[ndata-1]); + } + + /* Adjust t to the range 0.0 to 1.0 */ + mu=t/(double)ndata; + + /* Calculate interpolate */ + n=ndata-1; + result=0.0; + muk = 1; + munk = pow(1-mu,(double)n); + for (k=0;k<=n;k++) { + nn = n; + kn = k; + nkn = n - k; + blend = muk * munk; + muk *= mu; + munk /= (1-mu); + while (nn >= 1) { + blend *= nn; + nn--; + if (kn > 1) { + blend /= (double)kn; + kn--; + } + if (nkn > 1) { + blend /= (double)nkn; + nkn--; + } + } + result += data[k] * blend; + } + + return (result); +} + +/*! +\brief Draw a bezier curve with alpha blending. + +\param renderer The renderer to draw on. +\param vx Vertex array containing X coordinates of the points of the bezier curve. +\param vy Vertex array containing Y coordinates of the points of the bezier curve. +\param n Number of points in the vertex array. Minimum number is 3. +\param s Number of steps for the interpolation. Minimum number is 2. +\param color The color value of the bezier curve to draw (0xRRGGBBAA). + +\returns Returns 0 on success, -1 on failure. +*/ +int bezierColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, int s, Uint32 color) +{ + Uint8 *c = (Uint8 *)&color; + return bezierRGBA(renderer, vx, vy, n, s, c[0], c[1], c[2], c[3]); +} + +/*! +\brief Draw a bezier curve with alpha blending. + +\param renderer The renderer to draw on. +\param vx Vertex array containing X coordinates of the points of the bezier curve. +\param vy Vertex array containing Y coordinates of the points of the bezier curve. +\param n Number of points in the vertex array. Minimum number is 3. +\param s Number of steps for the interpolation. Minimum number is 2. +\param r The red value of the bezier curve to draw. +\param g The green value of the bezier curve to draw. +\param b The blue value of the bezier curve to draw. +\param a The alpha value of the bezier curve to draw. + +\returns Returns 0 on success, -1 on failure. +*/ +int bezierRGBA(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, int s, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + int result; + int i; + double *x, *y, t, stepsize; + Sint16 x1, y1, x2, y2; + + /* + * Sanity check + */ + if (n < 3) { + return (-1); + } + if (s < 2) { + return (-1); + } + + /* + * Variable setup + */ + stepsize=(double)1.0/(double)s; + + /* Transfer vertices into float arrays */ + if ((x=(double *)malloc(sizeof(double)*(n+1)))==NULL) { + return(-1); + } + if ((y=(double *)malloc(sizeof(double)*(n+1)))==NULL) { + free(x); + return(-1); + } + for (i=0; i<n; i++) { + x[i]=(double)vx[i]; + y[i]=(double)vy[i]; + } + x[n]=(double)vx[0]; + y[n]=(double)vy[0]; + + /* + * Set color + */ + result = 0; + result |= SDL_SetRenderDrawBlendMode(renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND); + result |= SDL_SetRenderDrawColor(renderer, r, g, b, a); + + /* + * Draw + */ + t=0.0; + x1=(Sint16)lrint(_evaluateBezier(x,n+1,t)); + y1=(Sint16)lrint(_evaluateBezier(y,n+1,t)); + for (i = 0; i <= (n*s); i++) { + t += stepsize; + x2=(Sint16)_evaluateBezier(x,n,t); + y2=(Sint16)_evaluateBezier(y,n,t); + result |= line(renderer, x1, y1, x2, y2); + x1 = x2; + y1 = y2; + } + + /* Clean up temporary array */ + free(x); + free(y); + + return (result); +} + + +/* ---- Thick Line */ +
+/*!
+\brief Internal function to initialize the Bresenham line iterator.
+
+Example of use:
+SDL2_gfxBresenhamIterator b;
+_bresenhamInitialize (&b, x1, y1, x2, y2);
+do {
+plot(b.x, b.y);
+} while (_bresenhamIterate(&b)==0);
+
+\param b Pointer to struct for bresenham line drawing state.
+\param x1 X coordinate of the first point of the line.
+\param y1 Y coordinate of the first point of the line.
+\param x2 X coordinate of the second point of the line.
+\param y2 Y coordinate of the second point of the line.
+
+\returns Returns 0 on success, -1 on failure.
+*/
+int _bresenhamInitialize(SDL2_gfxBresenhamIterator *b, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2)
+{
+ int temp;
+
+ if (b==NULL) {
+ return(-1);
+ }
+
+ b->x = x1;
+ b->y = y1;
+
+ /* dx = abs(x2-x1), s1 = sign(x2-x1) */
+ if ((b->dx = x2 - x1) != 0) {
+ if (b->dx < 0) {
+ b->dx = -b->dx;
+ b->s1 = -1;
+ } else {
+ b->s1 = 1;
+ }
+ } else {
+ b->s1 = 0;
+ }
+
+ /* dy = abs(y2-y1), s2 = sign(y2-y1) */
+ if ((b->dy = y2 - y1) != 0) {
+ if (b->dy < 0) {
+ b->dy = -b->dy;
+ b->s2 = -1;
+ } else {
+ b->s2 = 1;
+ }
+ } else {
+ b->s2 = 0;
+ }
+
+ if (b->dy > b->dx) {
+ temp = b->dx;
+ b->dx = b->dy;
+ b->dy = temp;
+ b->swapdir = 1;
+ } else {
+ b->swapdir = 0;
+ }
+
+ b->count = (b->dx<0) ? 0 : (unsigned int)b->dx;
+ b->dy <<= 1;
+ b->error = b->dy - b->dx;
+ b->dx <<= 1;
+
+ return(0);
+}
+
+
+/*!
+\brief Internal function to move Bresenham line iterator to the next position.
+
+Maybe updates the x and y coordinates of the iterator struct.
+
+\param b Pointer to struct for bresenham line drawing state.
+
+\returns Returns 0 on success, 1 if last point was reached, 2 if moving past end-of-line, -1 on failure.
+*/
+int _bresenhamIterate(SDL2_gfxBresenhamIterator *b)
+{
+ if (b==NULL) {
+ return (-1);
+ }
+
+ /* last point check */
+ if (b->count==0) {
+ return (2);
+ }
+
+ while (b->error >= 0) {
+ if (b->swapdir) {
+ b->x += b->s1;
+ } else {
+ b->y += b->s2;
+ }
+
+ b->error -= b->dx;
+ }
+
+ if (b->swapdir) {
+ b->y += b->s2;
+ } else {
+ b->x += b->s1;
+ }
+
+ b->error += b->dy;
+ b->count--;
+
+ /* count==0 indicates "end-of-line" */
+ return ((b->count) ? 0 : 1);
+}
+
+
+/*!
+\brief Internal function to to draw parallel lines with Murphy algorithm.
+
+\param m Pointer to struct for murphy iterator.
+\param x X coordinate of point.
+\param y Y coordinate of point.
+\param d1 Direction square/diagonal.
+*/
+void _murphyParaline(SDL2_gfxMurphyIterator *m, Sint16 x, Sint16 y, int d1)
+{
+ int p;
+ d1 = -d1;
+
+ for (p = 0; p <= m->u; p++) {
+
+ pixel(m->renderer, x, y);
+
+ if (d1 <= m->kt) {
+ if (m->oct2 == 0) {
+ x++;
+ } else {
+ if (m->quad4 == 0) {
+ y++;
+ } else {
+ y--;
+ }
+ }
+ d1 += m->kv;
+ } else {
+ x++;
+ if (m->quad4 == 0) {
+ y++;
+ } else {
+ y--;
+ }
+ d1 += m->kd;
+ }
+ }
+
+ m->tempx = x;
+ m->tempy = y;
+}
+
+/*!
+\brief Internal function to to draw one iteration of the Murphy algorithm.
+
+\param m Pointer to struct for murphy iterator.
+\param miter Iteration count.
+\param ml1bx X coordinate of a point.
+\param ml1by Y coordinate of a point.
+\param ml2bx X coordinate of a point.
+\param ml2by Y coordinate of a point.
+\param ml1x X coordinate of a point.
+\param ml1y Y coordinate of a point.
+\param ml2x X coordinate of a point.
+\param ml2y Y coordinate of a point.
+
+*/
+void _murphyIteration(SDL2_gfxMurphyIterator *m, Uint8 miter,
+ Uint16 ml1bx, Uint16 ml1by, Uint16 ml2bx, Uint16 ml2by,
+ Uint16 ml1x, Uint16 ml1y, Uint16 ml2x, Uint16 ml2y)
+{
+ int atemp1, atemp2;
+ int ftmp1, ftmp2;
+ Uint16 m1x, m1y, m2x, m2y;
+ Uint16 fix, fiy, lax, lay, curx, cury;
+ Sint16 px[4], py[4];
+ SDL2_gfxBresenhamIterator b;
+
+ if (miter > 1) {
+ if (m->first1x != -32768) {
+ fix = (m->first1x + m->first2x) / 2;
+ fiy = (m->first1y + m->first2y) / 2;
+ lax = (m->last1x + m->last2x) / 2;
+ lay = (m->last1y + m->last2y) / 2;
+ curx = (ml1x + ml2x) / 2;
+ cury = (ml1y + ml2y) / 2;
+
+ atemp1 = (fix - curx);
+ atemp2 = (fiy - cury);
+ ftmp1 = atemp1 * atemp1 + atemp2 * atemp2;
+ atemp1 = (lax - curx);
+ atemp2 = (lay - cury);
+ ftmp2 = atemp1 * atemp1 + atemp2 * atemp2;
+
+ if (ftmp1 <= ftmp2) {
+ m1x = m->first1x;
+ m1y = m->first1y;
+ m2x = m->first2x;
+ m2y = m->first2y;
+ } else {
+ m1x = m->last1x;
+ m1y = m->last1y;
+ m2x = m->last2x;
+ m2y = m->last2y;
+ }
+
+ atemp1 = (m2x - ml2x);
+ atemp2 = (m2y - ml2y);
+ ftmp1 = atemp1 * atemp1 + atemp2 * atemp2;
+ atemp1 = (m2x - ml2bx);
+ atemp2 = (m2y - ml2by);
+ ftmp2 = atemp1 * atemp1 + atemp2 * atemp2;
+
+ if (ftmp2 >= ftmp1) {
+ ftmp1 = ml2bx;
+ ftmp2 = ml2by;
+ ml2bx = ml2x;
+ ml2by = ml2y;
+ ml2x = ftmp1;
+ ml2y = ftmp2;
+ ftmp1 = ml1bx;
+ ftmp2 = ml1by;
+ ml1bx = ml1x;
+ ml1by = ml1y;
+ ml1x = ftmp1;
+ ml1y = ftmp2;
+ }
+
+ /*
+ * Lock the surface
+ */
+ _bresenhamInitialize(&b, m2x, m2y, m1x, m1y);
+ do {
+ pixel(m->renderer, b.x, b.y);
+ } while (_bresenhamIterate(&b)==0);
+
+ _bresenhamInitialize(&b, m1x, m1y, ml1bx, ml1by);
+ do {
+ pixel(m->renderer, b.x, b.y);
+ } while (_bresenhamIterate(&b)==0);
+
+ _bresenhamInitialize(&b, ml1bx, ml1by, ml2bx, ml2by);
+ do {
+ pixel(m->renderer, b.x, b.y);
+ } while (_bresenhamIterate(&b)==0);
+
+ _bresenhamInitialize(&b, ml2bx, ml2by, m2x, m2y);
+ do {
+ pixel(m->renderer, b.x, b.y);
+ } while (_bresenhamIterate(&b)==0);
+
+ px[0] = m1x;
+ px[1] = m2x;
+ px[2] = ml1bx;
+ px[3] = ml2bx;
+ py[0] = m1y;
+ py[1] = m2y;
+ py[2] = ml1by;
+ py[3] = ml2by;
+ polygon(m->renderer, px, py, 4);
+ }
+ }
+
+ m->last1x = ml1x;
+ m->last1y = ml1y;
+ m->last2x = ml2x;
+ m->last2y = ml2y;
+ m->first1x = ml1bx;
+ m->first1y = ml1by;
+ m->first2x = ml2bx;
+ m->first2y = ml2by;
+}
+
+
+#define HYPOT(x,y) sqrt((double)(x)*(double)(x)+(double)(y)*(double)(y))
+
+/*!
+\brief Internal function to to draw wide lines with Murphy algorithm.
+
+Draws lines parallel to ideal line.
+
+\param m Pointer to struct for murphy iterator.
+\param x1 X coordinate of first point.
+\param y1 Y coordinate of first point.
+\param x2 X coordinate of second point.
+\param y2 Y coordinate of second point.
+\param width Width of line.
+\param miter Iteration count.
+
+*/
+void _murphyWideline(SDL2_gfxMurphyIterator *m, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 width, Uint8 miter)
+{
+ float offset = (float)width / 2.f;
+
+ Sint16 temp;
+ Sint16 ptx, pty, ptxx, ptxy, ml1x, ml1y, ml2x, ml2y, ml1bx, ml1by, ml2bx, ml2by;
+
+ int d0, d1; /* difference terms d0=perpendicular to line, d1=along line */
+
+ int q; /* pel counter,q=perpendicular to line */
+ int tmp;
+
+ int dd; /* distance along line */
+ int tk; /* thickness threshold */
+ double ang; /* angle for initial point calculation */
+ double sang, cang;
+
+ /* Initialisation */
+ m->u = x2 - x1; /* delta x */
+ m->v = y2 - y1; /* delta y */
+
+ if (m->u < 0) { /* swap to make sure we are in quadrants 1 or 4 */
+ temp = x1;
+ x1 = x2;
+ x2 = temp;
+ temp = y1;
+ y1 = y2;
+ y2 = temp;
+ m->u *= -1;
+ m->v *= -1;
+ }
+
+ if (m->v < 0) { /* swap to 1st quadrant and flag */
+ m->v *= -1;
+ m->quad4 = 1;
+ } else {
+ m->quad4 = 0;
+ }
+
+ if (m->v > m->u) { /* swap things if in 2 octant */
+ tmp = m->u;
+ m->u = m->v;
+ m->v = tmp;
+ m->oct2 = 1;
+ } else {
+ m->oct2 = 0;
+ }
+
+ m->ku = m->u + m->u; /* change in l for square shift */
+ m->kv = m->v + m->v; /* change in d for square shift */
+ m->kd = m->kv - m->ku; /* change in d for diagonal shift */
+ m->kt = m->u - m->kv; /* diag/square decision threshold */
+
+ d0 = 0;
+ d1 = 0;
+ dd = 0;
+
+ ang = atan((double) m->v / (double) m->u); /* calc new initial point - offset both sides of ideal */
+ sang = sin(ang);
+ cang = cos(ang);
+
+ if (m->oct2 == 0) {
+ ptx = x1 + (Sint16)lrint(offset * sang);
+ if (m->quad4 == 0) {
+ pty = y1 - (Sint16)lrint(offset * cang);
+ } else {
+ pty = y1 + (Sint16)lrint(offset * cang);
+ }
+ } else {
+ ptx = x1 - (Sint16)lrint(offset * cang);
+ if (m->quad4 == 0) {
+ pty = y1 + (Sint16)lrint(offset * sang);
+ } else {
+ pty = y1 - (Sint16)lrint(offset * sang);
+ }
+ }
+
+ /* used here for constant thickness line */
+ tk = (int) (4. * HYPOT(ptx - x1, pty - y1) * HYPOT(m->u, m->v));
+
+ if (miter == 0) {
+ m->first1x = -32768;
+ m->first1y = -32768;
+ m->first2x = -32768;
+ m->first2y = -32768;
+ m->last1x = -32768;
+ m->last1y = -32768;
+ m->last2x = -32768;
+ m->last2y = -32768;
+ }
+ ptxx = ptx;
+ ptxy = pty;
+
+ for (q = 0; dd <= tk; q++) { /* outer loop, stepping perpendicular to line */
+
+ _murphyParaline(m, ptx, pty, d1); /* call to inner loop - right edge */
+ if (q == 0) {
+ ml1x = ptx;
+ ml1y = pty;
+ ml1bx = m->tempx;
+ ml1by = m->tempy;
+ } else {
+ ml2x = ptx;
+ ml2y = pty;
+ ml2bx = m->tempx;
+ ml2by = m->tempy;
+ }
+ if (d0 < m->kt) { /* square move */
+ if (m->oct2 == 0) {
+ if (m->quad4 == 0) {
+ pty++;
+ } else {
+ pty--;
+ }
+ } else {
+ ptx++;
+ }
+ } else { /* diagonal move */
+ dd += m->kv;
+ d0 -= m->ku;
+ if (d1 < m->kt) { /* normal diagonal */
+ if (m->oct2 == 0) {
+ ptx--;
+ if (m->quad4 == 0) {
+ pty++;
+ } else {
+ pty--;
+ }
+ } else {
+ ptx++;
+ if (m->quad4 == 0) {
+ pty--;
+ } else {
+ pty++;
+ }
+ }
+ d1 += m->kv;
+ } else { /* double square move, extra parallel line */
+ if (m->oct2 == 0) {
+ ptx--;
+ } else {
+ if (m->quad4 == 0) {
+ pty--;
+ } else {
+ pty++;
+ }
+ }
+ d1 += m->kd;
+ if (dd > tk) {
+ _murphyIteration(m, miter, ml1bx, ml1by, ml2bx, ml2by, ml1x, ml1y, ml2x, ml2y);
+ return; /* breakout on the extra line */
+ }
+ _murphyParaline(m, ptx, pty, d1);
+ if (m->oct2 == 0) {
+ if (m->quad4 == 0) {
+ pty++;
+ } else {
+
+ pty--;
+ }
+ } else {
+ ptx++;
+ }
+ }
+ }
+ dd += m->ku;
+ d0 += m->kv;
+ }
+
+ _murphyIteration(m, miter, ml1bx, ml1by, ml2bx, ml2by, ml1x, ml1y, ml2x, ml2y);
+}
+
+
+/*!
+\brief Draw a thick line with alpha blending.
+
+\param dst The surface to draw on.
+\param x1 X coordinate of the first point of the line.
+\param y1 Y coordinate of the first point of the line.
+\param x2 X coordinate of the second point of the line.
+\param y2 Y coordinate of the second point of the line.
+\param width Width of the line in pixels. Must be >0.
+\param color The color value of the line to draw (0xRRGGBBAA).
+
+\returns Returns 0 on success, -1 on failure.
+*/
+int thickLineColor(SDL_Renderer *renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 width, Uint32 color)
+{
+ Uint8 *c = (Uint8 *)&color; + return thickLineRGBA(renderer, x1, y1, x2, y2, width, c[0], c[1], c[2], c[3]); +}
+
+/*!
+\brief Draw a thick line with alpha blending.
+
+\param dst The surface to draw on.
+\param x1 X coordinate of the first point of the line.
+\param y1 Y coordinate of the first point of the line.
+\param x2 X coordinate of the second point of the line.
+\param y2 Y coordinate of the second point of the line.
+\param width Width of the line in pixels. Must be >0.
+\param r The red value of the character to draw.
+\param g The green value of the character to draw.
+\param b The blue value of the character to draw.
+\param a The alpha value of the character to draw.
+
+\returns Returns 0 on success, -1 on failure.
+*/
+int thickLineRGBA(SDL_Renderer *renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 width, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ int result;
+ int wh;
+ SDL2_gfxMurphyIterator m;
+
+ if (renderer == NULL) {
+ return -1;
+ }
+ if (width < 1) {
+ return -1;
+ }
+
+ /* Special case: thick "point" */
+ if ((x1 == x2) && (y1 == y2)) {
+ wh = width / 2;
+ return boxRGBA(renderer, x1 - wh, y1 - wh, x2 + width, y2 + width, r, g, b, a);
+ }
+
+ /*
+ * Set color
+ */
+ result = 0;
+ result |= SDL_SetRenderDrawBlendMode(renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND); + result |= SDL_SetRenderDrawColor(renderer, r, g, b, a); +
+ /*
+ * Draw
+ */
+ m.renderer = renderer;
+ _murphyWideline(&m, x1, y1, x2, y2, width, 0);
+ _murphyWideline(&m, x1, y1, x2, y2, width, 1);
+
+ return(0);
+}
diff --git a/src/sdl2gfx/SDL_gfxPrimitives.h b/src/sdl2gfx/SDL_gfxPrimitives.h new file mode 100644 index 000000000..58a08ca94 --- /dev/null +++ b/src/sdl2gfx/SDL_gfxPrimitives.h @@ -0,0 +1,241 @@ +/* + +SDL2_gfxPrimitives.h: graphics primitives for SDL + +Copyright (C) 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 _SDL2_gfxPrimitives_h +#define _SDL2_gfxPrimitives_h + +#include <math.h> +#ifndef M_PI +#define M_PI 3.1415926535897932384626433832795 +#endif + +#include "SDL.h" + +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + + /* ----- Versioning */ + +#define SDL2_GFXPRIMITIVES_MAJOR 1 +#define SDL2_GFXPRIMITIVES_MINOR 0 +#define SDL2_GFXPRIMITIVES_MICRO 0 + + + /* ---- Function Prototypes */ + +#ifdef _MSC_VER +# if defined(DLL_EXPORT) && !defined(LIBSDL2_GFX_DLL_IMPORT) +# define SDL2_GFXPRIMITIVES_SCOPE __declspec(dllexport) +# else +# ifdef LIBSDL2_GFX_DLL_IMPORT +# define SDL2_GFXPRIMITIVES_SCOPE __declspec(dllimport) +# endif +# endif +#endif +#ifndef SDL2_GFXPRIMITIVES_SCOPE +# define SDL2_GFXPRIMITIVES_SCOPE extern +#endif + + /* Note: all ___Color routines expect the color to be in format 0xRRGGBBAA */ + + /* Pixel */ + + SDL2_GFXPRIMITIVES_SCOPE int pixelColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int pixelRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Horizontal line */ + + SDL2_GFXPRIMITIVES_SCOPE int hlineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 x2, Sint16 y, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int hlineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 x2, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Vertical line */ + + SDL2_GFXPRIMITIVES_SCOPE int vlineColor(SDL_Renderer * renderer, Sint16 x, Sint16 y1, Sint16 y2, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int vlineRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y1, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Rectangle */ + + SDL2_GFXPRIMITIVES_SCOPE int rectangleColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int rectangleRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, + Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Rounded-Corner Rectangle */ + + SDL2_GFXPRIMITIVES_SCOPE int roundedRectangleColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 rad, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int roundedRectangleRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, + Sint16 x2, Sint16 y2, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Filled rectangle (Box) */ + + SDL2_GFXPRIMITIVES_SCOPE int boxColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int boxRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, + Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Rounded-Corner Filled rectangle (Box) */ + + SDL2_GFXPRIMITIVES_SCOPE int roundedBoxColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 rad, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int roundedBoxRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, + Sint16 y2, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Line */ + + SDL2_GFXPRIMITIVES_SCOPE int lineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int lineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, + Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* AA Line */ + + SDL2_GFXPRIMITIVES_SCOPE int aalineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int aalineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, + Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Thick Line */ + SDL2_GFXPRIMITIVES_SCOPE int thickLineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, + Uint8 width, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int thickLineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, + Uint8 width, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Circle */ + + SDL2_GFXPRIMITIVES_SCOPE int circleColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int circleRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Arc */ + + SDL2_GFXPRIMITIVES_SCOPE int arcColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int arcRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end, + Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* AA Circle */ + + SDL2_GFXPRIMITIVES_SCOPE int aacircleColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int aacircleRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, + Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Filled Circle */ + + SDL2_GFXPRIMITIVES_SCOPE int filledCircleColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 r, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int filledCircleRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, + Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Ellipse */ + + SDL2_GFXPRIMITIVES_SCOPE int ellipseColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int ellipseRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, + Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* AA Ellipse */ + + SDL2_GFXPRIMITIVES_SCOPE int aaellipseColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int aaellipseRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, + Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Filled Ellipse */ + + SDL2_GFXPRIMITIVES_SCOPE int filledEllipseColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int filledEllipseRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, + Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Pie */ + + SDL2_GFXPRIMITIVES_SCOPE int pieColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, + Sint16 start, Sint16 end, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int pieRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, + Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Filled Pie */ + + SDL2_GFXPRIMITIVES_SCOPE int filledPieColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, + Sint16 start, Sint16 end, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int filledPieRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, + Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Trigon */ + + SDL2_GFXPRIMITIVES_SCOPE int trigonColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int trigonRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, + Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* AA-Trigon */ + + SDL2_GFXPRIMITIVES_SCOPE int aatrigonColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int aatrigonRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, + Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Filled Trigon */ + + SDL2_GFXPRIMITIVES_SCOPE int filledTrigonColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int filledTrigonRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, + Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Polygon */ + + SDL2_GFXPRIMITIVES_SCOPE int polygonColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int polygonRGBA(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, + int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* AA-Polygon */ + + SDL2_GFXPRIMITIVES_SCOPE int aapolygonColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int aapolygonRGBA(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, + int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Filled Polygon */ + + SDL2_GFXPRIMITIVES_SCOPE int filledPolygonColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int filledPolygonRGBA(SDL_Renderer * renderer, const Sint16 * vx, + const Sint16 * vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Textured Polygon */ + + SDL2_GFXPRIMITIVES_SCOPE int texturedPolygon(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, SDL_Surface * texture,int texture_dx,int texture_dy); + + /* Bezier */ + + SDL2_GFXPRIMITIVES_SCOPE int bezierColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, int s, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int bezierRGBA(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, + int n, int s, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Characters/Strings */ + + SDL2_GFXPRIMITIVES_SCOPE void gfxPrimitivesSetFont(const void *fontdata, Uint32 cw, Uint32 ch); + SDL2_GFXPRIMITIVES_SCOPE void gfxPrimitivesSetFontRotation(Uint32 rotation); + SDL2_GFXPRIMITIVES_SCOPE int characterColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, char c, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int characterRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, char c, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + SDL2_GFXPRIMITIVES_SCOPE int stringColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, const char *s, Uint32 color); + SDL2_GFXPRIMITIVES_SCOPE int stringRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, const char *s, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + + /* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif + +#endif /* _SDL2_gfxPrimitives_h */ diff --git a/src/sdl2gfx/SDL_gfxPrimitives_font.h b/src/sdl2gfx/SDL_gfxPrimitives_font.h new file mode 100644 index 000000000..9fa45e8e8 --- /dev/null +++ b/src/sdl2gfx/SDL_gfxPrimitives_font.h @@ -0,0 +1,3082 @@ + +/* ---- 8x8 font definition ---- */ + +/* ZLIB (c) A. Schiffler 2012 */ + +#define GFX_FONTDATAMAX (8*256) + +static unsigned char gfxPrimitivesFontdata[GFX_FONTDATAMAX] = { + + /* + * 0 0x00 '^@' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 1 0x01 '^A' + */ + 0x7e, /* 01111110 */ + 0x81, /* 10000001 */ + 0xa5, /* 10100101 */ + 0x81, /* 10000001 */ + 0xbd, /* 10111101 */ + 0x99, /* 10011001 */ + 0x81, /* 10000001 */ + 0x7e, /* 01111110 */ + + /* + * 2 0x02 '^B' + */ + 0x7e, /* 01111110 */ + 0xff, /* 11111111 */ + 0xdb, /* 11011011 */ + 0xff, /* 11111111 */ + 0xc3, /* 11000011 */ + 0xe7, /* 11100111 */ + 0xff, /* 11111111 */ + 0x7e, /* 01111110 */ + + /* + * 3 0x03 '^C' + */ + 0x6c, /* 01101100 */ + 0xfe, /* 11111110 */ + 0xfe, /* 11111110 */ + 0xfe, /* 11111110 */ + 0x7c, /* 01111100 */ + 0x38, /* 00111000 */ + 0x10, /* 00010000 */ + 0x00, /* 00000000 */ + + /* + * 4 0x04 '^D' + */ + 0x10, /* 00010000 */ + 0x38, /* 00111000 */ + 0x7c, /* 01111100 */ + 0xfe, /* 11111110 */ + 0x7c, /* 01111100 */ + 0x38, /* 00111000 */ + 0x10, /* 00010000 */ + 0x00, /* 00000000 */ + + /* + * 5 0x05 '^E' + */ + 0x38, /* 00111000 */ + 0x7c, /* 01111100 */ + 0x38, /* 00111000 */ + 0xfe, /* 11111110 */ + 0xfe, /* 11111110 */ + 0xd6, /* 11010110 */ + 0x10, /* 00010000 */ + 0x38, /* 00111000 */ + + /* + * 6 0x06 '^F' + */ + 0x10, /* 00010000 */ + 0x38, /* 00111000 */ + 0x7c, /* 01111100 */ + 0xfe, /* 11111110 */ + 0xfe, /* 11111110 */ + 0x7c, /* 01111100 */ + 0x10, /* 00010000 */ + 0x38, /* 00111000 */ + + /* + * 7 0x07 '^G' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 8 0x08 '^H' + */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xe7, /* 11100111 */ + 0xc3, /* 11000011 */ + 0xc3, /* 11000011 */ + 0xe7, /* 11100111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + + /* + * 9 0x09 '^I' + */ + 0x00, /* 00000000 */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0x42, /* 01000010 */ + 0x42, /* 01000010 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* + * 10 0x0a '^J' + */ + 0xff, /* 11111111 */ + 0xc3, /* 11000011 */ + 0x99, /* 10011001 */ + 0xbd, /* 10111101 */ + 0xbd, /* 10111101 */ + 0x99, /* 10011001 */ + 0xc3, /* 11000011 */ + 0xff, /* 11111111 */ + + /* + * 11 0x0b '^K' + */ + 0x0f, /* 00001111 */ + 0x07, /* 00000111 */ + 0x0f, /* 00001111 */ + 0x7d, /* 01111101 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x78, /* 01111000 */ + + /* + * 12 0x0c '^L' + */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + + /* + * 13 0x0d '^M' + */ + 0x3f, /* 00111111 */ + 0x33, /* 00110011 */ + 0x3f, /* 00111111 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x70, /* 01110000 */ + 0xf0, /* 11110000 */ + 0xe0, /* 11100000 */ + + /* + * 14 0x0e '^N' + */ + 0x7f, /* 01111111 */ + 0x63, /* 01100011 */ + 0x7f, /* 01111111 */ + 0x63, /* 01100011 */ + 0x63, /* 01100011 */ + 0x67, /* 01100111 */ + 0xe6, /* 11100110 */ + 0xc0, /* 11000000 */ + + /* + * 15 0x0f '^O' + */ + 0x18, /* 00011000 */ + 0xdb, /* 11011011 */ + 0x3c, /* 00111100 */ + 0xe7, /* 11100111 */ + 0xe7, /* 11100111 */ + 0x3c, /* 00111100 */ + 0xdb, /* 11011011 */ + 0x18, /* 00011000 */ + + /* + * 16 0x10 '^P' + */ + 0x80, /* 10000000 */ + 0xe0, /* 11100000 */ + 0xf8, /* 11111000 */ + 0xfe, /* 11111110 */ + 0xf8, /* 11111000 */ + 0xe0, /* 11100000 */ + 0x80, /* 10000000 */ + 0x00, /* 00000000 */ + + /* + * 17 0x11 '^Q' + */ + 0x02, /* 00000010 */ + 0x0e, /* 00001110 */ + 0x3e, /* 00111110 */ + 0xfe, /* 11111110 */ + 0x3e, /* 00111110 */ + 0x0e, /* 00001110 */ + 0x02, /* 00000010 */ + 0x00, /* 00000000 */ + + /* + * 18 0x12 '^R' + */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + + /* + * 19 0x13 '^S' + */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x00, /* 00000000 */ + 0x66, /* 01100110 */ + 0x00, /* 00000000 */ + + /* + * 20 0x14 '^T' + */ + 0x7f, /* 01111111 */ + 0xdb, /* 11011011 */ + 0xdb, /* 11011011 */ + 0x7b, /* 01111011 */ + 0x1b, /* 00011011 */ + 0x1b, /* 00011011 */ + 0x1b, /* 00011011 */ + 0x00, /* 00000000 */ + + /* + * 21 0x15 '^U' + */ + 0x3e, /* 00111110 */ + 0x61, /* 01100001 */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x86, /* 10000110 */ + 0x7c, /* 01111100 */ + + /* + * 22 0x16 '^V' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x7e, /* 01111110 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + + /* + * 23 0x17 '^W' + */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0xff, /* 11111111 */ + + /* + * 24 0x18 '^X' + */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* + * 25 0x19 '^Y' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* + * 26 0x1a '^Z' + */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0xfe, /* 11111110 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 27 0x1b '^[' + */ + 0x00, /* 00000000 */ + 0x30, /* 00110000 */ + 0x60, /* 01100000 */ + 0xfe, /* 11111110 */ + 0x60, /* 01100000 */ + 0x30, /* 00110000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 28 0x1c '^\' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 29 0x1d '^]' + */ + 0x00, /* 00000000 */ + 0x24, /* 00100100 */ + 0x66, /* 01100110 */ + 0xff, /* 11111111 */ + 0x66, /* 01100110 */ + 0x24, /* 00100100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 30 0x1e '^^' + */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x7e, /* 01111110 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 31 0x1f '^_' + */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0x7e, /* 01111110 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 32 0x20 ' ' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 33 0x21 '!' + */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* + * 34 0x22 '"' + */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x24, /* 00100100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 35 0x23 '#' + */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0xfe, /* 11111110 */ + 0x6c, /* 01101100 */ + 0xfe, /* 11111110 */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0x00, /* 00000000 */ + + /* + * 36 0x24 '$' + */ + 0x18, /* 00011000 */ + 0x3e, /* 00111110 */ + 0x60, /* 01100000 */ + 0x3c, /* 00111100 */ + 0x06, /* 00000110 */ + 0x7c, /* 01111100 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* + * 37 0x25 '%' + */ + 0x00, /* 00000000 */ + 0xc6, /* 11000110 */ + 0xcc, /* 11001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x66, /* 01100110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* + * 38 0x26 '&' + */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x76, /* 01110110 */ + 0xdc, /* 11011100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* + * 39 0x27 ''' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 40 0x28 '(' + */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x00, /* 00000000 */ + + /* + * 41 0x29 ')' + */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x00, /* 00000000 */ + + /* + * 42 0x2a '*' + */ + 0x00, /* 00000000 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0xff, /* 11111111 */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 43 0x2b '+' + */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 44 0x2c ',' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + + /* + * 45 0x2d '-' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 46 0x2e '.' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* + * 47 0x2f '/' + */ + 0x06, /* 00000110 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x60, /* 01100000 */ + 0xc0, /* 11000000 */ + 0x80, /* 10000000 */ + 0x00, /* 00000000 */ + + /* + * 48 0x30 '0' + */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0xd6, /* 11010110 */ + 0xc6, /* 11000110 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x00, /* 00000000 */ + + /* + * 49 0x31 '1' + */ + 0x18, /* 00011000 */ + 0x38, /* 00111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + + /* + * 50 0x32 '2' + */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0x06, /* 00000110 */ + 0x1c, /* 00011100 */ + 0x30, /* 00110000 */ + 0x66, /* 01100110 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + + /* + * 51 0x33 '3' + */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0x06, /* 00000110 */ + 0x3c, /* 00111100 */ + 0x06, /* 00000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 52 0x34 '4' + */ + 0x1c, /* 00011100 */ + 0x3c, /* 00111100 */ + 0x6c, /* 01101100 */ + 0xcc, /* 11001100 */ + 0xfe, /* 11111110 */ + 0x0c, /* 00001100 */ + 0x1e, /* 00011110 */ + 0x00, /* 00000000 */ + + /* + * 53 0x35 '5' + */ + 0xfe, /* 11111110 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xfc, /* 11111100 */ + 0x06, /* 00000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 54 0x36 '6' + */ + 0x38, /* 00111000 */ + 0x60, /* 01100000 */ + 0xc0, /* 11000000 */ + 0xfc, /* 11111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 55 0x37 '7' + */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x00, /* 00000000 */ + + /* + * 56 0x38 '8' + */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 57 0x39 '9' + */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7e, /* 01111110 */ + 0x06, /* 00000110 */ + 0x0c, /* 00001100 */ + 0x78, /* 01111000 */ + 0x00, /* 00000000 */ + + /* + * 58 0x3a ':' + */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* + * 59 0x3b ';' + */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + + /* + * 60 0x3c '<' + */ + 0x06, /* 00000110 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x06, /* 00000110 */ + 0x00, /* 00000000 */ + + /* + * 61 0x3d '=' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 62 0x3e '>' + */ + 0x60, /* 01100000 */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x60, /* 01100000 */ + 0x00, /* 00000000 */ + + /* + * 63 0x3f '?' + */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* + * 64 0x40 '@' + */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xde, /* 11011110 */ + 0xde, /* 11011110 */ + 0xde, /* 11011110 */ + 0xc0, /* 11000000 */ + 0x78, /* 01111000 */ + 0x00, /* 00000000 */ + + /* + * 65 0x41 'A' + */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* + * 66 0x42 'B' + */ + 0xfc, /* 11111100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x7c, /* 01111100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0xfc, /* 11111100 */ + 0x00, /* 00000000 */ + + /* + * 67 0x43 'C' + */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* + * 68 0x44 'D' + */ + 0xf8, /* 11111000 */ + 0x6c, /* 01101100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x6c, /* 01101100 */ + 0xf8, /* 11111000 */ + 0x00, /* 00000000 */ + + /* + * 69 0x45 'E' + */ + 0xfe, /* 11111110 */ + 0x62, /* 01100010 */ + 0x68, /* 01101000 */ + 0x78, /* 01111000 */ + 0x68, /* 01101000 */ + 0x62, /* 01100010 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + + /* + * 70 0x46 'F' + */ + 0xfe, /* 11111110 */ + 0x62, /* 01100010 */ + 0x68, /* 01101000 */ + 0x78, /* 01111000 */ + 0x68, /* 01101000 */ + 0x60, /* 01100000 */ + 0xf0, /* 11110000 */ + 0x00, /* 00000000 */ + + /* + * 71 0x47 'G' + */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xce, /* 11001110 */ + 0x66, /* 01100110 */ + 0x3a, /* 00111010 */ + 0x00, /* 00000000 */ + + /* + * 72 0x48 'H' + */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* + * 73 0x49 'I' + */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* + * 74 0x4a 'J' + */ + 0x1e, /* 00011110 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x78, /* 01111000 */ + 0x00, /* 00000000 */ + + /* + * 75 0x4b 'K' + */ + 0xe6, /* 11100110 */ + 0x66, /* 01100110 */ + 0x6c, /* 01101100 */ + 0x78, /* 01111000 */ + 0x6c, /* 01101100 */ + 0x66, /* 01100110 */ + 0xe6, /* 11100110 */ + 0x00, /* 00000000 */ + + /* + * 76 0x4c 'L' + */ + 0xf0, /* 11110000 */ + 0x60, /* 01100000 */ + 0x60, /* 01100000 */ + 0x60, /* 01100000 */ + 0x62, /* 01100010 */ + 0x66, /* 01100110 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + + /* + * 77 0x4d 'M' + */ + 0xc6, /* 11000110 */ + 0xee, /* 11101110 */ + 0xfe, /* 11111110 */ + 0xfe, /* 11111110 */ + 0xd6, /* 11010110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* + * 78 0x4e 'N' + */ + 0xc6, /* 11000110 */ + 0xe6, /* 11100110 */ + 0xf6, /* 11110110 */ + 0xde, /* 11011110 */ + 0xce, /* 11001110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* + * 79 0x4f 'O' + */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 80 0x50 'P' + */ + 0xfc, /* 11111100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x7c, /* 01111100 */ + 0x60, /* 01100000 */ + 0x60, /* 01100000 */ + 0xf0, /* 11110000 */ + 0x00, /* 00000000 */ + + /* + * 81 0x51 'Q' + */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xce, /* 11001110 */ + 0x7c, /* 01111100 */ + 0x0e, /* 00001110 */ + + /* + * 82 0x52 'R' + */ + 0xfc, /* 11111100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x7c, /* 01111100 */ + 0x6c, /* 01101100 */ + 0x66, /* 01100110 */ + 0xe6, /* 11100110 */ + 0x00, /* 00000000 */ + + /* + * 83 0x53 'S' + */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* + * 84 0x54 'T' + */ + 0x7e, /* 01111110 */ + 0x7e, /* 01111110 */ + 0x5a, /* 01011010 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* + * 85 0x55 'U' + */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 86 0x56 'V' + */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x00, /* 00000000 */ + + /* + * 87 0x57 'W' + */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xd6, /* 11010110 */ + 0xd6, /* 11010110 */ + 0xfe, /* 11111110 */ + 0x6c, /* 01101100 */ + 0x00, /* 00000000 */ + + /* + * 88 0x58 'X' + */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* + * 89 0x59 'Y' + */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* + * 90 0x5a 'Z' + */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0x8c, /* 10001100 */ + 0x18, /* 00011000 */ + 0x32, /* 00110010 */ + 0x66, /* 01100110 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + + /* + * 91 0x5b '[' + */ + 0x3c, /* 00111100 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* + * 92 0x5c '\' + */ + 0xc0, /* 11000000 */ + 0x60, /* 01100000 */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x06, /* 00000110 */ + 0x02, /* 00000010 */ + 0x00, /* 00000000 */ + + /* + * 93 0x5d ']' + */ + 0x3c, /* 00111100 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* + * 94 0x5e '^' + */ + 0x10, /* 00010000 */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 95 0x5f '_' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + + /* + * 96 0x60 '`' + */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 97 0x61 'a' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x78, /* 01111000 */ + 0x0c, /* 00001100 */ + 0x7c, /* 01111100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* + * 98 0x62 'b' + */ + 0xe0, /* 11100000 */ + 0x60, /* 01100000 */ + 0x7c, /* 01111100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0xdc, /* 11011100 */ + 0x00, /* 00000000 */ + + /* + * 99 0x63 'c' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc0, /* 11000000 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 100 0x64 'd' + */ + 0x1c, /* 00011100 */ + 0x0c, /* 00001100 */ + 0x7c, /* 01111100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* + * 101 0x65 'e' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc0, /* 11000000 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 102 0x66 'f' + */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0x60, /* 01100000 */ + 0xf8, /* 11111000 */ + 0x60, /* 01100000 */ + 0x60, /* 01100000 */ + 0xf0, /* 11110000 */ + 0x00, /* 00000000 */ + + /* + * 103 0x67 'g' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x76, /* 01110110 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x7c, /* 01111100 */ + 0x0c, /* 00001100 */ + 0xf8, /* 11111000 */ + + /* + * 104 0x68 'h' + */ + 0xe0, /* 11100000 */ + 0x60, /* 01100000 */ + 0x6c, /* 01101100 */ + 0x76, /* 01110110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0xe6, /* 11100110 */ + 0x00, /* 00000000 */ + + /* + * 105 0x69 'i' + */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x38, /* 00111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* + * 106 0x6a 'j' + */ + 0x06, /* 00000110 */ + 0x00, /* 00000000 */ + 0x06, /* 00000110 */ + 0x06, /* 00000110 */ + 0x06, /* 00000110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + + /* + * 107 0x6b 'k' + */ + 0xe0, /* 11100000 */ + 0x60, /* 01100000 */ + 0x66, /* 01100110 */ + 0x6c, /* 01101100 */ + 0x78, /* 01111000 */ + 0x6c, /* 01101100 */ + 0xe6, /* 11100110 */ + 0x00, /* 00000000 */ + + /* + * 108 0x6c 'l' + */ + 0x38, /* 00111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* + * 109 0x6d 'm' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xec, /* 11101100 */ + 0xfe, /* 11111110 */ + 0xd6, /* 11010110 */ + 0xd6, /* 11010110 */ + 0xd6, /* 11010110 */ + 0x00, /* 00000000 */ + + /* + * 110 0x6e 'n' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xdc, /* 11011100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x00, /* 00000000 */ + + /* + * 111 0x6f 'o' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 112 0x70 'p' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xdc, /* 11011100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x7c, /* 01111100 */ + 0x60, /* 01100000 */ + 0xf0, /* 11110000 */ + + /* + * 113 0x71 'q' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x76, /* 01110110 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x7c, /* 01111100 */ + 0x0c, /* 00001100 */ + 0x1e, /* 00011110 */ + + /* + * 114 0x72 'r' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xdc, /* 11011100 */ + 0x76, /* 01110110 */ + 0x60, /* 01100000 */ + 0x60, /* 01100000 */ + 0xf0, /* 11110000 */ + 0x00, /* 00000000 */ + + /* + * 115 0x73 's' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0xc0, /* 11000000 */ + 0x7c, /* 01111100 */ + 0x06, /* 00000110 */ + 0xfc, /* 11111100 */ + 0x00, /* 00000000 */ + + /* + * 116 0x74 't' + */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0xfc, /* 11111100 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x36, /* 00110110 */ + 0x1c, /* 00011100 */ + 0x00, /* 00000000 */ + + /* + * 117 0x75 'u' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* + * 118 0x76 'v' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x00, /* 00000000 */ + + /* + * 119 0x77 'w' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xc6, /* 11000110 */ + 0xd6, /* 11010110 */ + 0xd6, /* 11010110 */ + 0xfe, /* 11111110 */ + 0x6c, /* 01101100 */ + 0x00, /* 00000000 */ + + /* + * 120 0x78 'x' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xc6, /* 11000110 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* + * 121 0x79 'y' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7e, /* 01111110 */ + 0x06, /* 00000110 */ + 0xfc, /* 11111100 */ + + /* + * 122 0x7a 'z' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x4c, /* 01001100 */ + 0x18, /* 00011000 */ + 0x32, /* 00110010 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + + /* + * 123 0x7b '{' + */ + 0x0e, /* 00001110 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x70, /* 01110000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x0e, /* 00001110 */ + 0x00, /* 00000000 */ + + /* + * 124 0x7c '|' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* + * 125 0x7d '}' + */ + 0x70, /* 01110000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x0e, /* 00001110 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x70, /* 01110000 */ + 0x00, /* 00000000 */ + + /* + * 126 0x7e '~' + */ + 0x76, /* 01110110 */ + 0xdc, /* 11011100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 127 0x7f '' + */ + 0x00, /* 00000000 */ + 0x10, /* 00010000 */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + + /* + * 128 0x80 '€' + */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x0c, /* 00001100 */ + 0x78, /* 01111000 */ + + /* + * 129 0x81 '' + */ + 0xcc, /* 11001100 */ + 0x00, /* 00000000 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* + * 130 0x82 '‚' + */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc0, /* 11000000 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 131 0x83 'ƒ' + */ + 0x7c, /* 01111100 */ + 0x82, /* 10000010 */ + 0x78, /* 01111000 */ + 0x0c, /* 00001100 */ + 0x7c, /* 01111100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* + * 132 0x84 '„' + */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + 0x78, /* 01111000 */ + 0x0c, /* 00001100 */ + 0x7c, /* 01111100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* + * 133 0x85 '…' + */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x78, /* 01111000 */ + 0x0c, /* 00001100 */ + 0x7c, /* 01111100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* + * 134 0x86 '†' + */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x78, /* 01111000 */ + 0x0c, /* 00001100 */ + 0x7c, /* 01111100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* + * 135 0x87 '‡' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0x7e, /* 01111110 */ + 0x0c, /* 00001100 */ + 0x38, /* 00111000 */ + + /* + * 136 0x88 'ˆ' + */ + 0x7c, /* 01111100 */ + 0x82, /* 10000010 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc0, /* 11000000 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 137 0x89 '‰' + */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc0, /* 11000000 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 138 0x8a 'Š' + */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc0, /* 11000000 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 139 0x8b '‹' + */ + 0x66, /* 01100110 */ + 0x00, /* 00000000 */ + 0x38, /* 00111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* + * 140 0x8c 'Œ' + */ + 0x7c, /* 01111100 */ + 0x82, /* 10000010 */ + 0x38, /* 00111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* + * 141 0x8d '' + */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x38, /* 00111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* + * 142 0x8e 'Ž' + */ + 0xc6, /* 11000110 */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* + * 143 0x8f '' + */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* + * 144 0x90 '' + */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0xfe, /* 11111110 */ + 0xc0, /* 11000000 */ + 0xf8, /* 11111000 */ + 0xc0, /* 11000000 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + + /* + * 145 0x91 '‘' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0xd8, /* 11011000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + + /* + * 146 0x92 '’' + */ + 0x3e, /* 00111110 */ + 0x6c, /* 01101100 */ + 0xcc, /* 11001100 */ + 0xfe, /* 11111110 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xce, /* 11001110 */ + 0x00, /* 00000000 */ + + /* + * 147 0x93 '“' + */ + 0x7c, /* 01111100 */ + 0x82, /* 10000010 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 148 0x94 '”' + */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 149 0x95 '•' + */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 150 0x96 '–' + */ + 0x78, /* 01111000 */ + 0x84, /* 10000100 */ + 0x00, /* 00000000 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* + * 151 0x97 '—' + */ + 0x60, /* 01100000 */ + 0x30, /* 00110000 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* + * 152 0x98 '˜' + */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7e, /* 01111110 */ + 0x06, /* 00000110 */ + 0xfc, /* 11111100 */ + + /* + * 153 0x99 '™' + */ + 0xc6, /* 11000110 */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x00, /* 00000000 */ + + /* + * 154 0x9a 'š' + */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 155 0x9b '›' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* + * 156 0x9c 'œ' + */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0x64, /* 01100100 */ + 0xf0, /* 11110000 */ + 0x60, /* 01100000 */ + 0x66, /* 01100110 */ + 0xfc, /* 11111100 */ + 0x00, /* 00000000 */ + + /* + * 157 0x9d '' + */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* + * 158 0x9e 'ž' + */ + 0xf8, /* 11111000 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xfa, /* 11111010 */ + 0xc6, /* 11000110 */ + 0xcf, /* 11001111 */ + 0xc6, /* 11000110 */ + 0xc7, /* 11000111 */ + + /* + * 159 0x9f 'Ÿ' + */ + 0x0e, /* 00001110 */ + 0x1b, /* 00011011 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0xd8, /* 11011000 */ + 0x70, /* 01110000 */ + 0x00, /* 00000000 */ + + /* + * 160 0xa0 ' ' + */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x78, /* 01111000 */ + 0x0c, /* 00001100 */ + 0x7c, /* 01111100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* + * 161 0xa1 '¡' + */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x38, /* 00111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* + * 162 0xa2 '¢' + */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* + * 163 0xa3 '£' + */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* + * 164 0xa4 '¤' + */ + 0x76, /* 01110110 */ + 0xdc, /* 11011100 */ + 0x00, /* 00000000 */ + 0xdc, /* 11011100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x00, /* 00000000 */ + + /* + * 165 0xa5 '¥' + */ + 0x76, /* 01110110 */ + 0xdc, /* 11011100 */ + 0x00, /* 00000000 */ + 0xe6, /* 11100110 */ + 0xf6, /* 11110110 */ + 0xde, /* 11011110 */ + 0xce, /* 11001110 */ + 0x00, /* 00000000 */ + + /* + * 166 0xa6 '¦' + */ + 0x3c, /* 00111100 */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0x3e, /* 00111110 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 167 0xa7 '§' + */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x00, /* 00000000 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 168 0xa8 '¨' + */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x63, /* 01100011 */ + 0x3e, /* 00111110 */ + 0x00, /* 00000000 */ + + /* + * 169 0xa9 '©' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xfe, /* 11111110 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 170 0xaa 'ª' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xfe, /* 11111110 */ + 0x06, /* 00000110 */ + 0x06, /* 00000110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 171 0xab '«' + */ + 0x63, /* 01100011 */ + 0xe6, /* 11100110 */ + 0x6c, /* 01101100 */ + 0x7e, /* 01111110 */ + 0x33, /* 00110011 */ + 0x66, /* 01100110 */ + 0xcc, /* 11001100 */ + 0x0f, /* 00001111 */ + + /* + * 172 0xac '¬' + */ + 0x63, /* 01100011 */ + 0xe6, /* 11100110 */ + 0x6c, /* 01101100 */ + 0x7a, /* 01111010 */ + 0x36, /* 00110110 */ + 0x6a, /* 01101010 */ + 0xdf, /* 11011111 */ + 0x06, /* 00000110 */ + + /* + * 173 0xad '' + */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* + * 174 0xae '®' + */ + 0x00, /* 00000000 */ + 0x33, /* 00110011 */ + 0x66, /* 01100110 */ + 0xcc, /* 11001100 */ + 0x66, /* 01100110 */ + 0x33, /* 00110011 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 175 0xaf '¯' + */ + 0x00, /* 00000000 */ + 0xcc, /* 11001100 */ + 0x66, /* 01100110 */ + 0x33, /* 00110011 */ + 0x66, /* 01100110 */ + 0xcc, /* 11001100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 176 0xb0 '°' + */ + 0x22, /* 00100010 */ + 0x88, /* 10001000 */ + 0x22, /* 00100010 */ + 0x88, /* 10001000 */ + 0x22, /* 00100010 */ + 0x88, /* 10001000 */ + 0x22, /* 00100010 */ + 0x88, /* 10001000 */ + + /* + * 177 0xb1 '±' + */ + 0x55, /* 01010101 */ + 0xaa, /* 10101010 */ + 0x55, /* 01010101 */ + 0xaa, /* 10101010 */ + 0x55, /* 01010101 */ + 0xaa, /* 10101010 */ + 0x55, /* 01010101 */ + 0xaa, /* 10101010 */ + + /* + * 178 0xb2 '²' + */ + 0x77, /* 01110111 */ + 0xdd, /* 11011101 */ + 0x77, /* 01110111 */ + 0xdd, /* 11011101 */ + 0x77, /* 01110111 */ + 0xdd, /* 11011101 */ + 0x77, /* 01110111 */ + 0xdd, /* 11011101 */ + + /* + * 179 0xb3 '³' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* + * 180 0xb4 '´' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xf8, /* 11111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* + * 181 0xb5 'µ' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xf8, /* 11111000 */ + 0x18, /* 00011000 */ + 0xf8, /* 11111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* + * 182 0xb6 '¶' + */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0xf6, /* 11110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* + * 183 0xb7 '·' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xfe, /* 11111110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* + * 184 0xb8 '¸' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xf8, /* 11111000 */ + 0x18, /* 00011000 */ + 0xf8, /* 11111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* + * 185 0xb9 '¹' + */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0xf6, /* 11110110 */ + 0x06, /* 00000110 */ + 0xf6, /* 11110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* + * 186 0xba 'º' + */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* + * 187 0xbb '»' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xfe, /* 11111110 */ + 0x06, /* 00000110 */ + 0xf6, /* 11110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* + * 188 0xbc '¼' + */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0xf6, /* 11110110 */ + 0x06, /* 00000110 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 189 0xbd '½' + */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 190 0xbe '¾' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xf8, /* 11111000 */ + 0x18, /* 00011000 */ + 0xf8, /* 11111000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 191 0xbf '¿' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xf8, /* 11111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* + * 192 0xc0 'À' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x1f, /* 00011111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 193 0xc1 'Á' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 194 0xc2 'Â' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* + * 195 0xc3 'Ã' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x1f, /* 00011111 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* + * 196 0xc4 'Ä' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 197 0xc5 'Å' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xff, /* 11111111 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* + * 198 0xc6 'Æ' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x1f, /* 00011111 */ + 0x18, /* 00011000 */ + 0x1f, /* 00011111 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* + * 199 0xc7 'Ç' + */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x37, /* 00110111 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* + * 200 0xc8 'È' + */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x37, /* 00110111 */ + 0x30, /* 00110000 */ + 0x3f, /* 00111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 201 0xc9 'É' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x3f, /* 00111111 */ + 0x30, /* 00110000 */ + 0x37, /* 00110111 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* + * 202 0xca 'Ê' + */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0xf7, /* 11110111 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 203 0xcb 'Ë' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0xf7, /* 11110111 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* + * 204 0xcc 'Ì' + */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x37, /* 00110111 */ + 0x30, /* 00110000 */ + 0x37, /* 00110111 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* + * 205 0xcd 'Í' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 206 0xce 'Î' + */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0xf7, /* 11110111 */ + 0x00, /* 00000000 */ + 0xf7, /* 11110111 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* + * 207 0xcf 'Ï' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 208 0xd0 'Ð' + */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 209 0xd1 'Ñ' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* + * 210 0xd2 'Ò' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* + * 211 0xd3 'Ó' + */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x3f, /* 00111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 212 0xd4 'Ô' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x1f, /* 00011111 */ + 0x18, /* 00011000 */ + 0x1f, /* 00011111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 213 0xd5 'Õ' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x1f, /* 00011111 */ + 0x18, /* 00011000 */ + 0x1f, /* 00011111 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* + * 214 0xd6 'Ö' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x3f, /* 00111111 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* + * 215 0xd7 '×' + */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0xff, /* 11111111 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* + * 216 0xd8 'Ø' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xff, /* 11111111 */ + 0x18, /* 00011000 */ + 0xff, /* 11111111 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* + * 217 0xd9 'Ù' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xf8, /* 11111000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 218 0xda 'Ú' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x1f, /* 00011111 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* + * 219 0xdb 'Û' + */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + + /* + * 220 0xdc 'Ü' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + + /* + * 221 0xdd 'Ý' + */ + 0xf0, /* 11110000 */ + 0xf0, /* 11110000 */ + 0xf0, /* 11110000 */ + 0xf0, /* 11110000 */ + 0xf0, /* 11110000 */ + 0xf0, /* 11110000 */ + 0xf0, /* 11110000 */ + 0xf0, /* 11110000 */ + + /* + * 222 0xde 'Þ' + */ + 0x0f, /* 00001111 */ + 0x0f, /* 00001111 */ + 0x0f, /* 00001111 */ + 0x0f, /* 00001111 */ + 0x0f, /* 00001111 */ + 0x0f, /* 00001111 */ + 0x0f, /* 00001111 */ + 0x0f, /* 00001111 */ + + /* + * 223 0xdf 'ß' + */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 224 0xe0 'à' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x76, /* 01110110 */ + 0xdc, /* 11011100 */ + 0xc8, /* 11001000 */ + 0xdc, /* 11011100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* + * 225 0xe1 'á' + */ + 0x78, /* 01111000 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xd8, /* 11011000 */ + 0xcc, /* 11001100 */ + 0xc6, /* 11000110 */ + 0xcc, /* 11001100 */ + 0x00, /* 00000000 */ + + /* + * 226 0xe2 'â' + */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0x00, /* 00000000 */ + + /* + * 227 0xe3 'ã' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xfe, /* 11111110 */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0x00, /* 00000000 */ + + /* + * 228 0xe4 'ä' + */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0x60, /* 01100000 */ + 0x30, /* 00110000 */ + 0x60, /* 01100000 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + + /* + * 229 0xe5 'å' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0xd8, /* 11011000 */ + 0xd8, /* 11011000 */ + 0xd8, /* 11011000 */ + 0x70, /* 01110000 */ + 0x00, /* 00000000 */ + + /* + * 230 0xe6 'æ' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x7c, /* 01111100 */ + 0xc0, /* 11000000 */ + + /* + * 231 0xe7 'ç' + */ + 0x00, /* 00000000 */ + 0x76, /* 01110110 */ + 0xdc, /* 11011100 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* + * 232 0xe8 'è' + */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + + /* + * 233 0xe9 'é' + */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x00, /* 00000000 */ + + /* + * 234 0xea 'ê' + */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0xee, /* 11101110 */ + 0x00, /* 00000000 */ + + /* + * 235 0xeb 'ë' + */ + 0x0e, /* 00001110 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x3e, /* 00111110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* + * 236 0xec 'ì' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0xdb, /* 11011011 */ + 0xdb, /* 11011011 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 237 0xed 'í' + */ + 0x06, /* 00000110 */ + 0x0c, /* 00001100 */ + 0x7e, /* 01111110 */ + 0xdb, /* 11011011 */ + 0xdb, /* 11011011 */ + 0x7e, /* 01111110 */ + 0x60, /* 01100000 */ + 0xc0, /* 11000000 */ + + /* + * 238 0xee 'î' + */ + 0x1e, /* 00011110 */ + 0x30, /* 00110000 */ + 0x60, /* 01100000 */ + 0x7e, /* 01111110 */ + 0x60, /* 01100000 */ + 0x30, /* 00110000 */ + 0x1e, /* 00011110 */ + 0x00, /* 00000000 */ + + /* + * 239 0xef 'ï' + */ + 0x00, /* 00000000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* + * 240 0xf0 'ð' + */ + 0x00, /* 00000000 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 241 0xf1 'ñ' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + + /* + * 242 0xf2 'ò' + */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + + /* + * 243 0xf3 'ó' + */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + + /* + * 244 0xf4 'ô' + */ + 0x0e, /* 00001110 */ + 0x1b, /* 00011011 */ + 0x1b, /* 00011011 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* + * 245 0xf5 'õ' + */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xd8, /* 11011000 */ + 0xd8, /* 11011000 */ + 0x70, /* 01110000 */ + + /* + * 246 0xf6 'ö' + */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 247 0xf7 '÷' + */ + 0x00, /* 00000000 */ + 0x76, /* 01110110 */ + 0xdc, /* 11011100 */ + 0x00, /* 00000000 */ + 0x76, /* 01110110 */ + 0xdc, /* 11011100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 248 0xf8 'ø' + */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 249 0xf9 'ù' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 250 0xfa 'ú' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 251 0xfb 'û' + */ + 0x0f, /* 00001111 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0xec, /* 11101100 */ + 0x6c, /* 01101100 */ + 0x3c, /* 00111100 */ + 0x1c, /* 00011100 */ + + /* + * 252 0xfc 'ü' + */ + 0x6c, /* 01101100 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 253 0xfd 'ý' + */ + 0x78, /* 01111000 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 254 0xfe 'þ' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x3c, /* 00111100 */ + 0x3c, /* 00111100 */ + 0x3c, /* 00111100 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* + * 255 0xff ' ' + */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + +}; diff --git a/src/sdl2gfx/SDL_rotozoom.c b/src/sdl2gfx/SDL_rotozoom.c new file mode 100644 index 000000000..6313f4008 --- /dev/null +++ b/src/sdl2gfx/SDL_rotozoom.c @@ -0,0 +1,1651 @@ +/* + +SDL2_rotozoom.c: rotozoomer, zoomer and shrinker for 32bit or 8bit surfaces + +Copyright (C) 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 +*/ +Uint32 _colorkey(SDL_Surface *src) +{ + Uint32 key = 0; + SDL_GetColorKey(src, &key); + 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. +*/ +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. +*/ +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. +*/ +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. +*/ +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. +*/ +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. +*/ +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. + +*/ +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; + + /* + * 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 + ); + + SDL_BlitSurface(src, NULL, rz_src, NULL); + + 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; + + /* + * 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); + } 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); + } + /* + * 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; + + /* + * 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); + + } 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); + } + + /* + * 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); + } 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); + } + /* + * 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; + } + } 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; + } + } + +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); +} diff --git a/src/sdl2gfx/SDL_rotozoom.h b/src/sdl2gfx/SDL_rotozoom.h new file mode 100644 index 000000000..f4c236ba4 --- /dev/null +++ b/src/sdl2gfx/SDL_rotozoom.h @@ -0,0 +1,123 @@ +/* + +SDL2_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 _SDL2_rotozoom_h +#define _SDL2_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.1415926535897932384626433832795 +#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(LIBSDL2_GFX_DLL_IMPORT) +# define SDL2_ROTOZOOM_SCOPE __declspec(dllexport) +# else +# ifdef LIBSDL2_GFX_DLL_IMPORT +# define SDL2_ROTOZOOM_SCOPE __declspec(dllimport) +# endif +# endif +#endif +#ifndef SDL2_ROTOZOOM_SCOPE +# define SDL2_ROTOZOOM_SCOPE extern +#endif + + /* + + Rotozoom functions + + */ + + SDL2_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth); + + SDL2_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurfaceXY + (SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth); + + + SDL2_ROTOZOOM_SCOPE void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth, + int *dstheight); + + SDL2_ROTOZOOM_SCOPE void rotozoomSurfaceSizeXY + (int width, int height, double angle, double zoomx, double zoomy, + int *dstwidth, int *dstheight); + + /* + + Zooming functions + + */ + + SDL2_ROTOZOOM_SCOPE SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth); + + SDL2_ROTOZOOM_SCOPE void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight); + + /* + + Shrinking functions + + */ + + SDL2_ROTOZOOM_SCOPE SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory); + + /* + + Specialized rotation functions + + */ + + SDL2_ROTOZOOM_SCOPE SDL_Surface* rotateSurface90Degrees(SDL_Surface* src, int numClockwiseTurns); + + /* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif + +#endif /* _SDL2_rotozoom_h */ |