test/automated/surface/surface.c
author Edgar Simo <bobbens@gmail.com>
Tue, 07 Jul 2009 11:25:56 +0000
branchgsoc2009_unit_tests
changeset 3718 9d71382713b5
parent 3716 ac6bc19a2dfb
child 3719 15373e31daff
permissions -rw-r--r--
Added 3 new tests: loadsurface, blitting, alpha blitting.
Alpha Blitting is not complete as it seems like SDL doesn't work well with alpha blitting yet.
bobbens@3715
     1
/**
bobbens@3715
     2
 * Automated SDL_Surface test.
bobbens@3715
     3
 *
bobbens@3715
     4
 * Written by Edgar Simo "bobbens"
bobbens@3715
     5
 *
bobbens@3715
     6
 * Released under Public Domain.
bobbens@3715
     7
 */
bobbens@3715
     8
bobbens@3715
     9
bobbens@3715
    10
#include "SDL.h"
bobbens@3715
    11
#include "SDL_at.h"
bobbens@3715
    12
bobbens@3715
    13
bobbens@3715
    14
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
bobbens@3715
    15
#  define RMASK   0xff000000 /**< Red bit mask. */
bobbens@3715
    16
#  define GMASK   0x00ff0000 /**< Green bit mask. */
bobbens@3715
    17
#  define BMASK   0x0000ff00 /**< Blue bit mask. */
bobbens@3715
    18
#  define AMASK   0x000000ff /**< Alpha bit mask. */
bobbens@3715
    19
#else
bobbens@3715
    20
#  define RMASK   0x000000ff /**< Red bit mask. */
bobbens@3715
    21
#  define GMASK   0x0000ff00 /**< Green bit mask. */
bobbens@3715
    22
#  define BMASK   0x00ff0000 /**< Blue bit mask. */
bobbens@3715
    23
#  define AMASK   0xff000000 /**< Alpha bit mask. */
bobbens@3715
    24
#endif
bobbens@3715
    25
bobbens@3715
    26
bobbens@3715
    27
typedef struct SurfaceImage_s {
bobbens@3715
    28
   unsigned int  width;
bobbens@3715
    29
   unsigned int  height;
bobbens@3715
    30
   unsigned int  bytes_per_pixel; /* 3:RGB, 4:RGBA */ 
bobbens@3715
    31
   const unsigned char pixel_data[];
bobbens@3715
    32
} SurfaceImage_t;
bobbens@3715
    33
bobbens@3715
    34
bobbens@3715
    35
/*
bobbens@3715
    36
 * Pull in images for testcases.
bobbens@3715
    37
 */
bobbens@3715
    38
#include "primitives.c"
bobbens@3716
    39
#include "blend.c"
bobbens@3718
    40
#include "face.c"
bobbens@3718
    41
#include "blit.c"
bobbens@3715
    42
bobbens@3715
    43
bobbens@3715
    44
/**
bobbens@3715
    45
 * @brief Compares a surface and a surface image for equality.
bobbens@3715
    46
 *
bobbens@3715
    47
 *    @param sur Surface to compare.
bobbens@3715
    48
 *    @param img Image to compare against.
bobbens@3715
    49
 *    @return 0 if they are the same, -1 on error and positive if different.
bobbens@3715
    50
 */
bobbens@3715
    51
