src/test/SDL_test_compare.c
changeset 6772 5229a117ef97
parent 6763 9cbd31a3450b
child 6773 5ebc5a9e35b4
     1.1 --- a/src/test/SDL_test_compare.c	Sat Dec 22 20:43:51 2012 -0800
     1.2 +++ b/src/test/SDL_test_compare.c	Mon Dec 24 14:43:57 2012 -0800
     1.3 @@ -42,29 +42,37 @@
     1.4     Uint8 R, G, B, A;
     1.5     Uint8 Rd, Gd, Bd, Ad;
     1.6  
     1.7 -   /* Make surfacee size is the same. */
     1.8 -   if ((surface->w != referenceSurface->w) || (surface->h != referenceSurface->h))
     1.9 -   {
    1.10 +   /* Validate input surfaces */
    1.11 +   if (surface == NULL || referenceSurface == NULL) {
    1.12        return -1;
    1.13     }
    1.14  
    1.15 +   /* Make surface size is the same. */
    1.16 +   if ((surface->w != referenceSurface->w) || (surface->h != referenceSurface->h)) {
    1.17 +      return -2;
    1.18 +   }
    1.19 +
    1.20 +   /* Sanitize input */
    1.21 +   if (allowable_error<0) {
    1.22 +      allowable_error = 0;
    1.23 +   }
    1.24 +   
    1.25     SDL_LockSurface( surface );
    1.26     SDL_LockSurface( referenceSurface );
    1.27  
    1.28     ret = 0;
    1.29     bpp = surface->format->BytesPerPixel;
    1.30     bpp_reference = referenceSurface->format->BytesPerPixel;
    1.31 -
    1.32     /* Compare image - should be same format. */
    1.33     for (j=0; j<surface->h; j++) {
    1.34        for (i=0; i<surface->w; i++) {
    1.35           p  = (Uint8 *)surface->pixels + j * surface->pitch + i * bpp;
    1.36           p_reference = (Uint8 *)referenceSurface->pixels + j * referenceSurface->pitch + i * bpp_reference;
    1.37 -         dist = 0;
    1.38  
    1.39           SDL_GetRGBA(*(Uint32*)p, surface->format, &R, &G, &B, &A);
    1.40           SDL_GetRGBA(*(Uint32*)p_reference, referenceSurface->format, &Rd, &Gd, &Bd, &Ad);
    1.41  
    1.42 +         dist = 0;
    1.43           dist += (R-Rd)*(R-Rd);
    1.44           dist += (G-Gd)*(G-Gd);
    1.45           dist += (B-Bd)*(B-Bd);