Changeset 1723 for testing

Show
Ignore:
Timestamp:
15/08/08 21:48:18 (5 months ago)
Author:
duncan
svm:headrev:

cc3e1ea1-1e01-0410-8d68-8b121e83a9d5:10895
Message:

Copied the zoom code from TestRotozoom?.c
Zooming image to full screen for 5 seconds

Location:
testing/Duncan/pygoom-2k4/tests
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • testing/Duncan/pygoom-2k4/tests/tux.c

    r1721 r1723  
    11#include <stdlib.h> 
    22#include <SDL/SDL.h> 
     3#include "SDL/SDL_rotozoom.h" 
     4 
     5void HandleEvent() 
     6{ 
     7    SDL_Event event;  
     8 
     9    /* Check for events */ 
     10        while ( SDL_PollEvent(&event) ) { 
     11                        switch (event.type) { 
     12             case SDL_KEYDOWN: 
     13             case SDL_QUIT: 
     14                                        exit(0); 
     15                                        break; 
     16            } 
     17    } 
     18} 
     19 
     20void ClearScreen(SDL_Surface *screen) 
     21{ 
     22    int i; 
     23    /* Set the screen to black */ 
     24    if ( SDL_LockSurface(screen) == 0 ) { 
     25        Uint8 *pixels; 
     26        pixels = (Uint8 *)screen->pixels; 
     27        for ( i=0; i<screen->h; ++i ) { 
     28            memset(pixels, 0, 
     29                screen->w*screen->format->BytesPerPixel); 
     30            pixels += screen->pitch; 
     31        } 
     32        SDL_UnlockSurface(screen); 
     33    } 
     34} 
     35 
     36void ZoomPicture (SDL_Surface *screen, SDL_Surface *image, int smooth)  
     37{ 
     38    SDL_Surface *rotozoom_image; 
     39    SDL_Rect dest; 
     40    int framecount, framemax, frameinc; 
     41    int new_w, new_h, new_x, new_y; 
     42    float zoomxf,zoomyf; 
     43    double factorx, factory, factor; 
     44    printf ("image  w=%d, h=%d\n", image->w, image->h); 
     45    printf ("screen w=%d, h=%d\n", screen->w, screen->h); 
     46    // Need to take into account the pixel aspect, this is 1:1? 
     47    factorx = (double)screen->w / (double)image->w; 
     48    factory = (double)screen->h / (double)image->h; 
     49    printf ("screen x=%.3f, y=%.3f\n", factorx, factory); 
     50    if (factorx < factory) { 
     51        printf ("scale full width\n"); 
     52        factor = factorx; 
     53    } else { 
     54        printf ("scale full height\n"); 
     55        factor = factory; 
     56    } 
     57    new_w = (int)(image->w * factor + 0.5); 
     58    new_h = (int)(image->h * factor + 0.5); 
     59    new_x = (screen->w - new_w) / 2; 
     60    new_y = (screen->h - new_h) / 2; 
     61    printf ("new x=%d, y=%d\n", new_x, new_y); 
     62    new_x = (int)(((double)screen->w - (double)new_w) / 2.0 + 0.5); 
     63    new_y = (int)(((double)screen->h - (double)new_h) / 2.0 + 0.5); 
     64    printf ("new w=%d, h=%d\n", new_w, new_h); 
     65    printf ("new x=%d, y=%d\n", new_x, new_y); 
     66    if ((rotozoom_image=zoomSurface (image, factor, factor, smooth))!=NULL) { 
     67        dest.x = new_x; 
     68        dest.y = new_y; 
     69        dest.w = rotozoom_image->w; 
     70        dest.h = rotozoom_image->h; 
     71        printf ("dest w=%d, h=%d\n", dest.w, dest.h); 
     72        if (SDL_BlitSurface(rotozoom_image, NULL, screen, &dest) < 0) { 
     73            fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); 
     74        } 
     75        SDL_FreeSurface(rotozoom_image); 
     76        SDL_Flip(screen); 
     77    } 
     78    /* Pause for 5 secs */ 
     79    SDL_Delay(5000); 
     80     
     81    /* Zoom and display the image */ 
     82    framemax=4*360; frameinc=1; 
     83    for (framecount=360; framecount<framemax; framecount += frameinc) { 
     84        if ((framecount % 360)==0) frameinc++; 
     85        HandleEvent(); 
     86        ClearScreen(screen); 
     87        zoomxf=(float)framecount/(float)framemax; 
     88        zoomxf=1.5*zoomxf*zoomxf; 
     89        zoomyf=0.5+fabs(1.0*sin((double)framecount/80.0)); 
     90        if ((framecount % 120)==0) { 
     91            printf ("  Frame: %i   Zoom: x=%.2f y=%.2f\n",framecount,zoomxf,zoomyf); 
     92        } 
     93        if ((rotozoom_image=zoomSurface (image, zoomxf, zoomyf, smooth))!=NULL) { 
     94            dest.x = (screen->w - rotozoom_image->w)/2;; 
     95            dest.y = (screen->h - rotozoom_image->h)/2; 
     96            dest.w = rotozoom_image->w; 
     97            dest.h = rotozoom_image->h; 
     98            if ( SDL_BlitSurface(rotozoom_image, NULL, screen, &dest) < 0 ) { 
     99                fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); 
     100                break; 
     101            } 
     102            SDL_FreeSurface(rotozoom_image); 
     103        } 
     104 
     105        /* Display by flipping screens */ 
     106        SDL_Flip(screen); 
     107    } 
     108     
     109    /* Pause for a sec */ 
     110    SDL_Delay(1000); 
     111} 
     112 
    3113int main(int argc, char *argv[]) 
    4114{ 
     
    14124    } 
    15125    atexit(SDL_Quit);  
    16     screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF); 
     126    //screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF); 
     127    screen = SDL_SetVideoMode(640, 480, 0, SDL_HWSURFACE | SDL_DOUBLEBUF); 
     128    /* Show some info */ 
     129    printf("Set %dx%dx%d mode\n", 
     130            screen->w, screen->h, screen->format->BitsPerPixel); 
     131    printf("Video surface located in %s memory.\n", 
     132            (screen->flags&SDL_HWSURFACE) ? "video" : "system"); 
     133    if (screen->flags & SDL_DOUBLEBUF) { 
     134        printf("Double-buffering enabled.\n"); 
     135    } 
     136 
    17137    SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 255)); 
    18138    if (screen == NULL) { 
     
    30150    dstblue.h = image->h + 1; 
    31151    SDL_SetColorKey(image, SDL_SRCCOLORKEY, SDL_MapRGB(image->format, 255, 0, 0));     
     152    ZoomPicture(screen, image, 1); 
    32153    while (!done) { 
    33154        while (SDL_PollEvent(&event)) {