19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Bring up a window and play with it */ 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <stdlib.h> 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <stdio.h> 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <string.h> 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define BENCHMARK_SDL 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define NOTICE(X) printf("%s", X); 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define WINDOW_WIDTH 640 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define WINDOW_HEIGHT 480 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL.h" 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_Surface *screen, *pic; 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_Overlay *overlay; 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint scale; 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint monochrome; 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint luminance; 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint w, h; 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void quit(int rc) 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Quit(); 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall exit(rc); 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* NOTE: These RGB conversion functions are not intended for speed, 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall only as examples. 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid RGBtoYUV(Uint8 *rgb, int *yuv, int monochrome, int luminance) 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (monochrome) 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if 1 /* these are the two formulas that I found on the FourCC site... */ 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall yuv[0] = 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2]; 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall yuv[1] = 128; 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall yuv[2] = 128; 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall yuv[0] = (0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16; 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall yuv[1] = 128; 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall yuv[2] = 128; 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if 1 /* these are the two formulas that I found on the FourCC site... */ 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall yuv[0] = 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2]; 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall yuv[1] = (rgb[2]-yuv[0])*0.565 + 128; 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall yuv[2] = (rgb[0]-yuv[0])*0.713 + 128; 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall yuv[0] = (0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16; 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall yuv[1] = 128 - (0.148 * rgb[0]) - (0.291 * rgb[1]) + (0.439 * rgb[2]); 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall yuv[2] = 128 + (0.439 * rgb[0]) - (0.368 * rgb[1]) - (0.071 * rgb[2]); 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (luminance!=100) 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall yuv[0]=yuv[0]*luminance/100; 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (yuv[0]>255) 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall yuv[0]=255; 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* clamp values...if you need to, we don't seem to have a need */ 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for(i=0;i<3;i++) 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(yuv[i]<0) 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall yuv[i]=0; 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(yuv[i]>255) 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall yuv[i]=255; 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid ConvertRGBtoYV12(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance) 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x,y; 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int yuv[3]; 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint8 *p,*op[3]; 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LockSurface(s); 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LockYUVOverlay(o); 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Black initialization */ 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall memset(o->pixels[0],0,o->pitches[0]*o->h); 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall memset(o->pixels[1],128,o->pitches[1]*((o->h+1)/2)); 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall memset(o->pixels[2],128,o->pitches[2]*((o->h+1)/2)); 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Convert */ 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for(y=0; y<s->h && y<o->h; y++) 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall p=((Uint8 *) s->pixels)+s->pitch*y; 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall op[0]=o->pixels[0]+o->pitches[0]*y; 1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall op[1]=o->pixels[1]+o->pitches[1]*(y/2); 1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall op[2]=o->pixels[2]+o->pitches[2]*(y/2); 1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for(x=0; x<s->w && x<o->w; x++) 1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall RGBtoYUV(p, yuv, monochrome, luminance); 1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *(op[0]++)=yuv[0]; 1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(x%2==0 && y%2==0) 1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *(op[1]++)=yuv[2]; 1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *(op[2]++)=yuv[1]; 1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall p+=s->format->BytesPerPixel; 1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UnlockYUVOverlay(o); 1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UnlockSurface(s); 1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid ConvertRGBtoIYUV(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance) 1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x,y; 1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int yuv[3]; 1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint8 *p,*op[3]; 1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LockSurface(s); 1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LockYUVOverlay(o); 1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Black initialization */ 1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall memset(o->pixels[0],0,o->pitches[0]*o->h); 1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall memset(o->pixels[1],128,o->pitches[1]*((o->h+1)/2)); 1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall memset(o->pixels[2],128,o->pitches[2]*((o->h+1)/2)); 1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Convert */ 1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for(y=0; y<s->h && y<o->h; y++) 1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall p=((Uint8 *) s->pixels)+s->pitch*y; 1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall op[0]=o->pixels[0]+o->pitches[0]*y; 1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall op[1]=o->pixels[1]+o->pitches[1]*(y/2); 1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall op[2]=o->pixels[2]+o->pitches[2]*(y/2); 1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for(x=0; x<s->w && x<o->w; x++) 1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall RGBtoYUV(p,yuv, monochrome, luminance); 1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *(op[0]++)=yuv[0]; 1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(x%2==0 && y%2==0) 1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *(op[1]++)=yuv[1]; 1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *(op[2]++)=yuv[2]; 1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall p+=s->format->BytesPerPixel; 1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UnlockYUVOverlay(o); 1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UnlockSurface(s); 1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid ConvertRGBtoUYVY(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance) 1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x,y; 1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int yuv[3]; 1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint8 *p,*op; 1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LockSurface(s); 1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LockYUVOverlay(o); 1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for(y=0; y<s->h && y<o->h; y++) 1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall p=((Uint8 *) s->pixels)+s->pitch*y; 1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall op=o->pixels[0]+o->pitches[0]*y; 1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for(x=0; x<s->w && x<o->w; x++) 1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall RGBtoYUV(p, yuv, monochrome, luminance); 1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(x%2==0) 1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *(op++)=yuv[1]; 1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *(op++)=yuv[0]; 1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *(op++)=yuv[2]; 1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *(op++)=yuv[0]; 1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall p+=s->format->BytesPerPixel; 1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UnlockYUVOverlay(o); 1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UnlockSurface(s); 1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid ConvertRGBtoYVYU(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance) 1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x,y; 1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int yuv[3]; 1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint8 *p,*op; 1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LockSurface(s); 2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LockYUVOverlay(o); 2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for(y=0; y<s->h && y<o->h; y++) 2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall p=((Uint8 *) s->pixels)+s->pitch*y; 2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall op=o->pixels[0]+o->pitches[0]*y; 2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for(x=0; x<s->w && x<o->w; x++) 2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall RGBtoYUV(p,yuv, monochrome, luminance); 2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(x%2==0) 2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *(op++)=yuv[0]; 2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *(op++)=yuv[2]; 2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall op[1]=yuv[1]; 2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *op=yuv[0]; 2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall op+=2; 2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall p+=s->format->BytesPerPixel; 2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UnlockYUVOverlay(o); 2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UnlockSurface(s); 2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid ConvertRGBtoYUY2(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance) 2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x,y; 2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int yuv[3]; 2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint8 *p,*op; 2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LockSurface(s); 2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LockYUVOverlay(o); 2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for(y=0; y<s->h && y<o->h; y++) 2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall p=((Uint8 *) s->pixels)+s->pitch*y; 2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall op=o->pixels[0]+o->pitches[0]*y; 2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for(x=0; x<s->w && x<o->w; x++) 2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall RGBtoYUV(p,yuv, monochrome, luminance); 2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(x%2==0) 2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *(op++)=yuv[0]; 2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *(op++)=yuv[1]; 2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall op[1]=yuv[2]; 2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *op=yuv[0]; 2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall op+=2; 2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall p+=s->format->BytesPerPixel; 2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UnlockYUVOverlay(o); 2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UnlockSurface(s); 2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid Draw() 2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Rect rect; 2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int i; 2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int disp; 2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(!scale) 2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.w=overlay->w; 2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.h=overlay->h; 2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for(i=0; i<h-rect.h && i<w-rect.w; i++) 2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.x=i; 2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.y=i; 2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_DisplayYUVOverlay(overlay,&rect); 2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.w=overlay->w/2; 2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.h=overlay->h/2; 2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.x=(w-rect.w)/2; 2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.y=(h-rect.h)/2; 2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall disp=rect.y-1; 2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for(i=0; i<disp; i++) 2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.w+=2; 2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.h+=2; 2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.x--; 2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rect.y--; 2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_DisplayYUVOverlay(overlay,&rect); 2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("Displayed %d times.\n",i); 3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void PrintUsage(char *argv0) 3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, "Usage: %s [arg] [arg] [arg] ...\n", argv0); 3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, "Where 'arg' is one of:\n"); 3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, " -delay <seconds>\n"); 3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, " -width <pixels>\n"); 3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, " -height <pixels>\n"); 3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, " -bpp <bits>\n"); 3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, " -format <fmt> (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n"); 3119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, " -hw\n"); 3129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, " -flip\n"); 3139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, " -scale (test scaling features, from 50%% upto window size)\n"); 3149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, " -mono (use monochromatic RGB2YUV conversion)\n"); 3159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, " -lum <perc> (use luminance correction during RGB2YUV conversion,\n"); 3169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, " from 0%% to unlimited, normal is 100%%)\n"); 3179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, " -help (shows this help)\n"); 3189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, " -fullscreen (test overlay in fullscreen mode)\n"); 3199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint main(int argc, char **argv) 3229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall char *argv0 = argv[0]; 3249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int flip; 3259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int delay; 3269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int desired_bpp; 3279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 video_flags, overlay_format; 3289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall char *bmpfile; 3299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef BENCHMARK_SDL 3309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 then, now; 3319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 3329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int i; 3339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set default options and check command-line */ 3359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flip = 0; 3369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall scale=0; 3379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall monochrome=0; 3389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall luminance=100; 3399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall delay = 1; 3409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall w = WINDOW_WIDTH; 3419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall h = WINDOW_HEIGHT; 3429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall desired_bpp = 0; 3439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video_flags = 0; 3449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay_format = SDL_YV12_OVERLAY; 3459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while ( argc > 1 ) { 3479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( strcmp(argv[1], "-delay") == 0 ) { 3489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( argv[2] ) { 3499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall delay = atoi(argv[2]); 3509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argv += 2; 3519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argc -= 2; 3529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 3539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, 3549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall "The -delay option requires an argument\n"); 3559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(1); 3569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 3589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( strcmp(argv[1], "-width") == 0 ) { 3599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( argv[2] && ((w = atoi(argv[2])) > 0) ) { 3609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argv += 2; 3619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argc -= 2; 3629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 3639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, 3649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall "The -width option requires an argument\n"); 3659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(1); 3669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 3689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( strcmp(argv[1], "-height") == 0 ) { 3699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( argv[2] && ((h = atoi(argv[2])) > 0) ) { 3709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argv += 2; 3719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argc -= 2; 3729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 3739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, 3749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall "The -height option requires an argument\n"); 3759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(1); 3769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 3789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( strcmp(argv[1], "-bpp") == 0 ) { 3799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( argv[2] ) { 3809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall desired_bpp = atoi(argv[2]); 3819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argv += 2; 3829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argc -= 2; 3839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 3849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, 3859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall "The -bpp option requires an argument\n"); 3869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(1); 3879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 3899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( strcmp(argv[1], "-lum") == 0 ) { 3909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( argv[2] ) { 3919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall luminance = atoi(argv[2]); 3929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argv += 2; 3939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argc -= 2; 3949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 3959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, 3969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall "The -lum option requires an argument\n"); 3979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(1); 3989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 4009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( strcmp(argv[1], "-format") == 0 ) { 4019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( argv[2] ) { 4029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(!strcmp(argv[2],"YV12")) 4039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay_format = SDL_YV12_OVERLAY; 4049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else if(!strcmp(argv[2],"IYUV")) 4059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay_format = SDL_IYUV_OVERLAY; 4069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else if(!strcmp(argv[2],"YUY2")) 4079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay_format = SDL_YUY2_OVERLAY; 4089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else if(!strcmp(argv[2],"UYVY")) 4099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay_format = SDL_UYVY_OVERLAY; 4109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else if(!strcmp(argv[2],"YVYU")) 4119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay_format = SDL_YVYU_OVERLAY; 4129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 4139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 4149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, "The -format option %s is not recognized\n",argv[2]); 4159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(1); 4169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argv += 2; 4189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argc -= 2; 4199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 4209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, 4219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall "The -format option requires an argument\n"); 4229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(1); 4239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 4259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( strcmp(argv[1], "-hw") == 0 ) { 4269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video_flags |= SDL_HWSURFACE; 4279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argv += 1; 4289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argc -= 1; 4299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 4309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( strcmp(argv[1], "-flip") == 0 ) { 4319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video_flags |= SDL_DOUBLEBUF; 4329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argv += 1; 4339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argc -= 1; 4349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 4359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( strcmp(argv[1], "-scale") == 0 ) { 4369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall scale = 1; 4379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argv += 1; 4389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argc -= 1; 4399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 4409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( strcmp(argv[1], "-mono") == 0 ) { 4419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall monochrome = 1; 4429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argv += 1; 4439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argc -= 1; 4449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 4459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (( strcmp(argv[1], "-help") == 0 ) || (strcmp(argv[1], "-h") == 0)) { 4469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall PrintUsage(argv0); 4479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(1); 4489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 4499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( strcmp(argv[1], "-fullscreen") == 0 ) { 4509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall video_flags |= SDL_FULLSCREEN; 4519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argv += 1; 4529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall argc -= 1; 4539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 4549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 4559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { 4579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, 4589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall "Couldn't initialize SDL: %s\n", SDL_GetError()); 4599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(1); 4609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Initialize the display */ 4639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags); 4649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( screen == NULL ) { 4659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", 4669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall w, h, desired_bpp, SDL_GetError()); 4679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall quit(1); 4689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("Set%s %dx%dx%d mode\n", 4709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall screen->flags & SDL_FULLSCREEN ? " fullscreen" : "", 4719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall screen->w, screen->h, screen->format->BitsPerPixel); 4729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("(video surface located in %s memory)\n", 4739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (screen->flags&SDL_HWSURFACE) ? "video" : "system"); 4749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( screen->flags & SDL_DOUBLEBUF ) { 4759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("Double-buffering enabled\n"); 4769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flip = 1; 4779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set the window manager title bar */ 4809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_WM_SetCaption("SDL test overlay", "testoverlay"); 4819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Load picture */ 4839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bmpfile=(argv[1]?argv[1]:"sample.bmp"); 4849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pic = SDL_LoadBMP(bmpfile); 4859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( pic == NULL ) { 4869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, 4879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GetError()); 4889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall quit(1); 4899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Convert the picture to 32bits, for easy conversion */ 4929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 4939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Surface *newsurf; 4949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PixelFormat format; 4959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.palette=NULL; 4979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.BitsPerPixel=32; 4989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.BytesPerPixel=4; 4999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_BYTEORDER == SDL_LIL_ENDIAN 5009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.Rshift=0; 5019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.Gshift=8; 5029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.Bshift=16; 5039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 5049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.Rshift=24; 5059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.Gshift=16; 5069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.Bshift=8; 5079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 5089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.Ashift=0; 5099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.Rmask=0xff<<format.Rshift; 5109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.Gmask=0xff<<format.Gshift; 5119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.Bmask=0xff<<format.Bshift; 5129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.Amask=0; 5139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.Rloss=0; 5149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.Gloss=0; 5159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.Bloss=0; 5169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.Aloss=8; 5179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.colorkey=0; 5189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall format.alpha=0; 5199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall newsurf=SDL_ConvertSurface(pic, &format, SDL_SWSURFACE); 5219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(!newsurf) 5229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 5239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, "Couldn't convert picture to 32bits RGB: %s\n", 5249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GetError()); 5259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall quit(1); 5269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_FreeSurface(pic); 5289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pic=newsurf; 5299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Create the overlay */ 5329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay = SDL_CreateYUVOverlay(pic->w, pic->h, overlay_format, screen); 5339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( overlay == NULL ) { 5349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, "Couldn't create overlay: %s\n", SDL_GetError()); 5359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall quit(1); 5369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("Created %dx%dx%d %s %s overlay\n",overlay->w,overlay->h,overlay->planes, 5389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->hw_overlay?"hardware":"software", 5399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->format==SDL_YV12_OVERLAY?"YV12": 5409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->format==SDL_IYUV_OVERLAY?"IYUV": 5419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->format==SDL_YUY2_OVERLAY?"YUY2": 5429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->format==SDL_UYVY_OVERLAY?"UYVY": 5439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->format==SDL_YVYU_OVERLAY?"YVYU": 5449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall "Unknown"); 5459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for(i=0; i<overlay->planes; i++) 5469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 5479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf(" plane %d: pitch=%d\n", i, overlay->pitches[i]); 5489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Convert to YUV, and draw to the overlay */ 5519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef BENCHMARK_SDL 5529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall then = SDL_GetTicks(); 5539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 5549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall switch(overlay->format) 5559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 5569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_YV12_OVERLAY: 5579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ConvertRGBtoYV12(pic,overlay,monochrome,luminance); 5589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 5599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_UYVY_OVERLAY: 5609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ConvertRGBtoUYVY(pic,overlay,monochrome,luminance); 5619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 5629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_YVYU_OVERLAY: 5639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ConvertRGBtoYVYU(pic,overlay,monochrome,luminance); 5649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 5659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_YUY2_OVERLAY: 5669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ConvertRGBtoYUY2(pic,overlay,monochrome,luminance); 5679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 5689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_IYUV_OVERLAY: 5699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ConvertRGBtoIYUV(pic,overlay,monochrome,luminance); 5709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 5719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall default: 5729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("cannot convert RGB picture to obtained YUV format!\n"); 5739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall quit(1); 5749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 5759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef BENCHMARK_SDL 5779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall now = SDL_GetTicks(); 5789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("Conversion Time: %d milliseconds\n", now-then); 5799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 5809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Do all the drawing work */ 5829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef BENCHMARK_SDL 5839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall then = SDL_GetTicks(); 5849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 5859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Draw(); 5869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef BENCHMARK_SDL 5879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall now = SDL_GetTicks(); 5889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("Time: %d milliseconds\n", now-then); 5899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 5909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Delay(delay*1000); 5919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Quit(); 5929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 5939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 5949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 595