free-image 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +5 -0
- data/free-image.gemspec +1 -1
- data/lib/free-image/bitmap.rb +6 -0
- data/lib/free-image/sources/abstract_source.rb +7 -0
- data/test/images/corrupt.jpg +0 -0
- data/test/test_bitmap.rb +8 -0
- data/test/test_file.rb +20 -1
- data/test/test_io.rb +22 -0
- data/test/test_memory.rb +20 -0
- metadata +8 -7
data/HISTORY
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
= Release History
|
2
2
|
|
3
|
+
== 0.6.2 / 2011-09-06 Charlie Savage
|
4
|
+
|
5
|
+
* Add null pointer checks when loading images
|
6
|
+
* Add null pointer check when creating a new image
|
7
|
+
|
3
8
|
== 0.6.1 / 2011-09-06 Charlie Savage
|
4
9
|
|
5
10
|
* Use release version on windows of FreeImage, not debug version.
|
data/free-image.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'free-image'
|
5
|
-
spec.version = '0.6.
|
5
|
+
spec.version = '0.6.2'
|
6
6
|
spec.summary = 'Ruby Bindings for the Free Image Library'
|
7
7
|
spec.description = <<-EOS
|
8
8
|
FreeImage is an Open Source library project for developers who would like to support
|
data/lib/free-image/bitmap.rb
CHANGED
@@ -98,6 +98,12 @@ module FreeImage
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def self.new(ptr, source = nil)
|
101
|
+
# Ptr must be set
|
102
|
+
if ptr.null?
|
103
|
+
error = Error.new(:unknown, "Cannot create a bitmap from a null pointer")
|
104
|
+
raise(error)
|
105
|
+
end
|
106
|
+
|
101
107
|
bitmap = super(ptr, source)
|
102
108
|
|
103
109
|
if block_given?
|
@@ -166,6 +166,13 @@ module FreeImage
|
|
166
166
|
end
|
167
167
|
|
168
168
|
ptr = load(format, flags)
|
169
|
+
|
170
|
+
# Make sure we didn't get a null pointer. This can
|
171
|
+
# happen - see test_file for example#test_corrupt_wrong_format
|
172
|
+
if ptr.null?
|
173
|
+
error = Error.new(:unknown, "Could not load the image")
|
174
|
+
raise(error)
|
175
|
+
end
|
169
176
|
Bitmap.new(ptr, self)
|
170
177
|
end
|
171
178
|
end
|
Binary file
|
data/test/test_bitmap.rb
CHANGED
@@ -34,6 +34,14 @@ class BitmapTest < Test::Unit::TestCase
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
def test_new_from_nil
|
38
|
+
ptr = FFI::Pointer::NULL
|
39
|
+
error = assert_raise(FreeImage::Error) do
|
40
|
+
FreeImage::Bitmap.new(ptr)
|
41
|
+
end
|
42
|
+
assert_equal("Cannot create a bitmap from a null pointer", error.message)
|
43
|
+
end
|
44
|
+
|
37
45
|
def test_clone
|
38
46
|
image = lena_image
|
39
47
|
clone = image.clone
|
data/test/test_file.rb
CHANGED
@@ -8,7 +8,7 @@ class FIFileTest < Test::Unit::TestCase
|
|
8
8
|
path = image_path(image)
|
9
9
|
FreeImage::File.new(path)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def test_format
|
13
13
|
assert_equal(:png, file.format)
|
14
14
|
end
|
@@ -48,4 +48,23 @@ class FIFileTest < Test::Unit::TestCase
|
|
48
48
|
tmp_file.close
|
49
49
|
tmp_file.unlink
|
50
50
|
end
|
51
|
+
|
52
|
+
def test_corrupt
|
53
|
+
path = image_path('corrupt.jpg')
|
54
|
+
file = FreeImage::File.new(path)
|
55
|
+
error = assert_raise(FreeImage::Error) do
|
56
|
+
file.open
|
57
|
+
end
|
58
|
+
assert_equal("Not a JPEG file: starts with 0xaa 0xc0", error.message)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_corrupt_wrong_format
|
62
|
+
path = image_path('corrupt.jpg')
|
63
|
+
file = FreeImage::File.new(path)
|
64
|
+
error = assert_raise(FreeImage::Error) do
|
65
|
+
# Be sneaky - say png!
|
66
|
+
file.open(:png)
|
67
|
+
end
|
68
|
+
assert_equal("Could not load the image", error.message)
|
69
|
+
end
|
51
70
|
end
|
data/test/test_io.rb
CHANGED
@@ -50,4 +50,26 @@ class IoTest < Test::Unit::TestCase
|
|
50
50
|
tmp_file.close
|
51
51
|
tmp_file.unlink
|
52
52
|
end
|
53
|
+
|
54
|
+
def test_corrupt
|
55
|
+
path = image_path('corrupt.jpg')
|
56
|
+
file = File.open(path)
|
57
|
+
io = FreeImage::IO.new(file)
|
58
|
+
|
59
|
+
error = assert_raise(FreeImage::Error) do
|
60
|
+
io.open
|
61
|
+
end
|
62
|
+
assert_equal("Cannot load :unknown image format", error.message)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_corrupt_wrong_format
|
66
|
+
path = image_path('corrupt.jpg')
|
67
|
+
file = File.open(path)
|
68
|
+
io = FreeImage::IO.new(file)
|
69
|
+
|
70
|
+
error = assert_raise(FreeImage::Error) do
|
71
|
+
io.open(:png)
|
72
|
+
end
|
73
|
+
assert_equal("Could not load the image", error.message)
|
74
|
+
end
|
53
75
|
end
|
data/test/test_memory.rb
CHANGED
@@ -62,4 +62,24 @@ class MemoryTest < Test::Unit::TestCase
|
|
62
62
|
assert_equal(dst.memory.bytes.encoding, Encoding::BINARY)
|
63
63
|
end
|
64
64
|
end
|
65
|
+
|
66
|
+
def test_corrupt
|
67
|
+
data = image_data('corrupt.jpg')
|
68
|
+
memory = FreeImage::Memory.new(data)
|
69
|
+
|
70
|
+
error = assert_raise(FreeImage::Error) do
|
71
|
+
memory.open
|
72
|
+
end
|
73
|
+
assert_equal("Cannot load :unknown image format", error.message)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_corrupt_wrong_format
|
77
|
+
data = image_data('corrupt.jpg')
|
78
|
+
memory = FreeImage::Memory.new(data)
|
79
|
+
|
80
|
+
error = assert_raise(FreeImage::Error) do
|
81
|
+
memory.open(:png)
|
82
|
+
end
|
83
|
+
assert_equal("Could not load the image", error.message)
|
84
|
+
end
|
65
85
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: free-image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-09-06 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
16
|
-
requirement: &
|
16
|
+
requirement: &23576770 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.10
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *23576770
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hanna-nouveau
|
27
|
-
requirement: &
|
27
|
+
requirement: &23576430 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *23576430
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: open4
|
38
|
-
requirement: &
|
38
|
+
requirement: &23575760 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *23575760
|
47
47
|
description: ! " FreeImage is an Open Source library project for developers who
|
48
48
|
would like to support\n popular graphics image formats like PNG, BMP, JPEG, TIFF
|
49
49
|
and others as needed by\n today's multimedia applications. FreeImage is easy
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- lib/free-image/types/rgb_triple.rb
|
92
92
|
- lib/free-image.rb
|
93
93
|
- test/cookbook.rb
|
94
|
+
- test/images/corrupt.jpg
|
94
95
|
- test/images/gradient.png
|
95
96
|
- test/images/lena.png
|
96
97
|
- test/images/lena.tiff
|