#include #include #include #include /* Default values */ #define FPS 60.0 #define DUR 1.0 #define POS 0 #define WIDTH 1920 #define HEIGHT 1080 #define OPACITY 1.0 float kexpout(float i, float f, float t) { if (i != f) { return i + (f - i) * (1 - pow(2, -10 * t)); } else if (t == 1) { return i + (f - i); } else { return i; } } int main(int argc, char *argv[]) { float fps = FPS, dur = DUR; int x = POS, y = POS, w = WIDTH, h = HEIGHT; int X = POS, Y = POS, W = WIDTH, H = HEIGHT; double o = OPACITY, O = OPACITY; char method[9]; int iX = 0, iY = 0, iW = 0, iH = 0, iO = 0; if (argc < 3) { fprintf(stderr, "Usage: %s -m method [OPTIONS]\n\n\ Available options:\n\ -m [expo-in|expo-out|sine-in|sine-out]\n\ -x [Start X pos] -X [End X pos]\n\ -y [Start Y pos] -Y [End Y pos]\n\ -w [Start width] -W [End width]\n\ -h [Start height] -H [End height]\n\ -o [Start opacity] -O [End opacity]\n", argv[0]); return EXIT_FAILURE; } if (argc % 2 == 0) { fprintf(stderr, "Error: Wrong number of arguments.\n"); return EXIT_FAILURE; } for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "-m") == 0) { strcpy(method, argv[++i]); } else if (strcmp(argv[i], "-f") == 0) { fps = atof(argv[++i]); } else if (strcmp(argv[i], "-d") == 0) { dur = atof(argv[++i]); } else if (strcmp(argv[i], "-X") == 0) { X = atof(argv[++i]); iX = 1; } else if (strcmp(argv[i], "-Y") == 0) { Y = atof(argv[++i]); iY = 1; } else if (strcmp(argv[i], "-W") == 0) { W = atof(argv[++i]); iW = 1; } else if (strcmp(argv[i], "-H") == 0) { H = atof(argv[++i]); iH = 1; } else if (strcmp(argv[i], "-O") == 0) { O = atof(argv[++i]); iO = 1; } else if (strcmp(argv[i], "-x") == 0) { x = atof(argv[++i]); if (!iX) X = x; } else if (strcmp(argv[i], "-y") == 0) { y = atof(argv[++i]); if (!iY) Y = y; } else if (strcmp(argv[i], "-w") == 0) { w = atof(argv[++i]); if (!iW) W = w; } else if (strcmp(argv[i], "-h") == 0) { h = atof(argv[++i]); if (!iH) H = h; } else if (strcmp(argv[i], "-o") == 0) { o = atof(argv[++i]); if (!iO) O = o; } else { fprintf(stderr, "Unknown option: %s\n", argv[i]); return EXIT_FAILURE; } } printf("[{\"DisplayName\": \"Generated %s\", ", method); printf("\"in\": 0, "); printf("\"max\": 0, "); printf("\"min\": 0, "); printf("\"name\": \"rect\", "); printf("\"opacity\": true, "); printf("\"out\": %.2f, ", fps); printf("\"type\": 7, "); printf("\"value\": \""); int keyframes = (int)ceil(fps * dur); int xpos = x, ypos = y, width = w, height = h; float opacity = o; for (int i = 0; i < keyframes - 1; i++) { float t = (float)i / (keyframes - 1); if (strcmp(method, "expo-out") == 0) { xpos = kexpout(x, X, t); ypos = kexpout(y, Y, t); width = kexpout(w, W, t); height = kexpout(h, H, t); opacity = kexpout(o, O, t); } printf("%d=%d %d %d %d %.7f;", i, xpos, ypos, width, height, opacity); } printf("\"}]\n"); return EXIT_SUCCESS; }