9{
10 char *path = NULL, *outPath = NULL;
11 int n = 6, retval = EXIT_FAILURE, benchmark = 0;
12 double k = 0.30;
13 double scaleDown = 0.45;
14 unsigned long long ctr, maxCtr = 1;
15 double startTime, endTime;
16
19
21
22
23 if (argc < 4)
24 {
25 fprintf(stderr, "Usage ./kaleidoscope <Input Image Path> <Output Image Path> <N>\n");
26 fprintf(stderr,
27 "Usage ./kaleidoscope <Input Image Path> <Output Image Path> <N> <Dim constant> <Scale factor>\n");
28 return retval;
29 }
30 fprintf(stderr, "Start...\n");
31
32 path = argv[1];
33 outPath = argv[2];
34 n = atoi(argv[3]);
35 if (argc == 5)
36 {
37 benchmark = 1;
38 maxCtr = atoll(argv[4]);
39 }
40 if (argc == 6)
41 {
42 k = atof(argv[4]);
43 scaleDown = atof(argv[5]);
44 }
45
46
47 if (n <= 2)
48 {
49 fprintf(stderr, "n should be greater than 2");
50 return EXIT_FAILURE;
51 }
52 if (scaleDown < 0.0 || scaleDown > 1.0)
53 {
54 fprintf(stderr, "Scale factor should be between 0.0 and 1.0");
55 return EXIT_FAILURE;
56 }
57
58
59 fprintf(stderr, "Reading %s ... ", path);
61 return retval;
62 fprintf(stderr, " %d\n", !retval);
63
64 fprintf(stderr, "Initializing ... ");
66 return EXIT_FAILURE;
68 return retval;
69 fprintf(stderr, " %d\n", !retval);
70
71 fprintf(stderr, "Processing ...");
72 startTime = (float)clock() / CLOCKS_PER_SEC;
73 for (ctr = 0; ctr < maxCtr; ++ctr)
74 {
76 if (!benchmark)
77 break;
78 }
79 endTime = (float)clock() / CLOCKS_PER_SEC;
80 fprintf(stderr, " 1\n");
81
82 if (benchmark)
83 fprintf(stderr, "FPS %5.3f\n", 1 / ((endTime - startTime) / maxCtr));
84
85 fprintf(stderr, "Saving %s... ", outPath);
86 if ((retval =
saveImage(outPath, &outData, TJPF_RGB, TJSAMP_444, 90)))
87 return retval;
88 fprintf(stderr, " %d\n", !retval);
89
93
94 fprintf(stderr, "Done...\n");
95
96 return retval;
97}
int initImageData(ImageData *img, int width, int height, int nComponents)
Allocates memory for image.
int saveImage(const char *path, ImageData *img, enum TJPF pixelFormat, enum TJSAMP samplingFormat, int jpegQuality)
Save image data to an output file.
void deInitImageData(ImageData *img)
Free memory allocated by read image.
int readImage(const char *path, ImageData *img)
Get image data from an input file.
char * getKaleidoscopeLibraryInfo()
Get the Kaleidoscope Library info as string.
int initKaleidoscope(KaleidoscopeHandle *handler, int n, int width, int height, int nComponents, double scaleDown)
Initializes kaleidoscope handler.
void processKaleidoscope(KaleidoscopeHandle *handler, double k, unsigned char *imgIn, unsigned char *imgOut)
Applies kaleidoscope effect to image.
void deInitKaleidoscope(KaleidoscopeHandle *handler)
Deinitializes kaleidoscope handler.
unsigned char nComponents
Struct for kaleidoscope effect generator.