static int surface_compare( SDL_Surface *sur, const SurfaceImage_t *img )
bobbens@3715
    52
{
bobbens@3715
    53
   int ret;
bobbens@3715
    54
   int i,j;
bobbens@3715
    55
   Uint32 pix;
bobbens@3715
    56
   int bpp;
bobbens@3715
    57
   Uint8 *p, *pd;
bobbens@3715
    58
bobbens@3715
    59
   /* Make sure size is the same. */
bobbens@3715
    60
   if ((sur->w != img->width) || (sur->h != img->height))
bobbens@3715
    61
      return -1;
bobbens@3715
    62
bobbens@3715
    63
   SDL_LockSurface( sur );
bobbens@3715
    64
bobbens@3715
    65
   ret = 0;
bobbens@3715
    66
   bpp = sur->format->BytesPerPixel;
bobbens@3715
    67
bobbens@3715
    68
   /* Compare image - should be same format. */
bobbens@3715
    69
   for (j=0; j<sur->h; j++) {
bobbens@3715
    70
      for (i=0; i<sur->w; i++) {
bobbens@3715
    71
         p  = (Uint8 *)sur->pixels + j * sur->pitch + i * bpp;
bobbens@3715
    72
         pd = (Uint8 *)img->pixel_data + (j*img->width + i) * img->bytes_per_pixel;
bobbens@3715
    73
         switch (bpp) {
bobbens@3715
    74
            case 1:
bobbens@3715
    75
               /* Paletted not supported atm. */
bobbens@3715
    76
               ret += 1;
bobbens@3715
    77
               break;
bobbens@3715
    78
bobbens@3715
    79
            case 2:
bobbens@3715
    80
               /* 16 BPP not supported atm. */
bobbens@3715
    81
               ret += 1;
bobbens@3715
    82
               break;
bobbens@3715
    83
bobbens@3715
    84
            case 3:
bobbens@3715
    85
               /* 24 BPP not supported atm. */
bobbens@3715
    86
               ret += 1;
bobbens@3715
    87
               break;
bobbens@3715
    88
bobbens@3715
    89
            case 4:
bobbens@3715
    90
               ret += !( (p[0] == pd[0]) &&
bobbens@3715
    91
                         (p[1] == pd[1]) &&
bobbens@3715
    92
                         (p[2] == pd[2]) );
bobbens@3715
    93
               break;
bobbens@3715
    94
         }
bobbens@3715
    95
      }
bobbens@3715
    96
   }
bobbens@3715
    97
  
bobbens@3715
    98
   SDL_UnlockSurface( sur );
bobbens@3715
    99
bobbens@3715
   100
   return ret;
bobbens@3715
   101
}
bobbens@3715
   102
bobbens@3715
   103
bobbens@3715
   104
/**
bobbens@3718
   105
 * @brief Tests sprite loading.
bobbens@3718
   106
 */
bobbens@3718
   107
static void surface_testLoad (void)
bobbens@3718
   108
{
bobbens@3718
   109
   int ret;
bobbens@3718
   110
   SDL_Surface *face, *rface, *testsur;
bobbens@3718
   111
bobbens@3718
   112
   SDL_ATbegin( "Load Test" );
bobbens@3718
   113
bobbens@3718
   114
   /* Create the blit surface. */
bobbens@3718
   115
   face = SDL_LoadBMP("../icon.bmp");
bobbens@3718
   116
   if (SDL_ATassert( "SDL_CreateLoadBmp", face != NULL))
bobbens@3718
   117
      return;
bobbens@3718
   118
bobbens@3718
   119
   /* Set transparent pixel as the pixel at (0,0) */
bobbens@3718
   120
   if (face->format->palette) {
bobbens@3718
   121
      ret = SDL_SetColorKey(face, (SDL_SRCCOLORKEY | SDL_RLEACCEL),
bobbens@3718
   122
            *(Uint8 *) face->pixels);
bobbens@3718
   123
      if (SDL_ATassert( "SDL_SetColorKey", ret == 0))
bobbens@3718
   124
         return;
bobbens@3718
   125
   }
bobbens@3718
   126
bobbens@3718
   127
   /* Create the test surface. */
bobbens@3718
   128
   testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, 
bobbens@3718
   129
         RMASK, GMASK, BMASK, AMASK );
bobbens@3718
   130
   if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
bobbens@3718
   131
      return;
bobbens@3718
   132
bobbens@3718
   133
   /* Convert to 32 bit to compare. */
bobbens@3718
   134
   rface = SDL_ConvertSurface( face, testsur->format, 0 );
bobbens@3718
   135
   if (SDL_ATassert( "SDL_ConvertSurface", rface != NULL))
