Skip to content

Commit

Permalink
Ensure a nonnegative calculated Clevels value (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
aploshay authored Feb 8, 2023
1 parent afc879e commit d676adf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/hydra/derivatives/processors/jpeg2k_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def calculate_recipe(args, quality, long_dim)
end

def level_count_for_size(long_dim)
return 0 if long_dim < 96
levels = 0
level_size = long_dim
while level_size >= 96
Expand Down
7 changes: 6 additions & 1 deletion spec/processors/jpeg2k_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
let(:image) { MiniMagick::Image.open(filename) }

describe "#calculate_recipe" do
it "calculates the number of levels from a size" do
it "calculates the number of levels from a size above the minimum threshold" do
dim = 7200
expect(described_class.level_count_for_size(dim)).to eq(6)
end

it "calculates the number of levels as 0 from a size below the minimum threshold" do
dim = 50
expect(described_class.level_count_for_size(dim)).to eq(0)
end

it "calculates the compression rates for each quality layer" do
compression_num = 10
layers = 8
Expand Down

0 comments on commit d676adf

Please sign in to comment.