free-image 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- 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_memory.rb
CHANGED
@@ -1,85 +1,84 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
data
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
bitmap
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.join(File.dirname(__FILE__),'test_helper')
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class MemoryTest < Test::Unit::TestCase
|
6
|
+
def memory(image = 'sample.png')
|
7
|
+
data = image_data(image)
|
8
|
+
FreeImage::Memory.new(data)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_wrap
|
12
|
+
assert_not_nil(memory)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_format
|
16
|
+
assert_equal(:png, memory.format)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_format_unknown
|
20
|
+
assert_equal(:unknown, memory('not_an_image.txt').format)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_load
|
24
|
+
bitmap = memory.open
|
25
|
+
assert_kind_of(FreeImage::Bitmap, bitmap)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_load_unknown
|
29
|
+
error = assert_raise(FreeImage::Error) do
|
30
|
+
memory('not_an_image.txt').open
|
31
|
+
end
|
32
|
+
assert_equal("Cannot load :unknown image format",
|
33
|
+
error.message)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_load_wrong_format
|
37
|
+
error = assert_raise(FreeImage::Error) do
|
38
|
+
memory.open(:jpeg, 0)
|
39
|
+
end
|
40
|
+
assert_equal("Not a JPEG file: starts with 0x89 0x50", error.to_s)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_bytes
|
44
|
+
bitmap1 = FreeImage::Bitmap.open(image_path('sample.png'))
|
45
|
+
|
46
|
+
memory = FreeImage::Memory.new(image_data('sample.png'))
|
47
|
+
bitmap2 = memory.open
|
48
|
+
|
49
|
+
assert_equal(bitmap1.bits, bitmap2.bits)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_save
|
53
|
+
dst = FreeImage::Memory.new
|
54
|
+
|
55
|
+
bitmap = memory.open
|
56
|
+
result = bitmap.save(dst, :png)
|
57
|
+
|
58
|
+
assert(result)
|
59
|
+
assert_not_nil(dst.memory.bytes)
|
60
|
+
if defined?(Encoding)
|
61
|
+
assert_equal(dst.memory.bytes.encoding, Encoding::BINARY)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_corrupt
|
66
|
+
data = image_data('corrupt.jpg')
|
67
|
+
memory = FreeImage::Memory.new(data)
|
68
|
+
|
69
|
+
error = assert_raise(FreeImage::Error) do
|
70
|
+
memory.open
|
71
|
+
end
|
72
|
+
assert_equal("Cannot load :unknown image format", error.message)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_corrupt_wrong_format
|
76
|
+
data = image_data('corrupt.jpg')
|
77
|
+
memory = FreeImage::Memory.new(data)
|
78
|
+
|
79
|
+
error = assert_raise(FreeImage::Error) do
|
80
|
+
memory.open(:png)
|
81
|
+
end
|
82
|
+
assert_equal("Could not load the image", error.message)
|
83
|
+
end
|
85
84
|
end
|
data/test/test_modify.rb
CHANGED
@@ -1,59 +1,76 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
assert_equal(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
result
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
assert_equal(
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
assert_equal(
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
assert_equal(
|
57
|
-
|
58
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.join(File.dirname(__FILE__),'test_helper')
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class ModifyTest < Test::Unit::TestCase
|
6
|
+
def test_copy
|
7
|
+
bitmap1 = FreeImage::Bitmap.open(image_path('sample.png'))
|
8
|
+
bitmap2 = bitmap1.copy(0, 0, 50, 60)
|
9
|
+
|
10
|
+
assert_kind_of(FreeImage::Bitmap, bitmap2)
|
11
|
+
assert_equal(50, bitmap2.width)
|
12
|
+
assert_equal(60, bitmap2.height)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_expand_canvas
|
16
|
+
bitmap = FreeImage::Bitmap.open(image_path('sample.png'))
|
17
|
+
color = FreeImage::RGBQuad.create(15, 30, 45)
|
18
|
+
|
19
|
+
result = bitmap.enlarge_canvas(1, 1, 1, 1, color)
|
20
|
+
assert_kind_of(FreeImage::Bitmap, result)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_fill_background
|
24
|
+
bitmap = FreeImage::Bitmap.open(image_path('sample.png'))
|
25
|
+
color = FreeImage::RGBQuad.create(15, 30, 45)
|
26
|
+
|
27
|
+
result = bitmap.fill_background!(color)
|
28
|
+
assert(result)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_paste
|
32
|
+
bitmap1 = FreeImage::Bitmap.open(image_path('sample.png'))
|
33
|
+
bitmap2 = FreeImage::Bitmap.open(image_path('sample.png'))
|
34
|
+
result = bitmap1.paste!(bitmap2, 0, 0, 0.5)
|
35
|
+
|
36
|
+
assert_kind_of(TrueClass, result)
|
37
|
+
assert_equal(240, bitmap2.width)
|
38
|
+
assert_equal(215, bitmap2.height)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_rescale
|
42
|
+
bitmap1 = FreeImage::Bitmap.open(image_path('sample.png'))
|
43
|
+
bitmap2 = bitmap1.rescale(120, 100, :box)
|
44
|
+
|
45
|
+
assert_kind_of(FreeImage::Bitmap, bitmap2)
|
46
|
+
assert_equal(120, bitmap2.width)
|
47
|
+
assert_equal(100, bitmap2.height)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_thumbnail
|
51
|
+
bitmap1 = FreeImage::Bitmap.open(image_path('sample.png'))
|
52
|
+
bitmap2 = bitmap1.make_thumbnail(100)
|
53
|
+
|
54
|
+
assert_kind_of(FreeImage::Bitmap, bitmap2)
|
55
|
+
assert_equal(100, bitmap2.width)
|
56
|
+
assert_equal(90, bitmap2.height)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_composite
|
60
|
+
image = FreeImage::Bitmap.open(image_path('sample.png'))
|
61
|
+
color = FreeImage::RGBQuad.create(0, 255, 0, 0)
|
62
|
+
composite = image.composite_with_color(color)
|
63
|
+
assert(composite)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_composite_with_color
|
67
|
+
image = FreeImage::Bitmap.open(image_path('sample.png'))
|
68
|
+
|
69
|
+
# Get background that is 24 bits and the same size as the original image
|
70
|
+
background = FreeImage::Bitmap.open(image_path('gradient.png'))
|
71
|
+
background = background.rescale(image.width, image.height, :box)
|
72
|
+
|
73
|
+
composite = image.composite(background)
|
74
|
+
assert(composite)
|
75
|
+
end
|
59
76
|
end
|
data/test/test_palette.rb
CHANGED
@@ -1,45 +1,44 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
palette
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
palette
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
assert_equal(
|
24
|
-
assert_equal(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.join(File.dirname(__FILE__),'test_helper')
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class PaletteTest < Test::Unit::TestCase
|
6
|
+
def test_palette
|
7
|
+
palette = sample_image.palette
|
8
|
+
assert_not_nil(palette)
|
9
|
+
assert_kind_of(FreeImage::Palette, palette)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_size
|
13
|
+
palette = sample_image.palette
|
14
|
+
assert_equal(256, palette.size)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_index
|
18
|
+
palette = sample_image.palette
|
19
|
+
rgb = palette[27]
|
20
|
+
|
21
|
+
assert_kind_of(FreeImage::RGBQuad, rgb)
|
22
|
+
assert_equal(201, rgb[:red])
|
23
|
+
assert_equal(253, rgb[:green])
|
24
|
+
assert_equal(0, rgb[:blue])
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_index_too_small
|
28
|
+
palette = sample_image.palette
|
29
|
+
|
30
|
+
error = assert_raise(RangeError) do
|
31
|
+
palette[-1]
|
32
|
+
end
|
33
|
+
assert_equal("Value is out of range 0..256. Value: -1", error.message)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_index_too_large
|
37
|
+
palette = sample_image.palette
|
38
|
+
|
39
|
+
error = assert_raise(RangeError) do
|
40
|
+
palette[300]
|
41
|
+
end
|
42
|
+
assert_equal("Value is out of range 0..256. Value: 300", error.message)
|
43
|
+
end
|
44
|
+
end
|
data/test/test_pixels.rb
CHANGED
@@ -1,62 +1,61 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
bytes
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
index
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
result
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
result
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
color
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
result
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
result
|
60
|
-
|
61
|
-
|
62
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.join(File.dirname(__FILE__),'test_helper')
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class PixelTest < Test::Unit::TestCase
|
6
|
+
def test_bits
|
7
|
+
bytes = sample_image.bits
|
8
|
+
assert_not_nil(bytes)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_pixel_index
|
12
|
+
index = sample_image.pixel_index(0, 0)
|
13
|
+
assert_equal(113, index)
|
14
|
+
|
15
|
+
index = lena_image.pixel_index(0, 0)
|
16
|
+
assert_nil(index)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_set_pixel_index
|
20
|
+
image = sample_image
|
21
|
+
result = image.set_pixel_index(0, 0, 14)
|
22
|
+
assert(result)
|
23
|
+
|
24
|
+
index = image.pixel_index(0, 0)
|
25
|
+
assert_equal(14, index)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_set_pixel_invalid
|
29
|
+
image = lena_image
|
30
|
+
result = image.set_pixel_index(0, 0, 14)
|
31
|
+
assert(!result)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_pixel_color
|
35
|
+
color = lena_image.pixel_color(0, 0)
|
36
|
+
assert_kind_of(FreeImage::RGBQuad, color)
|
37
|
+
|
38
|
+
color = sample_image.pixel_color(0, 0)
|
39
|
+
assert_nil(color)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_set_pixel_color
|
43
|
+
image = lena_image
|
44
|
+
|
45
|
+
color1 = FreeImage::RGBQuad.create(0, 0, 255)
|
46
|
+
result = image.set_pixel_color(0, 0, color1)
|
47
|
+
assert(result)
|
48
|
+
|
49
|
+
color2 = image.pixel_color(0, 0)
|
50
|
+
assert_equal(color1, color2)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_set_pixel_invalid
|
54
|
+
# Pixel colors aren't supported on paletted images
|
55
|
+
image = sample_image
|
56
|
+
|
57
|
+
color1 = FreeImage::RGBQuad.create(0, 0, 255)
|
58
|
+
result = image.set_pixel_color(0, 0, color1)
|
59
|
+
assert(!result)
|
60
|
+
end
|
61
|
+
end
|