assembly-image 1.7.8 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +3 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +3 -3
- data/.rubocop_todo.yml +17 -7
- data/README.md +3 -69
- data/assembly-image.gemspec +3 -3
- data/lib/assembly-image/image.rb +3 -16
- data/lib/assembly-image/images.rb +0 -5
- data/lib/assembly-image/jp2_creator.rb +17 -66
- data/lib/assembly-image.rb +3 -0
- data/profiles/cmyk.icc +0 -0
- data/spec/assembly/image/jp2_creator_spec.rb +3 -7
- data/spec/image_spec.rb +157 -112
- data/spec/images_spec.rb +38 -38
- data/spec/spec_helper.rb +117 -14
- data/spec/test_data/color_cmyk_tagged.tif +0 -0
- data/spec/test_data/color_cmyk_untagged.tif +0 -0
- data/spec/test_data/color_rgb_adobergb1998_lzw.tif +0 -0
- data/spec/test_data/color_rgb_srgb.jpg +0 -0
- data/spec/test_data/color_rgb_srgb.tif +0 -0
- data/spec/test_data/color_rgb_srgb_rot90cw.tif +0 -0
- data/spec/test_data/color_rgb_untagged.tif +0 -0
- data/spec/test_data/gray_gray_untagged.tif +0 -0
- metadata +40 -11
- data/bin/run_all_tests +0 -3
- data/lib/assembly-image/version.rb +0 -10
data/spec/spec_helper.rb
CHANGED
@@ -7,14 +7,17 @@ end
|
|
7
7
|
|
8
8
|
bootfile = File.expand_path(File.dirname(__FILE__) + '/../config/boot')
|
9
9
|
require bootfile
|
10
|
+
require 'ruby-vips'
|
11
|
+
require 'pry-byebug'
|
10
12
|
|
11
13
|
TEST_INPUT_DIR = File.join(Assembly::PATH_TO_IMAGE_GEM, 'spec', 'test_data', 'input')
|
12
14
|
TEST_OUTPUT_DIR = File.join(Assembly::PATH_TO_IMAGE_GEM, 'spec', 'test_data', 'output')
|
13
15
|
TEST_TIF_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.tif')
|
14
|
-
TEST_DPG_TIF_INPUT_FILE = File.join(TEST_INPUT_DIR, 'oo000oo0001_00_01.tif')
|
15
16
|
TEST_JPEG_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.jpg')
|
16
17
|
TEST_JP2_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.jp2')
|
17
18
|
TEST_JP2_OUTPUT_FILE = File.join(TEST_OUTPUT_DIR, 'test.jp2')
|
19
|
+
TEST_PROFILE_DIR = File.join(Assembly::PATH_TO_IMAGE_GEM, 'profiles')
|
20
|
+
TEST_DATA_DIR = File.join(Assembly::PATH_TO_IMAGE_GEM, 'spec', 'test_data')
|
18
21
|
TEST_DRUID = 'nx288wh8889'
|
19
22
|
|
20
23
|
RSpec.configure do |config|
|
@@ -101,31 +104,131 @@ RSpec.configure do |config|
|
|
101
104
|
Kernel.srand config.seed
|
102
105
|
end
|
103
106
|
|
107
|
+
# rubocop:disable Metrics/MethodLength
|
108
|
+
# Color values for 30-patch ColorGauge color target.
|
109
|
+
def color_gauge_values(type = 'adobeRGB')
|
110
|
+
# rubocop:disable Layout/SpaceInsideArrayLiteralBrackets
|
111
|
+
# rubocop:disable Layout/ExtraSpacing
|
112
|
+
adobe_rgb = [
|
113
|
+
[109, 83, 71], [187, 146, 129], [101, 120, 151], [ 97, 108, 68], [130, 128, 172],
|
114
|
+
[130, 187, 171], [ 64, 134, 165], [241, 242, 237], [231, 232, 229], [216, 217, 215],
|
115
|
+
[203, 204, 203], [202, 125, 55], [172, 87, 147], [174, 176, 175], [148, 150, 149],
|
116
|
+
[116, 119, 118], [ 91, 91, 92], [ 78, 92, 165], [227, 198, 55], [ 68, 70, 69],
|
117
|
+
[ 48, 48, 48], [ 32, 32, 32], [ 23, 23, 23], [175, 85, 97], [157, 60, 61],
|
118
|
+
[100, 148, 80], [ 53, 67, 141], [213, 160, 56], [167, 187, 77], [ 86, 61, 100]
|
119
|
+
]
|
120
|
+
|
121
|
+
srgb = [
|
122
|
+
[118, 82, 69], [202, 147, 129], [ 92, 121, 154], [ 92, 109, 64], [132, 129, 175],
|
123
|
+
[ 96, 188, 172], [ 0, 135, 168], [241, 242, 237], [231, 232, 229], [217, 218, 216],
|
124
|
+
[204, 205, 204], [225, 126, 46], [196, 86, 150], [175, 178, 177], [148, 151, 150],
|
125
|
+
[116, 120, 119], [ 91, 91, 92], [ 70, 92, 169], [238, 199, 27], [ 65, 68, 67],
|
126
|
+
[ 44, 44, 44], [ 26, 26, 26], [ 16, 16, 16], [200, 84, 97], [181, 57, 58],
|
127
|
+
[ 68, 149, 74], [ 42, 65, 145], [231, 161, 41], [160, 188, 65], [ 94, 58, 101]
|
128
|
+
]
|
129
|
+
|
130
|
+
cmyk = [
|
131
|
+
[120, 154, 169, 84], [ 69, 110, 120, 5], [169, 125, 64, 8], [154, 105, 207, 64],
|
132
|
+
[138, 125, 31, 0], [128, 26, 95, 0], [195, 95, 61, 3], [ 10, 5, 13, 0],
|
133
|
+
[ 20, 13, 18, 0], [ 36, 26, 31, 0], [ 51, 38, 41, 0], [ 46, 143, 236, 8],
|
134
|
+
[ 90, 202, 31, 0], [ 84, 64, 69, 0], [115, 90, 95, 0], [143, 115, 120, 28],
|
135
|
+
[161, 141, 136, 69], [205, 182, 8, 0], [ 33, 46, 238, 0], [172, 151, 151, 110],
|
136
|
+
[179, 164, 161, 156], [184, 169, 166, 189], [187, 172, 166, 205], [ 69, 197, 131, 20],
|
137
|
+
[ 69, 220, 189, 51], [161, 59, 223, 15], [241, 223, 28, 5], [ 44, 95, 238, 3],
|
138
|
+
[100, 31, 228, 0], [184, 210, 90, 56]
|
139
|
+
]
|
140
|
+
# rubocop:enable Layout/SpaceInsideArrayLiteralBrackets
|
141
|
+
# rubocop:enable Layout/ExtraSpacing
|
142
|
+
case type
|
143
|
+
when 'adobe_rgb'
|
144
|
+
adobe_rgb
|
145
|
+
when 'srgb'
|
146
|
+
srgb
|
147
|
+
when 'cmyk'
|
148
|
+
cmyk
|
149
|
+
else
|
150
|
+
raise 'Unknown color_gauge_values type.'
|
151
|
+
end
|
152
|
+
end
|
153
|
+
# rubocop:enable Metrics/MethodLength
|
154
|
+
|
104
155
|
# generate a sample image file with a specified profile
|
105
156
|
# rubocop:disable Metrics/AbcSize
|
106
157
|
# rubocop:disable Metrics/CyclomaticComplexity
|
107
158
|
# rubocop:disable Metrics/MethodLength
|
108
159
|
# rubocop:disable Metrics/PerceivedComplexity
|
109
160
|
def generate_test_image(file, params = {})
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
161
|
+
# Set default size for sample test image.
|
162
|
+
line_size = 1
|
163
|
+
box_size = 6
|
164
|
+
width = (box_size * 6) + (line_size * 7)
|
165
|
+
height = (box_size * 5) + (line_size * 6)
|
166
|
+
|
167
|
+
# Set parameters for image creation options.
|
168
|
+
image_type = params[:image_type] || File.extname(file)
|
169
|
+
bands = params[:bands] || 3
|
170
|
+
color = params[:color] || 'rgb'
|
171
|
+
depth = params[:depth] || 8
|
172
|
+
cg_type = params[:cg_type] || 'adobe_rgb'
|
173
|
+
compression = params[:compression]
|
174
|
+
profile = params[:profile]
|
175
|
+
|
176
|
+
temp_array = color_gauge_values(cg_type)
|
177
|
+
temp_image = Vips::Image.black(width, height, bands: temp_array.first.size)
|
178
|
+
(0..4).each do |i|
|
179
|
+
b = (box_size * i) + (line_size * (i + 1))
|
180
|
+
# d = b + box_size - line_size
|
181
|
+
(0...6).each do |j|
|
182
|
+
a = (box_size * j) + (line_size * (j + 1))
|
183
|
+
# c = a + box_size - line_size
|
184
|
+
colors = temp_array.shift
|
185
|
+
temp_image = temp_image.draw_rect(colors, a, b, box_size, box_size, fill: true)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
temp_image = color.eql?('cmyk') ? temp_image.copy(interpretation: :cmyk) : temp_image.copy(interpretation: :srgb)
|
190
|
+
|
191
|
+
temp_image = if color.eql?('grey') && bands == 3
|
192
|
+
mean = temp_image.bandmean
|
193
|
+
Vips::Image.bandjoin([mean, mean, mean])
|
194
|
+
elsif color.eql?('grey') && bands == 1
|
195
|
+
temp_image.bandmean
|
196
|
+
elsif color.eql?('bin') && bands == 3
|
197
|
+
mean = temp_image.bandmean < 128
|
198
|
+
Vips::Image.bandjoin([mean, mean, mean])
|
199
|
+
elsif color.eql?('bin') && bands == 1
|
200
|
+
temp_image.bandmean < 128
|
201
|
+
else
|
202
|
+
temp_image
|
203
|
+
end
|
204
|
+
|
205
|
+
options = {}
|
206
|
+
unless profile.nil?
|
207
|
+
profile_file = File.join(TEST_PROFILE_DIR, profile + '.icc')
|
208
|
+
options.merge!(profile: profile_file)
|
209
|
+
end
|
210
|
+
|
211
|
+
case image_type
|
212
|
+
when '.tiff', '.tif'
|
213
|
+
options.merge!(compression: compression) unless compression.nil?
|
214
|
+
options.merge!(squash: true) if depth.eql?(1)
|
215
|
+
temp_image.tiffsave(file, **options)
|
216
|
+
when '.jpeg', '.jpg'
|
217
|
+
temp_image.jpegsave(file, **options)
|
218
|
+
else
|
219
|
+
raise "unknown type: #{image_type}"
|
220
|
+
end
|
123
221
|
end
|
124
222
|
# rubocop:enable Metrics/AbcSize
|
125
223
|
# rubocop:enable Metrics/CyclomaticComplexity
|
126
224
|
# rubocop:enable Metrics/MethodLength
|
127
225
|
# rubocop:enable Metrics/PerceivedComplexity
|
128
226
|
|
227
|
+
def cleanup
|
228
|
+
remove_files(TEST_INPUT_DIR)
|
229
|
+
remove_files(TEST_OUTPUT_DIR)
|
230
|
+
end
|
231
|
+
|
129
232
|
def remove_files(dir)
|
130
233
|
Dir.foreach(dir) do |f|
|
131
234
|
fn = File.join(dir, f)
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assembly-image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Mangiafico
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2022-06-
|
14
|
+
date: 2022-06-27 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: assembly-objectfile
|
@@ -47,6 +47,34 @@ dependencies:
|
|
47
47
|
- - "<"
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '3'
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: ruby-vips
|
52
|
+
requirement: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '2.0'
|
57
|
+
type: :runtime
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '2.0'
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: pry-byebug
|
66
|
+
requirement: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
50
78
|
- !ruby/object:Gem::Dependency
|
51
79
|
name: rake
|
52
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -152,20 +180,27 @@ files:
|
|
152
180
|
- Rakefile
|
153
181
|
- assembly-image.gemspec
|
154
182
|
- bin/console
|
155
|
-
- bin/run_all_tests
|
156
183
|
- config/boot.rb
|
157
184
|
- lib/assembly-image.rb
|
158
185
|
- lib/assembly-image/image.rb
|
159
186
|
- lib/assembly-image/images.rb
|
160
187
|
- lib/assembly-image/jp2_creator.rb
|
161
|
-
- lib/assembly-image/version.rb
|
162
188
|
- profiles/AdobeRGB1998.icc
|
163
189
|
- profiles/DotGain20.icc
|
190
|
+
- profiles/cmyk.icc
|
164
191
|
- profiles/sRGBIEC6196621.icc
|
165
192
|
- spec/assembly/image/jp2_creator_spec.rb
|
166
193
|
- spec/image_spec.rb
|
167
194
|
- spec/images_spec.rb
|
168
195
|
- spec/spec_helper.rb
|
196
|
+
- spec/test_data/color_cmyk_tagged.tif
|
197
|
+
- spec/test_data/color_cmyk_untagged.tif
|
198
|
+
- spec/test_data/color_rgb_adobergb1998_lzw.tif
|
199
|
+
- spec/test_data/color_rgb_srgb.jpg
|
200
|
+
- spec/test_data/color_rgb_srgb.tif
|
201
|
+
- spec/test_data/color_rgb_srgb_rot90cw.tif
|
202
|
+
- spec/test_data/color_rgb_untagged.tif
|
203
|
+
- spec/test_data/gray_gray_untagged.tif
|
169
204
|
- spec/test_data/input/.empty
|
170
205
|
- spec/test_data/output/.empty
|
171
206
|
homepage: ''
|
@@ -192,10 +227,4 @@ signing_key:
|
|
192
227
|
specification_version: 4
|
193
228
|
summary: Ruby immplementation of image services needed to prepare objects to be accessioned
|
194
229
|
in SULAIR digital library
|
195
|
-
test_files:
|
196
|
-
- spec/assembly/image/jp2_creator_spec.rb
|
197
|
-
- spec/image_spec.rb
|
198
|
-
- spec/images_spec.rb
|
199
|
-
- spec/spec_helper.rb
|
200
|
-
- spec/test_data/input/.empty
|
201
|
-
- spec/test_data/output/.empty
|
230
|
+
test_files: []
|
data/bin/run_all_tests
DELETED