kaleidoscope 1.4.0
 
Loading...
Searching...
No Matches
kaleidoscope-cmd.c File Reference
#include "jpeg-utils/jpeg-utils.h"
#include "kaleidoscope.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Include dependency graph for kaleidoscope-cmd.c:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 8 of file kaleidoscope-cmd.c.

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
17 KaleidoscopeHandle handler;
18 ImageData imgData, outData;
19
20 fprintf(stderr, "Kaleidoscope Library %s\n", getKaleidoscopeLibraryInfo());
21
22 // Parse inputs
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 // Check inputs
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 // Process
59 fprintf(stderr, "Reading %s ... ", path);
60 if ((retval = readImage(path, &imgData)))
61 return retval;
62 fprintf(stderr, " %d\n", !retval);
63
64 fprintf(stderr, "Initializing ... ");
65 if (initImageData(&outData, imgData.width, imgData.height, imgData.nComponents))
66 return EXIT_FAILURE;
67 if ((retval = initKaleidoscope(&handler, n, imgData.width, imgData.height, imgData.nComponents, scaleDown)))
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 {
75 processKaleidoscope(&handler, k, imgData.data, outData.data);
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
90 deInitImageData(&imgData);
91 deInitImageData(&outData);
92 deInitKaleidoscope(&handler);
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.
Definition jpeg-utils.c:110
int saveImage(const char *path, ImageData *img, enum TJPF pixelFormat, enum TJSAMP samplingFormat, int jpegQuality)
Save image data to an output file.
Definition jpeg-utils.c:67
void deInitImageData(ImageData *img)
Free memory allocated by read image.
Definition jpeg-utils.c:122
int readImage(const char *path, ImageData *img)
Get image data from an input file.
Definition jpeg-utils.c:7
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.
Data struct for images.
Definition jpeg-utils.h:10
unsigned char nComponents
Definition jpeg-utils.h:13
unsigned char * data
Definition jpeg-utils.h:14
Struct for kaleidoscope effect generator.
Here is the call graph for this function: