diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c6cc28..78288b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/morandi/vips_image_processor.rb b/lib/morandi/vips_image_processor.rb index 349b758..1ed06e9 100644 --- a/lib/morandi/vips_image_processor.rb +++ b/lib/morandi/vips_image_processor.rb @@ -84,6 +84,7 @@ def process! end strip_alpha! + ensure_srgb! end def write_to_png(_write_to, _orientation = :any) @@ -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 @@ -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 diff --git a/spec/morandi_spec.rb b/spec/morandi_spec.rb index 656b293..d8fa4f1 100644 --- a/spec/morandi_spec.rb +++ b/spec/morandi_spec.rb @@ -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