File: store_pixels_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 (46 lines) | stat: -rw-r--r-- 1,703 bytes parent folder | download | duplicates (2)
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
require 'tmpdir'

RSpec.describe Magick::Image, '#store_pixels' do
  it 'works' do
    image = described_class.new(20, 20)
    pixels = image.get_pixels(0, 0, image.columns, 1)

    result = image.store_pixels(0, 0, image.columns, 1, pixels)
    expect(result).to be(image)

    pixels[0] = 'x'
    expect { image.store_pixels(0, 0, image.columns, 1, pixels) }.to raise_error(TypeError)
    expect { image.store_pixels(-1, 0, image.columns, 1, pixels) }.to raise_error(RangeError)
    expect { image.store_pixels(0, -1, image.columns, 1, pixels) }.to raise_error(RangeError)
    expect { image.store_pixels(0, 0, 1 + image.columns, 1, pixels) }.to raise_error(RangeError)
    expect { image.store_pixels(-1, 0, 1, 1 + image.rows, pixels) }.to raise_error(RangeError)
    expect { image.store_pixels(0, 0, image.columns, 1, ['x']) }.to raise_error(IndexError)
    expect { image.store_pixels(0, 0, image.columns, 1, 1234) }.to raise_error(IndexError)
  end

  it 'supports CMYK color' do
    image = described_class.new(1, 1)
    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.store_pixels(0, 0, 1, 1, [pixel])

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

    image2 = described_class.read(temp_file_path).first
    pixel = image2.get_pixels(0, 0, 1, 1).first

    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