-
Notifications
You must be signed in to change notification settings - Fork 0
/
scatter-color-bar.c
109 lines (81 loc) · 2.19 KB
/
scatter-color-bar.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "logging.h"
#include "io.h"
#include "opt.h"
#include "image.h"
extern LogLevel logLevel;
#define MAX_UPSCALE 4
int getTarget(char *srcPath, unsigned int *targetWidth, unsigned int *targetHeight)
{
if (sizeJpeg(srcPath, targetWidth, targetHeight)) {
logFatal("%s: Cannot open file.", srcPath);
}
return 0; // Win.
}
int printColorLine(char* srcPath)
{
unsigned int width, height;
double r, g, b;
unsigned char * frameData = NULL;
char timestampString[100] = "";
struct stat st;
if (!stat(srcPath, &st)) {
strftime(timestampString, 100, "%d/%m/%Y %H:%M:%S", localtime( &st.st_mtime));
}
if (sizeJpeg(srcPath, &width, &height)) {
logFatal("%s: Cannot open file.", srcPath);
}
frameData = (unsigned char*) malloc(width * height * N_COMPONENTS * sizeof(unsigned char));
if (loadJpeg(srcPath, &frameData, &width, &height))
{
logWarning("Loading failed.");
free(frameData);
return 1; // Fail.
}
imageColorMean(&r, &g, &b, frameData, width * height);
printf("<div style='background:rgb(%d, %d, %d);'>%s | %s</div>\n",
(unsigned char)round(r), (unsigned char)round(g), (unsigned char)round(b),
srcPath, timestampString);
free(frameData);
return 0; // Win.
}
int main (int argc, char **argv)
{
char ** inPathList;
unsigned int nInPath;
unsigned int fGiven, fStart, fEnd, fStep;
getOptionsScatterColorBar(&logLevel,
&inPathList, &nInPath,
&fGiven, &fStart, &fEnd, &fStep,
argc, argv);
if (fGiven)
{
int f;
for (f = fStart; f <= fEnd; f += fStep)
{
char * path;
substitutePositiveInteger(&path, inPathList[0], f);
logInfo(path);
printColorLine(path);
free(path);
}
}
else
{
unsigned int i;
for (i = 0; i < nInPath; i++)
{
char * path = inPathList[i];
logInfo(path);
printColorLine(path);
}
}
freePathList(&inPathList, nInPath);
return 0;
}