Skip to content

Commit 842e1a6

Browse files
committed
feat: ensure that output image is in srgb colourspace
That is a default behaviour for GdkPixbuf, so mirroring it in vips for better compatibility
1 parent 0cb5c4e commit 842e1a6

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1414
- Vips gamma
1515
- Vips stripping alpha
1616
- Explicit error when trying to use VipsProcessor with unsupported options
17+
- Vips cast to srgb when image uses a different colourspace
1718

1819
### Removed
1920
- [BREAKING] dropped support for a broken 'dominant' border colour

lib/morandi/vips_image_processor.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def process!
8484
end
8585

8686
strip_alpha!
87+
ensure_srgb!
8788
end
8889

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

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

166167
# Convert to greyscale using weights
167168
rgb_factors = RGB_LUMINANCE_EXTRACTION_FACTORS
@@ -185,5 +186,9 @@ def apply_filters!
185186
def not_equal_to_one(float)
186187
(float - 1.0).abs >= Float::EPSILON
187188
end
189+
190+
def ensure_srgb!
191+
@img = @img.colourspace(:srgb) unless @img.interpretation == :srgb
192+
end
188193
end
189194
end

spec/morandi_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@
470470
generate_test_image_greyscale(file_in, width: original_image_width, height: original_image_height)
471471
end
472472

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

0 commit comments

Comments
 (0)