Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Ace_K's LCD Pixel Scrubber. Run for at least 10 minutes, screens in severe
- * condition may need several hours. Do not stare at this if you have epilepsy*/
- #include <SDL/SDL.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- #define HRES 1920
- #define VRES 1080
- #define FPS 60
- Uint16 CreateHicolorPixel(SDL_PixelFormat * fmt, Uint8 red, Uint8 green,
- Uint8 blue)
- {
- Uint16 value;
- /* This series of bit shifts uses the information from the SDL_Format
- * structure to correctly compose a 16-bit pixel value from 8-bit RGB */
- value = ((red >> fmt->Rloss) << fmt->Rshift) +
- ((green >> fmt->Gloss) << fmt->Gshift) +
- ((blue >> fmt->Bloss) << fmt->Bshift);
- return value;
- }
- int main(int argc, char **argv)
- {
- (void) argc;
- (void) argv;
- SDL_Surface *screen;
- SDL_Event event;
- Uint16 *raw_pixels;
- int x, y;
- char quit = 0;
- u_int8_t pixel_mask = 0xFF;
- /* Init SDL */
- if (SDL_Init(SDL_INIT_VIDEO) != 0) {
- fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
- return 1;
- }
- /* Make sure SDL_Quit get's called when program exits */
- atexit(SDL_Quit);
- (void) SDL_ShowCursor(SDL_DISABLE);
- screen = SDL_SetVideoMode(HRES, VRES, 16, SDL_SWSURFACE |
- SDL_FULLSCREEN);
- if (screen == NULL) {
- fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError());
- return 1;
- }
- /* Get a pointer to the video surface's memory. */
- raw_pixels = (Uint16*) screen->pixels;
- /* create a scanline effect */
- while (!quit) {
- /*MSG PUMP*/
- if (SDL_PollEvent(&event)) {
- switch (event.type) {
- case SDL_QUIT:
- quit = 1;
- break;
- case SDL_KEYDOWN:
- switch (event.key.keysym.sym) {
- case SDLK_ESCAPE:
- case SDLK_q:
- quit = 1;
- break;
- }
- break;
- }
- }
- SDL_LockSurface(screen);
- pixel_mask = ~pixel_mask;
- for(x = 0; x < HRES; x++) {
- for(y = 0; y < VRES; y++) {
- Uint16 pixel_color;
- int offset;
- pixel_color = CreateHicolorPixel(screen->format, 0xFF ^ pixel_mask,
- 0xFF ^ pixel_mask,
- 0xFF ^ pixel_mask);
- offset = ((screen->pitch >> 1) * y + x);
- raw_pixels[offset] = pixel_color;
- pixel_mask = ~pixel_mask;
- }
- pixel_mask = ~pixel_mask;
- }
- SDL_UnlockSurface(screen);
- /* Sleep for 16ms between frame draws at 60hz */
- SDL_Delay(1000 / FPS);
- SDL_UpdateRect(screen, 0, 0, 0, 0);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment