Compares a surface and with reference image data for equality.
- Parameters
-
surface | Surface used in comparison |
referenceSurface | Test Surface used in comparison |
allowable_error | Allowable difference (=sum of squared difference for each RGB component) in blending accuracy. |
- Returns
- 0 if comparison succeeded, >0 (=number of pixels for which the comparison failed) if comparison failed, -1 if any of the surfaces were NULL, -2 if the surface sizes differ.
Definition at line 39 of file SDL_test_compare.c.
References _CompareSurfaceCount, SDL_PixelFormat::BytesPerPixel, SDL_Surface::format, G, SDL_Surface::h, i, j, NULL, SDL_Surface::pitch, SDL_Surface::pixels, SDL_GetRGBA, SDL_LockSurface, SDL_SaveBMP, SDL_snprintf, SDL_UnlockSurface, SDLTest_LogError(), and SDL_Surface::w.
Referenced by _compare(), surface_testBlit(), surface_testBlitAlphaMod(), surface_testBlitBlendAdd(), surface_testBlitBlendBlend(), surface_testBlitBlendLoop(), surface_testBlitBlendMod(), surface_testBlitBlendNone(), surface_testBlitColorMod(), surface_testCompleteSurfaceConversion(), and surface_testSurfaceConversion().
43 int bpp, bpp_reference;
46 int sampleErrorX = 0, sampleErrorY = 0, sampleDist = 0;
49 char imageFilename[128];
50 char referenceFilename[128];
53 if (surface ==
NULL || referenceSurface ==
NULL) {
58 if ((surface->
w != referenceSurface->
w) || (surface->
h != referenceSurface->
h)) {
63 if (allowable_error<0) {
74 for (j=0; j<surface->
h; j++) {
75 for (i=0; i<surface->
w; i++) {
77 p_reference = (
Uint8 *)referenceSurface->
pixels + j * referenceSurface->
pitch + i * bpp_reference;
83 dist += (R-Rd)*(R-Rd);
84 dist += (G-Gd)*(G-Gd);
85 dist += (B-Bd)*(B-Bd);
88 if (dist > allowable_error) {
105 SDLTest_LogError(
"Comparison of pixels with allowable error of %i failed %i times.", allowable_error, ret);
106 SDLTest_LogError(
"First detected occurrence at position %i,%i with a squared RGB-difference of %i.", sampleErrorX, sampleErrorY, sampleDist);
111 SDLTest_LogError(
"Surfaces from failed comparison saved as '%s' and '%s'", imageFilename, referenceFilename);
#define SDL_UnlockSurface
#define SDL_SaveBMP(surface, file)
static int _CompareSurfaceCount
void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(1)
Prints given message with a timestamp in the TEST category and the ERROR priority.
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)