bobbens@3718
   136
      return;
bobbens@3718
   137
bobbens@3718
   138
   /* See if it's the same. */
bobbens@3718
   139
   if (SDL_ATassert( "Primitives output not the same.",
bobbens@3718
   140
            surface_compare( rface, &img_face)==0 ))
bobbens@3718
   141
      return;
bobbens@3718
   142
bobbens@3718
   143
   /* Clean up. */
bobbens@3718
   144
   SDL_FreeSurface( testsur );
bobbens@3718
   145
   SDL_FreeSurface( rface );
bobbens@3718
   146
   SDL_FreeSurface( face );
bobbens@3718
   147
bobbens@3718
   148
   SDL_ATend();
bobbens@3718
   149
}
bobbens@3718
   150
bobbens@3718
   151
bobbens@3718
   152
/**
bobbens@3715
   153
 * @brief Tests the SDL primitives for rendering.
bobbens@3715
   154
 */
bobbens@3715
   155
static void surface_testPrimitives (void)
bobbens@3715
   156
{
bobbens@3715
   157
   int ret;
bobbens@3715
   158
   int x, y;
bobbens@3715
   159
   SDL_Rect rect;
bobbens@3715
   160
   SDL_Surface *testsur;
bobbens@3715
   161
bobbens@3715
   162
   SDL_ATbegin( "Primitives Test" );
bobbens@3715
   163
bobbens@3715
   164
   /* Create the surface. */
bobbens@3715
   165
   testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, 
bobbens@3715
   166
         RMASK, GMASK, BMASK, AMASK );
bobbens@3715
   167
   if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
bobbens@3715
   168
      return;
bobbens@3715
   169
bobbens@3715
   170
   /* Draw a rectangle. */
bobbens@3715
   171
   rect.x = 40;
bobbens@3715
   172
   rect.y = 0;
bobbens@3715
   173
   rect.w = 40;
bobbens@3715
   174
   rect.h = 80;
bobbens@3715
   175
   ret = SDL_FillRect( testsur, &rect,
bobbens@3715
   176
         SDL_MapRGB( testsur->format, 13, 73, 200 ) );
bobbens@3715
   177
   if (SDL_ATassert( "SDL_FillRect", ret == 0))
bobbens@3715
   178
      return;
bobbens@3715
   179
bobbens@3715
   180
   /* Draw a rectangle. */
bobbens@3715
   181
   rect.x = 10;
bobbens@3715
   182
   rect.y = 10;
bobbens@3715
   183
   rect.w = 60;
bobbens@3715
   184
   rect.h = 40;
bobbens@3715
   185
   ret = SDL_FillRect( testsur, &rect,
bobbens@3715
   186
         SDL_MapRGB( testsur->format, 200, 0, 100 ) );
bobbens@3715
   187
   if (SDL_ATassert( "SDL_FillRect", ret == 0))
bobbens@3715
   188
      return;
bobbens@3715
   189
bobbens@3715
   190
   /* Draw some points like so:
bobbens@3715
   191
    * X.X.X.X..
bobbens@3715
   192
    * .X.X.X.X.
bobbens@3715
   193
    * X.X.X.X.. */
bobbens@3715
   194
   for (y=0; y<3; y++) {
bobbens@3715
   195
      x = y % 2;
bobbens@3715
   196
      for (; x<80; x+=2)
bobbens@3715
   197
         ret = SDL_DrawPoint( testsur, x, y,
bobbens@3715
   198
               SDL_MapRGB( testsur->format, x*y, x*y/2, x*y/3 ) );
bobbens@3715
   199
      if (SDL_ATassert( "SDL_DrawPoint", ret == 0))
bobbens@3715
   200
         return;
bobbens@3715
   201
   }
bobbens@3715
   202
bobbens@3715
   203
   /* Draw some lines. */
bobbens@3715
   204
   ret = SDL_DrawLine( testsur, 0, 30, 80, 30,
bobbens@3715
   205
         SDL_MapRGB( testsur->format, 0, 255, 0 ) );
