assembly-image 1.7.5 → 1.7.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dee27ed2f2ed8bf8a3878bac7a41448a8f7a54fbdd8e1800434ce0af812bf1aa
4
- data.tar.gz: 8ff1e21029d7b8c4bbc045522a3d2e7fdc06c9940cc09c73287e1bf15e60a11f
3
+ metadata.gz: e78a7843a4627deebdd77c16dc4da9664eba77fd78f6889b5f92bd95d36d29b5
4
+ data.tar.gz: 96d0a7a29dc79c80a6a3b87820ee9f7d21a93b78fe5b0fcca56a9a97a4dae505
5
5
  SHA512:
6
- metadata.gz: edf348cb16c843850f0a496be66ec2db8e21587970caadf72b31b2ecddeb2387ab69e0c6b308e5c30d02a2e66dd4de67e01f260985ed238a546448b4aacf9667
7
- data.tar.gz: 27072b70647d8a657885f74ce952210efa0c070c10597ee4c7480029e845b78549c33478a5f503ebabc70e8d9c870e7376620d173e04b27eba31f0342517dca6
6
+ metadata.gz: 7d992715e82f337b62d3008e54d3d864c4e8731786ced7889800719c0629bb4cd6c329d13581ad7af6ac6048b7a5eb1cf6891a55df71d37cb599750dddf15f9e
7
+ data.tar.gz: fbd72421b362ec757faec2e68fb92ebbdf71379475a933cf8179cbb0754d19f39a2d74bede1676d5d7217846febb98a2d5e676ded1576e0097f7196d330d6dcf
@@ -62,9 +62,9 @@ module Assembly
62
62
  # Example:
63
63
  # source_img=Assembly::ObjectFile.new('/input/path_to_file.tif')
64
64
  # puts source_img.compressed? # gives true
65
- def compressed?
66
- exif.compression != 'Uncompressed'
67
- end
65
+ # def compressed?
66
+ # exif.compression != 'Uncompressed'
67
+ # end
68
68
 
69
69
  # Add an exif color profile descriptions to the image.
70
70
  # This is useful if your source TIFFs do not have color profile descriptions in the EXIF data, but you know what it should be.
@@ -128,37 +128,29 @@ module Assembly
128
128
  # derivative_img=source_img.create_jp2(:overwrite=>true)
129
129
  # puts derivative_img.mimetype # 'image/jp2'
130
130
  # puts derivative_image.path # '/input/path_to_file.jp2'
131
- # rubocop:disable Metrics/AbcSize
132
- # rubocop:disable Metrics/MethodLength
133
131
  # rubocop:disable Metrics/CyclomaticComplexity:
134
132
  def create_jp2(params = {})
135
133
  output = params[:output] || jp2_filename
136
134
  create_jp2_checks(output: output, overwrite: params[:overwrite])
137
135
 
138
136
  # Using instance variable so that can check in tests.
139
- source_path = if create_temp_tiff?
140
- @tmp_path = make_tmp_tiff(tmp_folder: params[:tmp_folder])
141
- else
142
- @path
143
- end
137
+ @tmp_path = make_tmp_tiff(tmp_folder: params[:tmp_folder])
144
138
 
145
- jp2_command = jp2_create_command(source_path: source_path, output: output)
139
+ jp2_command = jp2_create_command(source_path: @tmp_path, output: output)
146
140
  result = `#{jp2_command}`
147
141
  raise "JP2 creation command failed: #{jp2_command} with result #{result}" unless $CHILD_STATUS.success?
148
142
 
149
- File.delete(source_path) unless @tmp_path.nil? || params[:preserve_tmp_source]
143
+ File.delete(@tmp_path) unless @tmp_path.nil? || params[:preserve_tmp_source]
150
144
 
151
145
  # create output response object, which is an Assembly::Image type object
152
146
  Assembly::Image.new(output)
153
147
  end
154
- # rubocop:enable Metrics/AbcSize
155
- # rubocop:enable Metrics/MethodLength
156
148
 
157
149
  private
158
150
 
159
- def create_temp_tiff?
160
- mimetype != 'image/tiff' || compressed?
161
- end
151
+ # def create_temp_tiff?
152
+ # mimetype != 'image/tiff' || compressed?
153
+ # end
162
154
 
