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.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/HISTORY +30 -19
  3. data/LICENSE +20 -20
  4. data/README.rdoc +120 -120
  5. data/Rakefile +51 -47
  6. data/cookbook.rdoc +248 -237
  7. data/free-image.gemspec +30 -29
  8. data/lib/free-image.rb +1 -2
  9. data/lib/free-image/bitmap.rb +2 -2
  10. data/lib/free-image/enums/filters.rb +11 -11
  11. data/lib/free-image/errors.rb +43 -43
  12. data/lib/free-image/modules/conversions.rb +253 -253
  13. data/lib/free-image/modules/helper.rb +41 -41
  14. data/lib/free-image/modules/information.rb +20 -2
  15. data/lib/free-image/modules/modify.rb +299 -299
  16. data/lib/free-image/modules/pixels.rb +134 -134
  17. data/lib/free-image/modules/transforms.rb +90 -90
  18. data/lib/free-image/sources/abstract_source.rb +178 -178
  19. data/lib/free-image/sources/file.rb +114 -114
  20. data/lib/free-image/sources/io.rb +153 -153
  21. data/lib/free-image/sources/memory.rb +188 -188
  22. data/lib/free-image/types/boolean.rb +13 -13
  23. data/lib/free-image/types/ffi.rb +13 -13
  24. data/lib/free-image/types/info_header.rb +36 -0
  25. data/lib/free-image/types/rgb16.rb +31 -0
  26. data/test/cookbook.rb +45 -46
  27. data/test/images/sample_composite.png +0 -0
  28. data/test/images/test16.bmp +0 -0
  29. data/test/images/test16bf555.bmp +0 -0
  30. data/test/images/test16bf565.bmp +0 -0
  31. data/test/test_bitmap.rb +61 -63
  32. data/test/test_conversions.rb +85 -86
  33. data/test/test_file.rb +68 -69
  34. data/test/test_free_image.rb +14 -15
  35. data/test/test_helper.rb +14 -0
  36. data/test/test_information.rb +145 -117
  37. data/test/test_io.rb +73 -74
  38. data/test/test_memory.rb +83 -84
  39. data/test/test_modify.rb +75 -58
  40. data/test/test_palette.rb +44 -45
  41. data/test/test_pixels.rb +61 -62
  42. data/test/test_rgb_quad.rb +24 -25
  43. data/test/test_scanline.rb +64 -65
  44. data/test/test_suite.rb +12 -17
  45. data/test/test_transforms.rb +28 -29
  46. metadata +58 -31
