texstretch/main.c

42 lines
1.0 KiB
C
Raw Normal View History

2024-07-22 23:19:27 +00:00
#include <stdio.h>
#include <stdlib.h>
2024-07-22 23:40:13 +00:00
#include <stdint.h>
#include <string.h>
typedef uint8_t u8;
#define CDEPTH 255
#define log(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
#define panic(fmt, ...) { fprintf(stderr, "PANIC: " fmt "\n", ##__VA_ARGS__); exit(EXIT_FAILURE); }
// fb is framebuffer. Thsi dumps a color version (rgb) of a framebuffer
// to stdout, which you can pipe to a file or some shit idk
void dump_ppm(u8 * fb, int width, int height) {
log("Dumping framebuffer %dx%d", width, height);
printf("P3\n%d %d\n%d\n# Image start\n", width, height, CDEPTH);
for(int i = 0; i < width * height * 3; i+=3)
printf("%d %d %d\n", fb[i], fb[i+1], fb[i+2]);
printf("\n");
}
2024-07-22 23:19:27 +00:00
int main() {
2024-07-22 23:40:13 +00:00
log("Program start");
const int width = 512;
const int height = 512;
const int fbsize = width * height * 3 * sizeof(u8);
u8 * fb = malloc(fbsize);
if(!fb) {
panic("Can't allocate framebuffer");
}
memset(fb, 0, fbsize);
// We actually stretch a texture
dump_ppm(fb, width, height);
log("Program end");
2024-07-22 23:19:27 +00:00
}