163
155
  def create_jp2_checks(output:, overwrite:)
164
156
  check_for_file
@@ -204,6 +196,8 @@ module Assembly
204
196
  case mimetype
205
197
  when 'image/tiff'
206
198
  1
199
+ when 'image/jpeg'
200
+ 3
207
201
  end
208
202
  end
209
203
  end
@@ -219,6 +213,16 @@ module Assembly
219
213
  end
220
214
  end
221
215
 
216
+ # Get size of image data in bytes
217
+ def image_data_size
218
+ (samples_per_pixel * height * width * bits_per_sample) / 8
219
+ end
220
+
221
+ # Bigtiff needs to be used if size of image exceeds 2^32 bytes.
222
+ def need_bigtiff?
223
+ image_data_size >= 2**32
224
+ end
225
+
222
226
  # Get the number of JP2 layers to generate
223
227
  def layers
224
228
  pixdem = [width, height].max
@@ -278,17 +282,18 @@ module Assembly
278
282
  when 3
279
283
  options << '-type TrueColor'
280
284
  when 1
281
- if bits_per_sample == 1
282
- options << '-type Bilevel'
283
- options << '-depth 8' # force the production of a grayscale access derivative
284
- elsif bits_per_sample > 1
285
- options << '-type Grayscale'
286
- end
285
+ options << '-depth 8' # force the production of a grayscale access derivative
286
+ options << '-type Grayscale'
287
287
  end
288
288
 
289
289
  options << profile_conversion_switch(profile, tmp_folder: tmp_folder)
290
290
 
291
- tiff_command = "MAGICK_TEMPORARY_PATH=#{tmp_folder} convert -quiet -compress none #{options.join(' ')} '#{@path}[0]' '#{tmp_path}'"
291
+ # The output in the covnert command needs to be prefixed by the image type. By default ImageMagick
292
+ # will assume TIFF: when the file extension is .tif/.tiff. TIFF64: Needs to be forced when image will
293
+ # exceed 2^32 bytes in size
294
+ tiff_type = need_bigtiff? ? 'TIFF64:' : ''
295
+
296
+ tiff_command = "MAGICK_TEMPORARY_PATH=#{tmp_folder} convert -quiet -compress none #{options.join(' ')} '#{@path}[0]' #{tiff_type}'#{tmp_path}'"
292
297
  result = `#{tiff_command} 2>&1`
293
298
  raise "tiff convert command failed: #{tiff_command} with result #{result}" unless $CHILD_STATUS.success?
294
299
 
@@ -5,6 +5,6 @@ module Assembly
5
5
  # Main Image class
6
6
  class Image
7
7
  # Project version number
8
- VERSION = '1.7.5'
8
+ VERSION = '1.7.6'
9
9
  end
10
10
  end
@@ -29,14 +29,31 @@ describe Assembly::Image do
29
29
  expect(@ai.dpg_jp2_filename).to eq '/path/to/a/file_with_no_05_extension.jp2'
30
30
  end
31
31
 
32
- it 'creates the jp2 without a temp file when given an uncompressed RGB tif' do
33
- generate_test_image(TEST_TIF_INPUT_FILE)
32
+ # it 'creates the jp2 without a temp file when given an uncompressed RGB tif' do
33
+ # generate_test_image(TEST_TIF_INPUT_FILE)
34
+ # expect(File).to exist TEST_TIF_INPUT_FILE
35
+ # expect(File).to_not exist TEST_JP2_OUTPUT_FILE
36
+ # @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
37
+ # result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
38
+ # # Indicates a temp tiff was not created.
39
+ # expect(@ai.tmp_path).to be_nil
40
+ # expect(result).to be_a_kind_of Assembly::Image
41
+ # expect(result.path).to eq TEST_JP2_OUTPUT_FILE
42
+ # expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
43
+ # expect(result.exif.colorspace).to eq 'sRGB'
44
+ # @jp2 = Assembly::Image.new(TEST_JP2_OUTPUT_FILE)
45
+ # expect(@jp2.height).to eq 100
46
+ # expect(@jp2.width).to eq 100
47
+ # end
48
+
49
+ it 'creates the jp2 with a temp file when given an LZW compressed RGB tif' do
50
+ generate_test_image(TEST_TIF_INPUT_FILE, compress: 'lzw')
34
51
  expect(File).to exist TEST_TIF_INPUT_FILE
