Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: always save vips output in srgb colourspace #45

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 4 additions & 4 deletions spec/morandi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,19 +403,19 @@

context 'with increasing quality settings' do
let!(:max_quality_file) do
Morandi.process(file_in, { 'quality' => 100 }, 'sample/out-100.jpg')
Morandi.process(file_in, { 'quality' => 100 }, 'sample/out-100.jpg', 'processor' => processor_name)
end

let(:max_quality_file_size) { File.size('sample/out-100.jpg') }

let!(:default_of_97_quality_file) do
Morandi.process(file_in, {}, 'sample/out-97.jpg')
Morandi.process(file_in, {}, 'sample/out-97.jpg', 'processor' => processor_name)
end

let(:default_of_97_quality_file_size) { File.size('sample/out-97.jpg') }

let!(:quality_of_40_file) do
Morandi.process(file_in, { 'quality' => 40 }, 'sample/out-40.jpg')
Morandi.process(file_in, { 'quality' => 40 }, 'sample/out-40.jpg', 'processor' => processor_name)
end

let(:quality_of_40_file_size) { File.size('sample/out-40.jpg') }
Expand Down 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
Loading