free-image 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/HISTORY +30 -19
- data/LICENSE +20 -20
- data/README.rdoc +120 -120
- data/Rakefile +51 -47
- data/cookbook.rdoc +248 -237
- data/free-image.gemspec +30 -29
- data/lib/free-image.rb +1 -2
- data/lib/free-image/bitmap.rb +2 -2
- data/lib/free-image/enums/filters.rb +11 -11
- data/lib/free-image/errors.rb +43 -43
- data/lib/free-image/modules/conversions.rb +253 -253
- data/lib/free-image/modules/helper.rb +41 -41
- data/lib/free-image/modules/information.rb +20 -2
- data/lib/free-image/modules/modify.rb +299 -299
- data/lib/free-image/modules/pixels.rb +134 -134
- data/lib/free-image/modules/transforms.rb +90 -90
- data/lib/free-image/sources/abstract_source.rb +178 -178
- data/lib/free-image/sources/file.rb +114 -114
- data/lib/free-image/sources/io.rb +153 -153
- data/lib/free-image/sources/memory.rb +188 -188
- data/lib/free-image/types/boolean.rb +13 -13
- data/lib/free-image/types/ffi.rb +13 -13
- data/lib/free-image/types/info_header.rb +36 -0
- data/lib/free-image/types/rgb16.rb +31 -0
- data/test/cookbook.rb +45 -46
- data/test/images/sample_composite.png +0 -0
- data/test/images/test16.bmp +0 -0
- data/test/images/test16bf555.bmp +0 -0
- data/test/images/test16bf565.bmp +0 -0
- data/test/test_bitmap.rb +61 -63
- data/test/test_conversions.rb +85 -86
- data/test/test_file.rb +68 -69
- data/test/test_free_image.rb +14 -15
- data/test/test_helper.rb +14 -0
- data/test/test_information.rb +145 -117
- data/test/test_io.rb +73 -74
- data/test/test_memory.rb +83 -84
- data/test/test_modify.rb +75 -58
- data/test/test_palette.rb +44 -45
- data/test/test_pixels.rb +61 -62
- data/test/test_rgb_quad.rb +24 -25
- data/test/test_scanline.rb +64 -65
- data/test/test_suite.rb +12 -17
- data/test/test_transforms.rb +28 -29
- metadata +58 -31
data/test/test_free_image.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.join(File.dirname(__FILE__),'test_helper')
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class FreeImageTest < Test::Unit::TestCase
|
6
|
+
def test_copyright
|
7
|
+
assert_equal("This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See http://freeimage.sourceforge.net for details",
|
8
|
+
FreeImage.copyright)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_version
|
12
|
+
assert_equal(['3','17'], FreeImage.version.split('.')[0..1])
|
13
|
+
end
|
14
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -32,4 +32,18 @@ end
|
|
32
32
|
def lena_image
|
33
33
|
path = File.join(ROOT_DIR, 'test', 'images', 'lena.png')
|
34
34
|
FreeImage::Bitmap.open(path)
|
35
|
+
end
|
36
|
+
|
37
|
+
def bit16_bmp(bitfield=nil)
|
38
|
+
suffix = begin
|
39
|
+
if bitfield == 555
|
40
|
+
'bf555'
|
41
|
+
elsif bitfield == 565
|
42
|
+
'bf565'
|
43
|
+
else
|
44
|
+
''
|
45
|
+
end
|
46
|
+
end
|
47
|
+
path = File.join(ROOT_DIR, 'test', 'images', "test16#{suffix}.bmp")
|
48
|
+
FreeImage::Bitmap.open(path)
|
35
49
|
end
|
data/test/test_information.rb
CHANGED
@@ -1,118 +1,146 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require '
|
4
|
-
require 'test/unit'
|
5
|
-
|
6
|
-
class InformationTest < Test::Unit::TestCase
|
7
|
-
def
|
8
|
-
background_color =
|
9
|
-
assert_kind_of(FreeImage::RGBQuad, background_color)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
assert_equal(
|
31
|
-
end
|
32
|
-
|
33
|
-
def
|
34
|
-
assert_equal(
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
assert_equal(
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
image =
|
57
|
-
image.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
def
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
def
|
91
|
-
assert_equal(
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__),'test_helper')
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class InformationTest < Test::Unit::TestCase
|
7
|
+
def test_background_color_16bit
|
8
|
+
background_color = bit16_bmp.background_color
|
9
|
+
assert_kind_of(FreeImage::RGBQuad, background_color)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_background_color
|
13
|
+
background_color = sample_image.background_color
|
14
|
+
assert_kind_of(FreeImage::RGBQuad, background_color)
|
15
|
+
assert_equal(112, background_color[:red])
|
16
|
+
assert_equal(176, background_color[:green])
|
17
|
+
assert_equal(240, background_color[:blue])
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_background_color_set
|
21
|
+
image = sample_image
|
22
|
+
rgb = FreeImage::RGBQuad.create(7, 8, 9)
|
23
|
+
|
24
|
+
image.background_color = rgb
|
25
|
+
background_color = image.background_color
|
26
|
+
assert_equal(rgb, background_color)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_bits_per_pixel
|
30
|
+
assert_equal(8, sample_image.bits_per_pixel)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_blue_mask
|
34
|
+
assert_equal(FreeImage::RGBQuad::BLUE_MASK, lena_image.blue_mask)
|
35
|
+
assert_equal(FreeImage::RGB16::BLUE_MASK, bit16_bmp.blue_mask)
|
36
|
+
assert_equal(FreeImage::RGB16::BLUE_MASK, bit16_bmp(555).blue_mask)
|
37
|
+
assert_equal(FreeImage::RGB16::BLUE_MASK, bit16_bmp(565).blue_mask)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_color_type
|
41
|
+
assert_equal(:palette, sample_image.color_type)
|
42
|
+
assert_equal(:rgb, bit16_bmp(555).color_type)
|
43
|
+
assert_equal(:rgb, bit16_bmp(565).color_type)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_dib_size
|
47
|
+
assert_equal(52664, sample_image.dib_size)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_dots_per_meter_x
|
51
|
+
assert_equal(2835, sample_image.dots_per_meter_x)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_dots_per_meter_x_set
|
55
|
+
image = sample_image
|
56
|
+
image.dots_per_meter_x = 3000
|
57
|
+
assert_equal(3000, image.dots_per_meter_x)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_dots_per_meter_y
|
61
|
+
assert_equal(2835, sample_image.dots_per_meter_y)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_dots_per_meter_y_set
|
65
|
+
image = sample_image
|
66
|
+
image.dots_per_meter_y = 4000
|
67
|
+
assert_equal(4000, image.dots_per_meter_y)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_green_mask
|
71
|
+
assert_equal(FreeImage::RGB16::GREEN_MASK, bit16_bmp.green_mask)
|
72
|
+
assert_equal(FreeImage::RGB16::GREEN_MASK, bit16_bmp(555).green_mask)
|
73
|
+
assert_equal(FreeImage::RGB16BF565::GREEN_MASK, bit16_bmp(565).green_mask)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_has_background_color
|
77
|
+
assert(sample_image.has_background_color)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_has_pixels
|
81
|
+
assert(sample_image.has_pixels)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_has_rgb_masks
|
85
|
+
assert_equal(false, sample_image.has_rgb_masks)
|
86
|
+
assert_equal(false, lena_image.has_rgb_masks)
|
87
|
+
assert(bit16_bmp.has_rgb_masks)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_height
|
91
|
+
assert_equal(215, sample_image.height)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_image_type
|
95
|
+
assert_equal(:bitmap, sample_image.image_type)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_info_header
|
99
|
+
image = sample_image
|
100
|
+
info = image.info_header
|
101
|
+
assert_equal(215, info[:biHeight])
|
102
|
+
assert_equal(240, info[:biWidth])
|
103
|
+
assert_equal(2835, info[:biXPelsPerMeter])
|
104
|
+
assert_equal(2835, info[:biYPelsPerMeter])
|
105
|
+
assert_equal(0, info[:biCompression])
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_line
|
109
|
+
assert_equal(240, sample_image.line)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_pitch
|
113
|
+
assert_equal(240, sample_image.pitch)
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_red_mask
|
117
|
+
assert_equal(FreeImage::RGBQuad::RED_MASK, lena_image.red_mask)
|
118
|
+
assert_equal(FreeImage::RGB16::RED_MASK, bit16_bmp.red_mask)
|
119
|
+
assert_equal(FreeImage::RGB16::RED_MASK, bit16_bmp(555).red_mask)
|
120
|
+
assert_equal(FreeImage::RGB16BF565::RED_MASK, bit16_bmp(565).red_mask)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_transparent
|
124
|
+
assert(sample_image.transparent)
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_transparent_set
|
128
|
+
image = sample_image
|
129
|
+
image.transparent = false
|
130
|
+
assert(!image.transparent)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_transparent_index
|
134
|
+
assert_equal(6, sample_image.transparent_index)
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_transparent_index_set
|
138
|
+
image = sample_image
|
139
|
+
image.transparent_index = 4
|
140
|
+
assert_equal(4, image.transparent_index)
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_width
|
144
|
+
assert_equal(240, sample_image.width)
|
145
|
+
end
|
118
146
|
end
|
data/test/test_io.rb
CHANGED
@@ -1,75 +1,74 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
bitmap
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
result
|
47
|
-
assert(
|
48
|
-
|
49
|
-
|
50
|
-
tmp_file.
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.join(File.dirname(__FILE__),'test_helper')
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class IoTest < Test::Unit::TestCase
|
6
|
+
def io(image = 'sample.png')
|
7
|
+
path = image_path(image)
|
8
|
+
file = File.open(path)
|
9
|
+
FreeImage::IO.new(file)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_format
|
13
|
+
assert_equal(:png, io.format)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_format_unknown
|
17
|
+
assert_equal(:unknown, io('not_an_image.txt').format)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_load
|
21
|
+
bitmap = io.open
|
22
|
+
assert_kind_of(FreeImage::Bitmap, bitmap)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_load_unknown
|
26
|
+
error = assert_raise(FreeImage::Error) do
|
27
|
+
io('not_an_image.txt').open
|
28
|
+
end
|
29
|
+
assert_equal("Cannot load :unknown image format",
|
30
|
+
error.message)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_load_wrong_format
|
34
|
+
error = assert_raise(FreeImage::Error) do
|
35
|
+
io.open(:jpeg)
|
36
|
+
end
|
37
|
+
assert_equal("Not a JPEG file: starts with 0x89 0x50", error.to_s)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_save
|
41
|
+
tmp_file = Tempfile.new('test_free_image')
|
42
|
+
dst = FreeImage::IO.new(tmp_file)
|
43
|
+
|
44
|
+
bitmap = io.open
|
45
|
+
result = bitmap.save(dst, :png)
|
46
|
+
assert(result)
|
47
|
+
assert(File.exists?(tmp_file))
|
48
|
+
ensure
|
49
|
+
tmp_file.close
|
50
|
+
tmp_file.unlink
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_corrupt
|
54
|
+
path = image_path('corrupt.jpg')
|
55
|
+
file = File.open(path)
|
56
|
+
io = FreeImage::IO.new(file)
|
57
|
+
|
58
|
+
error = assert_raise(FreeImage::Error) do
|
59
|
+
io.open
|
60
|
+
end
|
61
|
+
assert_equal("Cannot load :unknown image format", error.message)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_corrupt_wrong_format
|
65
|
+
path = image_path('corrupt.jpg')
|
66
|
+
file = File.open(path)
|
67
|
+
io = FreeImage::IO.new(file)
|
68
|
+
|
69
|
+
error = assert_raise(FreeImage::Error) do
|
70
|
+
io.open(:png)
|
71
|
+
end
|
72
|
+
assert_equal("Could not load the image", error.message)
|
73
|
+
end
|
75
74
|
end
|