I can't sleep, so fixing bugs #39
[neverball] / share / image.c
index b5af04d..dad3929 100644 (file)
 
 #include "glext.h"
 #include "image.h"
+#include "base_image.h"
 #include "config.h"
 
 /*---------------------------------------------------------------------------*/
 
-void image_snap(char *filename)
+void image_snap(char *filename, int w, int h)
 {
-    int w = config_get_d(CONFIG_WIDTH);
-    int h = config_get_d(CONFIG_HEIGHT);
     int i;
 
     SDL_Surface *buf = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 24,
@@ -58,106 +57,6 @@ void image_size(int *W, int *H, int w, int h)
 
 /*---------------------------------------------------------------------------*/
 
-void image_swab(SDL_Surface *src)
-{
-    int i, j, b = (src->format->BitsPerPixel == 32) ? 4 : 3;
-    
-    SDL_LockSurface(src);
-    {
-        unsigned char *s = (unsigned char *) src->pixels;
-        unsigned char  t;
-
-        /* Iterate over each pixel of the image. */
-
-        for (i = 0; i < src->h; i++)
-            for (j = 0; j < src->w; j++)
-            {
-                int k = (i * src->w + j) * b;
-
-                /* Swap the red and blue channels of each. */
-
-                t        = s[k + 2];
-                s[k + 2] = s[k + 0];
-                s[k + 0] =        t;
-            }
-    }
-    SDL_UnlockSurface(src);
-}
-
-void image_white(SDL_Surface *src)
-{
-    int i, j, b = (src->format->BitsPerPixel == 32) ? 4 : 3;
-    
-    SDL_LockSurface(src);
-    {
-        unsigned char *s = (unsigned char *) src->pixels;
-
-        /* Iterate over each pixel of the image. */
-
-        for (i = 0; i < src->h; i++)
-            for (j = 0; j < src->w; j++)
-            {
-                int k = (i * src->w + j) * b;
-
-                /* Whiten the RGB channels without touching any Alpha. */
-
-                s[k + 0] = 0xFF;
-                s[k + 1] = 0xFF;
-                s[k + 2] = 0xFF;
-            }
-    }
-    SDL_UnlockSurface(src);
-}
-
-SDL_Surface *image_scale(SDL_Surface *src, int n)
-{
-    int si, di;
-    int sj, dj;
-    int k, b = (src->format->BitsPerPixel == 32) ? 4 : 3;
-
-    SDL_Surface *dst = SDL_CreateRGBSurface(SDL_SWSURFACE,
-                                            src->w / n,
-                                            src->h / n,
-                                            src->format->BitsPerPixel,
-                                            src->format->Rmask,
-                                            src->format->Gmask,
-                                            src->format->Bmask,
-                                            src->format->Amask);
-    if (dst)
-    {
-        SDL_LockSurface(src);
-        SDL_LockSurface(dst);
-        {
-            unsigned char *s = (unsigned char *) src->pixels;
-            unsigned char *d = (unsigned char *) dst->pixels;
-
-            /* Iterate each component of each distination pixel. */
-
-            for (di = 0; di < src->h / n; di++)
-                for (dj = 0; dj < src->w / n; dj++)
-                    for (k = 0; k < b; k++)
-                    {
-                        int c = 0;
-
-                        /* Average the NxN source pixel block for each. */
-
-                        for (si = di * n; si < (di + 1) * n; si++)
-                            for (sj = dj * n; sj < (dj + 1) * n; sj++)
-                                c += s[(si * src->w + sj) * b + k];
-
-                        d[(di * dst->w + dj) * b + k] =
-                            (unsigned char) (c / (n * n));
-                    }
-        }
-        SDL_UnlockSurface(dst);
-        SDL_UnlockSurface(src);
-    }
-
-    return dst;
-}
-
-/*---------------------------------------------------------------------------*/
-
 /*
  * Create on  OpenGL texture  object using the  given SDL  surface and
  * format,  scaled  using the  current  scale  factor.  When  scaling,
@@ -281,7 +180,7 @@ GLuint make_image_from_font(int *W, int *H,
 
     if (text && strlen(text) > 0)
     {
-        if ((src = TTF_RenderText_Blended(font, text, fg)))
+        if ((src = TTF_RenderUTF8_Blended(font, text, fg)))
         {
             int w2;
             int h2;