#include #include "mxfont.h" #include #include #include //# |_ For 333Mhz Overclock #include //# | SDL_Color back_buffer[480][272] = { 0 }; SDL_Surface *front = 0; struct SDL_Font *font = 0; int fade_r = 1, fade_g = 0, fade_b = 0; SDL_Surface *img[4] = { 0 }; SDL_Color *slow_get(SDL_Surface *surf, int x, int y) { void *buf = lock(surf, surf->format->BitsPerPixel); static SDL_Color c; getpixel(surf, x,y,surf->format->BitsPerPixel, surf->pitch, &c); unlock(buf); return &c; } void Init() { unsigned int i,z; scePowerSetClockFrequency(333, 333, 166); //# overclocked img[0] = SDL_LoadBMP("img1.bmp"); img[1] = SDL_LoadBMP("img2.bmp"); img[2] = SDL_LoadBMP("img3.bmp"); img[3] = SDL_LoadBMP("img4.bmp"); srand((unsigned int)time(0)); for(i = 0; i < 480; i++) for(z = 0; z < 272; z++) { back_buffer[i][z].r = slow_get(img[rand()%4], i,z)->r; back_buffer[i][z].g = slow_get(img[rand()%4], i,z)->g; back_buffer[i][z].b = slow_get(img[rand()%4], i,z)->b; } } void Blend(SDL_Surface *surf) { static float alpha = 1.0f; static unsigned int i,z; void *buf = lock(surf, surf->format->BitsPerPixel); for(i = 0; i < 480; i++) for(z = 0; z < 272; z++) { // get pixel struct SDL_Color col ; getpixel(surf, i,z,surf->format->BitsPerPixel, surf->pitch, &col); if((back_buffer[i][z].r = (unsigned char) (back_buffer[i][z].r) + ( alpha * col.r )) > 255) back_buffer[i][z].r = 255; if((back_buffer[i][z].g = (unsigned char) (back_buffer[i][z].g) + ( alpha * col.g )) > 255) back_buffer[i][z].g = 255; if((back_buffer[i][z].b = (unsigned char) (back_buffer[i][z].b) + ( alpha * col.b )) > 255) back_buffer[i][z].b = 255; } unlock(surf); } void Morph(SDL_Surface *surf) { static unsigned int i,z; for(i = 0; i < 439; i++) { for(z = 0; z < 271; z++) { int col[3]; col[0] = back_buffer[i][z].r + back_buffer[i+1][z].r + back_buffer[i][z+1].r + back_buffer[i+1][z+1].r; col[1] = back_buffer[i][z].g + back_buffer[i+1][z].g + back_buffer[i][z+1].g + back_buffer[i+1][z+1].g; col[2] = back_buffer[i][z].b + back_buffer[i+1][z].b + back_buffer[i][z+1].b + back_buffer[i+1][z+1].b; col[0] = col[0] / 4; col[1] = col[1] / 4; col[2] = col[2] / 4; if(fade_r == 1) { back_buffer[i][z].r = ++col[0]; back_buffer[i][z].g = --col[1]; back_buffer[i][z].b = --col[2]; } else if(fade_g == 1) { back_buffer[i][z].r = --col[0]; back_buffer[i][z].g = ++col[1]; back_buffer[i][z].b = --col[2]; } else if(fade_b == 1) { back_buffer[i][z].r = --col[0]; back_buffer[i][z].g = --col[1]; back_buffer[i][z].b = ++col[2]; } } } } void CopyBuffer(SDL_Surface *surf) { int i,z; void *buf; buf = lock(surf,surf->format); for(i = 0; i < surf->w; i++) for(z = 0; z < surf->h; z++) setpixel(buf, i,z,SDL_MapRGB(front->format,back_buffer[i][z].r, back_buffer[i][z].g, back_buffer[i][z].b),surf->format->BitsPerPixel, surf->pitch); unlock(surf); } void JaredBruniSaysAlphaFlameIt(SDL_Surface *surf) { Morph(surf); Blend(img[rand()%4]); CopyBuffer(front); } int SDL_main(int argc, char **argv) { SDL_Event e; int active = 1; struct SDL_Joystick *joy = 0; if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) return -1; if(!(front = SDL_SetVideoMode(480,272,0,0))) return -1; if(!(font = SDL_InitFont("font.mxf"))) { SDL_FreeSurface(front); return -1; } SDL_FillRect(front, 0, 0); SDL_PrintText(front, font, 10,10, SDL_MapRGB(front->format, 255,0,0), "Loading..."); SDL_UpdateRect(front, 0,0,480,272); Init(); joy = SDL_JoystickOpen(0); SDL_JoystickEventState(SDL_ENABLE); while(active == 1) { JaredBruniSaysAlphaFlameIt(front); if(SDL_PollEvent(&e)) { switch(e.type) { case SDL_QUIT: active = 0; break; case SDL_JOYBUTTONDOWN: { switch(e.jbutton.button) { case 0: fade_r = 1; fade_g = 0; fade_b = 0; break; case 1: fade_r = 0; fade_g = 1; fade_b = 0; break; case 2: fade_r = 0; fade_g = 0; fade_b = 1; break; } } break; } } SDL_UpdateRect(front, 0,0,480,272); } for(active = 0; active < 4; active++) SDL_FreeSurface(img[active]); SDL_FreeSurface(front); SDL_FreeFont(font); SDL_JoystickClose(joy); return 0; }