35
52
  expect(File).to_not exist TEST_JP2_OUTPUT_FILE
36
53
  @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
37
54
  result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
38
55
  # Indicates a temp tiff was not created.
39
- expect(@ai.tmp_path).to be_nil
56
+ expect(@ai.tmp_path).to_not be_nil
40
57
  expect(result).to be_a_kind_of Assembly::Image
41
58
  expect(result.path).to eq TEST_JP2_OUTPUT_FILE
42
59
  expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
@@ -46,43 +63,47 @@ describe Assembly::Image do
46
63
  expect(@jp2.width).to eq 100
47
64
  end
48
65
 
49
- it 'creates the jp2 with a temp file when given a compressed RGB tif' do
50
- generate_test_image(TEST_TIF_INPUT_FILE, compress: true)
66
+ it 'creates the jp2 with a temp file when given an uncompressed compressed RGB tif with more than 4GB of image data' do
67
+ skip 'This test will create a 4GB test image and a 4GB temporary image, so skipping by default.'
68
+ generate_test_image(TEST_TIF_INPUT_FILE, compress: 'none', width: '37838', height: '37838')
51
69
  expect(File).to exist TEST_TIF_INPUT_FILE
52
70
  expect(File).to_not exist TEST_JP2_OUTPUT_FILE
53
71
  @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
54
72
  result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
55
- # Indicates a temp tiff was not created.
56
73
  expect(@ai.tmp_path).to_not be_nil
57
74
  expect(result).to be_a_kind_of Assembly::Image
58
75
  expect(result.path).to eq TEST_JP2_OUTPUT_FILE
59
76
  expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
60
77
  expect(result.exif.colorspace).to eq 'sRGB'
61
78
  @jp2 = Assembly::Image.new(TEST_JP2_OUTPUT_FILE)
62
- expect(@jp2.height).to eq 100
63
- expect(@jp2.width).to eq 100
79
+ expect(@jp2.height).to eq 37_838
80
+ expect(@jp2.width).to eq 37_838
81
+ end
82
+
83
+ it 'creates the jp2 with a temp file when given an LZW compressed RGB tif with more than 4GB of image data' do
84
+ skip 'This test will create a 4GB temporary image, so skipping by default.'
85
+ generate_test_image(TEST_TIF_INPUT_FILE, compress: 'lzw', width: '37838', height: '37838')
86
+ expect(File).to exist TEST_TIF_INPUT_FILE
87
+ expect(File).to_not exist TEST_JP2_OUTPUT_FILE
88
+ @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
89
+ result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
90
+ expect(@ai.tmp_path).to_not be_nil
91
+ expect(result).to be_a_kind_of Assembly::Image
92
+ expect(result.path).to eq TEST_JP2_OUTPUT_FILE
93
+ expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
94
+ expect(result.exif.colorspace).to eq 'sRGB'
95
+ @jp2 = Assembly::Image.new(TEST_JP2_OUTPUT_FILE)
96
+ expect(@jp2.height).to eq 37_838
97
+ expect(@jp2.width).to eq 37_838
64
98
  end
65
99
 
66
100
  it 'creates grayscale jp2 when given a bitonal tif' do
67
- skip 'The latest version of Kakadu may require some changes for this work correctly'
68
- # error message is
69
- # JP2 creation command failed: kdu_compress -precise -no_weights -quiet Creversible=no Cmodes=BYPASS
70
- # Corder=RPCL Cblk=\{64,64\} Cprecincts=\{256,256\},\{256,256\},\{128,128\} ORGgen_plt=yes -rate 1.5 Clevels=5
71
- # Clayers=2 -i '/tmp/408d3740-e25f-4c1b-889f-3f138d088fe4.tif' -o '/home/travis/build/sul-dlss/assembly-image/spec/test_data/output/test.jp2'
72
- # with result Kakadu Error:
73
- # The number of colours associated with the colour space identified by the source
74
- # file (possible from an embedded ICC profile) is not consistent with the number
75
- # of supplied image components and/or colour palette. You can address this
76
- # problem by supplying a `-jp2_space' or `-jpx_space' argument to explicitly
77
- # identify a colour space that has anywhere from 1 to 1 colour components.
78
- generate_test_image(TEST_TIF_INPUT_FILE, image_type: 'Bilevel')
101
+ # Need to force group4 compression to get ImageMagick to create bitonal tiff
102
+ generate_test_image(TEST_TIF_INPUT_FILE, image_type: 'Bilevel', compress: 'group4')
79
103
  expect(File).to exist TEST_TIF_INPUT_FILE
