Skip to content

Commit

Permalink
Merge pull request #142 from projecthydra/long_dim-jp2_format
Browse files Browse the repository at this point in the history
Fix failing test for creation of JPEG2000 derivatives.
  • Loading branch information
jeremyf committed Mar 31, 2017
2 parents d6f371a + c196e6e commit 44803bc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@ pkg/
.ruby-gemset
fcrepo4-data/
fcrepo4-test-data/
coverage/
22 changes: 10 additions & 12 deletions lib/hydra/derivatives/processors/jpeg2k_image.rb
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions spec/processors/jpeg2k_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
9 changes: 5 additions & 4 deletions spec/units/transcoding_spec.rb
Expand Up @@ -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: [
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 44803bc

Please sign in to comment.