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.
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,15 +1,14 @@
1
- # encoding: UTF-8
2
-
3
- require './test_helper'
4
- require 'test/unit'
5
-
6
- class FreeImageTest < Test::Unit::TestCase
7
- def test_copyright
8
- assert_equal("This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See http://freeimage.sourceforge.net for details",
9
- FreeImage.copyright)
10
- end
11
-
12
- def test_version
13
- assert_equal("3.15.1", FreeImage.version)
14
- end
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
@@ -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
@@ -1,118 +1,146 @@
1
- # encoding: UTF-8
2
-
3
- require './test_helper'
4
- require 'test/unit'
5
-
6
- class InformationTest < Test::Unit::TestCase
7
- def test_background_color
8
- background_color = sample_image.background_color
9
- assert_kind_of(FreeImage::RGBQuad, background_color)
10
- assert_equal(112, background_color[:red])
11
- assert_equal(176, background_color[:green])
12
- assert_equal(240, background_color[:blue])
13
- end
14
-
15
- def test_background_color_set
16
- image = sample_image
17
- rgb = FreeImage::RGBQuad.create(7, 8, 9)
18
-
19
- image.background_color = rgb
20
- background_color = image.background_color
21
- assert_equal(rgb, background_color)
22
- end
23
-
24
- def test_bits_per_pixel
25
- assert_equal(8, sample_image.bits_per_pixel)
26
- end
27
-
28
- def test_blue_mask
29
- assert_equal(0, sample_image.blue_mask)
30
- assert_equal(FreeImage::RGBQuad::BLUE_MASK, lena_image.blue_mask)
31
- end
32
-
33
- def test_color_type
34
- assert_equal(:palette, sample_image.color_type)
35
- end
36
-
37
- def test_dib_size
38
- assert_equal(52664, sample_image.dib_size)
39
- end
40
-
41
- def test_dots_per_meter_x
42
- assert_equal(2835, sample_image.dots_per_meter_x)
43
- end
44
-
45
- def test_dots_per_meter_x_set
46
- image = sample_image
47
- image.dots_per_meter_x = 3000
48
- assert_equal(3000, image.dots_per_meter_x)
49
- end
50
-
51
- def test_dots_per_meter_y
52
- assert_equal(2835, sample_image.dots_per_meter_y)
53
- end
54
-
55
- def test_dots_per_meter_y_set
56
- image = sample_image
57
- image.dots_per_meter_y = 4000
58
- assert_equal(4000, image.dots_per_meter_y)
59
- end
60
-
61
- def test_green_mask
62
- assert_equal(0, sample_image.green_mask)
63
- assert_equal(FreeImage::RGBQuad::GREEN_MASK, lena_image.green_mask)
64
- end
65
-
66
- def test_has_background_color
67
- assert(sample_image.has_background_color)
68
- end
69
-
70
- def test_has_pixels
71
- assert(sample_image.has_pixels)
72
- end
73
-
74
- def test_height
75
- assert_equal(215, sample_image.height)
76
- end
77
-
78
- def test_image_type
79
- assert_equal(:bitmap, sample_image.image_type)
80
- end
81
-
82
- def test_line
83
- assert_equal(240, sample_image.line)
84
- end
85
-
86
- def test_pitch
87
- assert_equal(240, sample_image.pitch)
88
- end
89
-
90
- def test_red_mask
91
- assert_equal(0, sample_image.red_mask)
92
- assert_equal(FreeImage::RGBQuad::RED_MASK, lena_image.red_mask)
93
- end
94
-
95
- def test_transparent
96
- assert(sample_image.transparent)
97
- end
98
-
99
- def test_transparent_set
100
- image = sample_image
101
- image.transparent = false
102
- assert(!image.transparent)
103
- end
104
-
105
- def test_transparent_index
106
- assert_equal(6, sample_image.transparent_index)
107
- end
108
-
109
- def test_transparent_index_set
110
- image = sample_image
111
- image.transparent_index = 4
112
- assert_equal(4, image.transparent_index)
113
- end
114
-
115
- def test_width
116
- assert_equal(240, sample_image.width)
117
- end
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
@@ -1,75 +1,74 @@
1
- # encoding: UTF-8
2
-
3
- require './test_helper'
4
- require 'test/unit'
5
-
6
- class IoTest < Test::Unit::TestCase
7
- def io(image = 'sample.png')
8
- path = image_path(image)
9
- file = File.open(path)
10
- FreeImage::IO.new(file)
11
- end
12
-
13
- def test_format
14
- assert_equal(:png, io.format)
15
- end
16
-
17
- def test_format_unknown
18
- assert_equal(:unknown, io('not_an_image.txt').format)
19
- end
20
-
21
- def test_load
22
- bitmap = io.open
23
- assert_kind_of(FreeImage::Bitmap, bitmap)
24
- end
25
-
26
- def test_load_unknown
27
- error = assert_raise(FreeImage::Error) do
28
- io('not_an_image.txt').open
29
- end
30
- assert_equal("Cannot load :unknown image format",
31
- error.message)
32
- end
33
-
34
- def test_load_wrong_format
35
- error = assert_raise(FreeImage::Error) do
36
- io.open(:jpeg)
37
- end
38
- assert_equal("Not a JPEG file: starts with 0x89 0x50", error.to_s)
39
- end
40
-
41
- def test_save
42
- tmp_file = Tempfile.new('test_free_image')
43
- dst = FreeImage::IO.new(tmp_file)
44
-
45
- bitmap = io.open
46
- result = bitmap.save(dst, :png)
47
- assert(result)
48
- assert(File.exists?(tmp_file))
49
- ensure
50
- tmp_file.close
51
- tmp_file.unlink
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
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