From f9c61e4abd2276283794f688c2af6a1a1145f07e Mon Sep 17 00:00:00 2001 From: Daniel Pierce Date: Fri, 31 Mar 2017 13:23:34 -0400 Subject: [PATCH 1/5] Add coverage/ to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9f8204f..e40b6b6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ pkg/ .ruby-gemset fcrepo4-data/ fcrepo4-test-data/ +coverage/ From 2945c07f4a3555b9eb7e594a98e2c8ade6b5c4bc Mon Sep 17 00:00:00 2001 From: Daniel Pierce Date: Fri, 31 Mar 2017 13:25:21 -0400 Subject: [PATCH 2/5] Un-protect some class methods to fix #118 --- .../derivatives/processors/jpeg2k_image.rb | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/hydra/derivatives/processors/jpeg2k_image.rb b/lib/hydra/derivatives/processors/jpeg2k_image.rb index cb4f4b9..1e33965 100644 --- a/lib/hydra/derivatives/processors/jpeg2k_image.rb +++ b/lib/hydra/derivatives/processors/jpeg2k_image.rb @@ -73,20 +73,18 @@ def layer_rates(layer_count, compression_numerator) rates.map(&:to_s).join(',') end - protected - - def encode(path, recipe, output_file) - kdu_compress = Hydra::Derivatives.kdu_compress_path - execute "#{kdu_compress} -quiet -i #{path} -o #{output_file} #{recipe}" - end + def encode(path, recipe, output_file) + kdu_compress = Hydra::Derivatives.kdu_compress_path + execute "#{kdu_compress} -quiet -i #{path} -o #{output_file} #{recipe}" + end - def tmp_file(ext) - Dir::Tmpname.create(['sufia', ext], Hydra::Derivatives.temp_file_base) {} - end + def tmp_file(ext) + Dir::Tmpname.create(['sufia', ext], Hydra::Derivatives.temp_file_base) {} + end - def long_dim(image) - [image[:width], image[:height]].max - end + def long_dim(image) + [image[:width], image[:height]].max + end end def process From 4570561049838bb8b1b9f08d939c06df6af16b3f Mon Sep 17 00:00:00 2001 From: Daniel Pierce Date: Fri, 31 Mar 2017 13:29:11 -0400 Subject: [PATCH 3/5] Specify .jp2 mime type to prevent .txt being used by default. Don't use '-quiet' because it is already hardcoded in the kdu_compress command string. --- spec/units/transcoding_spec.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/spec/units/transcoding_spec.rb b/spec/units/transcoding_spec.rb index e2d3216..98d5d5d 100644 --- a/spec/units/transcoding_spec.rb +++ b/spec/units/transcoding_spec.rb @@ -58,10 +58,10 @@ def create_derivatives(_filename) when 'image/tiff' Jpeg2kImageDerivatives.create(self, source: :original_file, outputs: [ - { label: :resized, recipe: :default, processor: 'jpeg2k_image', resize: "600x600>", url: "#{uri}/resized" }, - { label: :config_lookup, recipe: :default, processor: 'jpeg2k_image', url: "#{uri}/config_lookup" }, - { label: :string_recipe, recipe: '-quiet', processor: 'jpeg2k_image', url: "#{uri}/string_recipe" }, - { label: :diy, processor: 'jpeg2k_image', url: "#{uri}/original_file_diy" }]) + { label: :resized, format: 'jp2', recipe: :default, processor: 'jpeg2k_image', resize: "600x600>", url: "#{uri}/resized" }, + { label: :config_lookup, format: 'jp2', recipe: :default, processor: 'jpeg2k_image', url: "#{uri}/config_lookup" }, + { label: :string_recipe, format: 'jp2', recipe: '-jp2_space sRGB', processor: 'jpeg2k_image', url: "#{uri}/string_recipe" }, + { label: :diy, format: 'jp2', processor: 'jpeg2k_image', url: "#{uri}/original_file_diy" }]) when 'image/x-adobe-dng' ImageDerivatives.create(self, source: :original_file, outputs: [ @@ -318,6 +318,7 @@ def create_derivatives(_filename) let(:file) do GenericFile.new(mime_type_from_fits: 'image/tiff').tap do |t| t.original_file.content = attachment + t.original_file.mime_type = 'image/tiff' t.save end end From af2af774441ee5bbeab6c4b24f468bf9aa71191f Mon Sep 17 00:00:00 2001 From: Daniel Pierce Date: Fri, 31 Mar 2017 14:52:10 -0400 Subject: [PATCH 4/5] Tests for newly unprotected methods. --- spec/processors/jpeg2k_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/processors/jpeg2k_spec.rb b/spec/processors/jpeg2k_spec.rb index b33d8d9..48dc277 100644 --- a/spec/processors/jpeg2k_spec.rb +++ b/spec/processors/jpeg2k_spec.rb @@ -3,6 +3,8 @@ describe Hydra::Derivatives::Processors::Jpeg2kImage do let(:object) { ActiveFedora::Base.new } + let(:filename) { File.expand_path('../../fixtures/test.tif', __FILE__) } + let(:image) { MiniMagick::Image.open(filename) } describe "#calculate_recipe" do it "calculates the number of levels from a size" do @@ -54,4 +56,25 @@ expect(r).to eq(described_class.calculate_recipe(args, 'grey', 7200)) end end + + describe "#encode" do + it "executes the external utility" do + expect(described_class).to receive(:execute) { 0 } + described_class.encode('infile', 'recipe', 'outfile') + # expect(Hydra::Derivatives::Processors::ShellBasedProcessor).to have_received(:execute) + end + end + + describe "#tmp_file" do + it "returns a temp file with the correct extension" do + f = described_class.tmp_file('test') + expect(f).to match(/sufia.*test$/) + end + end + + describe "long_dim" do + it "returns the image's largest dimension" do + expect(described_class.long_dim(image)).to eq(386) + end + end end From c196e6e9f21acce072373f36a1540b5a8172bc8c Mon Sep 17 00:00:00 2001 From: Daniel Pierce Date: Fri, 31 Mar 2017 17:10:49 -0400 Subject: [PATCH 5/5] Cleanup tests. --- spec/processors/jpeg2k_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/processors/jpeg2k_spec.rb b/spec/processors/jpeg2k_spec.rb index 48dc277..acd5951 100644 --- a/spec/processors/jpeg2k_spec.rb +++ b/spec/processors/jpeg2k_spec.rb @@ -61,14 +61,13 @@ it "executes the external utility" do expect(described_class).to receive(:execute) { 0 } described_class.encode('infile', 'recipe', 'outfile') - # expect(Hydra::Derivatives::Processors::ShellBasedProcessor).to have_received(:execute) end end describe "#tmp_file" do it "returns a temp file with the correct extension" do - f = described_class.tmp_file('test') - expect(f).to match(/sufia.*test$/) + f = described_class.tmp_file('.test') + expect(f).to end_with('.test') end end