Created
January 29, 2016 17:54
-
-
Save flibitijibibo/f02dba0e361f994db9b0 to your computer and use it in GitHub Desktop.
"Nascar Jacket" Generator, which I wrote to make an image for my MAGFest 2016 slides
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* "Nascar Jacket" Image Generator | |
* Written by Ethan "flibitijibibo" Lee | |
* | |
* Released under public domain. | |
* No warranty implied, use at your own risk. | |
* | |
* Directions: | |
* - Grab a bunch of header.jpg files from Steam store pages | |
* - Line them up in zero-indexed numerical order (0.jpg, 1.jpg, ...) | |
* - Edit the defines below to get the jacket you want | |
* - `cc jacket.c -lSDL2 -lSDL2_image` | |
* - ./a.out | |
* - Enjoy jacket.png! | |
*/ | |
#include <SDL2/SDL.h> | |
#include <SDL2/SDL_image.h> | |
#define NUM_IMG 35 | |
#define FINAL_W 5 | |
#define FINAL_H 7 | |
#define IMAGE_W 460 | |
#define IMAGE_H 215 | |
int main(int argc, char **argv) | |
{ | |
SDL_Surface *finalImg; | |
SDL_Surface *curImg; | |
SDL_Rect region; | |
char path[7]; | |
Uint8 i; | |
finalImg = SDL_CreateRGBSurface( | |
0, | |
IMAGE_W * FINAL_W, | |
IMAGE_H * FINAL_H, | |
32, | |
0x000000FF, | |
0x0000FF00, | |
0x00FF0000, | |
0xFF000000 | |
); | |
region.x = 0; | |
region.y = 0; | |
region.w = IMAGE_W; | |
region.h = IMAGE_H; | |
for (i = 0; i < NUM_IMG; i += 1) | |
{ | |
SDL_snprintf(path, sizeof(path), "%i.jpg", i); | |
curImg = IMG_Load(path); | |
SDL_BlitSurface(curImg, NULL, finalImg, ®ion); | |
SDL_FreeSurface(curImg); | |
region.x += IMAGE_W; | |
if (region.x >= finalImg->w) | |
{ | |
region.x = 0; | |
region.y += IMAGE_H; | |
} | |
} | |
IMG_SavePNG(finalImg, "jacket.png"); | |
SDL_FreeSurface(finalImg); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment