diff --git a/SDL_gfx.sln b/SDL_gfx.sln index 3241767..8f520e1 100644 --- a/SDL_gfx.sln +++ b/SDL_gfx.sln @@ -25,6 +25,31 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestFramerate", "Test\TestF {AE22EFD3-6E6D-48C0-AF3D-EF190406BEDC} = {AE22EFD3-6E6D-48C0-AF3D-EF190406BEDC} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestGfxBlit", "Test\TestGfxBlit.vcproj", "{AE22EFD3-6F6D-48C0-AF3D-EF112306BEDC}" + ProjectSection(ProjectDependencies) = postProject + {AE22EFD3-6E6D-48C0-AF3D-EF190406BEDC} = {AE22EFD3-6E6D-48C0-AF3D-EF190406BEDC} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestGfxTexture", "Test\TestGfxTexture.vcproj", "{AE22EFD3-6F6D-32C0-AA3D-EF190406BEDC}" + ProjectSection(ProjectDependencies) = postProject + {AE22EFD3-6E6D-48C0-AF3D-EF190406BEDC} = {AE22EFD3-6E6D-48C0-AF3D-EF190406BEDC} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestImageFilter", "Test\TestImageFilter.vcproj", "{AE22AFD3-6F6D-48C0-AF3D-EF190406AAAA}" + ProjectSection(ProjectDependencies) = postProject + {AE22EFD3-6E6D-48C0-AF3D-EF190406BEDC} = {AE22EFD3-6E6D-48C0-AF3D-EF190406BEDC} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestRotozoom", "Test\TestRotozoom.vcproj", "{AE98EFD3-6F6D-48C0-AF3D-EF560406BEDC}" + ProjectSection(ProjectDependencies) = postProject + {AE22EFD3-6E6D-48C0-AF3D-EF190406BEDC} = {AE22EFD3-6E6D-48C0-AF3D-EF190406BEDC} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestShrink", "Test\TestShrink.vcproj", "{AE22EFD3-6161-48C0-123D-EF190406BEDC}" + ProjectSection(ProjectDependencies) = postProject + {AE22EFD3-6E6D-48C0-AF3D-EF190406BEDC} = {AE22EFD3-6E6D-48C0-AF3D-EF190406BEDC} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -51,6 +76,26 @@ Global {AE22EFD3-6F6D-21C0-AF2D-EF190406BEDC}.Debug|Win32.Build.0 = Debug|Win32 {AE22EFD3-6F6D-21C0-AF2D-EF190406BEDC}.Release|Win32.ActiveCfg = Release|Win32 {AE22EFD3-6F6D-21C0-AF2D-EF190406BEDC}.Release|Win32.Build.0 = Release|Win32 + {AE22EFD3-6F6D-48C0-AF3D-EF112306BEDC}.Debug|Win32.ActiveCfg = Debug|Win32 + {AE22EFD3-6F6D-48C0-AF3D-EF112306BEDC}.Debug|Win32.Build.0 = Debug|Win32 + {AE22EFD3-6F6D-48C0-AF3D-EF112306BEDC}.Release|Win32.ActiveCfg = Release|Win32 + {AE22EFD3-6F6D-48C0-AF3D-EF112306BEDC}.Release|Win32.Build.0 = Release|Win32 + {AE22EFD3-6F6D-32C0-AA3D-EF190406BEDC}.Debug|Win32.ActiveCfg = Debug|Win32 + {AE22EFD3-6F6D-32C0-AA3D-EF190406BEDC}.Debug|Win32.Build.0 = Debug|Win32 + {AE22EFD3-6F6D-32C0-AA3D-EF190406BEDC}.Release|Win32.ActiveCfg = Release|Win32 + {AE22EFD3-6F6D-32C0-AA3D-EF190406BEDC}.Release|Win32.Build.0 = Release|Win32 + {AE22AFD3-6F6D-48C0-AF3D-EF190406AAAA}.Debug|Win32.ActiveCfg = Debug|Win32 + {AE22AFD3-6F6D-48C0-AF3D-EF190406AAAA}.Debug|Win32.Build.0 = Debug|Win32 + {AE22AFD3-6F6D-48C0-AF3D-EF190406AAAA}.Release|Win32.ActiveCfg = Release|Win32 + {AE22AFD3-6F6D-48C0-AF3D-EF190406AAAA}.Release|Win32.Build.0 = Release|Win32 + {AE98EFD3-6F6D-48C0-AF3D-EF560406BEDC}.Debug|Win32.ActiveCfg = Debug|Win32 + {AE98EFD3-6F6D-48C0-AF3D-EF560406BEDC}.Debug|Win32.Build.0 = Debug|Win32 + {AE98EFD3-6F6D-48C0-AF3D-EF560406BEDC}.Release|Win32.ActiveCfg = Release|Win32 + {AE98EFD3-6F6D-48C0-AF3D-EF560406BEDC}.Release|Win32.Build.0 = Release|Win32 + {AE22EFD3-6161-48C0-123D-EF190406BEDC}.Debug|Win32.ActiveCfg = Debug|Win32 + {AE22EFD3-6161-48C0-123D-EF190406BEDC}.Debug|Win32.Build.0 = Debug|Win32 + {AE22EFD3-6161-48C0-123D-EF190406BEDC}.Release|Win32.ActiveCfg = Release|Win32 + {AE22EFD3-6161-48C0-123D-EF190406BEDC}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -60,5 +105,10 @@ Global {AE22EFD3-7F7D-48C0-AF3D-EF190406BEDC} = {0E209CE5-31A3-4039-9437-7F74DC13D8C8} {AE33EFD3-6F6D-48C0-AF3D-EF190406BEDC} = {0E209CE5-31A3-4039-9437-7F74DC13D8C8} {AE22EFD3-6F6D-21C0-AF2D-EF190406BEDC} = {0E209CE5-31A3-4039-9437-7F74DC13D8C8} + {AE22EFD3-6F6D-48C0-AF3D-EF112306BEDC} = {0E209CE5-31A3-4039-9437-7F74DC13D8C8} + {AE22EFD3-6F6D-32C0-AA3D-EF190406BEDC} = {0E209CE5-31A3-4039-9437-7F74DC13D8C8} + {AE22AFD3-6F6D-48C0-AF3D-EF190406AAAA} = {0E209CE5-31A3-4039-9437-7F74DC13D8C8} + {AE98EFD3-6F6D-48C0-AF3D-EF560406BEDC} = {0E209CE5-31A3-4039-9437-7F74DC13D8C8} + {AE22EFD3-6161-48C0-123D-EF190406BEDC} = {0E209CE5-31A3-4039-9437-7F74DC13D8C8} EndGlobalSection EndGlobal diff --git a/SDL_gfx.vcproj b/SDL_gfx.vcproj index 0aef83c..4cc09f9 100644 --- a/SDL_gfx.vcproj +++ b/SDL_gfx.vcproj @@ -42,7 +42,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories=""..\SDL-1.2.14\include"" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;DLL_EXPORT" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;DLL_EXPORT;USE_MMX" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" @@ -91,7 +91,7 @@ /> +#include #endif #include @@ -31,9 +31,16 @@ #include "SDL.h" +#ifdef WIN32 +#include +#include "SDL_framerate.h" +#include "SDL_gfxPrimitives.h" +#include "SDL_gfxBlitFunc.h" +#else #include "SDL/SDL_framerate.h" #include "SDL/SDL_gfxPrimitives.h" #include "SDL/SDL_gfxBlitFunc.h" +#endif void HandleEvent() @@ -41,13 +48,13 @@ void HandleEvent() SDL_Event event; /* Check for events */ - while ( SDL_PollEvent(&event) ) { - switch (event.type) { + while ( SDL_PollEvent(&event) ) { + switch (event.type) { case SDL_KEYDOWN: case SDL_QUIT: - exit(0); - break; - } + exit(0); + break; + } } } @@ -62,12 +69,12 @@ void ClearScreen(SDL_Surface *screen) gray2 = SDL_MapRGB(screen->format, 32, 32, 32); pixels = (Uint8 *)screen->pixels; for ( i=0; ih; ++i ) { - if ((i % 32)<16) { - memset(pixels, gray1, screen->w*screen->format->BytesPerPixel); - } else { - memset(pixels, gray2, screen->w*screen->format->BytesPerPixel); + if ((i % 32)<16) { + memset(pixels, gray1, screen->w*screen->format->BytesPerPixel); + } else { + memset(pixels, gray2, screen->w*screen->format->BytesPerPixel); } - pixels += screen->pitch; + pixels += screen->pitch; } SDL_UnlockSurface(screen); } @@ -76,149 +83,140 @@ void ClearScreen(SDL_Surface *screen) void Draw(SDL_Surface *screen) { - int rate,i,x,y,s; - SDL_Rect dest,clip; - SDL_Surface *texture_image; - SDL_Surface *texture_target1; - SDL_Surface *texture_target2; - FPSmanager fpsm; - Uint32 rmask, gmask, bmask, amask; - - /* Define masks for 32bit surface */ + int rate,x,y,s; + SDL_Rect dest,clip; + SDL_Surface *texture_image; + SDL_Surface *texture_target1; + SDL_Surface *texture_target2; + FPSmanager fpsm; + Uint32 rmask, gmask, bmask, amask; + int width_half = screen->w/2; + int height_half = screen->h/2; + Uint32 text_color = 0xffffffff; + + /* Define masks for 32bit surface */ #if SDL_BYTEORDER == SDL_BIG_ENDIAN - rmask = 0xff000000; - gmask = 0x00ff0000; - bmask = 0x0000ff00; - amask = 0x000000ff; + rmask = 0xff000000; + gmask = 0x00ff0000; + bmask = 0x0000ff00; + amask = 0x000000ff; #else - rmask = 0x000000ff; - gmask = 0x0000ff00; - bmask = 0x00ff0000; - amask = 0xff000000; + rmask = 0x000000ff; + gmask = 0x0000ff00; + bmask = 0x00ff0000; + amask = 0xff000000; #endif - - /* Create semi-transparent textured surface */ - s=64; - texture_image = SDL_DisplayFormatAlpha(SDL_CreateRGBSurface(SDL_SWSURFACE, s, s, 32, rmask, gmask, bmask, amask)); - /* Add some color */ - boxRGBA(texture_image, 0, 0, s/2, s/2, 255, 0, 0, 255); - boxRGBA(texture_image, s/2, 0, s, s/2, 0, 255, 0, 255); - boxRGBA(texture_image, 0, s/2, s/2, s, 0, 0, 255, 255); - boxRGBA(texture_image, s/2, s/2, s, s, 255, 255, 255, 255); - /* Make 75%-transparent */ - SDL_gfxSetAlpha(texture_image, 96); - /* Set alpha channel use to per-pixel blending */ - SDL_SetAlpha(texture_image, SDL_SRCALPHA, 255); - - /* Create an all transparent surface */ - texture_target1 = SDL_DisplayFormatAlpha(SDL_CreateRGBSurface(SDL_SWSURFACE, 256, 256, 32, rmask, gmask, bmask, amask)); - /* Make 75%-transparent */ - SDL_gfxSetAlpha(texture_target1, 64); - /* Set alpha channel use to per-pixel blending */ - SDL_SetAlpha(texture_target1, SDL_SRCALPHA, 255); - - /* Create an all transparent surface (2) */ - texture_target2 = SDL_DisplayFormatAlpha(SDL_CreateRGBSurface(SDL_SWSURFACE, 256, 256, 32, rmask, gmask, bmask, amask)); - /* Make 75%-transparent */ - SDL_gfxSetAlpha(texture_target2, 64); - /* Set alpha channel use to per-pixel blending */ - SDL_SetAlpha(texture_target2, SDL_SRCALPHA, 255); - - /* Define clipping region for left box */ - clip.x = 640/2-256-10 ; - clip.y = 480/2-256/2 ; - clip.w = 256; - clip.h = 256; - - /* Initialize Framerate manager */ - SDL_initFramerate(&fpsm); - - /* Set/switch framerate */ - rate=15; - SDL_setFramerate(&fpsm,rate); - - - /* --- Drawing loop */ - while (1) { - - /* Event handler */ - HandleEvent(); - - /* Black screen */ - ClearScreen(screen); - - /* Random position of new texture */ - x=(rand() % (256+2*s))-s; - y=(rand() % (256+2*s))-s; - - /* Same for comparison texture */ - dest.x = x; - dest.y = y; - dest.w = texture_image->w; - dest.h = texture_image->h; - SDL_BlitSurface(texture_image, NULL, texture_target1, &dest); - - /* Blit image into the target using custom Blit function. */ - dest.x = x; - dest.y = y; - dest.w = texture_image->w; - dest.h = texture_image->h; - SDL_gfxBlitRGBA(texture_image, NULL, texture_target2, &dest); - - /* Draw comparison target on screen (left) */ - dest.x = 640/2-256-10; - dest.y = 480/2-256/2; - dest.w = 256; - dest.h = 256; - SDL_BlitSurface(texture_target1, NULL, screen, &dest); - - /* Draw combiner target on screen (right) */ - dest.x = 640/2+10; - dest.y = 480/2-256/2; - dest.w = 256; - dest.h = 256; - SDL_BlitSurface(texture_target2, NULL, screen, &dest); - - /* Draw some frames with titles */ - rectangleRGBA(screen, 640/2-256-10-1, 480/2-256/2-1, 640/2-256-10-1+257, 480/2-256/2-1+257, 255, 255, 255, 255); - rectangleRGBA(screen, 640/2+10-1, 480/2-256/2-1, 640/2+10-1+257, 480/2-256/2-1+257, 255, 255, 255, 255); - stringRGBA (screen, 640/2-256-10-1, 480/2-256/2-1-24, "Image --sdlBlit--> Target1", 255, 255, 255, 255); - stringRGBA (screen, 640/2-256-10-1, 480/2-256/2-1-12, "Target1 --sdlBlit--> Screen", 255, 255, 255, 255); - stringRGBA (screen, 640/2+10-1, 480/2-256/2-1-24, "Image --gfxBlit--> Target2", 255, 255, 255, 255); - stringRGBA (screen, 640/2+10-1, 480/2-256/2-1-12, "Target2 --sdlBlit--> Screen", 255, 255, 255, 255); - - stringRGBA (screen, 640/2-256-10-1, 480/2-256/2-1-60, "gfxBlitRGBA Demo: target A=64 (25%), image A=96 (37%)", 255, 255, 255, 255); - - /* Display by flipping screens */ - SDL_Flip(screen); - - /* Delay to fix rate */ - SDL_framerateDelay(&fpsm); - } + + /* Create semi-transparent textured surface */ + s=64; + texture_image = SDL_DisplayFormatAlpha(SDL_CreateRGBSurface(SDL_SWSURFACE, s, s, 32, rmask, gmask, bmask, amask)); + /* Add some color */ + boxRGBA(texture_image, 0, 0, s/2, s/2, 255, 0, 0, 255); + boxRGBA(texture_image, s/2, 0, s, s/2, 0, 255, 0, 255); + boxRGBA(texture_image, 0, s/2, s/2, s, 0, 0, 255, 255); + boxRGBA(texture_image, s/2, s/2, s, s, 255, 255, 255, 255); + /* Make 75%-transparent */ + SDL_gfxSetAlpha(texture_image, 96); + /* Set alpha channel use to per-pixel blending */ + SDL_SetAlpha(texture_image, SDL_SRCALPHA, 255); + + /* Create an all transparent surface */ + texture_target1 = SDL_DisplayFormatAlpha(SDL_CreateRGBSurface(SDL_SWSURFACE, 256, 256, 32, rmask, gmask, bmask, amask)); + /* Make 75%-transparent */ + SDL_gfxSetAlpha(texture_target1, 64); + /* Set alpha channel use to per-pixel blending */ + SDL_SetAlpha(texture_target1, SDL_SRCALPHA, 255); + + /* Create an all transparent surface (2) */ + texture_target2 = SDL_DisplayFormatAlpha(SDL_CreateRGBSurface(SDL_SWSURFACE, 256, 256, 32, rmask, gmask, bmask, amask)); + /* Make 75%-transparent */ + SDL_gfxSetAlpha(texture_target2, 64); + /* Set alpha channel use to per-pixel blending */ + SDL_SetAlpha(texture_target2, SDL_SRCALPHA, 255); + + /* Define clipping region for left box */ + clip.x = width_half-256-10 ; + clip.y = height_half-256/2 ; + clip.w = 256; + clip.h = 256; + + /* Initialize Framerate manager */ + SDL_initFramerate(&fpsm); + + /* Set/switch framerate */ + rate=5; + SDL_setFramerate(&fpsm,rate); + + /* --- Drawing loop */ + while (1) { + + /* Event handler */ + HandleEvent(); + + /* Black screen */ + ClearScreen(screen); + + /* Random position of new texture */ + x=(rand() % (256+2*s))-s; + y=(rand() % (256+2*s))-s; + + /* Same for comparison texture */ + dest.x = x; + dest.y = y; + dest.w = texture_image->w; + dest.h = texture_image->h; + SDL_BlitSurface(texture_image, NULL, texture_target1, &dest); + + /* Blit image into the target using custom Blit function. */ + dest.x = x; + dest.y = y; + dest.w = texture_image->w; + dest.h = texture_image->h; + SDL_gfxBlitRGBA(texture_image, NULL, texture_target2, &dest); + + /* Draw comparison target on screen (left) */ + dest.x = width_half-256-10; + dest.y = height_half-256/2; + dest.w = 256; + dest.h = 256; + SDL_BlitSurface(texture_target1, NULL, screen, &dest); + + /* Draw combiner target on screen (right) */ + dest.x = width_half+10; + dest.y = height_half-256/2; + dest.w = 256; + dest.h = 256; + SDL_BlitSurface(texture_target2, NULL, screen, &dest); + + /* Draw some frames with titles */ + rectangleColor(screen, width_half-256-10-1, height_half-256/2-1, width_half-256-10-1+257, height_half-256/2-1+257, text_color); + rectangleColor(screen, width_half+10-1, height_half-256/2-1, width_half+10-1+257, height_half-256/2-1+257, text_color); + stringColor(screen, width_half-256-10-1, height_half-256/2-1-36, " SDL Standard Blitter ", text_color); + stringColor(screen, width_half-256-10-1, height_half-256/2-1-24, "Image --sdlBlit--> Target1", text_color); + stringColor(screen, width_half-256-10-1, height_half-256/2-1-12, "Target1 --sdlBlit--> Screen", text_color); + stringColor(screen, width_half+10-1, height_half-256/2-1-36, " SDL_gfx Compositing Blitter", text_color); + stringColor(screen, width_half+10-1, height_half-256/2-1-24, "Image --gfxBlit--> Target2", text_color); + stringColor(screen, width_half+10-1, height_half-256/2-1-12, "Target2 --sdlBlit--> Screen", text_color); + + stringColor(screen, width_half-256-10-1, height_half-256/2-1-60, "gfxBlitRGBA Demo: Target1/2 A=64 (25%), Image A=96 (37%)", text_color); + + /* Display by flipping screens */ + SDL_Flip(screen); + + /* Delay to fix rate */ + SDL_framerateDelay(&fpsm); + } } -#ifdef WIN32 - extern char ** __argv; - extern int __argc; - int APIENTRY WinMain(HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPSTR lpCmdLine, - int nCmdShow) -#else // non WIN32 - int main ( int argc, char *argv[] ) -#endif +/* ======== */ + +int main(int argc, char *argv[]) { SDL_Surface *screen; int w, h; int desired_bpp; Uint32 video_flags; -#ifdef WIN32 - int argc; - char **argv; - argv = __argv; - argc = __argc; -#endif /* Title */ fprintf (stderr,"gfxBlitRGBA test\n"); @@ -234,47 +232,47 @@ void Draw(SDL_Surface *screen) argc -= 2; } else { fprintf(stderr, - "The -width option requires an argument\n"); - exit(1); - } - } else - if ( strcmp(argv[1], "-height") == 0 ) { - if ( argv[2] && ((h = atoi(argv[2])) > 0) ) { - argv += 2; - argc -= 2; - } else { - fprintf(stderr, - "The -height option requires an argument\n"); - exit(1); - } - } else - if ( strcmp(argv[1], "-bpp") == 0 ) { - if ( argv[2] ) { - desired_bpp = atoi(argv[2]); - argv += 2; - argc -= 2; - } else { - fprintf(stderr, - "The -bpp option requires an argument\n"); + "The -width option requires an argument\n"); exit(1); } } else - if ( strcmp(argv[1], "-warp") == 0 ) { - video_flags |= SDL_HWPALETTE; - argv += 1; - argc -= 1; - } else - if ( strcmp(argv[1], "-hw") == 0 ) { - video_flags |= SDL_HWSURFACE; - argv += 1; - argc -= 1; - } else - if ( strcmp(argv[1], "-fullscreen") == 0 ) { - video_flags |= SDL_FULLSCREEN; - argv += 1; - argc -= 1; - } else - break; + if ( strcmp(argv[1], "-height") == 0 ) { + if ( argv[2] && ((h = atoi(argv[2])) > 0) ) { + argv += 2; + argc -= 2; + } else { + fprintf(stderr, + "The -height option requires an argument\n"); + exit(1); + } + } else + if ( strcmp(argv[1], "-bpp") == 0 ) { + if ( argv[2] ) { + desired_bpp = atoi(argv[2]); + argv += 2; + argc -= 2; + } else { + fprintf(stderr, + "The -bpp option requires an argument\n"); + exit(1); + } + } else + if ( strcmp(argv[1], "-warp") == 0 ) { + video_flags |= SDL_HWPALETTE; + argv += 1; + argc -= 1; + } else + if ( strcmp(argv[1], "-hw") == 0 ) { + video_flags |= SDL_HWSURFACE; + argv += 1; + argc -= 1; + } else + if ( strcmp(argv[1], "-fullscreen") == 0 ) { + video_flags |= SDL_FULLSCREEN; + argv += 1; + argc -= 1; + } else + break; } /* Force double buffering */ @@ -292,16 +290,16 @@ void Draw(SDL_Surface *screen) screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags); if ( screen == NULL ) { fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", - w, h, desired_bpp, SDL_GetError()); + w, h, desired_bpp, SDL_GetError()); exit(1); } /* Show some info */ printf("Set %dx%dx%d mode\n", - screen->w, screen->h, screen->format->BitsPerPixel); + screen->w, screen->h, screen->format->BitsPerPixel); printf("Video surface located in %s memory.\n", - (screen->flags&SDL_HWSURFACE) ? "video" : "system"); - + (screen->flags&SDL_HWSURFACE) ? "video" : "system"); + /* Check for double buffering */ if ( screen->flags & SDL_DOUBLEBUF ) { printf("Double-buffering enabled - good!\n"); @@ -312,6 +310,6 @@ void Draw(SDL_Surface *screen) /* Do all the drawing work */ Draw (screen); - + return(0); } diff --git a/Test/TestGfxTexture.c b/Test/TestGfxTexture.c index 018063f..fd6046a 100644 --- a/Test/TestGfxTexture.c +++ b/Test/TestGfxTexture.c @@ -1,29 +1,25 @@ /* - TestGfxTexture - test program for textured polygon routine +TestGfxTexture - test program for textured polygon routine - Copyright (C) A. Schiffler, December 2006 - (Contributed by Kees Jongenburger) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. +Copyright (C) A. Schiffler, December 2006 +(Contributed by Kees Jongenburger) - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. -*/ +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -#ifdef WIN32 - #include -#endif +*/ #include #include @@ -32,22 +28,27 @@ #include "SDL.h" -#include "SDL/SDL_framerate.h" +#ifdef WIN32 +#include +#include "SDL_gfxPrimitives.h" +#include "SDL_framerate.h" +#else #include "SDL/SDL_gfxPrimitives.h" - +#include "SDL/SDL_framerate.h" +#endif void HandleEvent() { SDL_Event event; /* Check for events */ - while ( SDL_PollEvent(&event) ) { - switch (event.type) { + while ( SDL_PollEvent(&event) ) { + switch (event.type) { case SDL_KEYDOWN: case SDL_QUIT: - exit(0); - break; - } + exit(0); + break; + } } } @@ -69,115 +70,106 @@ void ClearScreen(SDL_Surface *screen) } } +#define NUM_POINTS 150 + void Draw(SDL_Surface *screen) { - int i,rate,x,y,dx,dy; - int psize = 150; - float sin_start = 0; - float sin_amp = 100; - Sint16 polygon_x[psize], polygon_y[psize]; - Sint16 polygon_alpha_x[4], polygon_alpha_y[4]; - SDL_Surface *texture; - SDL_Surface *texture_alpha; - FPSmanager fpsm; - - /* Load texture surfaces */ - texture = SDL_LoadBMP("texture.bmp"); - texture_alpha = SDL_LoadBMP("texture_alpha.bmp"); - SDL_SetAlpha(texture_alpha, SDL_SRCALPHA, 128); - - /* Initialize variables */ - srand(time(NULL)); - i=0; - x=screen->w/2; - y=screen->h/2; - dx=7; - dy=5; - - /* Initialize Framerate manager */ - SDL_initFramerate(&fpsm); - - /* Polygon for blended texture */ - polygon_alpha_x[0]= 0; - polygon_alpha_y[0]= 0; - polygon_alpha_x[1]= screen->w/2 ; - polygon_alpha_y[1]= 0; - polygon_alpha_x[2]= screen->w*2 /3; - polygon_alpha_y[2]= screen->h; - polygon_alpha_x[3]= 0; - polygon_alpha_y[3]= screen->h; - - /* Set/switch framerate */ - rate=25; - SDL_setFramerate(&fpsm,rate); - - /* Drawing loop */ - while (1) { - - /* Generate wave polygon */ - sin_start++; - polygon_x[0]= 0; - polygon_y[0]= screen->h; - polygon_x[1]= 0; - polygon_y[1]= screen->h/2; - for (i=2; i < psize -2 ; i++){ - polygon_x[i]= (screen->w * (i-2)) / (psize -5) ; - polygon_y[i]= sin(sin_start/100) * 200 + screen->h /2 -sin( (i +sin_start) / 20) * sin_amp; - } - - polygon_x[psize-2]= screen->w; - polygon_y[psize-2]= screen->h/2; - polygon_x[psize-1]= screen->w; - polygon_y[psize-1]= screen->h; - - /* Event handler */ - HandleEvent(); - - /* Black screen */ - ClearScreen(screen); - - /* Move */ - x += dx; - y += dy; - - /* Reflect */ - if ((x<0) || (x>screen->w)) { dx=-dx; } - if ((y<0) || (y>screen->h)) { dy=-dy; } - - /* Draw */ - texturedPolygon(screen,polygon_x,polygon_y,psize,texture,-(screen->w * (sin_start-2)) / (psize -5), -sin(sin_start/100) * 200); - texturedPolygon(screen,polygon_alpha_x,polygon_alpha_y,4,texture_alpha,sin_start,-sin_start); - - /* Display by flipping screens */ - SDL_Flip(screen); - - /* Delay to fix rate */ - SDL_framerateDelay(&fpsm); - } + int i,rate,x,y,dx,dy; + int psize = NUM_POINTS; + double sin_start = 0; + double sin_amp = 100; + Sint16 polygon_x[NUM_POINTS], polygon_y[NUM_POINTS]; + Sint16 polygon_alpha_x[4], polygon_alpha_y[4]; + SDL_Surface *texture; + SDL_Surface *texture_alpha; + FPSmanager fpsm; + int width_half = screen->w/2; + int height_half = screen->h/2; + + /* Load texture surfaces */ + texture = SDL_LoadBMP("texture.bmp"); + texture_alpha = SDL_LoadBMP("texture_alpha.bmp"); + SDL_SetAlpha(texture_alpha, SDL_SRCALPHA, 128); + + /* Initialize variables */ + srand((int)time(NULL)); + i=0; + x=width_half; + y=height_half; + dx=7; + dy=5; + + /* Initialize Framerate manager */ + SDL_initFramerate(&fpsm); + + /* Polygon for blended texture */ + polygon_alpha_x[0]= 0; + polygon_alpha_y[0]= 0; + polygon_alpha_x[1]= width_half; + polygon_alpha_y[1]= 0; + polygon_alpha_x[2]= screen->w*2 / 3; + polygon_alpha_y[2]= screen->h; + polygon_alpha_x[3]= 0; + polygon_alpha_y[3]= screen->h; + + /* Set/switch framerate */ + rate=25; + SDL_setFramerate(&fpsm,rate); + + /* Drawing loop */ + while (1) { + + /* Generate wave polygon */ + sin_start++; + polygon_x[0]= 0; + polygon_y[0]= screen->h; + polygon_x[1]= 0; + polygon_y[1]= height_half; + for (i=2; i < psize -2 ; i++){ + polygon_x[i]= (screen->w * (i-2)) / (psize -5) ; + polygon_y[i]= (Sint16)(sin(sin_start/100) * 200) + height_half - (Sint16)(sin((i + sin_start) / 20) * sin_amp); + } + + polygon_x[psize-2]= screen->w; + polygon_y[psize-2]= height_half; + polygon_x[psize-1]= screen->w; + polygon_y[psize-1]= screen->h; + + /* Event handler */ + HandleEvent(); + + /* Black screen */ + ClearScreen(screen); + + /* Move */ + x += dx; + y += dy; + + /* Reflect */ + if ((x<0) || (x>screen->w)) { dx=-dx; } + if ((y<0) || (y>screen->h)) { dy=-dy; } + + /* Draw */ + texturedPolygon(screen,polygon_x,polygon_y,psize,texture, -(screen->w * (Sint16)(sin_start-2)) / (psize - 5), -(Sint16)(sin(sin_start/100) * 200)); + texturedPolygon(screen,polygon_alpha_x,polygon_alpha_y,4,texture_alpha,(Sint16)sin_start,-(Sint16)sin_start); + + /* Display by flipping screens */ + SDL_Flip(screen); + + /* Delay to fix rate */ + SDL_framerateDelay(&fpsm); + } } -#ifdef WIN32 - extern char ** __argv; - extern int __argc; - int APIENTRY WinMain(HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPSTR lpCmdLine, - int nCmdShow) -#else // non WIN32 - int main ( int argc, char *argv[] ) -#endif +/* ======== */ + +int main ( int argc, char *argv[] ) { SDL_Surface *screen; int w, h; int desired_bpp; Uint32 video_flags; -#ifdef WIN32 - int argc; - char **argv; - argv = __argv; - argc = __argc; -#endif /* Title */ fprintf (stderr,"texturedPolygon test\n"); @@ -193,47 +185,47 @@ void Draw(SDL_Surface *screen) argc -= 2; } else { fprintf(stderr, - "The -width option requires an argument\n"); - exit(1); - } - } else - if ( strcmp(argv[1], "-height") == 0 ) { - if ( argv[2] && ((h = atoi(argv[2])) > 0) ) { - argv += 2; - argc -= 2; - } else { - fprintf(stderr, - "The -height option requires an argument\n"); + "The -width option requires an argument\n"); exit(1); } } else - if ( strcmp(argv[1], "-bpp") == 0 ) { - if ( argv[2] ) { - desired_bpp = atoi(argv[2]); - argv += 2; - argc -= 2; - } else { - fprintf(stderr, - "The -bpp option requires an argument\n"); - exit(1); - } - } else - if ( strcmp(argv[1], "-warp") == 0 ) { - video_flags |= SDL_HWPALETTE; - argv += 1; - argc -= 1; - } else - if ( strcmp(argv[1], "-hw") == 0 ) { - video_flags |= SDL_HWSURFACE; - argv += 1; - argc -= 1; - } else - if ( strcmp(argv[1], "-fullscreen") == 0 ) { - video_flags |= SDL_FULLSCREEN; - argv += 1; - argc -= 1; - } else - break; + if ( strcmp(argv[1], "-height") == 0 ) { + if ( argv[2] && ((h = atoi(argv[2])) > 0) ) { + argv += 2; + argc -= 2; + } else { + fprintf(stderr, + "The -height option requires an argument\n"); + exit(1); + } + } else + if ( strcmp(argv[1], "-bpp") == 0 ) { + if ( argv[2] ) { + desired_bpp = atoi(argv[2]); + argv += 2; + argc -= 2; + } else { + fprintf(stderr, + "The -bpp option requires an argument\n"); + exit(1); + } + } else + if ( strcmp(argv[1], "-warp") == 0 ) { + video_flags |= SDL_HWPALETTE; + argv += 1; + argc -= 1; + } else + if ( strcmp(argv[1], "-hw") == 0 ) { + video_flags |= SDL_HWSURFACE; + argv += 1; + argc -= 1; + } else + if ( strcmp(argv[1], "-fullscreen") == 0 ) { + video_flags |= SDL_FULLSCREEN; + argv += 1; + argc -= 1; + } else + break; } /* Force double buffering */ @@ -251,16 +243,16 @@ void Draw(SDL_Surface *screen) screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags); if ( screen == NULL ) { fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", - w, h, desired_bpp, SDL_GetError()); + w, h, desired_bpp, SDL_GetError()); exit(1); } /* Show some info */ printf("Set %dx%dx%d mode\n", - screen->w, screen->h, screen->format->BitsPerPixel); + screen->w, screen->h, screen->format->BitsPerPixel); printf("Video surface located in %s memory.\n", - (screen->flags&SDL_HWSURFACE) ? "video" : "system"); - + (screen->flags&SDL_HWSURFACE) ? "video" : "system"); + /* Check for double buffering */ if ( screen->flags & SDL_DOUBLEBUF ) { printf("Double-buffering enabled - good!\n"); @@ -271,6 +263,6 @@ void Draw(SDL_Surface *screen) /* Do all the drawing work */ Draw (screen); - + return(0); } diff --git a/Test/TestImageFilter.c b/Test/TestImageFilter.c index 1b7c8f6..9a310d5 100644 --- a/Test/TestImageFilter.c +++ b/Test/TestImageFilter.c @@ -1,8 +1,8 @@ /* - TestImageFilter - - Test program for MMX filter routines +TestImageFilter + +Test program for MMX filter routines */ @@ -12,505 +12,527 @@ #include "SDL.h" +#ifdef WIN32 +#include +#include "SDL_imageFilter.h" +#ifndef bcmp +#define bcmp(s1, s2, n) memcmp ((s1), (s2), (n)) +#endif +#else #include "SDL/SDL_imageFilter.h" +#endif + +int total_count = 0; +int ok_count = 0; void setup_src(unsigned char *src1, unsigned char *src2) { - int i; - - src1[0]=1; - src1[2]=1; - src1[1]=4; - src1[3]=3; - src1[4]=33; - for (i=5; i<14; i++) src1[i]=i; - src1[14]=8; - - src2[0]=1; - src2[1]=3; - src2[2]=3; - src2[3]=2; - src2[4]=44; - for (i=5; i<14; i++) src2[i]=14-i; - src2[14]=10; + int i; + + src1[0]=1; + src1[2]=1; + src1[1]=4; + src1[3]=3; + src1[4]=33; + for (i=5; i<14; i++) src1[i]=i; + src1[14]=8; + + src2[0]=1; + src2[1]=3; + src2[2]=3; + src2[3]=2; + src2[4]=44; + for (i=5; i<14; i++) src2[i]=14-i; + src2[14]=10; } void print_result(char *label,unsigned char *src1, unsigned char *src2, unsigned char *dst) { - int i; - char blabel[80]; - - memset((void *)blabel,(int)' ',80); - blabel[strlen(label)]=0; - printf ("%s pos %2d %2d %2d %2d %2d %2d %2d %2d %2d .. %2d\n",blabel,0,1,2,3,4,5,6,7,8,14); - printf ("%s src1 %02x %02x %02x %02x %02x %02x %02x %02x %02x .. %02x\n",blabel,src1[0],src1[1],src1[2],src1[3],src1[4],src1[5],src1[6],src1[7],src1[8],src1[14]); - if (src2) { - printf ("%s src2 %02x %02x %02x %02x %02x %02x %02x %02x %02x .. %02x\n",blabel,src2[0],src2[1],src2[2],src2[3],src2[4],src2[5],src2[6],src2[7],src2[8],src2[14]); - } - printf ("%s dest %02x %02x %02x %02x %02x %02x %02x %02x %02x .. %02x\n",label, dst[0], dst[1], dst[2], dst[3], dst[4], dst[5], dst[6], dst[7], dst[8],dst[14]); - printf ("\n"); + char blabel[80]; + + memset((void *)blabel,(int)' ',80); + blabel[strlen(label)]=0; + printf ("%s pos %2d %2d %2d %2d %2d %2d %2d %2d %2d .. %2d\n",blabel,0,1,2,3,4,5,6,7,8,14); + printf ("%s src1 %02x %02x %02x %02x %02x %02x %02x %02x %02x .. %02x\n",blabel,src1[0],src1[1],src1[2],src1[3],src1[4],src1[5],src1[6],src1[7],src1[8],src1[14]); + if (src2) { + printf ("%s src2 %02x %02x %02x %02x %02x %02x %02x %02x %02x .. %02x\n",blabel,src2[0],src2[1],src2[2],src2[3],src2[4],src2[5],src2[6],src2[7],src2[8],src2[14]); + } + printf ("%s dest %02x %02x %02x %02x %02x %02x %02x %02x %02x .. %02x\n",label, dst[0], dst[1], dst[2], dst[3], dst[4], dst[5], dst[6], dst[7], dst[8],dst[14]); + printf ("\n"); } void print_compare(unsigned char *dst1, unsigned char *dst2) { - if (bcmp(dst1,dst2,15)==0) { - printf ("OK\n"); - } else { - printf ("ERROR\n"); - } + total_count++; + if (bcmp(dst1,dst2,15)==0) { + printf ("OK\n"); + ok_count++; + } else { + printf ("ERROR\n"); + } +} + +void print_line() +{ + printf ("------------------------------------------------------------------------\n\n\n"); } -void print_line() { - printf ("------------------------------------------------------------------------\n\n\n"); +void pause() +{ + char ch; + do { + ch = getchar(); + putchar('.'); + } while (ch != '\n'); } /* ----------- main ---------- */ int main(int argc, char *argv[]) { + unsigned char src1[15],src2[15],dstm[15],dstc[15]; - unsigned char src1[15],src2[15],dstm[15],dstc[15]; - - /* SDL_imageFilter Test */ - - printf ("TestImageFilter\n\n"); - printf ("Testing an array of 15 bytes - first 8 bytes should be processed\n"); - printf ("by MMX or C code, the last 7 bytes only by C code.\n\n"); - - - print_line(); - - SDL_imageFilterMMXon(); - - setup_src(src1, src2); - SDL_imageFilterBitAnd ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); - print_result ("MMX BitAnd", src1, src2, dstm); - - SDL_imageFilterMMXoff(); - - setup_src(src1, src2); - SDL_imageFilterBitAnd ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); - print_result (" C BitAnd", src1, src2, dstc); - - print_compare(dstm,dstc); - print_line(); - - SDL_imageFilterMMXon(); - - setup_src(src1, src2); - SDL_imageFilterBitOr ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); - print_result ("MMX BitOr", src1, src2, dstm); - - SDL_imageFilterMMXoff(); - - setup_src(src1, src2); - SDL_imageFilterBitOr ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); - print_result (" C BitOr", src1, src2, dstc); - - print_compare(dstm,dstc); - print_line(); - - SDL_imageFilterMMXon(); + /* SDL_imageFilter Test */ - setup_src(src1, src2); - SDL_imageFilterAdd ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); - print_result ("MMX Add", src1, src2, dstm); + printf ("TestImageFilter\n\n"); + printf ("Testing an array of 15 bytes - first 8 bytes should be processed\n"); + printf ("by MMX or C code, the last 7 bytes only by C code.\n\n"); - SDL_imageFilterMMXoff(); + print_line(); - setup_src(src1, src2); - SDL_imageFilterAdd ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); - print_result (" C Add", src1, src2, dstc); + SDL_imageFilterMMXon(); + setup_src(src1, src2); + SDL_imageFilterBitAnd ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); + print_result ("MMX BitAnd", src1, src2, dstm); - print_compare(dstm,dstc); - print_line(); + SDL_imageFilterMMXoff(); - SDL_imageFilterMMXon(); + setup_src(src1, src2); + SDL_imageFilterBitAnd ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); + print_result (" C BitAnd", src1, src2, dstc); - setup_src(src1, src2); - SDL_imageFilterAbsDiff ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); - print_result ("MMX AbsDiff", src1, src2, dstm); + print_compare(dstm,dstc); + print_line(); - SDL_imageFilterMMXoff(); + SDL_imageFilterMMXon(); - setup_src(src1, src2); - SDL_imageFilterAbsDiff ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); - print_result (" C AbsDiff", src1, src2, dstc); + setup_src(src1, src2); + SDL_imageFilterBitOr ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); + print_result ("MMX BitOr", src1, src2, dstm); + SDL_imageFilterMMXoff(); - print_compare(dstm,dstc); - print_line(); + setup_src(src1, src2); + SDL_imageFilterBitOr ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); + print_result (" C BitOr", src1, src2, dstc); - SDL_imageFilterMMXon(); + print_compare(dstm,dstc); + print_line(); - setup_src(src1, src2); - SDL_imageFilterMean ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); - print_result ("MMX Mean", src1, src2, dstm); + SDL_imageFilterMMXon(); - SDL_imageFilterMMXoff(); + setup_src(src1, src2); + SDL_imageFilterAdd ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); + print_result ("MMX Add", src1, src2, dstm); - setup_src(src1, src2); - SDL_imageFilterMean ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); - print_result (" C Mean", src1, src2, dstc); + SDL_imageFilterMMXoff(); + setup_src(src1, src2); + SDL_imageFilterAdd ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); + print_result (" C Add", src1, src2, dstc); - print_compare(dstm,dstc); - print_line(); + print_compare(dstm,dstc); + print_line(); - SDL_imageFilterMMXon(); + SDL_imageFilterMMXon(); - setup_src(src1, src2); - SDL_imageFilterSub ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); - print_result ("MMX Sub", src1, src2, dstm); + setup_src(src1, src2); + SDL_imageFilterAbsDiff ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); + print_result ("MMX AbsDiff", src1, src2, dstm); - SDL_imageFilterMMXoff(); + SDL_imageFilterMMXoff(); - setup_src(src1, src2); - SDL_imageFilterSub ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); - print_result (" C Sub", src1, src2, dstc); + setup_src(src1, src2); + SDL_imageFilterAbsDiff ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); + print_result (" C AbsDiff", src1, src2, dstc); + print_compare(dstm,dstc); + print_line(); - print_compare(dstm,dstc); - print_line(); + SDL_imageFilterMMXon(); - SDL_imageFilterMMXon(); + setup_src(src1, src2); + SDL_imageFilterMean ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); + print_result ("MMX Mean", src1, src2, dstm); - setup_src(src1, src2); - SDL_imageFilterMult ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); - print_result ("MMX Mult", src1, src2, dstm); + SDL_imageFilterMMXoff(); - SDL_imageFilterMMXoff(); + setup_src(src1, src2); + SDL_imageFilterMean ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); + print_result (" C Mean", src1, src2, dstc); - setup_src(src1, src2); - SDL_imageFilterMult ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); - print_result (" C Mult", src1, src2, dstc); + print_compare(dstm,dstc); + print_line(); + SDL_imageFilterMMXon(); - print_compare(dstm,dstc); - print_line(); + setup_src(src1, src2); + SDL_imageFilterSub ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); + print_result ("MMX Sub", src1, src2, dstm); - SDL_imageFilterMMXon(); + SDL_imageFilterMMXoff(); - setup_src(src1, src2); - SDL_imageFilterMultNor ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); - print_result ("ASM MultNor", src1, src2, dstm); + setup_src(src1, src2); + SDL_imageFilterSub ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); + print_result (" C Sub", src1, src2, dstc); - SDL_imageFilterMMXoff(); + print_compare(dstm,dstc); + print_line(); - setup_src(src1, src2); - SDL_imageFilterMultNor ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); - print_result (" C MultNor", src1, src2, dstc); + SDL_imageFilterMMXon(); + setup_src(src1, src2); + SDL_imageFilterMult ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); + print_result ("MMX Mult", src1, src2, dstm); - print_compare(dstm,dstc); - print_line(); + SDL_imageFilterMMXoff(); - SDL_imageFilterMMXon(); + setup_src(src1, src2); + SDL_imageFilterMult ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); + print_result (" C Mult", src1, src2, dstc); - setup_src(src1, src2); - SDL_imageFilterMultDivby2 ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); - print_result ("MMX MultDivby2", src1, src2, dstm); + print_compare(dstm,dstc); + print_line(); - SDL_imageFilterMMXoff(); + SDL_imageFilterMMXon(); - setup_src(src1, src2); - SDL_imageFilterMultDivby2 ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); - print_result (" C MultDivby2", src1, src2, dstc); + setup_src(src1, src2); + SDL_imageFilterMultNor ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); + print_result ("ASM MultNor", src1, src2, dstm); + SDL_imageFilterMMXoff(); - print_compare(dstm,dstc); - print_line(); + setup_src(src1, src2); + SDL_imageFilterMultNor ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); + print_result (" C MultNor", src1, src2, dstc); - SDL_imageFilterMMXon(); + print_compare(dstm,dstc); + print_line(); - setup_src(src1, src2); - SDL_imageFilterMultDivby4 ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); - print_result ("MMX MultDivby4", src1, src2, dstm); + SDL_imageFilterMMXon(); - SDL_imageFilterMMXoff(); + setup_src(src1, src2); + SDL_imageFilterMultDivby2 ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); + print_result ("MMX MultDivby2", src1, src2, dstm); - setup_src(src1, src2); - SDL_imageFilterMultDivby4 ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); - print_result (" C MultDivby4", src1, src2, dstc); + SDL_imageFilterMMXoff(); + setup_src(src1, src2); + SDL_imageFilterMultDivby2 ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); + print_result (" C MultDivby2", src1, src2, dstc); - print_compare(dstm,dstc); - print_line(); - - SDL_imageFilterMMXon(); + print_compare(dstm,dstc); + print_line(); - setup_src(src1, src2); - SDL_imageFilterDiv ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); - print_result ("ASM Div", src1, src2, dstm); + SDL_imageFilterMMXon(); - SDL_imageFilterMMXoff(); + setup_src(src1, src2); + SDL_imageFilterMultDivby4 ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); + print_result ("MMX MultDivby4", src1, src2, dstm); - setup_src(src1, src2); - SDL_imageFilterDiv ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); - print_result (" C Div", src1, src2, dstc); + SDL_imageFilterMMXoff(); + setup_src(src1, src2); + SDL_imageFilterMultDivby4 ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); + print_result (" C MultDivby4", src1, src2, dstc); - print_compare(dstm,dstc); - print_line(); + print_compare(dstm,dstc); + print_line(); - SDL_imageFilterMMXon(); + SDL_imageFilterMMXon(); - setup_src(src1, src2); - SDL_imageFilterBitNegation ((unsigned char *)src1,(unsigned char *)dstm,15); - print_result ("MMX BitNegation", src1, NULL, dstm); + setup_src(src1, src2); + SDL_imageFilterDiv ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstm,15); + print_result ("ASM Div", src1, src2, dstm); - SDL_imageFilterMMXoff(); + SDL_imageFilterMMXoff(); - setup_src(src1, src2); - SDL_imageFilterBitNegation ((unsigned char *)src1,(unsigned char *)dstc,15); - print_result (" C BitNegation", src1, NULL, dstc); + setup_src(src1, src2); + SDL_imageFilterDiv ((unsigned char *)src1,(unsigned char *)src2,(unsigned char *)dstc,15); + print_result (" C Div", src1, src2, dstc); + print_compare(dstm,dstc); + print_line(); - print_compare(dstm,dstc); - print_line(); + SDL_imageFilterMMXon(); - SDL_imageFilterMMXon(); + setup_src(src1, src2); + SDL_imageFilterBitNegation ((unsigned char *)src1,(unsigned char *)dstm,15); + print_result ("MMX BitNegation", src1, NULL, dstm); - setup_src(src1, src2); - SDL_imageFilterAddByte ((unsigned char *)src1,(unsigned char *)dstm,15, 3); - print_result ("MMX AddByte(3)", src1, NULL, dstm); + SDL_imageFilterMMXoff(); - SDL_imageFilterMMXoff(); + setup_src(src1, src2); + SDL_imageFilterBitNegation ((unsigned char *)src1,(unsigned char *)dstc,15); + print_result (" C BitNegation", src1, NULL, dstc); - setup_src(src1, src2); - SDL_imageFilterAddByte ((unsigned char *)src1,(unsigned char *)dstc,15, 3); - print_result (" C AddByte(3)", src1, NULL, dstc); + print_compare(dstm,dstc); + print_line(); + SDL_imageFilterMMXon(); - print_compare(dstm,dstc); - print_line(); + setup_src(src1, src2); + SDL_imageFilterAddByte ((unsigned char *)src1,(unsigned char *)dstm,15, 3); + print_result ("MMX AddByte(3)", src1, NULL, dstm); - SDL_imageFilterMMXon(); + SDL_imageFilterMMXoff(); - setup_src(src1, src2); - SDL_imageFilterAddByteToHalf ((unsigned char *)src1,(unsigned char *)dstm,15, 3); - print_result ("MMX AddByteToHalf(3)", src1, NULL, dstm); + setup_src(src1, src2); + SDL_imageFilterAddByte ((unsigned char *)src1,(unsigned char *)dstc,15, 3); + print_result (" C AddByte(3)", src1, NULL, dstc); - SDL_imageFilterMMXoff(); + print_compare(dstm,dstc); + print_line(); - setup_src(src1, src2); - SDL_imageFilterAddByteToHalf ((unsigned char *)src1,(unsigned char *)dstc,15, 3); - print_result (" C AddByteToHalf(3)", src1, NULL, dstc); + SDL_imageFilterMMXon(); + setup_src(src1, src2); + SDL_imageFilterAddByteToHalf ((unsigned char *)src1,(unsigned char *)dstm,15, 3); + print_result ("MMX AddByteToHalf(3)", src1, NULL, dstm); - print_compare(dstm,dstc); - print_line(); + SDL_imageFilterMMXoff(); - SDL_imageFilterMMXon(); + setup_src(src1, src2); + SDL_imageFilterAddByteToHalf ((unsigned char *)src1,(unsigned char *)dstc,15, 3); + print_result (" C AddByteToHalf(3)", src1, NULL, dstc); - setup_src(src1, src2); - SDL_imageFilterSubByte ((unsigned char *)src1,(unsigned char *)dstm,15, 3); - print_result ("MMX SubByte(3)", src1, NULL, dstm); + print_compare(dstm,dstc); + print_line(); - SDL_imageFilterMMXoff(); + SDL_imageFilterMMXon(); - setup_src(src1, src2); - SDL_imageFilterSubByte ((unsigned char *)src1,(unsigned char *)dstc,15, 3); - print_result (" C SubByte(3)", src1, NULL, dstc); + setup_src(src1, src2); + SDL_imageFilterSubByte ((unsigned char *)src1,(unsigned char *)dstm,15, 3); + print_result ("MMX SubByte(3)", src1, NULL, dstm); + SDL_imageFilterMMXoff(); - print_compare(dstm,dstc); - print_line(); + setup_src(src1, src2); + SDL_imageFilterSubByte ((unsigned char *)src1,(unsigned char *)dstc,15, 3); + print_result (" C SubByte(3)", src1, NULL, dstc); - SDL_imageFilterMMXon(); + print_compare(dstm,dstc); + print_line(); - setup_src(src1, src2); - SDL_imageFilterShiftRight ((unsigned char *)src1,(unsigned char *)dstm,15, 1); - print_result ("MMX ShiftRight(1)", src1, NULL, dstm); + SDL_imageFilterMMXon(); - SDL_imageFilterMMXoff(); + setup_src(src1, src2); + SDL_imageFilterShiftRight ((unsigned char *)src1,(unsigned char *)dstm,15, 1); + print_result ("MMX ShiftRight(1)", src1, NULL, dstm); - setup_src(src1, src2); - SDL_imageFilterShiftRight ((unsigned char *)src1,(unsigned char *)dstc,15, 1); - print_result (" C ShiftRight(1)", src1, NULL, dstc); + SDL_imageFilterMMXoff(); - print_compare(dstm,dstc); - print_line(); + setup_src(src1, src2); + SDL_imageFilterShiftRight ((unsigned char *)src1,(unsigned char *)dstc,15, 1); + print_result (" C ShiftRight(1)", src1, NULL, dstc); - SDL_imageFilterMMXon(); + print_compare(dstm,dstc); + print_line(); - setup_src(src1, src2); - SDL_imageFilterMultByByte ((unsigned char *)src1,(unsigned char *)dstm,15, 3); - print_result ("MMX MultByByte(3)", src1, NULL, dstm); + SDL_imageFilterMMXon(); - SDL_imageFilterMMXoff(); + setup_src(src1, src2); + SDL_imageFilterMultByByte ((unsigned char *)src1,(unsigned char *)dstm,15, 3); + print_result ("MMX MultByByte(3)", src1, NULL, dstm); - setup_src(src1, src2); - SDL_imageFilterMultByByte ((unsigned char *)src1,(unsigned char *)dstc,15, 3); - print_result (" C MultByByte(3)", src1, NULL, dstc); + SDL_imageFilterMMXoff(); + setup_src(src1, src2); + SDL_imageFilterMultByByte ((unsigned char *)src1,(unsigned char *)dstc,15, 3); + print_result (" C MultByByte(3)", src1, NULL, dstc); - print_compare(dstm,dstc); - print_line(); + print_compare(dstm,dstc); + print_line(); - SDL_imageFilterMMXon(); + SDL_imageFilterMMXon(); - setup_src(src1, src2); - SDL_imageFilterShiftRightAndMultByByte ((unsigned char *)src1,(unsigned char *)dstm,15, 1, 3); - print_result ("MMX ShiftRightAndMultByByte(1,3)", src1, NULL, dstm); + setup_src(src1, src2); + SDL_imageFilterShiftRightAndMultByByte ((unsigned char *)src1,(unsigned char *)dstm,15, 1, 3); + print_result ("MMX ShiftRightAndMultByByte(1,3)", src1, NULL, dstm); - SDL_imageFilterMMXoff(); + SDL_imageFilterMMXoff(); - setup_src(src1, src2); - SDL_imageFilterShiftRightAndMultByByte ((unsigned char *)src1,(unsigned char *)dstc,15, 1, 3); - print_result (" C ShuftRightAndMultByByte(1,3)", src1, NULL, dstc); + setup_src(src1, src2); + SDL_imageFilterShiftRightAndMultByByte ((unsigned char *)src1,(unsigned char *)dstc,15, 1, 3); + print_result (" C ShuftRightAndMultByByte(1,3)", src1, NULL, dstc); + print_compare(dstm,dstc); + print_line(); - print_compare(dstm,dstc); - print_line(); + SDL_imageFilterMMXon(); - SDL_imageFilterMMXon(); + setup_src(src1, src2); + SDL_imageFilterShiftLeftByte ((unsigned char *)src1,(unsigned char *)dstm,15, 3); + print_result ("MMX ShiftLeftByte(3)", src1, NULL, dstm); - setup_src(src1, src2); - SDL_imageFilterShiftLeftByte ((unsigned char *)src1,(unsigned char *)dstm,15, 3); - print_result ("MMX ShiftLeftByte(3)", src1, NULL, dstm); + SDL_imageFilterMMXoff(); - SDL_imageFilterMMXoff(); + setup_src(src1, src2); + SDL_imageFilterShiftLeftByte ((unsigned char *)src1,(unsigned char *)dstc,15, 3); + print_result (" C ShiftLeftByte(3)", src1, NULL, dstc); - setup_src(src1, src2); - SDL_imageFilterShiftLeftByte ((unsigned char *)src1,(unsigned char *)dstc,15, 3); - print_result (" C ShiftLeftByte(3)", src1, NULL, dstc); + print_compare(dstm,dstc); + print_line(); + SDL_imageFilterMMXon(); - print_compare(dstm,dstc); - print_line(); + setup_src(src1, src2); + SDL_imageFilterShiftLeft ((unsigned char *)src1,(unsigned char *)dstm,15, 3); + print_result ("MMX ShiftLeft(3)", src1, NULL, dstm); - SDL_imageFilterMMXon(); + SDL_imageFilterMMXoff(); - setup_src(src1, src2); - SDL_imageFilterShiftLeft ((unsigned char *)src1,(unsigned char *)dstm,15, 3); - print_result ("MMX ShiftLeft(3)", src1, NULL, dstm); + setup_src(src1, src2); + SDL_imageFilterShiftLeft ((unsigned char *)src1,(unsigned char *)dstc,15, 3); + print_result (" C ShiftLeft(3)", src1, NULL, dstc); - SDL_imageFilterMMXoff(); + print_compare(dstm,dstc); + print_line(); - setup_src(src1, src2); - SDL_imageFilterShiftLeft ((unsigned char *)src1,(unsigned char *)dstc,15, 3); - print_result (" C ShiftLeft(3)", src1, NULL, dstc); + SDL_imageFilterMMXon(); + setup_src(src1, src2); + SDL_imageFilterBinarizeUsingThreshold ((unsigned char *)src1,(unsigned char *)dstm,15, 2); + print_result ("MMX BinarizeUsingThreshold(2)", src1, NULL, dstm); - print_compare(dstm,dstc); - print_line(); + SDL_imageFilterMMXoff(); - SDL_imageFilterMMXon(); + setup_src(src1, src2); + SDL_imageFilterBinarizeUsingThreshold ((unsigned char *)src1,(unsigned char *)dstc,15, 2); + print_result (" C BinarizeUsingThreshold(2)", src1, NULL, dstc); - setup_src(src1, src2); - SDL_imageFilterBinarizeUsingThreshold ((unsigned char *)src1,(unsigned char *)dstm,15, 2); - print_result ("MMX BinarizeUsingThreshold(2)", src1, NULL, dstm); + print_compare(dstm,dstc); + print_line(); - SDL_imageFilterMMXoff(); + SDL_imageFilterMMXon(); - setup_src(src1, src2); - SDL_imageFilterBinarizeUsingThreshold ((unsigned char *)src1,(unsigned char *)dstc,15, 2); - print_result (" C BinarizeUsingThreshold(2)", src1, NULL, dstc); + setup_src(src1, src2); + SDL_imageFilterClipToRange ((unsigned char *)src1,(unsigned char *)dstm,15, 1,7); + print_result ("MMX ClipToRange(1,7)", src1, NULL, dstm); + SDL_imageFilterMMXoff(); - print_compare(dstm,dstc); - print_line(); + setup_src(src1, src2); + SDL_imageFilterClipToRange ((unsigned char *)src1,(unsigned char *)dstc,15, 1,7); + print_result (" C ClipToRange(1,7)", src1, NULL, dstc); - SDL_imageFilterMMXon(); + print_compare(dstm,dstc); + print_line(); - setup_src(src1, src2); - SDL_imageFilterClipToRange ((unsigned char *)src1,(unsigned char *)dstm,15, 1,7); - print_result ("MMX ClipToRange(1,7)", src1, NULL, dstm); + SDL_imageFilterMMXon(); - SDL_imageFilterMMXoff(); + setup_src(src1, src2); + SDL_imageFilterNormalizeLinear ((unsigned char *)src1,(unsigned char *)dstm,15, 0,33,0,255); + print_result ("MMX NormalizeLinear(0,33,0,255)", src1, NULL, dstm); - setup_src(src1, src2); - SDL_imageFilterClipToRange ((unsigned char *)src1,(unsigned char *)dstc,15, 1,7); - print_result (" C ClipToRange(1,7)", src1, NULL, dstc); + SDL_imageFilterMMXoff(); + setup_src(src1, src2); + SDL_imageFilterNormalizeLinear ((unsigned char *)src1,(unsigned char *)dstc,15, 0,33,0,255); + print_result (" C NormalizeLinear(0,33,0,255)", src1, NULL, dstc); - print_compare(dstm,dstc); - print_line(); + print_compare(dstm,dstc); + print_line(); - SDL_imageFilterMMXon(); + /* Uint functions */ - setup_src(src1, src2); - SDL_imageFilterNormalizeLinear ((unsigned char *)src1,(unsigned char *)dstm,15, 0,33,0,255); - print_result ("MMX NormalizeLinear(0,33,0,255)", src1, NULL, dstm); + /* Disabled, since broken */ + /* - SDL_imageFilterMMXoff(); + SDL_imageFilterMMXon(); - setup_src(src1, src2); - SDL_imageFilterNormalizeLinear ((unsigned char *)src1,(unsigned char *)dstc,15, 0,33,0,255); - print_result (" C NormalizeLinear(0,33,0,255)", src1, NULL, dstc); + setup_src(src1, src2); + SDL_imageFilterAddUint ((unsigned char *)src1,(unsigned char *)dstm,15, 0x01020304); + print_result ("MMX AddUint(0x01020304)", src1, NULL, dstm); - print_compare(dstm,dstc); - print_line(); + SDL_imageFilterMMXoff(); - /* Uint functions */ + setup_src(src1, src2); + SDL_imageFilterAddUint ((unsigned char *)src1,(unsigned char *)dstc,15, 0x01020304); + print_result (" C AddUint(0x01020304)", src1, NULL, dstc); - /* Disabled, since broken */ - /* + print_compare(dstm,dstc); + print_line(); - SDL_imageFilterMMXon(); + SDL_imageFilterMMXon(); - setup_src(src1, src2); - SDL_imageFilterAddUint ((unsigned char *)src1,(unsigned char *)dstm,15, 0x01020304); - print_result ("MMX AddUint(0x01020304)", src1, NULL, dstm); + setup_src(src1, src2); + SDL_imageFilterSubUint ((unsigned char *)src1,(unsigned char *)dstm,15, 0x01020304); + print_result ("MMX SubUint(0x01020304)", src1, NULL, dstm); - SDL_imageFilterMMXoff(); + SDL_imageFilterMMXoff(); - setup_src(src1, src2); - SDL_imageFilterAddUint ((unsigned char *)src1,(unsigned char *)dstc,15, 0x01020304); - print_result (" C AddUint(0x01020304)", src1, NULL, dstc); + setup_src(src1, src2); + SDL_imageFilterSubUint ((unsigned char *)src1,(unsigned char *)dstc,15, 0x01020304); + print_result (" C SubUint(0x01020304)", src1, NULL, dstc); - print_compare(dstm,dstc); - print_line(); + print_compare(dstm,dstc); + print_line(); - SDL_imageFilterMMXon(); + SDL_imageFilterMMXon(); - setup_src(src1, src2); - SDL_imageFilterSubUint ((unsigned char *)src1,(unsigned char *)dstm,15, 0x01020304); - print_result ("MMX SubUint(0x01020304)", src1, NULL, dstm); + setup_src(src1, src2); + SDL_imageFilterShiftRightUint ((unsigned char *)src1,(unsigned char *)dstm,15, 4); + print_result ("MMX ShiftRightUint(4)", src1, NULL, dstm); - SDL_imageFilterMMXoff(); + SDL_imageFilterMMXoff(); - setup_src(src1, src2); - SDL_imageFilterSubUint ((unsigned char *)src1,(unsigned char *)dstc,15, 0x01020304); - print_result (" C SubUint(0x01020304)", src1, NULL, dstc); + setup_src(src1, src2); + SDL_imageFilterShiftRightUint ((unsigned char *)src1,(unsigned char *)dstc,15, 4); + print_result (" C ShiftRightUint(4)", src1, NULL, dstc); - print_compare(dstm,dstc); - print_line(); + print_compare(dstm,dstc); + print_line(); - SDL_imageFilterMMXon(); + SDL_imageFilterMMXon(); - setup_src(src1, src2); - SDL_imageFilterShiftRightUint ((unsigned char *)src1,(unsigned char *)dstm,15, 4); - print_result ("MMX ShiftRightUint(4)", src1, NULL, dstm); + setup_src(src1, src2); + SDL_imageFilterShiftLeftUint ((unsigned char *)src1,(unsigned char *)dstm,15, 4); + print_result ("MMX ShiftLeftUint(4)", src1, NULL, dstm); - SDL_imageFilterMMXoff(); + SDL_imageFilterMMXoff(); - setup_src(src1, src2); - SDL_imageFilterShiftRightUint ((unsigned char *)src1,(unsigned char *)dstc,15, 4); - print_result (" C ShiftRightUint(4)", src1, NULL, dstc); + setup_src(src1, src2); + SDL_imageFilterShiftLeftUint ((unsigned char *)src1,(unsigned char *)dstc,15, 4); + print_result (" C ShiftLeftUint(4)", src1, NULL, dstc); - print_compare(dstm,dstc); - print_line(); + print_compare(dstm,dstc); + print_line(); - SDL_imageFilterMMXon(); + */ - setup_src(src1, src2); - SDL_imageFilterShiftLeftUint ((unsigned char *)src1,(unsigned char *)dstm,15, 4); - print_result ("MMX ShiftLeftUint(4)", src1, NULL, dstm); +#ifdef USE_MMX + SDL_imageFilterMMXon(); + if (SDL_imageFilterMMXdetect()) + { + printf("MMX was detected\n\n"); + } + else + { + printf("MMX was NOT detected\n\n"); + } +#else + printf("MMX support disabled in SDL_gfx.\n\n"); +#endif - SDL_imageFilterMMXoff(); + printf ("Result: %i of %i passed OK.\n", ok_count, total_count); - setup_src(src1, src2); - SDL_imageFilterShiftLeftUint ((unsigned char *)src1,(unsigned char *)dstc,15, 4); - print_result (" C ShiftLeftUint(4)", src1, NULL, dstc); +#ifdef WIN32 + printf("Press Enter to continue ..."); + pause(); +#endif - print_compare(dstm,dstc); - print_line(); - - */ - - exit(0); + exit(0); } diff --git a/Test/TestRotozoom.c b/Test/TestRotozoom.c index 5bb781f..fdd8293 100644 --- a/Test/TestRotozoom.c +++ b/Test/TestRotozoom.c @@ -1,16 +1,12 @@ /* - TestRotozoom - - Test program for rotozoom routines +TestRotozoom - Copyright (C) A. Schiffler, July 2001-2009, GPL +Test program for rotozoom routines -*/ +Copyright (C) A. Schiffler, July 2001-2009, GPL -#ifdef WIN32 - #include -#endif +*/ #include #include @@ -18,12 +14,17 @@ #include "SDL.h" +#ifdef WIN32 +#include +#include "SDL_rotozoom.h" +#else #include "SDL/SDL_rotozoom.h" +#endif /* Custom rotation setup */ -float custom_angle=0.0; -float custom_fx=1.0; -float custom_fy=1.0; +double custom_angle=0.0; +double custom_fx=1.0; +double custom_fy=1.0; int custom_smooth=0; /* Delay between frames */ @@ -34,13 +35,13 @@ void HandleEvent() SDL_Event event; /* Check for events */ - while ( SDL_PollEvent(&event) ) { - switch (event.type) { + while ( SDL_PollEvent(&event) ) { + switch (event.type) { case SDL_KEYDOWN: case SDL_QUIT: - exit(0); - break; - } + exit(0); + break; + } } } @@ -65,7 +66,7 @@ void RotatePicture (SDL_Surface *screen, SDL_Surface *picture, int rotate, int f SDL_Surface *rotozoom_picture; SDL_Rect dest; int framecount, framemax, frameinc; - float angle, zoomf, zoomfx, zoomfy; + double angle, zoomf, zoomfx, zoomfy; /* Rotate and display the picture */ framemax=4*360; frameinc=1; @@ -73,96 +74,96 @@ void RotatePicture (SDL_Surface *screen, SDL_Surface *picture, int rotate, int f if ((framecount % 360)==0) frameinc++; HandleEvent(); ClearScreen(screen); - zoomf=(float)(framecount+2*360)/(float)framemax; - zoomf=1.5*zoomf*zoomf; - /* Are we in flipping mode? */ + zoomf=(float)(framecount+2*360)/(float)framemax; + zoomf=1.5*zoomf*zoomf; + /* Are we in flipping mode? */ if (flip) { - /* Flip X factor */ - if (flip & 1) { - zoomfx=-zoomf; - } else { - zoomfx=zoomf; - } - /* Flip Y factor */ - if (flip & 2) { - zoomfy=-zoomf; - } else { - zoomfy=zoomf; - } - angle=framecount*rotate; - if (((framecount % 120)==0) || (delay>0)) { - printf (" Frame: %i Rotate: angle=%.2f Zoom: x=%.2f y=%.2f\n",framecount,angle,zoomfx,zoomfy); - } - if ((rotozoom_picture=rotozoomSurfaceXY (picture, angle, zoomfx, zoomfy, smooth))!=NULL) { - dest.x = (screen->w - rotozoom_picture->w)/2;; - dest.y = (screen->h - rotozoom_picture->h)/2; - dest.w = rotozoom_picture->w; - dest.h = rotozoom_picture->h; - if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { - fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); - break; + /* Flip X factor */ + if (flip & 1) { + zoomfx=-zoomf; + } else { + zoomfx=zoomf; } - SDL_FreeSurface(rotozoom_picture); + /* Flip Y factor */ + if (flip & 2) { + zoomfy=-zoomf; + } else { + zoomfy=zoomf; + } + angle=framecount*rotate; + if (((framecount % 120)==0) || (delay>0)) { + printf (" Frame: %i Rotate: angle=%.2f Zoom: x=%.2f y=%.2f\n",framecount,angle,zoomfx,zoomfy); + } + if ((rotozoom_picture=rotozoomSurfaceXY (picture, angle, zoomfx, zoomfy, smooth))!=NULL) { + dest.x = (screen->w - rotozoom_picture->w)/2;; + dest.y = (screen->h - rotozoom_picture->h)/2; + dest.w = rotozoom_picture->w; + dest.h = rotozoom_picture->h; + if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { + fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); + break; + } + SDL_FreeSurface(rotozoom_picture); } } else { - angle=framecount*rotate; - if ((framecount % 120)==0) { - printf (" Frame: %i Rotate: angle=%.2f Zoom: f=%.2f \n",framecount,angle,zoomf); - } - if ((rotozoom_picture=rotozoomSurface (picture, angle, zoomf, smooth))!=NULL) { - dest.x = (screen->w - rotozoom_picture->w)/2;; - dest.y = (screen->h - rotozoom_picture->h)/2; - dest.w = rotozoom_picture->w; - dest.h = rotozoom_picture->h; - if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { - fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); - break; + angle=framecount*rotate; + if ((framecount % 120)==0) { + printf (" Frame: %i Rotate: angle=%.2f Zoom: f=%.2f \n",framecount,angle,zoomf); } - SDL_FreeSurface(rotozoom_picture); + if ((rotozoom_picture=rotozoomSurface (picture, angle, zoomf, smooth))!=NULL) { + dest.x = (screen->w - rotozoom_picture->w)/2;; + dest.y = (screen->h - rotozoom_picture->h)/2; + dest.w = rotozoom_picture->w; + dest.h = rotozoom_picture->h; + if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { + fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); + break; + } + SDL_FreeSurface(rotozoom_picture); } - } + } /* Display by flipping screens */ SDL_Flip(screen); /* Maybe delay */ if (delay>0) { - SDL_Delay(delay); + SDL_Delay(delay); } } - + if (rotate) { /* Final display with angle=0 */ HandleEvent(); ClearScreen(screen); if (flip) { - if ((rotozoom_picture=rotozoomSurfaceXY (picture, 0.01, zoomfx, zoomfy, smooth))!=NULL) { - dest.x = (screen->w - rotozoom_picture->w)/2;; - dest.y = (screen->h - rotozoom_picture->h)/2; - dest.w = rotozoom_picture->w; - dest.h = rotozoom_picture->h; - if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { - fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); - return; - } - SDL_FreeSurface(rotozoom_picture); - } + if ((rotozoom_picture=rotozoomSurfaceXY (picture, 0.01, zoomfx, zoomfy, smooth))!=NULL) { + dest.x = (screen->w - rotozoom_picture->w)/2;; + dest.y = (screen->h - rotozoom_picture->h)/2; + dest.w = rotozoom_picture->w; + dest.h = rotozoom_picture->h; + if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { + fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); + return; + } + SDL_FreeSurface(rotozoom_picture); + } } else { - if ((rotozoom_picture=rotozoomSurface (picture, 0.01, zoomf, smooth))!=NULL) { - dest.x = (screen->w - rotozoom_picture->w)/2;; - dest.y = (screen->h - rotozoom_picture->h)/2; - dest.w = rotozoom_picture->w; - dest.h = rotozoom_picture->h; - if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { - fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); - return; - } - SDL_FreeSurface(rotozoom_picture); - } - } + if ((rotozoom_picture=rotozoomSurface (picture, 0.01, zoomf, smooth))!=NULL) { + dest.x = (screen->w - rotozoom_picture->w)/2;; + dest.y = (screen->h - rotozoom_picture->h)/2; + dest.w = rotozoom_picture->w; + dest.h = rotozoom_picture->h; + if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { + fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); + return; + } + SDL_FreeSurface(rotozoom_picture); + } + } /* Display by flipping screens */ SDL_Flip(screen); /* Maybe delay */ if (delay>0) { - SDL_Delay(delay); + SDL_Delay(delay); } } @@ -175,7 +176,7 @@ void ZoomPicture (SDL_Surface *screen, SDL_Surface *picture, int smooth) SDL_Surface *rotozoom_picture; SDL_Rect dest; int framecount, framemax, frameinc; - float zoomxf,zoomyf; + double zoomxf,zoomyf; /* Zoom and display the picture */ framemax=4*360; frameinc=1; @@ -183,12 +184,12 @@ void ZoomPicture (SDL_Surface *screen, SDL_Surface *picture, int smooth) if ((framecount % 360)==0) frameinc++; HandleEvent(); ClearScreen(screen); - zoomxf=(float)framecount/(float)framemax; - zoomxf=1.5*zoomxf*zoomxf; - zoomyf=0.5+fabs(1.0*sin((double)framecount/80.0)); - if ((framecount % 120)==0) { - printf (" Frame: %i Zoom: x=%.2f y=%.2f\n",framecount,zoomxf,zoomyf); - } + zoomxf=(float)framecount/(float)framemax; + zoomxf=1.5*zoomxf*zoomxf; + zoomyf=0.5+fabs(1.0*sin((double)framecount/80.0)); + if ((framecount % 120)==0) { + printf (" Frame: %i Zoom: x=%.2f y=%.2f\n",framecount,zoomxf,zoomyf); + } if ((rotozoom_picture=zoomSurface (picture, zoomxf, zoomyf, smooth))!=NULL) { dest.x = (screen->w - rotozoom_picture->w)/2;; dest.y = (screen->h - rotozoom_picture->h)/2; @@ -205,10 +206,10 @@ void ZoomPicture (SDL_Surface *screen, SDL_Surface *picture, int smooth) SDL_Flip(screen); /* Maybe delay */ if (delay>0) { - SDL_Delay(delay); + SDL_Delay(delay); } } - + /* Pause for a sec */ SDL_Delay(1000); } @@ -222,7 +223,7 @@ void ZoomPicture (SDL_Surface *screen, SDL_Surface *picture, int smooth) #define FLIP_XY 3 -void CustomTest(SDL_Surface *screen, SDL_Surface *picture, float a, float x, float y, int smooth){ +void CustomTest(SDL_Surface *screen, SDL_Surface *picture, double a, double x, double y, int smooth){ SDL_Surface *rotozoom_picture; SDL_Rect dest; @@ -230,23 +231,23 @@ void CustomTest(SDL_Surface *screen, SDL_Surface *picture, float a, float x, flo HandleEvent(); ClearScreen(screen); - if ((rotozoom_picture=rotozoomSurfaceXY (picture, a, x, y, smooth))!=NULL) { - dest.x = (screen->w - rotozoom_picture->w)/2;; - dest.y = (screen->h - rotozoom_picture->h)/2; - dest.w = rotozoom_picture->w; - dest.h = rotozoom_picture->h; - if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { - fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); - return; - } - SDL_FreeSurface(rotozoom_picture); + if ((rotozoom_picture=rotozoomSurfaceXY (picture, a, x, y, smooth))!=NULL) { + dest.x = (screen->w - rotozoom_picture->w)/2;; + dest.y = (screen->h - rotozoom_picture->h)/2; + dest.w = rotozoom_picture->w; + dest.h = rotozoom_picture->h; + if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { + fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); + return; + } + SDL_FreeSurface(rotozoom_picture); } /* Display by flipping screens */ SDL_Flip(screen); /* Maybe delay */ if (delay>0) { - SDL_Delay(delay); + SDL_Delay(delay); } SDL_Delay(1000); @@ -260,41 +261,41 @@ void Draw (SDL_Surface *screen, int start) /* --------- 8 bit test -------- */ if (start<=6) { - - /* Message */ - fprintf (stderr,"Loading 8bit image\n"); - /* Load the image into a surface */ - bmpfile = "sample8.bmp"; - fprintf(stderr, "Loading picture: %s\n", bmpfile); - picture = SDL_LoadBMP(bmpfile); - if ( picture == NULL ) { - fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); - return; - } + /* Message */ + fprintf (stderr,"Loading 8bit image\n"); + + /* Load the image into a surface */ + bmpfile = "sample8.bmp"; + fprintf(stderr, "Loading picture: %s\n", bmpfile); + picture = SDL_LoadBMP(bmpfile); + if ( picture == NULL ) { + fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); + return; + } - fprintf (stderr,"1. rotozoom: Rotating and zooming\n"); - RotatePicture(screen,picture,ROTATE_ON,FLIP_OFF,SMOOTHING_OFF); + fprintf (stderr,"1. rotozoom: Rotating and zooming\n"); + RotatePicture(screen,picture,ROTATE_ON,FLIP_OFF,SMOOTHING_OFF); - fprintf (stderr,"2. rotozoom: Just zooming (angle=0)\n"); - RotatePicture(screen,picture,ROTATE_OFF,FLIP_OFF,SMOOTHING_OFF); + fprintf (stderr,"2. rotozoom: Just zooming (angle=0)\n"); + RotatePicture(screen,picture,ROTATE_OFF,FLIP_OFF,SMOOTHING_OFF); - fprintf (stderr,"3. zoom: Just zooming\n"); - ZoomPicture(screen,picture,SMOOTHING_OFF); + fprintf (stderr,"3. zoom: Just zooming\n"); + ZoomPicture(screen,picture,SMOOTHING_OFF); - fprintf (stderr,"4. rotozoom: Rotating and zooming, interpolation on but unused\n"); - RotatePicture(screen,picture,ROTATE_ON,FLIP_OFF,SMOOTHING_ON); + fprintf (stderr,"4. rotozoom: Rotating and zooming, interpolation on but unused\n"); + RotatePicture(screen,picture,ROTATE_ON,FLIP_OFF,SMOOTHING_ON); - fprintf (stderr,"5. rotozoom: Just zooming (angle=0), interpolation on but unused\n"); - RotatePicture(screen,picture,ROTATE_OFF,FLIP_OFF,SMOOTHING_ON); + fprintf (stderr,"5. rotozoom: Just zooming (angle=0), interpolation on but unused\n"); + RotatePicture(screen,picture,ROTATE_OFF,FLIP_OFF,SMOOTHING_ON); - fprintf (stderr,"6. zoom: Just zooming, interpolation on but unused\n"); - ZoomPicture(screen,picture,SMOOTHING_ON); + fprintf (stderr,"6. zoom: Just zooming, interpolation on but unused\n"); + ZoomPicture(screen,picture,SMOOTHING_ON); + + /* Free the picture */ + SDL_FreeSurface(picture); - /* Free the picture */ - SDL_FreeSurface(picture); - } /* -------- 24 bit test --------- */ @@ -302,220 +303,205 @@ void Draw (SDL_Surface *screen, int start) if (start<=12) { - /* Message */ - fprintf (stderr,"Loading 24bit image\n"); + /* Message */ + fprintf (stderr,"Loading 24bit image\n"); - /* Load the image into a surface */ - bmpfile = "sample24.bmp"; - fprintf(stderr, "Loading picture: %s\n", bmpfile); - picture = SDL_LoadBMP(bmpfile); - if ( picture == NULL ) { - fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); - return; - } + /* Load the image into a surface */ + bmpfile = "sample24.bmp"; + fprintf(stderr, "Loading picture: %s\n", bmpfile); + picture = SDL_LoadBMP(bmpfile); + if ( picture == NULL ) { + fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); + return; + } - fprintf (stderr,"7. rotozoom: Rotating and zooming, no interpolation\n"); - RotatePicture(screen,picture,ROTATE_ON,FLIP_OFF,SMOOTHING_OFF); + fprintf (stderr,"7. rotozoom: Rotating and zooming, no interpolation\n"); + RotatePicture(screen,picture,ROTATE_ON,FLIP_OFF,SMOOTHING_OFF); - fprintf (stderr,"8. rotozoom: Just zooming (angle=0), no interpolation\n"); - RotatePicture(screen,picture,ROTATE_ON,FLIP_OFF,SMOOTHING_OFF); + fprintf (stderr,"8. rotozoom: Just zooming (angle=0), no interpolation\n"); + RotatePicture(screen,picture,ROTATE_ON,FLIP_OFF,SMOOTHING_OFF); - fprintf (stderr,"9. zoom: Just zooming, no interpolation\n"); - ZoomPicture(screen,picture,SMOOTHING_OFF); + fprintf (stderr,"9. zoom: Just zooming, no interpolation\n"); + ZoomPicture(screen,picture,SMOOTHING_OFF); - fprintf (stderr,"10. rotozoom: Rotating and zooming, with interpolation\n"); - RotatePicture(screen,picture,ROTATE_ON,FLIP_OFF,SMOOTHING_ON); + fprintf (stderr,"10. rotozoom: Rotating and zooming, with interpolation\n"); + RotatePicture(screen,picture,ROTATE_ON,FLIP_OFF,SMOOTHING_ON); - fprintf (stderr,"11. rotozoom: Just zooming (angle=0), with interpolation\n"); - RotatePicture(screen,picture,ROTATE_OFF,FLIP_OFF,SMOOTHING_ON); + fprintf (stderr,"11. rotozoom: Just zooming (angle=0), with interpolation\n"); + RotatePicture(screen,picture,ROTATE_OFF,FLIP_OFF,SMOOTHING_ON); - fprintf (stderr,"12. zoom: Just zooming, with interpolation\n"); - ZoomPicture(screen,picture,SMOOTHING_ON); + fprintf (stderr,"12. zoom: Just zooming, with interpolation\n"); + ZoomPicture(screen,picture,SMOOTHING_ON); - /* Free the picture */ - SDL_FreeSurface(picture); + /* Free the picture */ + SDL_FreeSurface(picture); } - + /* -------- 32 bit test --------- */ if (start<=16) { - /* Message */ - fprintf (stderr,"Loading 24bit image\n"); - - /* Load the image into a surface */ - bmpfile = "sample24.bmp"; - fprintf(stderr, "Loading picture: %s\n", bmpfile); - picture = SDL_LoadBMP(bmpfile); - if ( picture == NULL ) { - fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); - return; - } - - /* New source surface is 32bit with defined RGBA ordering */ - /* Much faster to do this once rather than the routine on the fly */ - fprintf (stderr,"Converting 24bit image into 32bit RGBA surface ...\n"); - picture_again = SDL_CreateRGBSurface(SDL_SWSURFACE, picture->w, picture->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); - SDL_BlitSurface(picture,NULL,picture_again,NULL); - - /* Message */ - fprintf (stderr,"13. Rotating and zooming, with interpolation\n"); - RotatePicture(screen,picture_again,ROTATE_ON,FLIP_OFF,SMOOTHING_ON); - - /* Message */ - fprintf (stderr,"14. Just zooming (angle=0), with interpolation\n"); - RotatePicture(screen,picture_again,ROTATE_OFF,FLIP_OFF,SMOOTHING_ON); - - SDL_FreeSurface(picture_again); - - /* New source surface is 32bit with defined ABGR ordering */ - /* Much faster to do this once rather than the routine on the fly */ - fprintf (stderr,"Converting 24bit image into 32bit ABGR surface ...\n"); - picture_again = SDL_CreateRGBSurface(SDL_SWSURFACE, picture->w, picture->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); - SDL_BlitSurface(picture,NULL,picture_again,NULL); - - /* Message */ - fprintf (stderr,"15. Rotating and zooming, with interpolation\n"); - RotatePicture(screen,picture_again,ROTATE_ON,FLIP_OFF,SMOOTHING_ON); - - /* Message */ - fprintf (stderr,"16. Just zooming (angle=0), with interpolation\n"); - RotatePicture(screen,picture_again,ROTATE_OFF,FLIP_OFF,SMOOTHING_ON); - - SDL_FreeSurface(picture_again); - - /* Free the picture */ - SDL_FreeSurface(picture); - - } - + /* Message */ + fprintf (stderr,"Loading 24bit image\n"); + + /* Load the image into a surface */ + bmpfile = "sample24.bmp"; + fprintf(stderr, "Loading picture: %s\n", bmpfile); + picture = SDL_LoadBMP(bmpfile); + if ( picture == NULL ) { + fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); + return; + } + + /* New source surface is 32bit with defined RGBA ordering */ + /* Much faster to do this once rather than the routine on the fly */ + fprintf (stderr,"Converting 24bit image into 32bit RGBA surface ...\n"); + picture_again = SDL_CreateRGBSurface(SDL_SWSURFACE, picture->w, picture->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); + SDL_BlitSurface(picture,NULL,picture_again,NULL); + + /* Message */ + fprintf (stderr,"13. Rotating and zooming, with interpolation\n"); + RotatePicture(screen,picture_again,ROTATE_ON,FLIP_OFF,SMOOTHING_ON); + + /* Message */ + fprintf (stderr,"14. Just zooming (angle=0), with interpolation\n"); + RotatePicture(screen,picture_again,ROTATE_OFF,FLIP_OFF,SMOOTHING_ON); + + SDL_FreeSurface(picture_again); + + /* New source surface is 32bit with defined ABGR ordering */ + /* Much faster to do this once rather than the routine on the fly */ + fprintf (stderr,"Converting 24bit image into 32bit ABGR surface ...\n"); + picture_again = SDL_CreateRGBSurface(SDL_SWSURFACE, picture->w, picture->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); + SDL_BlitSurface(picture,NULL,picture_again,NULL); + + /* Message */ + fprintf (stderr,"15. Rotating and zooming, with interpolation\n"); + RotatePicture(screen,picture_again,ROTATE_ON,FLIP_OFF,SMOOTHING_ON); + + /* Message */ + fprintf (stderr,"16. Just zooming (angle=0), with interpolation\n"); + RotatePicture(screen,picture_again,ROTATE_OFF,FLIP_OFF,SMOOTHING_ON); + + SDL_FreeSurface(picture_again); + + /* Free the picture */ + SDL_FreeSurface(picture); + + } + /* -------- 32 bit flip test --------- */ - if (start<=19) { - - /* Message */ - fprintf (stderr,"Loading 24bit image\n"); - - /* Load the image into a surface */ - bmpfile = "sample24.bmp"; - fprintf(stderr, "Loading picture: %s\n", bmpfile); - picture = SDL_LoadBMP(bmpfile); - if ( picture == NULL ) { - fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); - return; - } - - /* Excercise flipping functions on 32bit RGBA */ - fprintf (stderr,"Converting 24bit image into 32bit RGBA surface ...\n"); - picture_again = SDL_CreateRGBSurface(SDL_SWSURFACE, picture->w, picture->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); - SDL_BlitSurface(picture,NULL,picture_again,NULL); - - /* Message */ - fprintf (stderr,"17. Rotating with x-flip, no interpolation\n"); - RotatePicture(screen,picture_again,ROTATE_ON,FLIP_X,SMOOTHING_OFF); - - /* Message */ - fprintf (stderr,"18. Rotating with y-flip, no interpolation\n"); - RotatePicture(screen,picture_again,ROTATE_ON,FLIP_Y,SMOOTHING_OFF); - - /* Message */ - fprintf (stderr,"19. Rotating with xy-flip, no interpolation\n"); - RotatePicture(screen,picture_again,ROTATE_ON,FLIP_XY,SMOOTHING_OFF); - - /* Message */ - fprintf (stderr,"20. Rotating with x-flip, with interpolation\n"); - RotatePicture(screen,picture_again,ROTATE_ON,FLIP_X,SMOOTHING_ON); - - /* Message */ - fprintf (stderr,"21. Rotating with y-flip, with interpolation\n"); - RotatePicture(screen,picture_again,ROTATE_ON,FLIP_Y,SMOOTHING_ON); - - /* Message */ - fprintf (stderr,"22. Rotating with xy-flip, with interpolation\n"); - RotatePicture(screen,picture_again,ROTATE_ON,FLIP_XY,SMOOTHING_ON); - - SDL_FreeSurface(picture_again); - - /* Free the picture */ - SDL_FreeSurface(picture); - - } - - if (start<=23) { - - /* Message */ - fprintf (stderr,"Loading 24bit image\n"); - - /* Load the image into a surface */ - bmpfile = "sample24.bmp"; - fprintf(stderr, "Loading picture: %s\n", bmpfile); - picture = SDL_LoadBMP(bmpfile); - if ( picture == NULL ) { - fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); - return; - } - - /* Excercise flipping functions on 32bit RGBA */ - fprintf (stderr,"Converting 24bit image into 32bit RGBA surface ...\n"); - picture_again = SDL_CreateRGBSurface(SDL_SWSURFACE, picture->w, picture->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); - SDL_BlitSurface(picture,NULL,picture_again,NULL); - - fprintf (stderr,"23. CustomTest, values from commandline (32bit)\n"); - CustomTest(screen, picture_again, custom_angle, custom_fx, custom_fy, custom_smooth); - - SDL_FreeSurface(picture_again); - - /* Free the picture */ - SDL_FreeSurface(picture); - - /* Message */ - fprintf (stderr,"Loading 8bit image\n"); - - /* Load the image into a surface */ - bmpfile = "sample8.bmp"; - fprintf(stderr, "Loading picture: %s\n", bmpfile); - picture = SDL_LoadBMP(bmpfile); - if ( picture == NULL ) { - fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); - return; - } - - fprintf (stderr,"24. CustomTest, values from commandline (8bit)\n"); - CustomTest(screen, picture, custom_angle, custom_fx, custom_fy, custom_smooth); - - /* Free the picture */ - SDL_FreeSurface(picture); - - } - + if (start<=19) { + + /* Message */ + fprintf (stderr,"Loading 24bit image\n"); + + /* Load the image into a surface */ + bmpfile = "sample24.bmp"; + fprintf(stderr, "Loading picture: %s\n", bmpfile); + picture = SDL_LoadBMP(bmpfile); + if ( picture == NULL ) { + fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); + return; + } + + /* Excercise flipping functions on 32bit RGBA */ + fprintf (stderr,"Converting 24bit image into 32bit RGBA surface ...\n"); + picture_again = SDL_CreateRGBSurface(SDL_SWSURFACE, picture->w, picture->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); + SDL_BlitSurface(picture,NULL,picture_again,NULL); + + /* Message */ + fprintf (stderr,"17. Rotating with x-flip, no interpolation\n"); + RotatePicture(screen,picture_again,ROTATE_ON,FLIP_X,SMOOTHING_OFF); + + /* Message */ + fprintf (stderr,"18. Rotating with y-flip, no interpolation\n"); + RotatePicture(screen,picture_again,ROTATE_ON,FLIP_Y,SMOOTHING_OFF); + + /* Message */ + fprintf (stderr,"19. Rotating with xy-flip, no interpolation\n"); + RotatePicture(screen,picture_again,ROTATE_ON,FLIP_XY,SMOOTHING_OFF); + + /* Message */ + fprintf (stderr,"20. Rotating with x-flip, with interpolation\n"); + RotatePicture(screen,picture_again,ROTATE_ON,FLIP_X,SMOOTHING_ON); + + /* Message */ + fprintf (stderr,"21. Rotating with y-flip, with interpolation\n"); + RotatePicture(screen,picture_again,ROTATE_ON,FLIP_Y,SMOOTHING_ON); + + /* Message */ + fprintf (stderr,"22. Rotating with xy-flip, with interpolation\n"); + RotatePicture(screen,picture_again,ROTATE_ON,FLIP_XY,SMOOTHING_ON); + + SDL_FreeSurface(picture_again); + + /* Free the picture */ + SDL_FreeSurface(picture); + + } + + if (start<=23) { + + /* Message */ + fprintf (stderr,"Loading 24bit image\n"); + + /* Load the image into a surface */ + bmpfile = "sample24.bmp"; + fprintf(stderr, "Loading picture: %s\n", bmpfile); + picture = SDL_LoadBMP(bmpfile); + if ( picture == NULL ) { + fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); + return; + } + + /* Excercise flipping functions on 32bit RGBA */ + fprintf (stderr,"Converting 24bit image into 32bit RGBA surface ...\n"); + picture_again = SDL_CreateRGBSurface(SDL_SWSURFACE, picture->w, picture->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); + SDL_BlitSurface(picture,NULL,picture_again,NULL); + + fprintf (stderr,"23. CustomTest, values from commandline (32bit)\n"); + CustomTest(screen, picture_again, custom_angle, custom_fx, custom_fy, custom_smooth); + + SDL_FreeSurface(picture_again); + + /* Free the picture */ + SDL_FreeSurface(picture); + + /* Message */ + fprintf (stderr,"Loading 8bit image\n"); + + /* Load the image into a surface */ + bmpfile = "sample8.bmp"; + fprintf(stderr, "Loading picture: %s\n", bmpfile); + picture = SDL_LoadBMP(bmpfile); + if ( picture == NULL ) { + fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); + return; + } + + fprintf (stderr,"24. CustomTest, values from commandline (8bit)\n"); + CustomTest(screen, picture, custom_angle, custom_fx, custom_fy, custom_smooth); + + /* Free the picture */ + SDL_FreeSurface(picture); + + } + return; } -#ifdef WIN32 - extern char ** __argv; - extern int __argc; - int APIENTRY WinMain(HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPSTR lpCmdLine, - int nCmdShow) -#else // non WIN32 - int main ( int argc, char *argv[] ) -#endif +int main ( int argc, char *argv[] ) { SDL_Surface *screen; int w, h; int desired_bpp; Uint32 video_flags; int start; -#ifdef WIN32 - int argc; - char **argv; - argv = __argv; - argc = __argc; -#endif /* Title */ fprintf (stderr,"SDL_rotozoom test\n"); @@ -533,97 +519,97 @@ void Draw (SDL_Surface *screen, int start) argc -= 2; } else { fprintf(stderr, - "The -start option requires an argument\n"); - exit(1); - } - } else - if ( strcmp(argv[1], "-delay") == 0 ) { - if ( argv[2] && ((delay = atoi(argv[2])) > 0) ) { - argv += 2; - argc -= 2; - } else { - fprintf(stderr, - "The -delay option requires an argument\n"); + "The -start option requires an argument\n"); exit(1); } } else - if ( strcmp(argv[1], "-width") == 0 ) { - if ( argv[2] && ((w = atoi(argv[2])) > 0) ) { - argv += 2; - argc -= 2; - } else { - fprintf(stderr, - "The -width option requires an argument\n"); - exit(1); - } - } else - if ( strcmp(argv[1], "-height") == 0 ) { - if ( argv[2] && ((h = atoi(argv[2])) > 0) ) { - argv += 2; - argc -= 2; - } else { - fprintf(stderr, - "The -height option requires an argument\n"); - exit(1); - } - } else - if ( strcmp(argv[1], "-bpp") == 0 ) { - if ( argv[2] ) { - desired_bpp = atoi(argv[2]); - argv += 2; - argc -= 2; - } else { - fprintf(stderr, - "The -bpp option requires an argument\n"); - exit(1); - } - } else - if ( strcmp(argv[1], "-warp") == 0 ) { - video_flags |= SDL_HWPALETTE; - argv += 1; - argc -= 1; - } else - if ( strcmp(argv[1], "-hw") == 0 ) { - video_flags |= SDL_HWSURFACE; - argv += 1; - argc -= 1; - } else - if ( strcmp(argv[1], "-fullscreen") == 0 ) { - video_flags |= SDL_FULLSCREEN; - argv += 1; - argc -= 1; - } else - if ( strcmp(argv[1], "-custom") == 0 ) { - if (( argv[2] ) && ( argv[3] ) && ( argv[4] ) && (argv[5] )) { - custom_angle = atof(argv[2]); - custom_fx = atof(argv[3]); - custom_fy = atof(argv[4]); - custom_smooth = atoi(argv[5]); - argv += 5; - argc -= 5; - } else { - fprintf(stderr, - "The -custom option requires 4 arguments\n"); - exit(1); - } - } else - if (( strcmp(argv[1], "-help") == 0 ) || (strcmp(argv[1], "--help") == 0)) { - printf ("Usage:\n"); - printf (" -start # Set starting test number (1=8bit, 7=24bit, 13=24bit, 23=custom)\n"); - printf (" -delay # Set delay between frames in ms (default: 0=off)\n"); - printf (" (if >0, enables verbose frame logging\n"); - printf (" -width # Screen width (Default: %i)\n",w); - printf (" -height # Screen height (Default: %i)\n",h); - printf (" -bpp # Screen bpp\n"); - printf (" -warp Enable hardware palette\n"); - printf (" -hw Enable hardware surface\n"); - printf (" -fullscreen Enable fullscreen mode\n"); - printf (" -custom # # # # Custom: angle scalex scaley smooth\n"); - printf (" scalex/scaley<0, enables flip on axis\n"); - printf (" smooth=0/1\n"); - exit(0); - } else - break; + if ( strcmp(argv[1], "-delay") == 0 ) { + if ( argv[2] && ((delay = atoi(argv[2])) > 0) ) { + argv += 2; + argc -= 2; + } else { + fprintf(stderr, + "The -delay option requires an argument\n"); + exit(1); + } + } else + if ( strcmp(argv[1], "-width") == 0 ) { + if ( argv[2] && ((w = atoi(argv[2])) > 0) ) { + argv += 2; + argc -= 2; + } else { + fprintf(stderr, + "The -width option requires an argument\n"); + exit(1); + } + } else + if ( strcmp(argv[1], "-height") == 0 ) { + if ( argv[2] && ((h = atoi(argv[2])) > 0) ) { + argv += 2; + argc -= 2; + } else { + fprintf(stderr, + "The -height option requires an argument\n"); + exit(1); + } + } else + if ( strcmp(argv[1], "-bpp") == 0 ) { + if ( argv[2] ) { + desired_bpp = atoi(argv[2]); + argv += 2; + argc -= 2; + } else { + fprintf(stderr, + "The -bpp option requires an argument\n"); + exit(1); + } + } else + if ( strcmp(argv[1], "-warp") == 0 ) { + video_flags |= SDL_HWPALETTE; + argv += 1; + argc -= 1; + } else + if ( strcmp(argv[1], "-hw") == 0 ) { + video_flags |= SDL_HWSURFACE; + argv += 1; + argc -= 1; + } else + if ( strcmp(argv[1], "-fullscreen") == 0 ) { + video_flags |= SDL_FULLSCREEN; + argv += 1; + argc -= 1; + } else + if ( strcmp(argv[1], "-custom") == 0 ) { + if (( argv[2] ) && ( argv[3] ) && ( argv[4] ) && (argv[5] )) { + custom_angle = atof(argv[2]); + custom_fx = atof(argv[3]); + custom_fy = atof(argv[4]); + custom_smooth = atoi(argv[5]); + argv += 5; + argc -= 5; + } else { + fprintf(stderr, + "The -custom option requires 4 arguments\n"); + exit(1); + } + } else + if (( strcmp(argv[1], "-help") == 0 ) || (strcmp(argv[1], "--help") == 0)) { + printf ("Usage:\n"); + printf (" -start # Set starting test number (1=8bit, 7=24bit, 13=24bit, 23=custom)\n"); + printf (" -delay # Set delay between frames in ms (default: 0=off)\n"); + printf (" (if >0, enables verbose frame logging\n"); + printf (" -width # Screen width (Default: %i)\n",w); + printf (" -height # Screen height (Default: %i)\n",h); + printf (" -bpp # Screen bpp\n"); + printf (" -warp Enable hardware palette\n"); + printf (" -hw Enable hardware surface\n"); + printf (" -fullscreen Enable fullscreen mode\n"); + printf (" -custom # # # # Custom: angle scalex scaley smooth\n"); + printf (" scalex/scaley<0, enables flip on axis\n"); + printf (" smooth=0/1\n"); + exit(0); + } else + break; } /* Force double buffering */ @@ -641,16 +627,16 @@ void Draw (SDL_Surface *screen, int start) screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags); if ( screen == NULL ) { fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", - w, h, desired_bpp, SDL_GetError()); + w, h, desired_bpp, SDL_GetError()); exit(1); } /* Show some info */ printf("Set %dx%dx%d mode\n", - screen->w, screen->h, screen->format->BitsPerPixel); + screen->w, screen->h, screen->format->BitsPerPixel); printf("Video surface located in %s memory.\n", - (screen->flags&SDL_HWSURFACE) ? "video" : "system"); - + (screen->flags&SDL_HWSURFACE) ? "video" : "system"); + /* Check for double buffering */ if ( screen->flags & SDL_DOUBLEBUF ) { printf("Double-buffering enabled - good!\n"); @@ -661,6 +647,6 @@ void Draw (SDL_Surface *screen, int start) /* Do all the drawing work */ Draw (screen, start); - + return(0); } diff --git a/Test/TestShrink.c b/Test/TestShrink.c index 45eb877..51775a8 100644 --- a/Test/TestShrink.c +++ b/Test/TestShrink.c @@ -1,16 +1,12 @@ /* - TestShrink - - Test program for shrink routines +TestShrink - Copyright (C) A. Schiffler, July 2006, GPL +Test program for shrink routines -*/ +Copyright (C) A. Schiffler, July 2006, GPL -#ifdef WIN32 - #include -#endif +*/ #include #include @@ -18,20 +14,25 @@ #include "SDL.h" +#ifdef WIN32 +#include +#include "SDL_rotozoom.h" +#else #include "SDL/SDL_rotozoom.h" +#endif void HandleEvent() { SDL_Event event; /* Check for events */ - while ( SDL_PollEvent(&event) ) { - switch (event.type) { + while ( SDL_PollEvent(&event) ) { + switch (event.type) { case SDL_KEYDOWN: case SDL_QUIT: - exit(0); - break; - } + exit(0); + break; + } } } @@ -59,32 +60,32 @@ void ShrinkPicture (SDL_Surface *screen, SDL_Surface *picture) int factorx, factory; for (factorx=1; factorx<6; factorx++) { - for (factory=1; factory<6; factory++) { - - HandleEvent(); - - ClearScreen(screen); - if ((shrink_picture=shrinkSurface (picture, factorx, factory))!=NULL) { - dest.x = (screen->w - shrink_picture->w)/2;; - dest.y = (screen->h - shrink_picture->h)/2; - dest.w = shrink_picture->w; - dest.h = shrink_picture->h; - if ( SDL_BlitSurface(shrink_picture, NULL, screen, &dest) < 0 ) { - fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); - break; + for (factory=1; factory<6; factory++) { + + HandleEvent(); + + ClearScreen(screen); + if ((shrink_picture=shrinkSurface (picture, factorx, factory))!=NULL) { + dest.x = (screen->w - shrink_picture->w)/2;; + dest.y = (screen->h - shrink_picture->h)/2; + dest.w = shrink_picture->w; + dest.h = shrink_picture->h; + if ( SDL_BlitSurface(shrink_picture, NULL, screen, &dest) < 0 ) { + fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); + break; + } + SDL_FreeSurface(shrink_picture); } - SDL_FreeSurface(shrink_picture); - } - /* Display by flipping screens */ - SDL_Flip(screen); + /* Display by flipping screens */ + SDL_Flip(screen); - /* Pause for 0.25 sec */ - SDL_Delay(250); + /* Pause for 0.25 sec */ + SDL_Delay(250); - } + } } - + } @@ -96,49 +97,49 @@ void Draw (SDL_Surface *screen, int start) /* --------- 8 bit test -------- */ if (start<=1) { - - /* Message */ - fprintf (stderr,"Loading 8bit square image\n"); - - /* Load the image into a surface */ - bmpfile = "sample8-box.bmp"; - fprintf(stderr, "Loading picture: %s\n", bmpfile); - picture = SDL_LoadBMP(bmpfile); - if ( picture == NULL ) { - fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); - return; - } - - - fprintf (stderr,"1. shrink 8bit\n"); - ShrinkPicture(screen,picture); - - /* Free the picture */ - SDL_FreeSurface(picture); - + + /* Message */ + fprintf (stderr,"Loading 8bit square image\n"); + + /* Load the image into a surface */ + bmpfile = "sample8-box.bmp"; + fprintf(stderr, "Loading picture: %s\n", bmpfile); + picture = SDL_LoadBMP(bmpfile); + if ( picture == NULL ) { + fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); + return; + } + + + fprintf (stderr,"1. shrink 8bit\n"); + ShrinkPicture(screen,picture); + + /* Free the picture */ + SDL_FreeSurface(picture); + } if (start<=2) { - - /* Message */ - fprintf (stderr,"Loading 8bit image\n"); - - /* Load the image into a surface */ - bmpfile = "sample8.bmp"; - fprintf(stderr, "Loading picture: %s\n", bmpfile); - picture = SDL_LoadBMP(bmpfile); - if ( picture == NULL ) { - fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); - return; - } - - - fprintf (stderr,"1. shrink 8bit\n"); - ShrinkPicture(screen,picture); - - /* Free the picture */ - SDL_FreeSurface(picture); - + + /* Message */ + fprintf (stderr,"Loading 8bit image\n"); + + /* Load the image into a surface */ + bmpfile = "sample8.bmp"; + fprintf(stderr, "Loading picture: %s\n", bmpfile); + picture = SDL_LoadBMP(bmpfile); + if ( picture == NULL ) { + fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); + return; + } + + + fprintf (stderr,"1. shrink 8bit\n"); + ShrinkPicture(screen,picture); + + /* Free the picture */ + SDL_FreeSurface(picture); + } /* -------- 24 bit test --------- */ @@ -146,136 +147,121 @@ void Draw (SDL_Surface *screen, int start) if (start<=3) { - /* Message */ - fprintf (stderr,"Loading 24bit square image\n"); + /* Message */ + fprintf (stderr,"Loading 24bit square image\n"); - /* Load the image into a surface */ - bmpfile = "sample24-box.bmp"; - fprintf(stderr, "Loading picture: %s\n", bmpfile); - picture = SDL_LoadBMP(bmpfile); - if ( picture == NULL ) { - fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); - return; - } + /* Load the image into a surface */ + bmpfile = "sample24-box.bmp"; + fprintf(stderr, "Loading picture: %s\n", bmpfile); + picture = SDL_LoadBMP(bmpfile); + if ( picture == NULL ) { + fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); + return; + } - fprintf (stderr,"2. shrink 24bit\n"); - ShrinkPicture(screen,picture); + fprintf (stderr,"2. shrink 24bit\n"); + ShrinkPicture(screen,picture); - /* Free the picture */ - SDL_FreeSurface(picture); + /* Free the picture */ + SDL_FreeSurface(picture); } if (start<=4) { - /* Message */ - fprintf (stderr,"Loading 24bit image\n"); + /* Message */ + fprintf (stderr,"Loading 24bit image\n"); - /* Load the image into a surface */ - bmpfile = "sample24.bmp"; - fprintf(stderr, "Loading picture: %s\n", bmpfile); - picture = SDL_LoadBMP(bmpfile); - if ( picture == NULL ) { - fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); - return; - } + /* Load the image into a surface */ + bmpfile = "sample24.bmp"; + fprintf(stderr, "Loading picture: %s\n", bmpfile); + picture = SDL_LoadBMP(bmpfile); + if ( picture == NULL ) { + fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); + return; + } - fprintf (stderr,"2. shrink 24bit\n"); - ShrinkPicture(screen,picture); + fprintf (stderr,"2. shrink 24bit\n"); + ShrinkPicture(screen,picture); - /* Free the picture */ - SDL_FreeSurface(picture); + /* Free the picture */ + SDL_FreeSurface(picture); } - + /* -------- 32 bit test --------- */ if (start<=5) { - /* Message */ - fprintf (stderr,"Loading 24bit square image\n"); - - /* Load the image into a surface */ - bmpfile = "sample24-box.bmp"; - fprintf(stderr, "Loading picture: %s\n", bmpfile); - picture = SDL_LoadBMP(bmpfile); - if ( picture == NULL ) { - fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); - return; - } - - /* New source surface is 32bit with defined RGBA ordering */ - /* Much faster to do this once rather than the routine on the fly */ - fprintf (stderr,"Converting 24bit image into 32bit RGBA surface ...\n"); - picture_again = SDL_CreateRGBSurface(SDL_SWSURFACE, picture->w, picture->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); - SDL_BlitSurface(picture,NULL,picture_again,NULL); - - /* Message */ - fprintf (stderr,"3. shrink 32bit \n"); - ShrinkPicture(screen,picture_again); - - /* Free the picture2 */ - SDL_FreeSurface(picture_again); - SDL_FreeSurface(picture); - - } + /* Message */ + fprintf (stderr,"Loading 24bit square image\n"); + + /* Load the image into a surface */ + bmpfile = "sample24-box.bmp"; + fprintf(stderr, "Loading picture: %s\n", bmpfile); + picture = SDL_LoadBMP(bmpfile); + if ( picture == NULL ) { + fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); + return; + } + + /* New source surface is 32bit with defined RGBA ordering */ + /* Much faster to do this once rather than the routine on the fly */ + fprintf (stderr,"Converting 24bit image into 32bit RGBA surface ...\n"); + picture_again = SDL_CreateRGBSurface(SDL_SWSURFACE, picture->w, picture->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); + SDL_BlitSurface(picture,NULL,picture_again,NULL); + + /* Message */ + fprintf (stderr,"3. shrink 32bit \n"); + ShrinkPicture(screen,picture_again); + + /* Free the picture2 */ + SDL_FreeSurface(picture_again); + SDL_FreeSurface(picture); + + } if (start<=6) { - /* Message */ - fprintf (stderr,"Loading 24bit image\n"); - - /* Load the image into a surface */ - bmpfile = "sample24.bmp"; - fprintf(stderr, "Loading picture: %s\n", bmpfile); - picture = SDL_LoadBMP(bmpfile); - if ( picture == NULL ) { - fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); - return; - } - - /* New source surface is 32bit with defined RGBA ordering */ - /* Much faster to do this once rather than the routine on the fly */ - fprintf (stderr,"Converting 24bit image into 32bit RGBA surface ...\n"); - picture_again = SDL_CreateRGBSurface(SDL_SWSURFACE, picture->w, picture->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); - SDL_BlitSurface(picture,NULL,picture_again,NULL); - - /* Message */ - fprintf (stderr,"3. shrink 32bit \n"); - ShrinkPicture(screen,picture_again); - - /* Free the picture2 */ - SDL_FreeSurface(picture_again); - SDL_FreeSurface(picture); - - } - + /* Message */ + fprintf (stderr,"Loading 24bit image\n"); + + /* Load the image into a surface */ + bmpfile = "sample24.bmp"; + fprintf(stderr, "Loading picture: %s\n", bmpfile); + picture = SDL_LoadBMP(bmpfile); + if ( picture == NULL ) { + fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); + return; + } + + /* New source surface is 32bit with defined RGBA ordering */ + /* Much faster to do this once rather than the routine on the fly */ + fprintf (stderr,"Converting 24bit image into 32bit RGBA surface ...\n"); + picture_again = SDL_CreateRGBSurface(SDL_SWSURFACE, picture->w, picture->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); + SDL_BlitSurface(picture,NULL,picture_again,NULL); + + /* Message */ + fprintf (stderr,"3. shrink 32bit \n"); + ShrinkPicture(screen,picture_again); + + /* Free the picture2 */ + SDL_FreeSurface(picture_again); + SDL_FreeSurface(picture); + + } + return; } -#ifdef WIN32 - extern char ** __argv; - extern int __argc; - int APIENTRY WinMain(HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPSTR lpCmdLine, - int nCmdShow) -#else // non WIN32 - int main ( int argc, char *argv[] ) -#endif +int main ( int argc, char *argv[] ) { SDL_Surface *screen; int w, h; int desired_bpp; Uint32 video_flags; int start; -#ifdef WIN32 - int argc; - char **argv; - argv = __argv; - argc = __argc; -#endif /* Title */ fprintf (stderr,"SDL_rotozoom test\n"); @@ -292,68 +278,68 @@ void Draw (SDL_Surface *screen, int start) argc -= 2; } else { fprintf(stderr, - "The -start option requires an argument\n"); + "The -start option requires an argument\n"); exit(1); } } else - if ( strcmp(argv[1], "-width") == 0 ) { - if ( argv[2] && ((w = atoi(argv[2])) > 0) ) { - argv += 2; - argc -= 2; - } else { - fprintf(stderr, - "The -width option requires an argument\n"); - exit(1); - } - } else - if ( strcmp(argv[1], "-height") == 0 ) { - if ( argv[2] && ((h = atoi(argv[2])) > 0) ) { - argv += 2; - argc -= 2; - } else { - fprintf(stderr, - "The -height option requires an argument\n"); - exit(1); - } - } else - if ( strcmp(argv[1], "-bpp") == 0 ) { - if ( argv[2] ) { - desired_bpp = atoi(argv[2]); - argv += 2; - argc -= 2; - } else { - fprintf(stderr, - "The -bpp option requires an argument\n"); - exit(1); - } - } else - if ( strcmp(argv[1], "-warp") == 0 ) { - video_flags |= SDL_HWPALETTE; - argv += 1; - argc -= 1; - } else - if ( strcmp(argv[1], "-hw") == 0 ) { - video_flags |= SDL_HWSURFACE; - argv += 1; - argc -= 1; - } else - if ( strcmp(argv[1], "-fullscreen") == 0 ) { - video_flags |= SDL_FULLSCREEN; - argv += 1; - argc -= 1; - } else - if (( strcmp(argv[1], "-help") == 0 ) || (strcmp(argv[1], "--help") == 0)) { - printf ("Usage:\n"); - printf (" -start # Set starting test number (1=8bit, 3=24bit, 5=32bit)\n"); - printf (" -width # Screen width (Default: %i)\n",w); - printf (" -height # Screen height (Default: %i)\n",h); - printf (" -bpp # Screen bpp\n"); - printf (" -warp Enable hardware palette\n"); - printf (" -hw Enable hardware surface\n"); - printf (" -fullscreen Enable fullscreen mode\n"); - - } else - break; + if ( strcmp(argv[1], "-width") == 0 ) { + if ( argv[2] && ((w = atoi(argv[2])) > 0) ) { + argv += 2; + argc -= 2; + } else { + fprintf(stderr, + "The -width option requires an argument\n"); + exit(1); + } + } else + if ( strcmp(argv[1], "-height") == 0 ) { + if ( argv[2] && ((h = atoi(argv[2])) > 0) ) { + argv += 2; + argc -= 2; + } else { + fprintf(stderr, + "The -height option requires an argument\n"); + exit(1); + } + } else + if ( strcmp(argv[1], "-bpp") == 0 ) { + if ( argv[2] ) { + desired_bpp = atoi(argv[2]); + argv += 2; + argc -= 2; + } else { + fprintf(stderr, + "The -bpp option requires an argument\n"); + exit(1); + } + } else + if ( strcmp(argv[1], "-warp") == 0 ) { + video_flags |= SDL_HWPALETTE; + argv += 1; + argc -= 1; + } else + if ( strcmp(argv[1], "-hw") == 0 ) { + video_flags |= SDL_HWSURFACE; + argv += 1; + argc -= 1; + } else + if ( strcmp(argv[1], "-fullscreen") == 0 ) { + video_flags |= SDL_FULLSCREEN; + argv += 1; + argc -= 1; + } else + if (( strcmp(argv[1], "-help") == 0 ) || (strcmp(argv[1], "--help") == 0)) { + printf ("Usage:\n"); + printf (" -start # Set starting test number (1=8bit, 3=24bit, 5=32bit)\n"); + printf (" -width # Screen width (Default: %i)\n",w); + printf (" -height # Screen height (Default: %i)\n",h); + printf (" -bpp # Screen bpp\n"); + printf (" -warp Enable hardware palette\n"); + printf (" -hw Enable hardware surface\n"); + printf (" -fullscreen Enable fullscreen mode\n"); + + } else + break; } /* Force double buffering */ @@ -371,16 +357,16 @@ void Draw (SDL_Surface *screen, int start) screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags); if ( screen == NULL ) { fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", - w, h, desired_bpp, SDL_GetError()); + w, h, desired_bpp, SDL_GetError()); exit(1); } /* Show some info */ printf("Set %dx%dx%d mode\n", - screen->w, screen->h, screen->format->BitsPerPixel); + screen->w, screen->h, screen->format->BitsPerPixel); printf("Video surface located in %s memory.\n", - (screen->flags&SDL_HWSURFACE) ? "video" : "system"); - + (screen->flags&SDL_HWSURFACE) ? "video" : "system"); + /* Check for double buffering */ if ( screen->flags & SDL_DOUBLEBUF ) { printf("Double-buffering enabled - good!\n"); @@ -391,6 +377,6 @@ void Draw (SDL_Surface *screen, int start) /* Do all the drawing work */ Draw (screen, start); - + return(0); }