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/ 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 diff --git a/spec/processors/jpeg2k_spec.rb b/spec/processors/jpeg2k_spec.rb index b33d8d9..acd5951 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,24 @@ 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') + 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 end_with('.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 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