-
Notifications
You must be signed in to change notification settings - Fork 0
/
PALETTE.pl
executable file
·161 lines (150 loc) · 5.08 KB
/
PALETTE.pl
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/perl
use File::Find qw(find);
use Cwd;
use Env;
use Term::ANSIColor qw(:constants);
$script = $0;
print BOLD BLUE "script : $script\n";print RESET;
@tmp=split(/\//,$script);
$scriptname=$tmp[$#tmp];
@tmp=split(/\./,$scriptname);
$scriptname=lc $tmp[0];
$CWD=getcwd;
#get project name
@tmp=split(/\//,$CWD);
$PROJECT=$tmp[$#tmp];
print BOLD BLUE "project : $PROJECT\n";print RESET;
sub isnum ($) {
#returns 0 if string 1 if number
#http://www.perlmonks.org/?node=How%20to%20check%20if%20a%20scalar%20value%20is%20numeric%20or%20string%3F
return 0 if $_[0] eq '';
$_[0] ^ $_[0] ? 0 : 1
}
sub list_dirs {
my @dirs = @_;
my @files;
find({ wanted => sub { push @files, $_ } , no_chdir => 1 }, @dirs);
return @files;
}
#defaults
$INDIR="./";
$DO8=1;
$DO16=1;
$DO32=1;
$DO64=1;
$DOCUSTOM=1;
$CUSTOM=128;
$VERBOSE=1;
if ($#ARGV == -1) {
print "usage: $scriptname.pl \n";
print "-idir dirin [$INDIR]\n";
print "-do8 [$DO8] : do 8colors palette\n";
print "-do16 [$DO16] : do 16colors palette\n";
print "-do32 [$DO32] : do 32colors palette\n";
print "-do64 [$DO64] : do 64colors palette\n";
print "-docustom customvalue [$DOCUSTOM,$CUSTOM]\n";
exit;
}
for ($arg=0;$arg <= $#ARGV;$arg++)
{
if (@ARGV[$arg] eq "-idir")
{
$INDIR=@ARGV[$arg+1];
print "in dir : $INDIR\n";
}
if (@ARGV[$arg] eq "-do8")
{
$DO8=1;
print "do8 : $DO8\n";
}
if (@ARGV[$arg] eq "-do16")
{
$DO16=1;
print "do16 : $DO16\n";
}
if (@ARGV[$arg] eq "-do32")
{
$DO32=1;
print "do32 : $DO32\n";
}
if (@ARGV[$arg] eq "-do64")
{
$DO64=1;
print "do64 : $DO64\n";
}
if (@ARGV[$arg] eq "-docustom")
{
$DOCUSTOM=1;
$CUSTOM=@ARGV[$arg+1];
print "docustom : $CUSTOM \n";
}
}
$GMIC = "/shared/foss-18/gmic-2.8.0_pre/src/gmic";
my @dirs = $INDIR;
my @subdirs;
find({ wanted => sub { push @subdirs, $_ } , no_chdir => 1 }, @dirs);
foreach $subdir (sort { substr($a, 1) <=> substr($b, 1) } @subdirs)
{
if (-d "$subdir") #make sure it is a directory
{
print "scanning dir : $subdir\n";
opendir SUBDIR, "$subdir";
@images = grep { /.jpg/ || /.jpeg/ || /.png/} readdir SUBDIR;
closedir SUBDIR;
foreach $image (@images)
{
@ima=split(/\./,$image);
$EXT=@ima[$#ima];
$imaroot="";
for ($i=0;$i<$#ima;$i++) {
$imaroot=$imaroot.@ima[$i]."_";
}
print "$image $imaroot $EXT \n";
if ($DO8) {
$sample=8;
$cmd="$GMIC $subdir/$image -resize2dx 1500 --colormap $sample,1,1 -resize2dy[1] 64,1 -remove[0] -o $subdir/$imaroot\sample$sample\_sorted.jpg";
print "$cmd\n";
system $cmd;
$cmd="$GMIC $subdir/$image -resize2dx 1500 --colormap $sample,1,2 -resize2dy[1] 64,1 -remove[0] -o $subdir/$imaroot\sample$sample\_importance.jpg";
print "$cmd\n";
system $cmd;
}
if ($DO16) {
$sample=16;
$cmd="$GMIC $subdir/$image -resize2dx 1500 --colormap $sample,1,1 -resize2dy[1] 64,1 -remove[0] -o $subdir/$imaroot\sample$sample\_sorted.jpg";
print "$cmd\n";
system $cmd;
$cmd="$GMIC $subdir/$image -resize2dx 1500 --colormap $sample,1,2 -resize2dy[1] 64,1 -remove[0] -o $subdir/$imaroot\sample$sample\_importance.jpg";
print "$cmd\n";
system $cmd;
}
if ($DO32) {
$sample=32;
$cmd="$GMIC $subdir/$image -resize2dx 1500 --colormap $sample,1,1 -resize2dy[1] 64,1 -remove[0] -o $subdir/$imaroot\sample$sample\_sorted.jpg";
print "$cmd\n";
system $cmd;
$cmd="$GMIC $subdir/$image -resize2dx 1500 --colormap $sample,1,2 -resize2dy[1] 64,1 -remove[0] -o $subdir/$imaroot\sample$sample\_importance.jpg";
print "$cmd\n";
system $cmd;
}
if ($DO64) {
$sample=64;
$cmd="$GMIC $subdir/$image -resize2dx 1500 --colormap $sample,1,1 -resize2dy[1] 64,1 -remove[0] -o $subdir/$imaroot\sample$sample\_sorted.jpg";
print "$cmd\n";
system $cmd;
$cmd="$GMIC $subdir/$image -resize2dx 1500 --colormap $sample,1,2 -resize2dy[1] 64,1 -remove[0] -o $subdir/$imaroot\sample$sample\_importance.jpg";
print "$cmd\n";
system $cmd;
}
if ($DOCUSTOM) {
$sample=$CUSTOM;
$cmd="$GMIC $subdir/$image -resize2dx 1500 --colormap $sample,1,1 -resize2dy[1] 64,1 -remove[0] -o $subdir/$imaroot\sample$sample\_sorted.jpg";
print "$cmd\n";
system $cmd;
$cmd="$GMIC $subdir/$image -resize2dx 1500 --colormap $sample,1,2 -resize2dy[1] 64,1 -remove[0] -o $subdir/$imaroot\sample$sample\_importance.jpg";
print "$cmd\n";
system $cmd;
}
}
}
}