bobbens@3715
   206
   if (SDL_ATassert( "SDL_DrawLine", ret == 0))
bobbens@3715
   207
      return;
bobbens@3715
   208
   ret = SDL_DrawLine( testsur, 40, 30, 40, 60,
bobbens@3715
   209
         SDL_MapRGB( testsur->format, 55, 55, 5 ) );
bobbens@3715
   210
   if (SDL_ATassert( "SDL_DrawLine", ret == 0))
bobbens@3715
   211
      return;
bobbens@3715
   212
   ret = SDL_DrawLine( testsur, 0, 60, 80, 0,
bobbens@3715
   213
         SDL_MapRGB( testsur->format, 5, 105, 105 ) );
bobbens@3715
   214
   if (SDL_ATassert( "SDL_DrawLine", ret == 0))
bobbens@3715
   215
      return;
bobbens@3715
   216
bobbens@3715
   217
   /* See if it's the same. */
bobbens@3715
   218
   if (SDL_ATassert( "Primitives output not the same.",
bobbens@3715
   219
            surface_compare( testsur, &img_primitives )==0 ))
bobbens@3715
   220
      return;
bobbens@3715
   221
bobbens@3715
   222
   /* Clean up. */
bobbens@3715
   223
   SDL_FreeSurface( testsur );
bobbens@3715
   224
bobbens@3715
   225
   SDL_ATend();
bobbens@3715
   226
}
bobbens@3715
   227
bobbens@3715
   228
bobbens@3715
   229
/**
bobbens@3716
   230
 * @brief Tests the SDL primitives with alpha for rendering.
bobbens@3716
   231
 */
bobbens@3716
   232
static void surface_testPrimitivesAlpha (void)
bobbens@3716
   233
{
bobbens@3716
   234
   int ret;
bobbens@3716
   235
   int i, j;
bobbens@3716
   236
   SDL_Rect rect;
bobbens@3716
   237
   SDL_Surface *testsur;
bobbens@3716
   238
bobbens@3716
   239
   SDL_ATbegin( "Primitives Alpha Test" );
bobbens@3716
   240
bobbens@3716
   241
   /* Create the surface. */
bobbens@3716
   242
   testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, 
bobbens@3716
   243
         RMASK, GMASK, BMASK, AMASK );
bobbens@3718
   244
   if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
bobbens@3718
   245
      return;
bobbens@3716
   246
bobbens@3716
   247
   /* Create some rectangles for each blend mode. */
bobbens@3716
   248
   ret = SDL_BlendRect( testsur, NULL, SDL_BLENDMODE_NONE, 255, 255, 255, 0 );
bobbens@3716
   249
   if (SDL_ATassert( "SDL_BlendRect", ret == 0))
bobbens@3716
   250
      return;
bobbens@3716
   251
   rect.x = 10;
bobbens@3716
   252
   rect.y = 25;
bobbens@3716
   253
   rect.w = 40;
bobbens@3716
   254
   rect.h = 25;
bobbens@3716
   255
   ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_ADD, 240, 10, 10, 75 );
bobbens@3716
   256
   if (SDL_ATassert( "SDL_BlendRect", ret == 0))
bobbens@3716
   257
      return;
bobbens@3716
   258
   rect.x = 30;
bobbens@3716
   259
   rect.y = 40;
bobbens@3716
   260
   rect.w = 45;
bobbens@3716
   261
   rect.h = 15;
bobbens@3716
   262
   ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_BLEND, 10, 240, 10, 100 );
bobbens@3716
   263
   if (SDL_ATassert( "SDL_BlendRect", ret == 0))
bobbens@3716
   264
      return;
bobbens@3716
   265
   rect.x = 25;
bobbens@3716
   266
   rect.y = 25;
bobbens@3716
   267
   rect.w = 25;
bobbens@3716
   268
   rect.h = 25;
bobbens@3716
   269
   ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_MOD, 10, 10, 240, 125 );
