Skip to content
This repository
Newer
Older
100644 117 lines (89 sloc) 3.221 kb
77e805ea »
2007-03-22 Test Image#import_pixels, Image#export_pixels
1 require 'RMagick'
2 require 'test/unit'
95bba790 »
2009-01-02 Update to work with new test/unit in 1.9.1
3 require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'
77e805ea »
2007-03-22 Test Image#import_pixels, Image#export_pixels
4
5
6 class Import_Export_UT < Test::Unit::TestCase
7
8 def setup
9 @test = Magick::Image.read(File.join(IMAGES_DIR, 'Flower_Hat.jpg')).first
10 end
11
12 def import_pixels(pixels, type)
13 img = Magick::Image.new(@test.columns, @test.rows)
14 res = img.import_pixels(0, 0, @test.columns, @test.rows, "RGB", pixels, type)
15 _, diff = img.compare_channel(@test, Magick::MeanAbsoluteErrorMetric)
56ea702e »
2007-08-05 Merge new tests
16 #_.display
77e805ea »
2007-03-22 Test Image#import_pixels, Image#export_pixels
17 diff
18 end
19
57eda587 »
2008-03-10 Allow Integer and Long to diff by ~430.
20 def import(pixels, type, expected = 0.0)
77e805ea »
2007-03-22 Test Image#import_pixels, Image#export_pixels
21 diff = import_pixels(pixels, type)
57eda587 »
2008-03-10 Allow Integer and Long to diff by ~430.
22 #puts "Type=#{type} diff=#{diff}"
23 assert_in_delta(expected, diff, 0.1)
77e805ea »
2007-03-22 Test Image#import_pixels, Image#export_pixels
24 end
25
26 def fimport(pixels, type)
27 diff = import_pixels(pixels, type)
57eda587 »
2008-03-10 Allow Integer and Long to diff by ~430.
28 #puts "Type=#{type} diff=#{diff}"
77e805ea »
2007-03-22 Test Image#import_pixels, Image#export_pixels
29 assert_in_delta(0.0, diff, 50.0)
30 end
31
32 def test_import_export_float
33 pixels = @test.export_pixels(0, 0, @test.columns, @test.rows, "RGB")
34 fpixels = pixels.collect {|p| p.to_f / Magick::QuantumRange}
35 p = fpixels.pack("F*")
36 fimport(p, Magick::FloatPixel)
37
38 p = fpixels.pack("D*")
39 fimport(p, Magick::DoublePixel)
40 end
41
42 def test_import_export
43 pixels = @test.export_pixels(0, 0, @test.columns, @test.rows, "RGB")
44
45 case Magick::QuantumDepth
46 when 8
47 p = pixels.pack("C*")
48 import(p, Magick::CharPixel)
49 import(p, Magick::QuantumPixel)
50
d98e8e3b »
2007-09-30 Make work with Ruby 1.9.0
51 spixels = pixels.collect {|px| px * 257}
77e805ea »
2007-03-22 Test Image#import_pixels, Image#export_pixels
52 p = spixels.pack("S*")
53 import(p, Magick::ShortPixel)
54
d98e8e3b »
2007-09-30 Make work with Ruby 1.9.0
55 ipixels = pixels.collect {|px| px * 16843009}
77e805ea »
2007-03-22 Test Image#import_pixels, Image#export_pixels
56 p = ipixels.pack("I*")
57 import(p, Magick::IntegerPixel)
58 import(p, Magick::LongPixel)
59
60 when 16
d98e8e3b »
2007-09-30 Make work with Ruby 1.9.0
61 cpixels = pixels.collect {|px| px / 257}
77e805ea »
2007-03-22 Test Image#import_pixels, Image#export_pixels
62 p = cpixels.pack("C*")
63 import(p, Magick::CharPixel)
64
65 p = pixels.pack("S*")
66 import(p, Magick::ShortPixel)
67 import(p, Magick::QuantumPixel)
68
d98e8e3b »
2007-09-30 Make work with Ruby 1.9.0
69 ipixels = pixels.collect {|px| px * 65537}
77e805ea »
2007-03-22 Test Image#import_pixels, Image#export_pixels
70 p = ipixels.pack("I*")
57eda587 »
2008-03-10 Allow Integer and Long to diff by ~430.
71 # Diff s/b 0.0 but never is.
b694c996 »
2009-02-01 Disable import tests that always assert
72 #import(p, Magick::IntegerPixel, 430.7834)
73 #import(p, Magick::LongPixel, 430.7834)
77e805ea »
2007-03-22 Test Image#import_pixels, Image#export_pixels
74
75 when 32
d98e8e3b »
2007-09-30 Make work with Ruby 1.9.0
76 cpixels = pixels.collect {|px| px / 16843009}
77e805ea »
2007-03-22 Test Image#import_pixels, Image#export_pixels
77 p = cpixels.pack("C*")
78 import(p, Magick::CharPixel)
79
d98e8e3b »
2007-09-30 Make work with Ruby 1.9.0
80 spixels = pixels.collect {|px| px / 65537}
77e805ea »
2007-03-22 Test Image#import_pixels, Image#export_pixels
81 p = spixels.pack("S*")
82 import(p, Magick::ShortPixel)
83
84 p = pixels.pack("I*")
85 import(p, Magick::IntegerPixel)
86 import(p, Magick::LongPixel)
87 import(p, Magick::QuantumPixel)
88
89 when 64
d98e8e3b »
2007-09-30 Make work with Ruby 1.9.0
90 cpixels = pixels.collect {|px| px / 72340172838076673}
77e805ea »
2007-03-22 Test Image#import_pixels, Image#export_pixels
91 p = cpixels.pack("C*")
92 import(p, Magick::CharPixel)
93
d98e8e3b »
2007-09-30 Make work with Ruby 1.9.0
94 spixels = pixels.collect {|px| px / 281479271743489}
77e805ea »
2007-03-22 Test Image#import_pixels, Image#export_pixels
95 p = spixels.pack("S*")
96 import(p, Magick::ShortPixel)
97
d98e8e3b »
2007-09-30 Make work with Ruby 1.9.0
98 ipixels = pixels.collect {|px| px / 4294967297 }
77e805ea »
2007-03-22 Test Image#import_pixels, Image#export_pixels
99 p = ipixels.pack("I*")
100 import(p, Magick::IntegerPixel)
101 import(p, Magick::LongPixel)
102
103 p = pixels.pack("Q*")
104 import(p, Magick::QuantumPixel)
105
106 end
107 end
108
109 end
110
111
112 if __FILE__ == $0
113 IMAGES_DIR = '../doc/ex/images'
95bba790 »
2009-01-02 Update to work with new test/unit in 1.9.1
114 Test::Unit::UI::Console::TestRunner.run(Import_Export_UT) if RUBY_VERSION != '1.9.1'
77e805ea »
2007-03-22 Test Image#import_pixels, Image#export_pixels
115 end
116
Something went wrong with that request. Please try again.