/* gcc -std=c99 *.c -lm && ./a.out | mpv --no-correct-pts --container-fps-override=30 -
 * gcc -std=c99 *.c -lm && ./a.out | ffmpeg -r 30 -i - output.mp4
 */

#include "FrameRender/FrameRender.h"
#include "FrameRender/P_Checker.h"
#include "FrameRender/P_Circle.h"
#include "FrameRender/P_Image.h"
#include "FrameRender/P_Square.h"
#include "FrameRender/P_TransformCenter.h"
#include "FrameRender/P_TransformRotate.h"
#include "RGBImage.h"
#include "math.h"
#include <stdlib.h>

int
main() {
	RGBImage frame = RGBImage_new(512, 512);

	RGBImage bclc = ppm_read(fopen("bclc.ppm", "rb"));

	PixelCallback* callbacks[] = {
		Checker_setup((Checker){
			.squareSize = 64, .colorA = 0xFF000000, .colorB = 0xFFFF00FF,
		}),
		TransformCenter_setup((TransformCenter){
			.centerX = frame.width / 2, .centerY = frame.height / 2,
		}),
		Square_setup((Square){
			.width = 100, .height = 100, .color = 0xFFFFFF00,
		}),
		NULL,
		TransformRotate_setup((TransformRotate){
			.angle = M_PI_4 / 2,
		}),
		Square_setup((Square){
			.width = 200, .height = 200, .color = 0xFF00FFFF,
		}),
		NULL,
		TransformCenter_setup((TransformCenter){
			.centerX = frame.width * 3/4, .centerY = frame.height / 2,
		}),
		Circle_setup((Circle){
			.radius = 50, .color = 0x80FFFFFF,
		}),
		NULL,
		TransformCenter_setup((TransformCenter){
			.centerX = frame.width / 8, .centerY = frame.height * 3/5,
		}),
		Image_setup((Image){
			.img = bclc,
			.scale = 0.2,
		}),
	};
	u32 sizeCallbacks = sizeof(callbacks) / sizeof(*callbacks);

	RenderFrame(frame, (const PixelCallback**)callbacks, sizeCallbacks);
	ppm6_write(stdout, frame);

	RGBImage_delete(&frame);
	RGBImage_delete(&bclc);
	for (u32 i = 0; i < sizeCallbacks; ++i) {
		if (callbacks[i] == NULL) continue;
		free(callbacks[i]->callback_self);
		free(callbacks[i]);
	}

	return 0;
}
