grayphash 0.0.10 → 0.0.11.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/grayphash/grayphash.cpp +44 -3
- metadata +4 -4
data/ext/grayphash/grayphash.cpp
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
extern "C" VALUE t_about(VALUE self)
|
13
13
|
{
|
14
|
-
return rb_str_new_cstr("pHash 0.9.4. Copyright 2008-2010 Aetilius, Inc. Included only some image functions (grayphash v-0.0.
|
14
|
+
return rb_str_new_cstr("pHash 0.9.4. Copyright 2008-2010 Aetilius, Inc. Included only some image functions (grayphash v-0.0.11.4).");
|
15
15
|
}
|
16
16
|
|
17
17
|
|
@@ -79,8 +79,8 @@
|
|
79
79
|
ulong64 phash = 0;
|
80
80
|
ph_dct_imagehash(file, phash);
|
81
81
|
|
82
|
-
if(phash==0)
|
83
|
-
|
82
|
+
//if(phash==0)
|
83
|
+
// rb_raise(rb_eFatal, "PHash cannot be 0 but it calcutaled as it. Probably you load PNG file with transparency or this file is not exists.");
|
84
84
|
|
85
85
|
rb_iv_set(self, "@phash", ULL2NUM(phash));
|
86
86
|
|
@@ -170,6 +170,46 @@
|
|
170
170
|
}
|
171
171
|
|
172
172
|
|
173
|
+
extern "C" VALUE t_main_hue(VALUE self, VALUE lfile) {
|
174
|
+
Check_Type(lfile, T_STRING);
|
175
|
+
char* file = RSTRING_PTR(lfile);
|
176
|
+
|
177
|
+
CImg<uint8_t> src;
|
178
|
+
src.load(file);
|
179
|
+
|
180
|
+
CImg<float> meanfilter(7,7,1,1,1);
|
181
|
+
CImg<float> img;
|
182
|
+
if (src.spectrum() == 3){
|
183
|
+
img = src.RGBtoHSV().channel(0).get_convolve(meanfilter);
|
184
|
+
} else if (src.spectrum() == 4){
|
185
|
+
int width = img.width();
|
186
|
+
int height = img.height();
|
187
|
+
int depth = img.depth();
|
188
|
+
img = src.crop(0,0,0,0,width-1,height-1,depth-1,2).RGBtoHSV().channel(0).get_convolve(meanfilter);
|
189
|
+
} else {
|
190
|
+
img = src.channel(0).get_convolve(meanfilter);
|
191
|
+
}
|
192
|
+
|
193
|
+
//float total = img.width() * img.height();
|
194
|
+
const CImg<int> hist = img.histogram(256);
|
195
|
+
int max_pos = 0;
|
196
|
+
int max_hist = 0;
|
197
|
+
int space = 4;
|
198
|
+
for(int pos=0;pos<256;pos+=space) {
|
199
|
+
int accum = 0;
|
200
|
+
for(int i=0;i<space;i++) {
|
201
|
+
accum += hist[pos+i];
|
202
|
+
}
|
203
|
+
if(accum > max_hist){
|
204
|
+
max_hist = accum;
|
205
|
+
max_pos = pos;
|
206
|
+
}
|
207
|
+
}
|
208
|
+
|
209
|
+
return INT2NUM(max_pos);
|
210
|
+
}
|
211
|
+
|
212
|
+
|
173
213
|
VALUE Grayphash;
|
174
214
|
|
175
215
|
extern "C" void Init_grayphash()
|
@@ -181,5 +221,6 @@
|
|
181
221
|
rb_define_method(Grayphash, "histogram", (ruby_method*) &t_histogram, 2);
|
182
222
|
rb_define_method(Grayphash, "histogram", (ruby_method*) &t_histogram, 2);
|
183
223
|
rb_define_method(Grayphash, "histogram4lumin", (ruby_method*) &t_histogram4lumin, 1);
|
224
|
+
rb_define_method(Grayphash, "main_hue", (ruby_method*) &t_main_hue, 1);
|
184
225
|
}
|
185
226
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grayphash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: pHash image wrapper
|
15
15
|
email: tauraloke@gmail.com
|
@@ -43,8 +43,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
43
|
version: '0'
|
44
44
|
requirements: []
|
45
45
|
rubyforge_project: grayphash
|
46
|
-
rubygems_version: 1.8.
|
46
|
+
rubygems_version: 1.8.23
|
47
47
|
signing_key:
|
48
48
|
specification_version: 3
|
49
|
-
summary: Simple wrapper for some pHash image functions
|
49
|
+
summary: Simple wrapper for some pHash and CImg image functions
|
50
50
|
test_files: []
|