2023-10-19 22:57:01 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2023-10-22 21:17:45 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2023-10-21 21:11:22 +02:00
|
|
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
|
|
|
#include "stb_image_write.h"
|
2023-10-19 22:57:01 +02:00
|
|
|
|
|
|
|
FILE *fd;
|
|
|
|
size_t file_sz;
|
2023-10-21 21:11:22 +02:00
|
|
|
unsigned char *file_cnt, *canvas;
|
|
|
|
char *filename_output;
|
2023-10-19 22:57:01 +02:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2023-10-21 21:11:22 +02:00
|
|
|
argv++;
|
2023-10-22 21:17:45 +02:00
|
|
|
while(--argc){
|
2023-10-19 22:57:01 +02:00
|
|
|
|
|
|
|
const char* filename = *argv++;
|
2023-10-21 21:11:22 +02:00
|
|
|
filename_output = malloc(sizeof(char) * strlen(filename) + 8);
|
|
|
|
strcpy(filename_output, filename);
|
2023-10-19 22:57:01 +02:00
|
|
|
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);
|
|
|
|
|
2023-10-21 21:11:22 +02:00
|
|
|
canvas = calloc(256*256, sizeof(char));
|
2023-10-19 22:57:01 +02:00
|
|
|
|
2023-10-22 21:17:45 +02:00
|
|
|
double weight = (double)file_sz / 255;
|
|
|
|
|
2023-10-21 21:11:22 +02:00
|
|
|
for (size_t i = 0; i < file_sz - 1; ++i) {
|
|
|
|
unsigned char at_pos = file_cnt[i], next_pos = file_cnt[i+1];
|
2023-10-22 21:17:45 +02:00
|
|
|
canvas[at_pos + next_pos * 256] += weight;
|
2023-10-21 21:11:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
stbi_write_png(strcat(filename_output, ".out.png"), 256, 256, 1, canvas, 256);
|
|
|
|
|
|
|
|
free(canvas);
|
2023-10-19 22:57:01 +02:00
|
|
|
free(file_cnt);
|
2023-10-21 21:11:22 +02:00
|
|
|
free(filename_output);
|
2023-10-19 22:57:01 +02:00
|
|
|
fclose(fd);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|