Skip to content

Commit

Permalink
feat: ensure that output image is in srgb colourspace
Browse files Browse the repository at this point in the history
That is a default behaviour for GdkPixbuf, so mirroring it in vips for better compatibility
  • Loading branch information
knarewski committed Dec 13, 2024
1 parent 0c07b4f commit 093a0b0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Vips gamma
- Vips stripping alpha
- Explicit error when trying to use VipsProcessor with unsupported options
- Vips cast to srgb when image uses a different colourspace

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

strip_alpha!
ensure_srgb!
end

def write_to_png(_write_to, _orientation = :any)
Expand Down Expand Up @@ -160,8 +161,8 @@ def apply_filters!
filter_name = @options['fx']
return unless SUPPORTED_FILTERS.include?(filter_name)

# The filter-related constants assume RGB colourspace, so it requires conversion
@img = @img.colourspace(:srgb) unless @img.interpretation == :srgb
# The filter-related constants assume RGB colourspace, so it requires early conversion
ensure_srgb!

# Convert to greyscale using weights
rgb_factors = RGB_LUMINANCE_EXTRACTION_FACTORS
Expand All @@ -185,5 +186,9 @@ def apply_filters!
def not_equal_to_one(float)
(float - 1.0).abs >= Float::EPSILON
end

def ensure_srgb!
@img = @img.colourspace(:srgb) unless @img.interpretation == :srgb
end
end
end
2 changes: 1 addition & 1 deletion spec/morandi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@
generate_test_image_greyscale(file_in, width: original_image_width, height: original_image_height)
end

it 'changes greyscale image to srgb', vips_wip: processor_name == 'vips' do
it 'changes greyscale image to srgb' do
expect(file_in).to match_colourspace('gray') # Testing a setup to protect from a hidden regression
process_image

Expand Down

0 comments on commit 093a0b0

Please sign in to comment.