#include #include #define STB_IMAGE_WRITE_IMPLEMENTATION #include "stb_image_write.h" #include FILE *fd; size_t file_sz; unsigned char *file_cnt, *canvas; char *filename_output; int main(int argc, char *argv[]) { argv++; while(argc--){ const char* filename = *argv++; filename_output = malloc(sizeof(char) * strlen(filename) + 8); strcpy(filename_output, filename); fd = fopen(filename, "r"); if(fd == NULL){ fprintf(stderr, "couldn't open this file: %s\n", filename); continue; } // get file size fseek(fd, 0, SEEK_END); file_sz = ftell(fd); rewind(fd); file_cnt = malloc(sizeof(char)*file_sz); fread(file_cnt, sizeof(char), file_sz, fd); canvas = calloc(256*256, sizeof(char)); for (size_t i = 0; i < file_sz - 1; ++i) { unsigned char at_pos = file_cnt[i], next_pos = file_cnt[i+1]; canvas[at_pos + next_pos * 256] = 255; } stbi_write_png(strcat(filename_output, ".out.png"), 256, 256, 1, canvas, 256); free(canvas); free(file_cnt); free(filename_output); fclose(fd); } return 0; }