@@ -1,85 +1,84 @@
1
- # encoding: UTF-8
2
-
3
- require './test_helper'
4
- require 'test/unit'
5
-
6
- class MemoryTest < Test::Unit::TestCase
7
- def memory(image = 'sample.png')
8
- data = image_data(image)
9
- FreeImage::Memory.new(data)
10
- end
11
-
12
- def test_wrap
13
- assert_not_nil(memory)
14
- end
15
-
16
- def test_format
17
- assert_equal(:png, memory.format)
18
- end
19
-
20
- def test_format_unknown
21
- assert_equal(:unknown, memory('not_an_image.txt').format)
22
- end
23
-
24
- def test_load
25
- bitmap = memory.open
26
- assert_kind_of(FreeImage::Bitmap, bitmap)
27
- end
28
-
29
- def test_load_unknown
30
- error = assert_raise(FreeImage::Error) do
31
- memory('not_an_image.txt').open
32
- end
33
- assert_equal("Cannot load :unknown image format",
34
- error.message)
35
- end
36
-
37
- def test_load_wrong_format
38
- error = assert_raise(FreeImage::Error) do
39
- memory.open(:jpeg, 0)
40
- end
41
- assert_equal("Not a JPEG file: starts with 0x89 0x50", error.to_s)
42
- end
43
-
44
- def test_bytes
45
- bitmap1 = FreeImage::Bitmap.open(image_path('sample.png'))
46
-
47
- memory = FreeImage::Memory.new(image_data('sample.png'))
48
- bitmap2 = memory.open
49
-
50
- assert_equal(bitmap1.bits, bitmap2.bits)
51
- end
52
-
53
- def test_save
54
- dst = FreeImage::Memory.new
55
-
56
- bitmap = memory.open
57
- result = bitmap.save(dst, :png)
58
-
59
- assert(result)
60
- assert_not_nil(dst.memory.bytes)
61
- if defined?(Encoding)
62
- assert_equal(dst.memory.bytes.encoding, Encoding::BINARY)
63
- end
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
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
@@ -1,59 +1,76 @@
1
- # encoding: UTF-8
2
-
3
- require './test_helper'
4
- require 'test/unit'
5
-
6
- class ModifyTest < Test::Unit::TestCase
7
- def test_copy
8
- bitmap1 = FreeImage::Bitmap.open(image_path('sample.png'))
9
- bitmap2 = bitmap1.copy(0, 0, 50, 60)
10
-
11
- assert_kind_of(FreeImage::Bitmap, bitmap2)
12
- assert_equal(50, bitmap2.width)
13
- assert_equal(60, bitmap2.height)
14
- end
15
-
16
- def test_expand_canvas
17
- bitmap = FreeImage::Bitmap.open(image_path('sample.png'))
18
- color = FreeImage::RGBQuad.create(15, 30, 45)
19
-
20
- result = bitmap.enlarge_canvas(1, 1, 1, 1, color)
21
- assert_kind_of(FreeImage::Bitmap, result)
22
- end
23
-
24
- def test_fill_background
25
- bitmap = FreeImage::Bitmap.open(image_path('sample.png'))
26
- color = FreeImage::RGBQuad.create(15, 30, 45)
27
-
28
- result = bitmap.fill_background!(color)
29
- assert(result)
30
- end
31
-
32
- def test_paste
33
- bitmap1 = FreeImage::Bitmap.open(image_path('sample.png'))
34
- bitmap2 = FreeImage::Bitmap.open(image_path('sample.png'))
35
- result = bitmap1.paste!(bitmap2, 0, 0, 0.5)
36
-
37
- assert_kind_of(TrueClass, result)
38
- assert_equal(240, bitmap2.width)
39
- assert_equal(215, bitmap2.height)
40
- end
41
-
42
- def test_rescale
43
- bitmap1 = FreeImage::Bitmap.open(image_path('sample.png'))
44
- bitmap2 = bitmap1.rescale(120, 100, :box)
45
-
46
- assert_kind_of(FreeImage::Bitmap, bitmap2)
47
- assert_equal(120, bitmap2.width)
48
- assert_equal(100, bitmap2.height)
49
- end
50
-
51
- def test_thumbnail
52
- bitmap1 = FreeImage::Bitmap.open(image_path('sample.png'))
53
- bitmap2 = bitmap1.make_thumbnail(100)
54
-
55
- assert_kind_of(FreeImage::Bitmap, bitmap2)
56
- assert_equal(100, bitmap2.width)
57
- assert_equal(90, bitmap2.height)
58
- end
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
@@ -1,45 +1,44 @@
1
- # encoding: UTF-8
2
-
3
- require './test_helper'
4
- require 'test/unit'
5
-
6
- class PaletteTest < Test::Unit::TestCase
7
- def test_palette
8
- palette = sample_image.palette
9
- assert_not_nil(palette)
10
- assert_kind_of(FreeImage::Palette, palette)
11
- end
12
-
13
- def test_size
14
- palette = sample_image.palette
15
- assert_equal(256, palette.size)
16
- end
17
-
18
- def test_index
19
- palette = sample_image.palette
20
- rgb = palette[27]
21
-
22
- assert_kind_of(FreeImage::RGBQuad, rgb)
23
- assert_equal(201, rgb[:red])
24
- assert_equal(253, rgb[:green])
25
- assert_equal(0, rgb[:blue])
26
- end
27
-
28
- def test_index_too_small
29
- palette = sample_image.palette
30
-
31
- error = assert_raise(RangeError) do
32
- palette[-1]
33
- end
34
- assert_equal("Value is out of range 0..256. Value: -1", error.message)
35
- end
36
-
37
- def test_index_too_large
38
- palette = sample_image.palette
39
-
40
- error = assert_raise(RangeError) do
41
- palette[300]
42
- end
43
- assert_equal("Value is out of range 0..256. Value: 300", error.message)
44
- end
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
@@ -1,62 +1,61 @@
1
- # encoding: UTF-8
2
-
3
- require './test_helper'
4
- require 'test/unit'
5
-
6
- class PixelTest < Test::Unit::TestCase
7
- def test_bits
8
- bytes = sample_image.bits
9
- assert_not_nil(bytes)
10
- end
11
-
12
- def test_pixel_index
13
- index = sample_image.pixel_index(0, 0)
14
- assert_equal(113, index)
15
-
16
- index = lena_image.pixel_index(0, 0)
17
- assert_nil(index)
18
- end
19
-
20
- def test_set_pixel_index
21
- image = sample_image
22
- result = image.set_pixel_index(0, 0, 14)
23
- assert(result)
24
-
25
- index = image.pixel_index(0, 0)
26
- assert_equal(14, index)
27
- end
28
-
29
- def test_set_pixel_invalid
30
- image = lena_image
31
- result = image.set_pixel_index(0, 0, 14)
32
- assert(!result)
33
- end
34
-
35
- def test_pixel_color
36
- color = lena_image.pixel_color(0, 0)
37
- assert_kind_of(FreeImage::RGBQuad, color)
38
-
39
- color = sample_image.pixel_color(0, 0)
40
- assert_nil(color)
41
- end
42
-
43
- def test_set_pixel_color
44
- image = lena_image
45
-
46
- color1 = FreeImage::RGBQuad.create(0, 0, 255)
47
- result = image.set_pixel_color(0, 0, color1)
48
- assert(result)
49
-
50
- color2 = image.pixel_color(0, 0)
51
- assert_equal(color1, color2)
52
- end
53
-
54
- def test_set_pixel_invalid
55
- # Pixel colors aren't supported on paletted images
56
- image = sample_image
57
-
58
- color1 = FreeImage::RGBQuad.create(0, 0, 255)
59
- result = image.set_pixel_color(0, 0, color1)
60
- assert(!result)
61
- end
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