assembly-image 1.6.8 → 1.6.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.rspec +1 -0
- data/.rubocop.yml +13 -0
- data/.rubocop_todo.yml +263 -0
- data/.travis.yml +26 -0
- data/Gemfile +1 -2
- data/README.md +158 -0
- data/Rakefile +3 -6
- data/assembly-image.gemspec +13 -14
- data/lib/assembly-image.rb +2 -2
- data/lib/assembly-image/image.rb +41 -41
- data/lib/assembly-image/images.rb +31 -22
- data/lib/assembly-image/version.rb +2 -2
- data/spec/image_spec.rb +97 -90
- data/spec/images_spec.rb +17 -17
- data/spec/spec_helper.rb +16 -11
- metadata +36 -56
- data/README.rdoc +0 -145
data/Rakefile
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require 'dlss/rake/dlss_release'
|
4
|
-
Dlss::Release.new
|
1
|
+
require 'bundler/gem_tasks'
|
5
2
|
|
6
3
|
require 'rspec/core/rake_task'
|
7
4
|
|
8
|
-
desc
|
5
|
+
desc 'Run specs'
|
9
6
|
RSpec::Core::RakeTask.new(:spec)
|
10
7
|
|
11
|
-
task :default => :spec
|
8
|
+
task :default => :spec
|
data/assembly-image.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
$LOAD_PATH.push File.expand_path(
|
1
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
2
2
|
require 'assembly-image/version'
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'assembly-image'
|
6
6
|
s.version = Assembly::Image::VERSION
|
7
|
-
s.authors = [
|
8
|
-
s.email = [
|
9
|
-
s.homepage =
|
7
|
+
s.authors = ['Peter Mangiafico', 'Renzo Sanchez-Silva','Monty Hindman','Tony Calavano']
|
8
|
+
s.email = ['pmangiafico@stanford.edu']
|
9
|
+
s.homepage = ''
|
10
10
|
s.summary = %q{Ruby immplementation of image services needed to prepare objects to be accessioned in SULAIR digital library}
|
11
11
|
s.description = %q{Contains classes to create derivative image files and perform other image operations}
|
12
12
|
|
@@ -14,17 +14,16 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.files = `git ls-files`.split("\n")
|
16
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
-
s.
|
17
|
+
s.bindir = 'exe'
|
18
|
+
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
19
|
s.require_paths = ['lib']
|
19
20
|
|
20
21
|
s.add_dependency 'uuidtools'
|
21
|
-
s.add_dependency 'assembly-objectfile',
|
22
|
-
s.add_dependency 'mini_exiftool',
|
23
|
-
s.add_dependency 'activesupport', '>3'
|
24
|
-
s.add_dependency 'nokogiri'
|
22
|
+
s.add_dependency 'assembly-objectfile', '>= 1.6.4'
|
23
|
+
s.add_dependency 'mini_exiftool', '>= 1.6', '< 3'
|
25
24
|
|
26
|
-
s.add_development_dependency
|
27
|
-
s.add_development_dependency
|
28
|
-
s.add_development_dependency
|
29
|
-
|
30
|
-
end
|
25
|
+
s.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
s.add_development_dependency 'yard'
|
27
|
+
s.add_development_dependency 'rake'
|
28
|
+
|
29
|
+
end
|
data/lib/assembly-image.rb
CHANGED
data/lib/assembly-image/image.rb
CHANGED
@@ -2,7 +2,7 @@ require 'uuidtools'
|
|
2
2
|
require 'assembly-objectfile'
|
3
3
|
|
4
4
|
module Assembly
|
5
|
-
|
5
|
+
|
6
6
|
# The Image class contains methods to operate on an image.
|
7
7
|
class Image
|
8
8
|
|
@@ -23,7 +23,7 @@ module Assembly
|
|
23
23
|
def valid?
|
24
24
|
valid_image? # behavior is defined in assembly-objectfile gem
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
# Get the image color profile
|
28
28
|
#
|
29
29
|
# @return [string] image color profile
|
@@ -33,7 +33,7 @@ module Assembly
|
|
33
33
|
def profile
|
34
34
|
exif.nil? ? nil : exif['profiledescription']
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
# Get the image height from exif data
|
38
38
|
#
|
39
39
|
# @return [integer] image height in pixels
|
@@ -49,7 +49,7 @@ module Assembly
|
|
49
49
|
# @return [integer] image height in pixels
|
50
50
|
# Example:
|
51
51
|
# source_img=Assembly::Image.new('/input/path_to_file.tif')
|
52
|
-
# puts source_img.width # gives 100
|
52
|
+
# puts source_img.width # gives 100
|
53
53
|
def width
|
54
54
|
exif.imagewidth
|
55
55
|
end
|
@@ -81,7 +81,7 @@ module Assembly
|
|
81
81
|
puts "** Error for #{filename}: #{e.message}"
|
82
82
|
end
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
# Returns the full default jp2 path and filename that will be created from the given image
|
86
86
|
#
|
87
87
|
# @return [string] full default jp2 path and filename that will be created from the given image
|
@@ -101,7 +101,7 @@ module Assembly
|
|
101
101
|
def dpg_jp2_filename
|
102
102
|
jp2_filename.gsub('_00_','_05_')
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
# Create a JP2 file for the current image.
|
106
106
|
# Important note: this will not work for multipage TIFFs.
|
107
107
|
#
|
@@ -122,18 +122,18 @@ module Assembly
|
|
122
122
|
|
123
123
|
check_for_file
|
124
124
|
|
125
|
-
raise
|
126
|
-
|
125
|
+
raise 'input file is not a valid image, or is the wrong mimetype' if !self.jp2able?
|
126
|
+
|
127
127
|
output = params[:output] || jp2_filename
|
128
128
|
overwrite = params[:overwrite] || false
|
129
129
|
|
130
130
|
raise SecurityError,"output #{output} exists, cannot overwrite" if !overwrite && File.exists?(output)
|
131
131
|
|
132
|
-
raise SecurityError,
|
132
|
+
raise SecurityError,'cannot recreate jp2 over itself' if overwrite && mimetype=='image/jp2' && output == @path
|
133
133
|
|
134
134
|
tmp_folder = params[:tmp_folder] || '/tmp'
|
135
135
|
raise "tmp_folder #{tmp_folder} does not exists" unless File.exists?(tmp_folder)
|
136
|
-
|
136
|
+
|
137
137
|
output_profile = 'sRGBIEC6196621' # params[:output_profile] || 'sRGBIEC6196621' # eventually we may allow the user to specify the output_profile...when we do, you can just uncomment this code and update the tests that check for this
|
138
138
|
preserve_tmp_source = params[:preserve_tmp_source] || false
|
139
139
|
path_to_profiles = File.join(Assembly::PATH_TO_IMAGE_GEM,'profiles')
|
@@ -141,76 +141,76 @@ module Assembly
|
|
141
141
|
|
142
142
|
raise "output profile #{output_profile} invalid" if !File.exists?(output_profile_file)
|
143
143
|
|
144
|
-
samples_per_pixel=exif['samplesperpixel'].to_s ||
|
145
|
-
bits_per_sample=exif['bitspersample'] ||
|
146
|
-
|
144
|
+
samples_per_pixel=exif['samplesperpixel'].to_s || ''
|
145
|
+
bits_per_sample=exif['bitspersample'] || ''
|
146
|
+
|
147
147
|
path_to_profiles = File.join(Assembly::PATH_TO_IMAGE_GEM,'profiles')
|
148
|
-
|
148
|
+
|
149
149
|
if !profile.nil? # if the input color profile exists, contract paths to the profile and setup the command
|
150
|
-
|
150
|
+
|
151
151
|
input_profile = profile.gsub(/[^[:alnum:]]/, '') # remove all non alpha-numeric characters, so we can get to a filename
|
152
|
-
|
152
|
+
|
153
153
|
# construct a path to the input profile, which might exist either in the gem itself or in the tmp folder
|
154
154
|
input_profile_file_gem = File.join(path_to_profiles,"#{input_profile}.icc")
|
155
155
|
input_profile_file_tmp = File.join(tmp_folder,"#{input_profile}.icc")
|
156
156
|
input_profile_file = File.exists?(input_profile_file_gem) ? input_profile_file_gem : input_profile_file_tmp
|
157
|
-
|
157
|
+
|
158
158
|
# if input profile was extracted and does not matches an existing known profile either in the gem or in the tmp folder,
|
159
159
|
# we'll issue an imagicmagick command to extract the profile to the tmp folder
|
160
160
|
unless File.exists?(input_profile_file)
|
161
161
|
input_profile_extraction_command = "MAGICK_TEMPORARY_PATH=#{tmp_folder} convert '#{@path}'[0] #{input_profile_file}" # extract profile from input image
|
162
162
|
result=`#{input_profile_extraction_command} 2>&1`
|
163
163
|
raise "input profile extraction command failed: #{input_profile_extraction_command} with result #{result}" unless $?.success?
|
164
|
-
raise
|
164
|
+
raise 'input profile is not a known profile and could not be extracted from input file' unless File.exists?(input_profile_file) # if extraction failed or we cannot write the file, throw exception
|
165
165
|
end
|
166
166
|
|
167
167
|
profile_conversion_switch = "-profile #{input_profile_file} -profile #{output_profile_file}"
|
168
|
-
|
168
|
+
|
169
169
|
else
|
170
|
-
|
171
|
-
profile_conversion_switch =
|
170
|
+
|
171
|
+
profile_conversion_switch = '' # no conversion needed if input color profile does not exist
|
172
172
|
|
173
173
|
end
|
174
|
-
|
174
|
+
|
175
175
|
# make temp tiff filename
|
176
176
|
@tmp_path = "#{tmp_folder}/#{UUIDTools::UUID.random_create.to_s}.tif"
|
177
|
-
|
178
|
-
options =
|
177
|
+
|
178
|
+
options = ''
|
179
179
|
case samples_per_pixel
|
180
|
-
when
|
181
|
-
options +=
|
182
|
-
when
|
180
|
+
when '3'
|
181
|
+
options += '-type TrueColor'
|
182
|
+
when '1'
|
183
183
|
if bits_per_sample.to_i == 1
|
184
|
-
options +=
|
184
|
+
options += '-type Bilevel'
|
185
185
|
elsif bits_per_sample.to_i > 1
|
186
|
-
options +=
|
186
|
+
options += '-type Grayscale'
|
187
187
|
end
|
188
188
|
end
|
189
189
|
tiff_command = "MAGICK_TEMPORARY_PATH=#{tmp_folder} convert -quiet -compress none #{profile_conversion_switch} #{options} '#{@path}[0]' '#{@tmp_path}'"
|
190
190
|
result=`#{tiff_command} 2>&1`
|
191
191
|
raise "tiff convert command failed: #{tiff_command} with result #{result}" unless $?.success?
|
192
|
-
|
192
|
+
|
193
193
|
pixdem = width > height ? width : height
|
194
194
|
layers = (( Math.log(pixdem) / Math.log(2) ) - ( Math.log(96) / Math.log(2) )).ceil + 1
|
195
|
-
|
195
|
+
|
196
196
|
# jp2 creation command
|
197
|
-
kdu_bin =
|
198
|
-
options =
|
199
|
-
options +=
|
200
|
-
options +=
|
201
|
-
|
202
|
-
|
197
|
+
kdu_bin = 'kdu_compress '
|
198
|
+
options = ''
|
199
|
+
options += ' -jp2_space sRGB ' if samples_per_pixel == '3'
|
200
|
+
options += ' -precise -no_weights -quiet Creversible=no Cmodes=BYPASS Corder=RPCL ' +
|
201
|
+
'Cblk=\\{64,64\\} Cprecincts=\\{256,256\\},\\{256,256\\},\\{128,128\\} ' +
|
202
|
+
'ORGgen_plt=yes -rate 1.5 Clevels=5 '
|
203
203
|
jp2_command = "#{kdu_bin} #{options} Clayers=#{layers.to_s} -i '#{@tmp_path}' -o '#{output}'"
|
204
204
|
result=`#{jp2_command} 2>&1`
|
205
205
|
raise "JP2 creation command failed: #{jp2_command} with result #{result}" unless $?.success?
|
206
|
-
|
206
|
+
|
207
207
|
File.delete(@tmp_path) unless preserve_tmp_source
|
208
208
|
|
209
209
|
# create output response object, which is an Assembly::Image type object
|
210
|
-
|
211
|
-
|
210
|
+
Assembly::Image.new(output)
|
211
|
+
|
212
212
|
end
|
213
213
|
|
214
214
|
end
|
215
|
-
|
215
|
+
|
216
216
|
end
|
@@ -1,8 +1,17 @@
|
|
1
|
+
require 'logger'
|
1
2
|
module Assembly
|
2
|
-
|
3
|
+
|
3
4
|
# The Images class contains methods to operate on multiple images in batch.
|
4
5
|
class Images
|
5
6
|
|
7
|
+
def self.logger
|
8
|
+
@logger ||= Logger.new(STDERR)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.logger= logger
|
12
|
+
@logger = logger
|
13
|
+
end
|
14
|
+
|
6
15
|
# Pass in a source path and have exif color profile descriptions added to all images contained.
|
7
16
|
# This is useful if your source TIFFs do not have color profile descriptions in the EXIF data, but you know what it should be.
|
8
17
|
# This will allow the images to pass the validty check and have JP2s created successfully.
|
@@ -18,27 +27,27 @@ module Assembly
|
|
18
27
|
# * :extension => defines the types of files that will be processed (default '.tif')
|
19
28
|
#
|
20
29
|
# Example:
|
21
|
-
# Assembly::Images.batch_add_exif_profile_description('/full_path_to_tifs','Adobe RGB 1998')
|
30
|
+
# Assembly::Images.batch_add_exif_profile_description('/full_path_to_tifs','Adobe RGB 1998')
|
22
31
|
def self.batch_add_exif_profile_description(source,profile_name,params={})
|
23
32
|
|
24
33
|
extension = params[:extension] || 'tif'
|
25
34
|
recursive = params[:recursive] || false
|
26
35
|
force = params[:force] || false
|
27
|
-
|
28
|
-
raise
|
29
|
-
|
30
|
-
|
36
|
+
|
37
|
+
raise 'Input path does not exist' unless File.directory?(source)
|
38
|
+
|
39
|
+
logger.debug "Source: #{source}"
|
31
40
|
|
32
41
|
# iterate over input directory looking for tifs
|
33
|
-
pattern = recursive ? "**/*.#{extension}" : "*.#{extension}*"
|
42
|
+
pattern = recursive ? "**/*.#{extension}" : "*.#{extension}*"
|
34
43
|
Dir.glob(File.join(source,pattern)).each do |file|
|
35
44
|
img=Assembly::Image.new(file)
|
36
|
-
|
45
|
+
logger.debug "Processing #{file}"
|
37
46
|
img.add_exif_profile_description(profile_name,force)
|
38
47
|
end
|
39
|
-
|
48
|
+
'Complete'
|
40
49
|
end
|
41
|
-
|
50
|
+
|
42
51
|
# Pass in a source path and get JP2s generate for each tiff that is in the source path
|
43
52
|
#
|
44
53
|
# If not passed in, the destination will be a "jp2" subfolder within the source folder.
|
@@ -55,20 +64,20 @@ module Assembly
|
|
55
64
|
# Example:
|
56
65
|
# Assembly::Images.batch_generate_jp2('/full_path_to_tifs')
|
57
66
|
def self.batch_generate_jp2(source,params={})
|
58
|
-
|
59
|
-
raise
|
67
|
+
|
68
|
+
raise 'Input path does not exist' unless File.directory?(source)
|
60
69
|
output = params[:output] || File.join(source,'jp2') # default output directgory is jp2 sub-directory from source
|
61
70
|
extension = params[:extension] || 'tif'
|
62
71
|
overwrite = params[:overwrite] || false
|
63
72
|
recursive = params[:recursive] || false
|
64
|
-
|
73
|
+
|
65
74
|
Dir.mkdir(output) unless File.directory?(output) # attemp to make output directory
|
66
|
-
raise
|
75
|
+
raise 'Output path does not exist or could not be created' unless File.directory?(output)
|
76
|
+
|
77
|
+
logger.debug "Source: #{source}"
|
78
|
+
logger.debug "Destination: #{output}"
|
67
79
|
|
68
|
-
|
69
|
-
puts "Destination: #{output}"
|
70
|
-
|
71
|
-
pattern = recursive ? "**/*.#{extension}" : "*.#{extension}*"
|
80
|
+
pattern = recursive ? "**/*.#{extension}" : "*.#{extension}*"
|
72
81
|
|
73
82
|
# iterate over input directory looking for tifs
|
74
83
|
Dir.glob(File.join(source,pattern)).each do |file|
|
@@ -76,13 +85,13 @@ module Assembly
|
|
76
85
|
output_img=File.join(output,File.basename(file,File.extname(file))+'.jp2') # output image gets same file name as source, but with a jp2 extension and in the correct output directory
|
77
86
|
begin
|
78
87
|
derivative_img=source_img.create_jp2(:overwrite=>overwrite,:output=>output_img)
|
79
|
-
|
88
|
+
logger.debug "Generated jp2 for #{File.basename(file)}"
|
80
89
|
rescue Exception => e
|
81
|
-
|
90
|
+
logger.debug "** Error for #{File.basename(file)}: #{e.message}"
|
82
91
|
end
|
83
92
|
end
|
84
|
-
|
85
|
-
|
93
|
+
'Complete'
|
94
|
+
|
86
95
|
end
|
87
96
|
end
|
88
97
|
end
|
data/spec/image_spec.rb
CHANGED
@@ -2,100 +2,108 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Assembly::Image do
|
4
4
|
|
5
|
-
it
|
5
|
+
it 'should not run if no input file is passed in' do
|
6
6
|
@ai=Assembly::Image.new('')
|
7
|
-
|
7
|
+
expect{@ai.create_jp2}.to raise_error
|
8
8
|
end
|
9
|
-
|
10
|
-
it
|
9
|
+
|
10
|
+
it 'should indicate the default jp2 filename' do
|
11
11
|
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
12
|
-
@ai.jp2_filename.
|
12
|
+
expect(@ai.jp2_filename).to eq TEST_TIF_INPUT_FILE.gsub('.tif','.jp2')
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
16
|
-
@ai = Assembly::Image.new(
|
17
|
-
@ai.jp2_filename.
|
15
|
+
it 'should indicate the default jp2 filename' do
|
16
|
+
@ai = Assembly::Image.new('/path/to/a/file_with_no_extension')
|
17
|
+
expect(@ai.jp2_filename).to eq '/path/to/a/file_with_no_extension.jp2'
|
18
18
|
end
|
19
|
-
|
20
|
-
it
|
19
|
+
|
20
|
+
it 'should indicate the default DPG jp2 filename' do
|
21
21
|
@ai = Assembly::Image.new(TEST_DPG_TIF_INPUT_FILE)
|
22
|
-
@ai.dpg_jp2_filename.
|
22
|
+
expect(@ai.dpg_jp2_filename).to eq TEST_DPG_TIF_INPUT_FILE.gsub('.tif','.jp2').gsub('_00_','_05_')
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
26
|
-
@ai = Assembly::Image.new(
|
27
|
-
@ai.dpg_jp2_filename.
|
25
|
+
it 'should indicate the default jp2 filename' do
|
26
|
+
@ai = Assembly::Image.new('/path/to/a/file_with_no_00_extension')
|
27
|
+
expect(@ai.dpg_jp2_filename).to eq '/path/to/a/file_with_no_05_extension.jp2'
|
28
28
|
end
|
29
|
-
|
30
|
-
it
|
29
|
+
|
30
|
+
it 'should create jp2 when given an RGB tif' do
|
31
31
|
generate_test_image(TEST_TIF_INPUT_FILE)
|
32
32
|
expect(File).to exist TEST_TIF_INPUT_FILE
|
33
33
|
expect(File).to_not exist TEST_JP2_OUTPUT_FILE
|
34
34
|
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
35
35
|
result=@ai.create_jp2(:output => TEST_JP2_OUTPUT_FILE)
|
36
|
-
result.
|
37
|
-
result.path.
|
38
|
-
|
39
|
-
result.exif.colorspace.
|
36
|
+
expect(result).to be_a_kind_of Assembly::Image
|
37
|
+
expect(result.path).to eq TEST_JP2_OUTPUT_FILE
|
38
|
+
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
39
|
+
expect(result.exif.colorspace).to eq 'sRGB'
|
40
40
|
@jp2=Assembly::Image.new(TEST_JP2_OUTPUT_FILE)
|
41
|
-
@jp2.height.
|
42
|
-
@jp2.width.
|
43
|
-
end
|
44
|
-
|
45
|
-
it
|
46
|
-
|
41
|
+
expect(@jp2.height).to eq 100
|
42
|
+
expect(@jp2.width).to eq 100
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should create grayscale jp2 when given a bitonal tif' do
|
46
|
+
skip 'The latest version of Kakadu may require some changes for this work correctly'
|
47
|
+
# error message is
|
48
|
+
# JP2 creation command failed: kdu_compress -precise -no_weights -quiet Creversible=no Cmodes=BYPASS Corder=RPCL Cblk=\{64,64\} Cprecincts=\{256,256\},\{256,256\},\{128,128\} ORGgen_plt=yes -rate 1.5 Clevels=5 Clayers=2 -i '/tmp/408d3740-e25f-4c1b-889f-3f138d088fe4.tif' -o '/home/travis/build/sul-dlss/assembly-image/spec/test_data/output/test.jp2' with result Kakadu Error:
|
49
|
+
# The number of colours associated with the colour space identified by the source
|
50
|
+
# file (possible from an embedded ICC profile) is not consistent with the number
|
51
|
+
# of supplied image components and/or colour palette. You can address this
|
52
|
+
# problem by supplying a `-jp2_space' or `-jpx_space' argument to explicitly
|
53
|
+
# identify a colour space that has anywhere from 1 to 1 colour components.
|
54
|
+
generate_test_image(TEST_TIF_INPUT_FILE,:color=>'white',:image_type=>'Bilevel')
|
47
55
|
expect(File).to exist TEST_TIF_INPUT_FILE
|
48
56
|
expect(File).to_not exist TEST_JP2_OUTPUT_FILE
|
49
57
|
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
50
|
-
@ai.
|
58
|
+
expect(@ai).to have_color_profile
|
51
59
|
result=@ai.create_jp2(:output => TEST_JP2_OUTPUT_FILE)
|
52
|
-
|
53
|
-
result.exif.colorspace.
|
60
|
+
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
61
|
+
expect(result.exif.colorspace).to eq 'Grayscale'
|
54
62
|
end
|
55
63
|
|
56
|
-
it
|
57
|
-
generate_test_image(TEST_TIF_INPUT_FILE,:color=>'white',:image_type=>
|
64
|
+
it 'should create color jp2 when given a color tif but bitonal image data (1 channels and 1 bits per pixel)' do
|
65
|
+
generate_test_image(TEST_TIF_INPUT_FILE,:color=>'white',:image_type=>'TrueColor',:profile=>'')
|
58
66
|
expect(File).to exist TEST_TIF_INPUT_FILE
|
59
67
|
expect(File).to_not exist TEST_JP2_OUTPUT_FILE
|
60
68
|
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
61
|
-
@ai.
|
69
|
+
expect(@ai).to_not have_color_profile
|
62
70
|
result=@ai.create_jp2(:output => TEST_JP2_OUTPUT_FILE)
|
63
|
-
|
64
|
-
result.exif.colorspace.
|
71
|
+
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
72
|
+
expect(result.exif.colorspace).to eq 'sRGB'
|
65
73
|
end
|
66
74
|
|
67
|
-
it
|
68
|
-
generate_test_image(TEST_TIF_INPUT_FILE,:color=>'white',:image_type=>
|
75
|
+
it 'should create grayscale jp2 when given a graycale tif but with bitonal image data (1 channel and 1 bits per pixel)' do
|
76
|
+
generate_test_image(TEST_TIF_INPUT_FILE,:color=>'white',:image_type=>'Grayscale',:profile=>'')
|
69
77
|
expect(File).to exist TEST_TIF_INPUT_FILE
|
70
78
|
expect(File).to_not exist TEST_JP2_OUTPUT_FILE
|
71
79
|
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
72
|
-
@ai.
|
80
|
+
expect(@ai).to_not have_color_profile
|
73
81
|
result=@ai.create_jp2(:output => TEST_JP2_OUTPUT_FILE)
|
74
|
-
|
75
|
-
result.exif.colorspace.
|
82
|
+
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
83
|
+
expect(result.exif.colorspace).to eq 'Grayscale'
|
76
84
|
end
|
77
85
|
|
78
|
-
it
|
79
|
-
generate_test_image(TEST_TIF_INPUT_FILE,:color=>'gray',:image_type=>
|
86
|
+
it 'should create color jp2 when given a color tif but with greyscale image data (1 channel and 8 bits per pixel)' do
|
87
|
+
generate_test_image(TEST_TIF_INPUT_FILE,:color=>'gray',:image_type=>'TrueColor',:profile=>'')
|
80
88
|
expect(File).to exist TEST_TIF_INPUT_FILE
|
81
89
|
expect(File).to_not exist TEST_JP2_OUTPUT_FILE
|
82
90
|
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
83
|
-
@ai.
|
91
|
+
expect(@ai).to_not have_color_profile
|
84
92
|
result=@ai.create_jp2(:output => TEST_JP2_OUTPUT_FILE)
|
85
|
-
|
86
|
-
result.exif.colorspace.
|
93
|
+
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
94
|
+
expect(result.exif.colorspace).to eq 'sRGB'
|
87
95
|
end
|
88
|
-
|
89
|
-
it
|
96
|
+
|
97
|
+
it 'should create a jp2 when the source image has no profile' do
|
90
98
|
generate_test_image(TEST_TIF_INPUT_FILE,:profile=>'') # generate a test input with no profile
|
91
99
|
expect(File).to exist TEST_TIF_INPUT_FILE
|
92
100
|
expect(File).to_not exist TEST_JP2_OUTPUT_FILE
|
93
101
|
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
94
|
-
@ai.
|
95
|
-
@ai.
|
96
|
-
@ai.
|
102
|
+
expect(@ai).to_not have_color_profile
|
103
|
+
expect(@ai).to be_a_valid_image
|
104
|
+
expect(@ai).to be_jp2able
|
97
105
|
@ai.create_jp2(:output => TEST_JP2_OUTPUT_FILE)
|
98
|
-
|
106
|
+
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
99
107
|
end
|
100
108
|
|
101
109
|
it "should not run if the output file exists and you don't allow overwriting" do
|
@@ -104,94 +112,93 @@ describe Assembly::Image do
|
|
104
112
|
expect(File).to exist TEST_TIF_INPUT_FILE
|
105
113
|
expect(File).to exist TEST_JP2_OUTPUT_FILE
|
106
114
|
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
107
|
-
|
115
|
+
expect{@ai.create_jp2(:output => TEST_JP2_OUTPUT_FILE)}.to raise_error(SecurityError)
|
108
116
|
end
|
109
117
|
|
110
|
-
it
|
118
|
+
it 'should get the correct image height and width' do
|
111
119
|
generate_test_image(TEST_TIF_INPUT_FILE)
|
112
120
|
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
113
|
-
@ai.height.
|
114
|
-
@ai.width.
|
121
|
+
expect(@ai.height).to eq 100
|
122
|
+
expect(@ai.width).to eq 100
|
115
123
|
end
|
116
|
-
|
117
|
-
it
|
124
|
+
|
125
|
+
it 'should not run if the input file is a jp2' do
|
118
126
|
generate_test_image(TEST_JP2_OUTPUT_FILE)
|
119
127
|
expect(File).to exist TEST_JP2_OUTPUT_FILE
|
120
128
|
@ai = Assembly::Image.new(TEST_JP2_OUTPUT_FILE)
|
121
|
-
@ai.
|
122
|
-
@ai.
|
123
|
-
|
129
|
+
expect(@ai).to be_valid_image
|
130
|
+
expect(@ai).to_not be_jp2able
|
131
|
+
expect { @ai.create_jp2 }.to raise_error
|
124
132
|
end
|
125
133
|
|
126
|
-
it
|
134
|
+
it 'should run if you specify a bogus output profile, because this is not currently an option' do
|
127
135
|
generate_test_image(TEST_TIF_INPUT_FILE)
|
128
136
|
expect(File).to exist TEST_TIF_INPUT_FILE
|
129
137
|
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
130
138
|
result=@ai.create_jp2(:output_profile=>'bogusness')
|
131
|
-
result.
|
132
|
-
result.path.
|
133
|
-
|
134
|
-
result.exif.colorspace.
|
139
|
+
expect(result).to be_a_kind_of Assembly::Image
|
140
|
+
expect(result.path).to eq TEST_JP2_INPUT_FILE
|
141
|
+
expect(TEST_JP2_INPUT_FILE).to be_a_jp2
|
142
|
+
expect(result.exif.colorspace).to eq 'sRGB'
|
135
143
|
end
|
136
144
|
|
137
|
-
it
|
145
|
+
it 'should not run if you specify a bogus tmp folder' do
|
138
146
|
generate_test_image(TEST_TIF_INPUT_FILE)
|
139
147
|
bogus_folder='/crapsticks'
|
140
148
|
expect(File).to exist TEST_TIF_INPUT_FILE
|
141
149
|
expect(File).to_not exist bogus_folder
|
142
150
|
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
143
|
-
|
151
|
+
expect { @ai.create_jp2(:tmp_folder=>bogus_folder) }.to raise_error
|
144
152
|
end
|
145
153
|
|
146
|
-
it
|
154
|
+
it 'should create a jp2 and preserve the temporary file if specified' do
|
147
155
|
generate_test_image(TEST_TIF_INPUT_FILE)
|
148
156
|
expect(File).to exist TEST_TIF_INPUT_FILE
|
149
157
|
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
150
158
|
result=@ai.create_jp2(:output => TEST_JP2_OUTPUT_FILE, :preserve_tmp_source=>true)
|
151
|
-
result.
|
152
|
-
result.path.
|
153
|
-
|
154
|
-
result.exif.colorspace.
|
155
|
-
File.exists?(@ai.tmp_path).
|
159
|
+
expect(result).to be_a_kind_of Assembly::Image
|
160
|
+
expect(result.path).to eq TEST_JP2_OUTPUT_FILE
|
161
|
+
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
162
|
+
expect(result.exif.colorspace).to eq 'sRGB'
|
163
|
+
expect(File.exists?(@ai.tmp_path)).to be true
|
156
164
|
end
|
157
165
|
|
158
|
-
it
|
166
|
+
it 'should create jp2 of the same filename and in the same location as the input if no output file is specified, and should cleanup tmp file' do
|
159
167
|
generate_test_image(TEST_TIF_INPUT_FILE)
|
160
168
|
expect(File).to exist TEST_TIF_INPUT_FILE
|
161
|
-
File.exists?(TEST_JP2_INPUT_FILE).
|
169
|
+
expect(File.exists?(TEST_JP2_INPUT_FILE)).to be false
|
162
170
|
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
163
171
|
result=@ai.create_jp2
|
164
|
-
result.
|
165
|
-
result.path.
|
166
|
-
|
167
|
-
result.exif.colorspace.
|
168
|
-
File.exists?(@ai.tmp_path).
|
172
|
+
expect(result).to be_a_kind_of Assembly::Image
|
173
|
+
expect(result.path).to eq TEST_JP2_INPUT_FILE
|
174
|
+
expect(TEST_JP2_INPUT_FILE).to be_a_jp2
|
175
|
+
expect(result.exif.colorspace).to eq 'sRGB'
|
176
|
+
expect(File.exists?(@ai.tmp_path)).to be false
|
169
177
|
end
|
170
178
|
|
171
|
-
it
|
179
|
+
it 'should create jp2 from input JPEG of the same filename and in the same location as the input if no output file is specified, and should cleanup tmp file' do
|
172
180
|
generate_test_image(TEST_JPEG_INPUT_FILE)
|
173
181
|
expect(File).to exist TEST_JPEG_INPUT_FILE
|
174
182
|
expect(File).to_not exist TEST_JP2_INPUT_FILE
|
175
183
|
@ai = Assembly::Image.new(TEST_JPEG_INPUT_FILE)
|
176
184
|
result=@ai.create_jp2
|
177
|
-
result.
|
178
|
-
result.path.
|
179
|
-
|
180
|
-
|
181
|
-
File.exists?(@ai.tmp_path).should be false
|
185
|
+
expect(result).to be_a_kind_of Assembly::Image
|
186
|
+
expect(result.path).to eq TEST_JP2_INPUT_FILE
|
187
|
+
expect(TEST_JP2_INPUT_FILE).to be_a_jp2
|
188
|
+
expect(File.exists?(@ai.tmp_path)).to be false
|
182
189
|
end
|
183
190
|
|
184
|
-
it
|
191
|
+
it 'should recreate jp2 if the output file exists and if you allow overwriting' do
|
185
192
|
generate_test_image(TEST_TIF_INPUT_FILE)
|
186
193
|
generate_test_image(TEST_JP2_OUTPUT_FILE)
|
187
194
|
expect(File).to exist TEST_TIF_INPUT_FILE
|
188
195
|
expect(File).to exist TEST_JP2_OUTPUT_FILE
|
189
196
|
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
190
197
|
result=@ai.create_jp2(:output => TEST_JP2_OUTPUT_FILE,:overwrite => true)
|
191
|
-
result.
|
192
|
-
result.path.
|
193
|
-
|
194
|
-
result.exif.colorspace.
|
198
|
+
expect(result).to be_a_kind_of Assembly::Image
|
199
|
+
expect(result.path).to eq TEST_JP2_OUTPUT_FILE
|
200
|
+
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
201
|
+
expect(result.exif.colorspace).to eq 'sRGB'
|
195
202
|
end
|
196
203
|
|
197
204
|
after(:each) do
|