File: pixel_color_spec.rb

package info (click to toggle)
ruby-rmagick 6.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,232 kB
  • sloc: cpp: 19,563; ruby: 17,147; sh: 88; javascript: 36; makefile: 13
file content (51 lines) | stat: -rw-r--r-- 1,748 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
RSpec.describe Magick::Image, '#pixel_color' do
  it 'works' do
    image = described_class.new(20, 20)

    result = image.pixel_color(0, 0)
    expect(result).to be_instance_of(Magick::Pixel)

    result = image.pixel_color(0, 0)
    expect(result.to_color).to eq('#FFFFFFFFFFFF')
    result = image.pixel_color(0, 0, 'red')
    expect(result.to_color).to eq('#FFFFFFFFFFFF')
    result = image.pixel_color(0, 0)
    expect(result.to_color).to eq('#FFFF00000000')

    blue = Magick::Pixel.new(0, 0, Magick::QuantumRange)
    expect { image.pixel_color(0, 0, blue) }.not_to raise_error
    # If args are out-of-bounds return the background color
    image = described_class.new(10, 10) { |options| options.background_color = 'blue' }
    expect(image.pixel_color(50, 50).to_color).to eq('#00000000FFFF')

    image.class_type = Magick::PseudoClass
    result = image.pixel_color(0, 0, 'red')
    expect(result.to_color).to eq('#00000000FFFF')
  end

  it 'get/set CYMK color', unsupported_before('6.8.0') do
    image = described_class.new(20, 30) { |options| options.quality = 100 }
    image.colorspace = Magick::CMYKColorspace

    pixel = Magick::Pixel.new
    pixel.cyan    = 49  * 257
    pixel.magenta = 181 * 257
    pixel.yellow  = 1   * 257
    pixel.black   = 183 * 257

    image.pixel_color(15, 20, pixel)

    temp_file_path = File.join(Dir.tmpdir, 'rmagick_pixel_color.jpg')
    image.write(temp_file_path)

    image2 = described_class.read(temp_file_path).first
    pixel = image2.pixel_color(15, 20)

    expect(pixel.cyan).to    equal(49  * 257)
    expect(pixel.magenta).to equal(181 * 257)
    expect(pixel.yellow).to  equal(1   * 257)
    expect(pixel.black).to   equal(183 * 257)

    File.delete(temp_file_path)
  end
end