bobbens@3716
   270
   if (SDL_ATassert( "SDL_BlendRect", ret == 0))
bobbens@3716
   271
      return;
bobbens@3716
   272
bobbens@3716
   273
   /* Draw blended lines, lines for everyone. */
bobbens@3716
   274
   for (i=0; i<testsur->w; i+=2)  {
bobbens@3716
   275
      ret = SDL_BlendLine( testsur, 0, 0, i, 59,
bobbens@3716
   276
            (((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
bobbens@3716
   277
               (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD,
bobbens@3716
   278
            60+2*j, 240-2*j, 50, 3*j );
bobbens@3716
   279
      if (SDL_ATassert( "SDL_BlendLine", ret == 0))
bobbens@3716
   280
         return;
bobbens@3716
   281
   }
bobbens@3716
   282
   for (i=0; i<testsur->h; i+=2)  {
bobbens@3716
   283
      ret = SDL_BlendLine( testsur, 0, 0, 79, i,
bobbens@3716
   284
            (((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
bobbens@3716
   285
               (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD,
bobbens@3716
   286
            60+2*j, 240-2*j, 50, 3*j );
bobbens@3716
   287
      if (SDL_ATassert( "SDL_BlendLine", ret == 0))
bobbens@3716
   288
         return;
bobbens@3716
   289
   }
bobbens@3716
   290
bobbens@3716
   291
   /* Draw points. */
bobbens@3716
   292
   for (j=0; j<testsur->h; j+=3) {
bobbens@3716
   293
      for (i=0; i<testsur->w; i+=3) {
bobbens@3716
   294
      ret = SDL_BlendPoint( testsur, i, j,
bobbens@3716
   295
            ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND :
bobbens@3716
   296
               ((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD,
bobbens@3716
   297
            j*4, i*3, j*4, i*3 );
bobbens@3716
   298
      if (SDL_ATassert( "SDL_BlendPoint", ret == 0))
bobbens@3716
   299
         return;
bobbens@3716
   300
      }
bobbens@3716
   301
   }
bobbens@3716
   302
bobbens@3716
   303
   /* See if it's the same. */
bobbens@3716
   304
   if (SDL_ATassert( "Primitives output not the same.",
bobbens@3716
   305
            surface_compare( testsur, &img_blend )==0 ))
bobbens@3716
   306
      return;
bobbens@3716
   307
bobbens@3716
   308
   /* Clean up. */
bobbens@3716
   309
   SDL_FreeSurface( testsur );
bobbens@3716
   310
bobbens@3716
   311
   SDL_ATend();
bobbens@3716
   312
}
bobbens@3716
   313
bobbens@3716
   314
bobbens@3716
   315
/**
bobbens@3718
   316
 * @brief Tests some blitting routines.
bobbens@3718
   317
 */
bobbens@3718
   318
static void surface_testBlit (void)
bobbens@3718
   319
{
bobbens@3718
   320
   int ret;
bobbens@3718
   321
   SDL_Rect rect;
bobbens@3718
   322
   SDL_Surface *face, *testsur;
bobbens@3718
   323
   int i, j, ni, nj;
bobbens@3718
   324
   int mode;
bobbens@3718
   325
bobbens@3718
   326
   SDL_ATbegin( "Blit Test" );
bobbens@3718
   327
bobbens@3718
   328
   /* Create the blit surface. */
bobbens@3718
   329
   face = SDL_LoadBMP("../icon.bmp");
bobbens@3718
   330
   if (SDL_ATassert( "SDL_CreateLoadBmp", face != NULL))
bobbens@3718
   331
      return;
bobbens@3718
   332
bobbens@3718
   333
   /* Set transparent pixel as the pixel at (0,0) */
bobbens@3718
   334
   if (face->format->palette)
bobbens@3718
   335
      SDL_SetColorKey(face, (SDL_SRCCOLORKEY | SDL_RLEACCEL),
bobbens@3718
   336
            *(Uint8 *) face->pixels);
bobbens@3718
   337
   /*
bobbens@3718
   338
   face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
bobbens@3718
   339
         img_face.width, img_face.height, 32, img_face.width*4,
bobbens@3718
   340
         RMASK, GMASK, BMASK, AMASK );
bobbens@3718
   341
   if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL))
bobbens@3718
   342
      return;
bobbens@3718
   343
   */
bobbens@3718
   344
bobbens@3718
   345
   /* Create the test surface. */
bobbens@3718
   346
   testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, 
bobbens@3718
   347
         RMASK, GMASK, BMASK, AMASK );
bobbens@3718
   348
   if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
bobbens@3718
   349
      return;
bobbens@3718
   350
bobbens@3718
   351
   /* Steps to take. */
bobbens@3718
   352
   ni = 40;
bobbens@3718
   353
   nj = 30;
bobbens@3718
   354
bobbens@3718
   355
   /* Constant values. */
bobbens@3718
   356
   rect.w = face->w;
bobbens@3718
   357
   rect.h = face->h;
bobbens@3718
   358
bobbens@3718
   359
   /* Loop blit. */
bobbens@3718
   360
   for (j=0; j <= testsur->h - face->h; j+=4) {
bobbens@3718
   361
      for (i=0; i <= testsur->w - face->w; i+=4) {
bobbens@3718
   362
         /* Blitting. */
bobbens@3718
   363
         rect.x = i;
bobbens@3718
   364
         rect.y = j;
bobbens@3718
   365
         ret = SDL_BlitSurface( face, NULL, testsur, &rect );
bobbens@3718
   366
         if (SDL_ATassert( "SDL_BlitSurface", ret == 0))
bobbens@3718
   367
            return;
bobbens@3718
   368
      }
bobbens@3718
   369
   }
bobbens@3718
   370
bobbens@3718
   371
   /* See if it's the same. */
bobbens@3718
   372
   if (SDL_ATassert( "Blitting output not the same.",
bobbens@3718
   373
            surface_compare( testsur, &img_blit )==0 ))
bobbens@3718
   374
      return;
bobbens@3718
   375
bobbens@3718
   376
   /* Clean up. */
bobbens@3718
   377
   SDL_FreeSurface( face );
bobbens@3718
   378
   SDL_FreeSurface( testsur );
bobbens@3718
   379
bobbens@3718
   380
   SDL_ATend();
bobbens@3718
   381
}
bobbens@3718
   382
bobbens@3718
   383
bobbens@3718
   384
/**
bobbens@3718
   385
 * @brief Tests some more blitting routines.
bobbens@3718
   386
 */
bobbens@3718
   387
static void surface_testBlitAlpha (void)
bobbens@3718
   388
{
bobbens@3718
   389
   int ret;
bobbens@3718
   390
   SDL_Rect rect;
bobbens@3718
   391
   SDL_Surface *face, *testsur;
bobbens@3718
   392
   int i, j, ni, nj;
bobbens@3718
   393
   int mode;
bobbens@3718
   394
bobbens@3718
   395
   SDL_ATbegin( "Blit Alpha Test" );
bobbens@3718
   396
bobbens@3718
   397
   /* Create the blit surface. */
bobbens@3718
   398
   face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
bobbens@3718
   399
         img_face.width, img_face.height, 32, img_face.width*4,
bobbens@3718
   400
         RMASK, GMASK, BMASK, AMASK );
bobbens@3718
   401
   if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL))
bobbens@3718
   402
      return;
bobbens@3718
   403
bobbens@3718
   404
   /* Create the test surface. */
bobbens@3718
   405
   testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, 
bobbens@3718
   406
         RMASK, GMASK, BMASK, AMASK );
bobbens@3718
   407
   if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
bobbens@3718
   408
      return;
bobbens@3718
   409
bobbens@3718
   410
   /* Steps to take. */
bobbens@3718
   411
   ni = 40;
bobbens@3718
   412
   nj = 30;
bobbens@3718
   413
bobbens@3718
   414
   /* Constant values. */
bobbens@3718
   415
   rect.w = face->w;
bobbens@3718
   416
   rect.h = face->h;
bobbens@3718
   417
bobbens@3718
   418
   /* Loop blit. */
bobbens@3718
   419
   for (j=0; j <= testsur->h - face->h; j+=4) {
bobbens@3718
   420
      for (i=0; i <= testsur->w - face->w; i+=4) {
bobbens@3718
   421
bobbens@3718
   422
         /* Set colour mod. */
bobbens@3718
   423
         ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j );
bobbens@3718
   424
         if (SDL_ATassert( "SDL_SetSurfaceColorMod", ret == 0))
bobbens@3718
   425
            return;
bobbens@3718
   426
bobbens@3718
   427
         /* Set alpha mod. */
bobbens@3718
   428
         ret = SDL_SetSurfaceAlphaMod( face, (255/ni)*i );
bobbens@3718
   429
         if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0))
bobbens@3718
   430
            return;
bobbens@3718
   431
bobbens@3718
   432
         /* Crazy blending mode magic. */
bobbens@3718
   433
         mode = (i*j)%5;
bobbens@3718
   434
         if      (mode==0) mode = SDL_BLENDMODE_NONE;
bobbens@3718
   435
         else if (mode==1) mode = SDL_BLENDMODE_MASK;
bobbens@3718
   436
         else if (mode==2) mode = SDL_BLENDMODE_BLEND;
bobbens@3718
   437
         else if (mode==3) mode = SDL_BLENDMODE_ADD;
bobbens@3718
   438
         else if (mode==4) mode = SDL_BLENDMODE_MOD;
bobbens@3718
   439
         ret = SDL_SetSurfaceBlendMode( face, mode );
bobbens@3718
   440
         if (SDL_ATassert( "SDL_SetSurfaceBlendMode", ret == 0))
bobbens@3718
   441
            return;
bobbens@3718
   442
bobbens@3718
   443
         /* Blitting. */
bobbens@3718
   444
         rect.x = i;
bobbens@3718
   445
         rect.y = j;
bobbens@3718
   446
         ret = SDL_BlitSurface( face, NULL, testsur, &rect );
bobbens@3718
   447
         if (SDL_ATassert( "SDL_BlitSurface", ret == 0))
bobbens@3718
   448
            return;
bobbens@3718
   449
      }
bobbens@3718
   450
   }
bobbens@3718
   451
bobbens@3718
   452
   SDL_SaveBMP( testsur, "blit.bmp" );
bobbens@3718
   453
bobbens@3718
   454
   /* Clean up. */
bobbens@3718
   455
   SDL_FreeSurface( face );
bobbens@3718
   456
   SDL_FreeSurface( testsur );
bobbens@3718
   457
bobbens@3718
   458
   SDL_ATend();
bobbens@3718
   459
}
bobbens@3718
   460
bobbens@3718
   461
bobbens@3718
   462
/**
bobbens@3715
   463
 * @brief Entry point.
bobbens@3715
   464
 */
bobbens@3715
   465
int main( int argc, const char *argv[] )
bobbens@3715
   466
{
bobbens@3715
   467
   SDL_ATinit( "SDL_Surface" );
bobbens@3715
   468
bobbens@3715
   469
   /* Initializes the SDL subsystems. */
bobbens@3715
   470
   SDL_Init(0);
bobbens@3715
   471
bobbens@3718
   472
   surface_testLoad();
bobbens@3715
   473
   surface_testPrimitives();
bobbens@3716
   474
   surface_testPrimitivesAlpha();
bobbens@3718
   475
   surface_testBlit();
bobbens@3718
   476
   /*surface_testBlitAlpha();*/
bobbens@3715
   477
bobbens@3715
   478
   /* Exit SDL. */
bobbens@3715
   479
   SDL_Quit();
bobbens@3715
   480
bobbens@3715
   481
   return SDL_ATfinish(1);
bobbens@3715
   482
}