80
104
  expect(File).to_not exist TEST_JP2_OUTPUT_FILE
81
105
  @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
82
- expect(@ai).to have_color_profile
83
106
  result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
84
- # Indicates a temp tiff was not created.
85
- expect(@ai.tmp_path).to be_nil
86
107
  expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
87
108
  expect(result.exif.colorspace).to eq 'Grayscale'
88
109
  end
@@ -94,8 +115,6 @@ describe Assembly::Image do
94
115
  @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
95
116
  expect(@ai).to_not have_color_profile
96
117
  result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
97
- # Indicates a temp tiff was not created.
98
- expect(@ai.tmp_path).to be_nil
99
118
  expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
100
119
  expect(result.exif.colorspace).to eq 'sRGB'
101
120
  end
@@ -232,7 +251,6 @@ describe Assembly::Image do
232
251
  expect(result.path).to eq TEST_JP2_INPUT_FILE
233
252
  expect(TEST_JP2_INPUT_FILE).to be_a_jp2
234
253
  expect(result.exif.colorspace).to eq 'sRGB'
235
- expect(@ai.tmp_path).to be_nil
236
254
  end
237
255
 
238
256
  it 'recreates jp2 if the output file exists and if you allow overwriting' do
@@ -16,22 +16,26 @@ TEST_DRUID = 'nx288wh8889'
16
16
  # rubocop:disable Metrics/AbcSize
17
17
  # rubocop:disable Metrics/CyclomaticComplexity
18
18
  # rubocop:disable Metrics/MethodLength
19
+ # rubocop:disable Metrics/PerceivedComplexity
19
20
  def generate_test_image(file, params = {})
21
+ width = params[:width] || '100'
22
+ height = params[:height] || '100'
20
23
  color = params[:color] || 'TrueColor'
21
24
  profile = params[:profile] || 'sRGBIEC6196621'
22
25
  image_type = params[:image_type]
23
- create_command = "convert rose: -scale 100x100\! -type #{color} "
26
+ create_command = "convert rose: -scale #{width}x#{height}\! -type #{color} "
24
27
  create_command += ' -profile ' + File.join(Assembly::PATH_TO_IMAGE_GEM, 'profiles', profile + '.icc') + ' ' unless profile == ''
25
28
  create_command += " -type #{image_type} " if image_type
26
29
  create_command += ' -compress lzw ' if params[:compress]
27
30
  create_command += file
28
31
  create_command += ' 2>&1'
29
- output = `#{ create_command }`
32
+ output = `#{create_command}`
30
33
  raise "Failed to create test image #{file} (#{params}): \n#{output}" unless $CHILD_STATUS.success?
31
34
  end
32
35
  # rubocop:enable Metrics/AbcSize
33
36
  # rubocop:enable Metrics/CyclomaticComplexity
34
37
  # rubocop:enable Metrics/MethodLength
38
+ # rubocop:enable Metrics/PerceivedComplexity
35
39
 
36
40
  def remove_files(dir)
37
41
  Dir.foreach(dir) do |f|
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: 1.7.5
4
+ version: 1.7.6
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: 2019-07-26 00:00:00.000000000 Z
14
+ date: 2019-08-13 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: assembly-objectfile
@@ -154,14 +154,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
156
  requirements: []
157
- rubygems_version: 3.0.3
157
+ rubyforge_project: assembly-image
158
+ rubygems_version: 2.7.8
158
159
  signing_key:
159
160
  specification_version: 4
160
161
  summary: Ruby immplementation of image services needed to prepare objects to be accessioned
161
162
  in SULAIR digital library
162
- test_files:
163
- - spec/image_spec.rb
164
- - spec/images_spec.rb
165
- - spec/spec_helper.rb
166
- - spec/test_data/input/.empty
167
- - spec/test_data/output/.empty
163
+ test_files: []