| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include <stdio.h> |
| 5 |
#include <stdlib.h> |
| 6 |
#include <string.h> |
| 7 |
|
| 8 |
#include "SDL/SDL.h" |
| 9 |
#include "SDL/SDL_video.h" |
| 10 |
#include "SDL/SDL_mouse.h" |
| 11 |
#include "SDL/SDL_syswm.h" |
| 12 |
|
| 13 |
#ifndef SDL_VERSIONNUM |
| 14 |
#define SDL_VERSIONNUM(X, Y, Z) (X)*1000 + (Y)*100 + (Z) |
| 15 |
#endif |
| 16 |
|
| 17 |
#define _SDL_VER SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL) |
| 18 |
|
| 19 |
#if _SDL_VER < 1103 |
| 20 |
int main(int argc, char *argv[]) { return 0; } |
| 21 |
#else |
| 22 |
|
| 23 |
static const char* def_file = "KylieMinogue.bmp"; |
| 24 |
static int width = 640; |
| 25 |
static int height = 480; |
| 26 |
static int fourcc = SDL_YV12_OVERLAY; |
| 27 |
|
| 28 |
int main(int argc, char *argv[]) |
| 29 |
{ |
| 30 |
SDL_Surface* screen; |
| 31 |
SDL_Surface* bitmap; |
| 32 |
SDL_Overlay* overlay; |
| 33 |
Uint8 video_bpp; |
| 34 |
Uint32 videoflags; |
| 35 |
Uint8 *buffer; |
| 36 |
int i, done; |
| 37 |
SDL_Event event; |
| 38 |
SDL_Rect rect; |
| 39 |
int use_yuv; |
| 40 |
|
| 41 |
|
| 42 |
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { |
| 43 |
fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); |
| 44 |
exit(1); |
| 45 |
} |
| 46 |
atexit(SDL_Quit); |
| 47 |
SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); |
| 48 |
|
| 49 |
video_bpp = 0; |
| 50 |
videoflags = SDL_SWSURFACE | SDL_RESIZABLE; |
| 51 |
while ( argc > 1 ) { |
| 52 |
--argc; |
| 53 |
if ( strcmp(argv[argc-1], "-bpp") == 0 ) { |
| 54 |
video_bpp = atoi(argv[argc]); |
| 55 |
--argc; |
| 56 |
} else if ( strcmp(argv[argc], "-warp") == 0 ) { |
| 57 |
videoflags |= SDL_HWPALETTE; |
| 58 |
} else if ( strcmp(argv[argc], "-w") == 0 ) { |
| 59 |
width = atoi(argv[++argc]); |
| 60 |
} else if ( strcmp(argv[argc], "-h") == 0 ) { |
| 61 |
height = atoi(argv[++argc]); |
| 62 |
} else if ( strcmp(argv[argc], "-hw") == 0 ) { |
| 63 |
videoflags |= SDL_HWSURFACE; |
| 64 |
} else if ( strcmp(argv[argc], "-yv12") == 0 ) { |
| 65 |
fourcc = SDL_YV12_OVERLAY; |
| 66 |
} else if ( strcmp(argv[argc], "-iyuv") == 0 ) { |
| 67 |
fourcc = SDL_IYUV_OVERLAY; |
| 68 |
} else if ( strcmp(argv[argc], "-yuy2") == 0 ) { |
| 69 |
fourcc = SDL_YV12_OVERLAY; |
| 70 |
} else if ( strcmp(argv[argc], "-uyvy") == 0 ) { |
| 71 |
fourcc = SDL_UYVY_OVERLAY; |
| 72 |
} else if ( strcmp(argv[argc], "-yvyu") == 0 ) { |
| 73 |
fourcc = SDL_YVYU_OVERLAY; |
| 74 |
} else if ( strcmp(argv[argc], "-fullscreen") == 0 ) { |
| 75 |
videoflags |= SDL_FULLSCREEN; |
| 76 |
} else { |
| 77 |
fprintf(stderr, "Usage: %s [-bpp N] [-warp] [-hw] [-fullscreen]" |
| 78 |
"[-yuy2|-iyuv|-yv12|-uyvy|-yvyu] [-w #width] [-h #height]" |
| 79 |
"\n", |
| 80 |
argv[0]); |
| 81 |
exit(1); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
if ( (screen=SDL_SetVideoMode(width, height, video_bpp, videoflags)) == NULL ) { |
| 87 |
fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n", |
| 88 |
video_bpp, SDL_GetError()); |
| 89 |
exit(2); |
| 90 |
} |
| 91 |
|
| 92 |
overlay = SDL_CreateYUVOverlay(width, height, fourcc, screen); |
| 93 |
|
| 94 |
|
| 95 |
if ( SDL_LockSurface(screen) < 0 ) { |
| 96 |
fprintf(stderr, "Couldn't lock the display surface: %s\n", |
| 97 |
SDL_GetError()); |
| 98 |
exit(2); |
| 99 |
} |
| 100 |
buffer=(Uint8 *)screen->pixels; |
| 101 |
for ( i=screen->h/2; i<screen->h; i++ ) { |
| 102 |
memset(buffer, (i*255)/screen->h, screen->pitch); |
| 103 |
buffer += screen->pitch; |
| 104 |
} |
| 105 |
SDL_UnlockSurface(screen); |
| 106 |
SDL_UpdateRect(screen, 0, 0, 0, 0); |
| 107 |
|
| 108 |
buffer = (Uint8 *)overlay->pixels[0]; |
| 109 |
for (i = 0; i < screen->h; i++) |
| 110 |
{ |
| 111 |
memset(buffer, i, overlay->pitches[0]); |
| 112 |
buffer += overlay->pitches[0]; |
| 113 |
} |
| 114 |
|
| 115 |
rect.x = rect.y = 0; |
| 116 |
rect.w = width; |
| 117 |
rect.h = height; |
| 118 |
SDL_DisplayYUVOverlay(overlay, &rect); |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
bitmap = SDL_LoadBMP(def_file); |
| 123 |
if ( bitmap == NULL ) { |
| 124 |
exit(1); |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
done = 0; |
| 129 |
while ( !done ) { |
| 130 |
|
| 131 |
while ( SDL_PollEvent(&event) ) { |
| 132 |
switch (event.type) { |
| 133 |
case SDL_MOUSEBUTTONDOWN: { |
| 134 |
SDL_Rect dst; |
| 135 |
|
| 136 |
dst.x = event.button.x - bitmap->w/2; |
| 137 |
dst.y = event.button.y - bitmap->h/2; |
| 138 |
dst.w = bitmap->w; |
| 139 |
dst.h = bitmap->h; |
| 140 |
SDL_BlitSurface(bitmap, NULL, screen, &dst); |
| 141 |
SDL_UpdateRects(screen,1,&dst); |
| 142 |
SDL_DisplayYUVOverlay(overlay, &rect); |
| 143 |
} |
| 144 |
break; |
| 145 |
case SDL_KEYDOWN: |
| 146 |
switch (event.key.keysym.sym) |
| 147 |
{ |
| 148 |
case SDLK_q: |
| 149 |
case SDLK_ESCAPE: |
| 150 |
case SDLK_RETURN: |
| 151 |
done = 1; |
| 152 |
break; |
| 153 |
case SDLK_SPACE: |
| 154 |
|
| 155 |
|
| 156 |
printf("KEYSPACE\n"); |
| 157 |
break; |
| 158 |
} |
| 159 |
break; |
| 160 |
case SDL_QUIT: |
| 161 |
done = 1; |
| 162 |
break; |
| 163 |
default: |
| 164 |
|
| 165 |
SDL_DisplayYUVOverlay(overlay, &rect); |
| 166 |
break; |
| 167 |
} |
| 168 |
} |
| 169 |
} |
| 170 |
SDL_FreeSurface(bitmap); |
| 171 |
return(0); |
| 172 |
} |
| 173 |
#endif |