Guest User

lcdscrub.c

a guest
Mar 28th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.52 KB | None | 0 0
  1. /* Ace_K's LCD Pixel Scrubber. Run for at least 10 minutes, screens in severe
  2.  * condition may need several hours. Do not stare at this if you have epilepsy*/
  3.  
  4. #include <SDL/SDL.h>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <unistd.h>
  8.  
  9. #define HRES 1920
  10. #define VRES 1080
  11. #define FPS  60
  12.  
  13. Uint16 CreateHicolorPixel(SDL_PixelFormat * fmt, Uint8 red, Uint8 green,
  14.               Uint8 blue)
  15. {
  16.     Uint16 value;
  17.     /* This series of bit shifts uses the information from the SDL_Format
  18.      * structure to correctly compose a 16-bit pixel value from 8-bit RGB */
  19.     value = ((red   >> fmt->Rloss) << fmt->Rshift) +
  20.         ((green >> fmt->Gloss) << fmt->Gshift) +
  21.         ((blue  >> fmt->Bloss) << fmt->Bshift);
  22.        
  23.     return value;
  24. }
  25.  
  26. int main(int argc, char **argv)
  27. {
  28.     (void) argc;
  29.     (void) argv;
  30.    
  31.     SDL_Surface *screen;
  32.     SDL_Event   event;
  33.     Uint16  *raw_pixels;
  34.     int x, y;
  35.     char quit = 0;
  36.     u_int8_t pixel_mask = 0xFF;
  37.    
  38.     /* Init SDL */
  39.     if (SDL_Init(SDL_INIT_VIDEO) != 0) {
  40.         fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
  41.         return 1;
  42.     }
  43.     /* Make sure SDL_Quit get's called when program exits */
  44.     atexit(SDL_Quit);
  45.     (void) SDL_ShowCursor(SDL_DISABLE);
  46.     screen = SDL_SetVideoMode(HRES, VRES, 16, SDL_SWSURFACE |
  47.                           SDL_FULLSCREEN);
  48.     if (screen == NULL) {
  49.         fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError());
  50.         return 1;
  51.     }
  52.    
  53.     /* Get a pointer to the video surface's memory. */
  54.     raw_pixels = (Uint16*) screen->pixels;
  55.    
  56.     /* create a scanline effect */
  57.     while (!quit) {
  58.         /*MSG PUMP*/
  59.         if (SDL_PollEvent(&event)) {
  60.             switch (event.type) {
  61.                 case SDL_QUIT:
  62.                     quit = 1;
  63.                     break;
  64.                 case SDL_KEYDOWN:
  65.                     switch (event.key.keysym.sym) {
  66.                         case SDLK_ESCAPE:
  67.                         case SDLK_q:
  68.                             quit = 1;
  69.                             break;
  70.                     }
  71.                     break;
  72.             }
  73.         }
  74.    
  75.         SDL_LockSurface(screen);
  76.         pixel_mask = ~pixel_mask;
  77.         for(x = 0; x < HRES; x++) {
  78.             for(y = 0; y < VRES; y++) {
  79.                 Uint16 pixel_color;
  80.                 int offset;
  81.                 pixel_color = CreateHicolorPixel(screen->format, 0xFF ^ pixel_mask,
  82.                                          0xFF ^ pixel_mask,
  83.                                          0xFF ^ pixel_mask);
  84.                                                  
  85.                 offset = ((screen->pitch >> 1) * y + x);
  86.                 raw_pixels[offset] = pixel_color;
  87.                 pixel_mask = ~pixel_mask;
  88.             }
  89.             pixel_mask = ~pixel_mask;
  90.         }
  91.         SDL_UnlockSurface(screen);
  92.    
  93.         /* Sleep for 16ms between frame draws at 60hz */
  94.         SDL_Delay(1000 / FPS);
  95.         SDL_UpdateRect(screen, 0, 0, 0, 0);
  96.     }
  97.    
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment