fisualizer/fisualizer.c
Anthony Debucquoy 6c4944f985
First version out
It certainly is full of bug but the main goal is done so i'm kinda happy
^^
2023-10-22 21:17:45 +02:00

54 lines
1.1 KiB
C

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
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));
double weight = (double)file_sz / 255;
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] += weight;
}
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;
}