Skip to content

Commit

Permalink
fix: use imagemagick's "convert" to generate a solid image for testing
Browse files Browse the repository at this point in the history
Due to using file_arg instead of file_in, the previous solution was unnecessarily generating
plasma image and displayed a wrong input image in visual report, now it is fixed

It also makes the code simpler and more consistent with generation of other images
  • Loading branch information
knarewski committed Nov 14, 2024
1 parent b75f98a commit 638faed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
21 changes: 4 additions & 17 deletions spec/colour_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,12 @@ def generate_test_image_greyscale(at_file_path, width: 600, height: 300)
def generate_test_image(at_file_path, fill:, width: 600, height: 300)
fill = Array(fill).flatten

system(
'convert',
'-size',
"#{width}x#{height}",
'-seed',
'5432',
*fill,
at_file_path
)
generate_image_options = ['convert', '-size', "#{width}x#{height}", '-seed', '5432', *fill, at_file_path]
system(*generate_image_options) || raise("Failed to generate image.\nCommand: #{generate_image_options.join(' ')}")
end

def solid_colour_image(width, height, colour = 0x000000ff)
pb = GdkPixbuf::Pixbuf.new(colorspace: GdkPixbuf::Colorspace::RGB,
has_alpha: false,
bits_per_sample: 8,
width: width,
height: height)
pb.fill!(colour)
pb
def generate_test_image_solid(at_file_path, width: 600, height: 300, colour: '#000000')
generate_test_image(at_file_path, width: width, height: height, fill: "canvas:#{colour}")
end

def crude_average_colour(pixbuf)
Expand Down
11 changes: 7 additions & 4 deletions spec/morandi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,10 @@
end

context 'with a gray image and invalid spots' do
let(:file_arg) { solid_colour_image(800, 800, 0x666666ff) }
let(:file_in) { 'sample/sample.jpg' }
let(:original_image_width) { 800 }
let(:original_image_height) { 800 }
let(:generate_image) { generate_test_image_solid(file_in, width: 800, height: 800, colour: '#666666') }
let(:options) { { 'redeye' => [[540, 650], [-100, 100]] } }

it 'should not break or corrupt the image' do
Expand All @@ -587,9 +590,9 @@
expect(File).to exist(file_out)
expect(processed_image_type).to eq('jpeg')

expect(crude_average_colour(file_arg.subpixbuf(505, 605, 100, 100))).to be_greyish
expect(crude_average_colour(GdkPixbuf::Pixbuf.new(file: file_out).subpixbuf(505, 605, 100,
100))).to be_greyish
expect(crude_average_colour(GdkPixbuf::Pixbuf.new(file: file_in).subpixbuf(505, 605, 100, 100))).to be_greyish
expect(crude_average_colour(GdkPixbuf::Pixbuf.new(file: file_out).subpixbuf(505, 605, 100, 100)))
.to be_greyish
end
end
end
Expand Down

0 comments on commit 638faed

Please sign in to comment.