djatoka 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Rakefile +7 -2
- data/djatoka.gemspec +3 -2
- data/lib/djatoka/iiif_request.rb +67 -11
- data/test/test_iiif_request.rb +78 -3
- metadata +17 -5
- data/Gemfile.lock +0 -75
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54f7a843ae143b4d2f5aade72d9b56ee09c2c045
|
4
|
+
data.tar.gz: 5ee17e4138e0922c4bdfb4358382bc31e56ac70e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e625b0f1180dc75c17412359799130f6e79664f2e8ee2ac7d20dfe924695b4c109e7882402e69b13ee79b95834797a3eec119ad4fce5b5dbfa0b4df8a3c5673
|
7
|
+
data.tar.gz: a53814884c76dc41b74b74ed260ce9f6b1893c76a9edbe125da03b62813c37c7dd2ffd5a3c82f0b5a4314b9e8accdded89b4c1130607299fe7e165b55110f279
|
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
-
|
2
|
-
require '
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
Bundler::GemHelper.install_tasks
|
3
8
|
|
4
9
|
require 'rake/testtask'
|
5
10
|
Rake::TestTask.new(:test) do |test|
|
data/djatoka.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{djatoka}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
s.authors = ["Jason Ronallo", "Willy Mene"]
|
10
10
|
s.email = %q{jronallo@gmail.com wmene@stanford.edu}
|
11
11
|
s.homepage = %q{http://github.com/jronallo/djatoka}
|
@@ -23,7 +23,8 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_dependency "mime-types"
|
24
24
|
|
25
25
|
s.add_dependency "trollop"
|
26
|
-
|
26
|
+
|
27
|
+
s.add_development_dependency "test-unit"
|
27
28
|
s.add_development_dependency "mocha"
|
28
29
|
s.add_development_dependency "fakeweb"
|
29
30
|
s.add_development_dependency "shoulda"
|
data/lib/djatoka/iiif_request.rb
CHANGED
@@ -106,17 +106,37 @@ module Djatoka
|
|
106
106
|
end
|
107
107
|
|
108
108
|
region = @resolver.region(@id)
|
109
|
-
|
109
|
+
offsets = []
|
110
|
+
region_dimensions = []
|
110
111
|
|
111
|
-
|
112
|
-
|
113
|
-
|
112
|
+
case @iiif_params[:region]
|
113
|
+
when 'full'
|
114
|
+
# noop
|
115
|
+
when 'square'
|
116
|
+
w = metadata.width.to_i
|
117
|
+
h = metadata.height.to_i
|
118
|
+
min, max = [w,h].minmax
|
119
|
+
|
120
|
+
offset = (max - min) / 2
|
121
|
+
|
122
|
+
region_dimensions = [min, min]
|
123
|
+
|
124
|
+
if h >= w
|
125
|
+
offsets = [0, offset]
|
126
|
+
else
|
127
|
+
offsets = [offset, 0]
|
128
|
+
end
|
129
|
+
when /^(\d+),(\d+),(\d+),(\d+)$/
|
130
|
+
offsets = [$1, $2]
|
131
|
+
region_dimensions = [$3, $4]
|
132
|
+
when /^pct:([\d\.]+),([\d\.]+),([\d\.]+),([\d\.]+)$/
|
114
133
|
x = (($1.to_f / 100.0) * metadata.width.to_f).to_i
|
115
134
|
y = (($2.to_f / 100.0) * metadata.height.to_f).to_i
|
116
135
|
w = (($3.to_f / 100.0) * metadata.width.to_f).to_i
|
117
136
|
h = (($4.to_f / 100.0) * metadata.height.to_f).to_i
|
118
|
-
|
119
|
-
|
137
|
+
offsets = [x, y]
|
138
|
+
region_dimensions = [w, h]
|
139
|
+
else
|
120
140
|
raise IiifInvalidParam.new "region", @iiif_params[:region]
|
121
141
|
end
|
122
142
|
|
@@ -127,22 +147,40 @@ module Djatoka
|
|
127
147
|
s #noop
|
128
148
|
when /^(\d+),$/
|
129
149
|
region.scale( ["#{$1}", "0"] ) #w => w,0
|
150
|
+
region.level(djatoka_level((region_dimensions.first || metadata.width).to_i / $1.to_f))
|
130
151
|
when /^,(\d+)$/
|
131
152
|
region.scale( ["0", "#{$1}"] ) #h => 0,h
|
153
|
+
region.level(djatoka_level((region_dimensions.last || metadata.height).to_i / $1.to_f))
|
132
154
|
when /^pct:(\d*\.?\d*)$/i
|
133
155
|
dj_scale = $1.to_f / 100.0
|
134
|
-
|
156
|
+
level = djatoka_level(1 / dj_scale)
|
157
|
+
reduce = max_level - level.to_i
|
158
|
+
region.scale((dj_scale * 2**reduce).to_s)
|
159
|
+
region.level(level)
|
135
160
|
when /^(\d+),(\d+)$/
|
136
161
|
region.scale("#{$1},#{$2}")
|
162
|
+
region.level(djatoka_level((region_dimensions.first || metadata.width).to_i / $1.to_f))
|
137
163
|
when /^!(\d+),(\d+)$/
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
164
|
+
region_dimensions = [metadata.width.to_f, metadata.height.to_f] if region_dimensions.empty?
|
165
|
+
scale = [$1.to_f / region_dimensions.first.to_f, $2.to_f / region_dimensions.last.to_f].min
|
166
|
+
|
167
|
+
width = region_dimensions.first.to_f * scale
|
168
|
+
height = region_dimensions.last.to_f * scale
|
169
|
+
|
170
|
+
region.scale([width.ceil, height.ceil])
|
171
|
+
region.level(djatoka_level(region_dimensions.first.to_f / width))
|
142
172
|
else
|
143
173
|
raise IiifInvalidParam.new "size", s
|
144
174
|
end
|
145
175
|
|
176
|
+
unless offsets.empty?
|
177
|
+
reduce = max_level - region.query.fetch(:level, max_level).to_i
|
178
|
+
w, h = region_dimensions.map { |d| d.to_i / (2**reduce) }
|
179
|
+
|
180
|
+
x, y = offsets
|
181
|
+
region.region("#{y},#{x},#{h},#{w}")
|
182
|
+
end
|
183
|
+
|
146
184
|
unless(@iiif_params[:rotation].numeric?)
|
147
185
|
raise IiifInvalidParam.new "rotation", @iiif_params[:rotation]
|
148
186
|
end
|
@@ -170,6 +208,24 @@ module Djatoka
|
|
170
208
|
|
171
209
|
end
|
172
210
|
|
211
|
+
def djatoka_level(ratio)
|
212
|
+
return max_level if ratio <= 1
|
213
|
+
level = max_level - Math.log2(ratio).to_i
|
214
|
+
|
215
|
+
if level < 1
|
216
|
+
1
|
217
|
+
else
|
218
|
+
level
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def max_level
|
223
|
+
@max_level ||= metadata.levels.to_i
|
224
|
+
end
|
225
|
+
|
226
|
+
def metadata
|
227
|
+
@metadata ||= @resolver.metadata(@id).perform
|
228
|
+
end
|
173
229
|
end
|
174
230
|
|
175
231
|
end
|
data/test/test_iiif_request.rb
CHANGED
@@ -39,6 +39,11 @@ class TestDjatokaIiifRequest < Test::Unit::TestCase
|
|
39
39
|
@req.size('full').rotation('0').quality('default').format('jpg')
|
40
40
|
end
|
41
41
|
|
42
|
+
should 'set square requests' do
|
43
|
+
reg = @req.region('square').djatoka_region
|
44
|
+
assert_equal '0,874,3372,3372', reg.query.region
|
45
|
+
end
|
46
|
+
|
42
47
|
should 'set x,y,w,h requests' do
|
43
48
|
reg = @req.region('10,20,50,100').djatoka_region
|
44
49
|
assert_equal '20,10,100,50', reg.query.region
|
@@ -56,6 +61,68 @@ class TestDjatokaIiifRequest < Test::Unit::TestCase
|
|
56
61
|
end
|
57
62
|
end
|
58
63
|
|
64
|
+
context 'translates region and size into DWT levels' do
|
65
|
+
context 'with a given region' do
|
66
|
+
setup do
|
67
|
+
@req.region('0,0,800,600').rotation('0').quality('default').format('jpg')
|
68
|
+
end
|
69
|
+
|
70
|
+
should 'set levels to the correct scale value' do
|
71
|
+
reg = @req.size('1600,').djatoka_region
|
72
|
+
assert_equal '6', reg.query.level
|
73
|
+
|
74
|
+
reg = @req.size('800,').djatoka_region
|
75
|
+
assert_equal '6', reg.query.level
|
76
|
+
|
77
|
+
reg = @req.size('400,').djatoka_region
|
78
|
+
assert_equal '5', reg.query.level
|
79
|
+
|
80
|
+
reg = @req.size('399,').djatoka_region
|
81
|
+
assert_equal '5', reg.query.level
|
82
|
+
|
83
|
+
reg = @req.size('200,').djatoka_region
|
84
|
+
assert_equal '4', reg.query.level
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'with the full image' do
|
89
|
+
setup do
|
90
|
+
@req.region('full').rotation('0').quality('default').format('jpg')
|
91
|
+
end
|
92
|
+
|
93
|
+
should 'set levels to the correct scale value' do
|
94
|
+
reg = @req.size('5120,').djatoka_region
|
95
|
+
assert_equal '6', reg.query.level
|
96
|
+
|
97
|
+
reg = @req.size('399,').djatoka_region
|
98
|
+
assert_equal '3', reg.query.level
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'with a pct size' do
|
103
|
+
setup do
|
104
|
+
@req.region('full').rotation('0').quality('default').format('jpg')
|
105
|
+
end
|
106
|
+
|
107
|
+
should 'set levels to the correct scale value' do
|
108
|
+
reg = @req.size('pct:100').djatoka_region
|
109
|
+
assert_equal '6', reg.query.level
|
110
|
+
|
111
|
+
reg = @req.size('pct:125').djatoka_region
|
112
|
+
assert_equal '6', reg.query.level
|
113
|
+
|
114
|
+
reg = @req.size('pct:50').djatoka_region
|
115
|
+
assert_equal '5', reg.query.level
|
116
|
+
|
117
|
+
reg = @req.size('pct:49').djatoka_region
|
118
|
+
assert_equal '5', reg.query.level
|
119
|
+
|
120
|
+
reg = @req.size('pct:23.52').djatoka_region
|
121
|
+
assert_equal '4', reg.query.level
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
59
126
|
context 'translates size parameters' do
|
60
127
|
setup do
|
61
128
|
@req.region('10,20,50,100').rotation('0').quality('default').format('jpg')
|
@@ -69,17 +136,25 @@ class TestDjatokaIiifRequest < Test::Unit::TestCase
|
|
69
136
|
should 'set ",h" requests to the correct scale value' do
|
70
137
|
reg = @req.size(',900').djatoka_region
|
71
138
|
assert_equal '0,900', reg.query.scale
|
139
|
+
assert_equal '6', reg.query.level
|
72
140
|
end
|
73
141
|
|
74
142
|
should 'set "pct:n" requests to the correct scale value' do
|
75
143
|
reg = @req.size('pct:75').djatoka_region
|
76
144
|
assert_equal '0.75', reg.query.scale
|
145
|
+
assert_equal '6', reg.query.level
|
77
146
|
|
78
147
|
reg = @req.size('pct:125').djatoka_region
|
79
148
|
assert_equal '1.25', reg.query.scale
|
149
|
+
assert_equal '6', reg.query.level
|
150
|
+
|
151
|
+
reg = @req.size('pct:20').djatoka_region
|
152
|
+
assert_equal '0.8', reg.query.scale
|
153
|
+
assert_equal '4', reg.query.level
|
80
154
|
|
81
155
|
reg = @req.size('pct:6.25').djatoka_region
|
82
|
-
assert_equal '0
|
156
|
+
assert_equal '1.0', reg.query.scale
|
157
|
+
assert_equal '2', reg.query.level
|
83
158
|
end
|
84
159
|
|
85
160
|
should 'set "w,h" requests to the correct scale value' do
|
@@ -89,10 +164,10 @@ class TestDjatokaIiifRequest < Test::Unit::TestCase
|
|
89
164
|
|
90
165
|
should 'set "!w,h" requests to the correct scale value' do
|
91
166
|
reg = @req.size('!1024,768').djatoka_region
|
92
|
-
assert_equal '
|
167
|
+
assert_equal '384,768', reg.query.scale
|
93
168
|
|
94
169
|
reg = @req.size('!1024,500').djatoka_region
|
95
|
-
assert_equal '
|
170
|
+
assert_equal '250,500', reg.query.scale
|
96
171
|
end
|
97
172
|
|
98
173
|
should 'raise an exception if the value cannot be parsed into a Float' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: djatoka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Ronallo
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-10-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
@@ -81,6 +81,20 @@ dependencies:
|
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: test-unit
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
84
98
|
- !ruby/object:Gem::Dependency
|
85
99
|
name: mocha
|
86
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,7 +163,6 @@ files:
|
|
149
163
|
- ".gitignore"
|
150
164
|
- ".travis.yml"
|
151
165
|
- Gemfile
|
152
|
-
- Gemfile.lock
|
153
166
|
- LICENSE
|
154
167
|
- README.rdoc
|
155
168
|
- Rakefile
|
@@ -213,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
226
|
version: '0'
|
214
227
|
requirements: []
|
215
228
|
rubyforge_project: djatoka
|
216
|
-
rubygems_version: 2.4.
|
229
|
+
rubygems_version: 2.4.8
|
217
230
|
signing_key:
|
218
231
|
specification_version: 4
|
219
232
|
summary: Djatoka image server helpers for Ruby and Rails.
|
@@ -233,4 +246,3 @@ test_files:
|
|
233
246
|
- test/test_region.rb
|
234
247
|
- test/test_resolver.rb
|
235
248
|
- test/test_view_helpers.rb
|
236
|
-
has_rdoc:
|
data/Gemfile.lock
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
djatoka (0.2.4)
|
5
|
-
addressable
|
6
|
-
hashie
|
7
|
-
json
|
8
|
-
mime-types
|
9
|
-
trollop
|
10
|
-
|
11
|
-
GEM
|
12
|
-
remote: https://rubygems.org/
|
13
|
-
specs:
|
14
|
-
activesupport (3.2.13)
|
15
|
-
i18n (= 0.6.1)
|
16
|
-
multi_json (~> 1.0)
|
17
|
-
addressable (2.3.6)
|
18
|
-
bourne (1.4.0)
|
19
|
-
mocha (~> 0.13.2)
|
20
|
-
coderay (1.0.9)
|
21
|
-
equivalent-xml (0.3.0)
|
22
|
-
nokogiri (>= 1.4.3)
|
23
|
-
fakeweb (1.3.0)
|
24
|
-
ffi (1.6.0-java)
|
25
|
-
hashie (2.1.1)
|
26
|
-
i18n (0.6.1)
|
27
|
-
json (1.7.7)
|
28
|
-
json (1.7.7-java)
|
29
|
-
metaclass (0.0.1)
|
30
|
-
method_source (0.8.1)
|
31
|
-
mime-types (2.2)
|
32
|
-
mocha (0.13.3)
|
33
|
-
metaclass (~> 0.0.1)
|
34
|
-
multi_json (1.7.2)
|
35
|
-
nokogiri (1.5.9)
|
36
|
-
nokogiri (1.5.9-java)
|
37
|
-
pry (0.9.12)
|
38
|
-
coderay (~> 1.0.5)
|
39
|
-
method_source (~> 0.8)
|
40
|
-
slop (~> 3.4)
|
41
|
-
pry (0.9.12-java)
|
42
|
-
coderay (~> 1.0.5)
|
43
|
-
method_source (~> 0.8)
|
44
|
-
slop (~> 3.4)
|
45
|
-
spoon (~> 0.0)
|
46
|
-
rake (10.0.4)
|
47
|
-
rb-readline (0.4.2)
|
48
|
-
rdoc (4.0.1)
|
49
|
-
json (~> 1.4)
|
50
|
-
shoulda (3.4.0)
|
51
|
-
shoulda-context (~> 1.0, >= 1.0.1)
|
52
|
-
shoulda-matchers (~> 1.0, >= 1.4.1)
|
53
|
-
shoulda-context (1.0.2)
|
54
|
-
shoulda-matchers (1.5.4)
|
55
|
-
activesupport (>= 3.0.0)
|
56
|
-
bourne (~> 1.3)
|
57
|
-
slop (3.4.4)
|
58
|
-
spoon (0.0.3)
|
59
|
-
ffi
|
60
|
-
trollop (2.0)
|
61
|
-
|
62
|
-
PLATFORMS
|
63
|
-
java
|
64
|
-
ruby
|
65
|
-
|
66
|
-
DEPENDENCIES
|
67
|
-
djatoka!
|
68
|
-
equivalent-xml
|
69
|
-
fakeweb
|
70
|
-
mocha
|
71
|
-
pry
|
72
|
-
rake
|
73
|
-
rb-readline
|
74
|
-
rdoc (>= 2.4.2)
|
75
|
-
shoulda
|