Last active
December 28, 2015 03:59
-
-
Save vijfhoek/7438775 to your computer and use it in GitHub Desktop.
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
#define _CRT_SECURE_NO_WARNINGS /* Shut up, Visual Studio */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <SOIL.h> | |
const char *asciichars = "#*+=-:. "; | |
int main(int argc, char **argv) { | |
if (argc != 3) { printf("Syntax: %s <infile> <outfile>\n", argv[0]); return -1; } | |
int width, height, channels; | |
unsigned char *data = SOIL_load_image(argv[1], &width, &height, &channels, 1); | |
if (!data) { printf("Loading error: %s\n", SOIL_last_result()); return -1; } | |
char *output = new char[(height/2 + 1) * (width+1)]; | |
int i = 0; | |
for (int y = 0; y < height; y += 2) { /* +2 to compensate for characters being higher than they're wide */ | |
for (int x = 0; x < width; ++x) | |
output[i++] = asciichars[data[y * width + x] >> 5]; | |
output[i++] = '\n'; | |
} | |
FILE *out = fopen(argv[2], "w"); | |
if (!out) return -1; | |
fwrite(output, 1, height/2 * (width + 1), out); | |
fclose(out); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment