Skip to content

Commit

Permalink
feat: add gamma support to vips image processor
Browse files Browse the repository at this point in the history
The visual tests difference:
- plasma-gamma - MAE (Mean Average Error): 0.0105821
The vips image appears to have minimally higher contrast, best visible on purple pixels
  • Loading branch information
knarewski committed Dec 6, 2024
1 parent 3523a63 commit 66239ee
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Vips crop
- Vips rotate
- Vips straighten
- Vips gamma

### Removed
- [BREAKING] dropped support for a broken 'dominant' border colour
Expand Down
8 changes: 8 additions & 0 deletions lib/morandi/vips_image_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def process!
@scale = 1.0
end


apply_gamma!

Check notice on line 65 in lib/morandi/vips_image_processor.rb

View workflow job for this annotation

GitHub Actions / RuboCop Action

lib/morandi/vips_image_processor.rb#L64-L65

Extra blank line detected. [Layout/EmptyLines]
apply_rotate!
apply_crop!
apply_filters!
Expand All @@ -87,6 +89,12 @@ def write_to_jpeg(target_path, quality = nil)

private

def apply_gamma!
return unless @options['gamma'] && not_equal_to_one(@options['gamma'])

@img = @img.gamma(exponent: @options['gamma'])
end

def angle
@options['angle'].to_i % 360
end
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions spec/morandi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@
end
end

context 'when given a gamma option', vips_wip: processor_name == 'vips' do
context 'when given a gamma option' do
let(:options) { { 'gamma' => 2.0 } }

it 'should apply the gamma to the image' do
Expand All @@ -288,7 +288,7 @@
expect(File).to exist(file_out)
expect(processed_image_type).to eq('jpeg')

expect(file_out).to match_reference_image('plasma-gamma')
expect(file_out).to match_reference_image(reference_image_prefix, 'plasma-gamma')
end
end

Expand Down

0 comments on commit 66239ee

Please sign in to comment.