free-image 0.5.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 (74) hide show
  1. data/HISTORY +5 -0
  2. data/LICENSE +21 -0
  3. data/README.rdoc +99 -0
  4. data/Rakefile +47 -0
  5. data/cookbook.rdoc +239 -0
  6. data/free-image.gemspec +30 -0
  7. data/lib/free-image.rb +101 -0
  8. data/lib/free-image/bitmap.rb +154 -0
  9. data/lib/free-image/enums/color_types.rb +24 -0
  10. data/lib/free-image/enums/dithers.rb +24 -0
  11. data/lib/free-image/enums/filters.rb +12 -0
  12. data/lib/free-image/enums/formats.rb +84 -0
  13. data/lib/free-image/enums/image_types.rb +36 -0
  14. data/lib/free-image/errors.rb +44 -0
  15. data/lib/free-image/modules/conversions.rb +166 -0
  16. data/lib/free-image/modules/helper.rb +42 -0
  17. data/lib/free-image/modules/icc.rb +41 -0
  18. data/lib/free-image/modules/information.rb +305 -0
  19. data/lib/free-image/modules/modify.rb +261 -0
  20. data/lib/free-image/modules/pixels.rb +135 -0
  21. data/lib/free-image/modules/transforms.rb +83 -0
  22. data/lib/free-image/palette.rb +44 -0
  23. data/lib/free-image/scanline.rb +151 -0
  24. data/lib/free-image/sources/abstract_source.rb +172 -0
  25. data/lib/free-image/sources/file.rb +115 -0
  26. data/lib/free-image/sources/io.rb +154 -0
  27. data/lib/free-image/sources/memory.rb +189 -0
  28. data/lib/free-image/types/boolean.rb +14 -0
  29. data/lib/free-image/types/complex.rb +9 -0
  30. data/lib/free-image/types/ffi.rb +14 -0
  31. data/lib/free-image/types/rgb16.rb +11 -0
  32. data/lib/free-image/types/rgb_quad.rb +82 -0
  33. data/lib/free-image/types/rgb_triple.rb +42 -0
  34. data/lib/free-image/types/rgba16.rb +12 -0
  35. data/lib/free-image/types/rgbaf.rb +12 -0
  36. data/lib/free-image/types/rgbf.rb +11 -0
  37. data/test/cookbook.rb +46 -0
  38. data/test/images/gradient.png +0 -0
  39. data/test/images/lena.png +0 -0
  40. data/test/images/lena.tiff +0 -0
  41. data/test/images/lena_flipped.png +0 -0
  42. data/test/images/lena_rescale_bicubic.png +0 -0
  43. data/test/images/lena_rescale_bilinear.png +0 -0
  44. data/test/images/lena_rescale_box.png +0 -0
  45. data/test/images/lena_rescale_bspline.png +0 -0
  46. data/test/images/lena_rescale_catmullrom.png +0 -0
  47. data/test/images/lena_rescale_lanczos3.png +0 -0
  48. data/test/images/lena_rotate_45.png +0 -0
  49. data/test/images/lena_rotate_ex_45_masked.png +0 -0
  50. data/test/images/lena_rotate_ex_45_mirrored.png +0 -0
  51. data/test/images/lena_rotate_ex_45_top_left.png +0 -0
  52. data/test/images/lena_thumbnail.png +0 -0
  53. data/test/images/lena_thumbnail_border_enlarge.png +0 -0
  54. data/test/images/lena_thumbnail_border_paste.png +0 -0
  55. data/test/images/lena_thumbnail_border_scanline.png +0 -0
  56. data/test/images/not_an_image.txt +0 -0
  57. data/test/images/sample.png +0 -0
  58. data/test/images/sample_composite_color.png +0 -0
  59. data/test/test_bitmap.rb +43 -0
  60. data/test/test_conversions.rb +86 -0
  61. data/test/test_file.rb +51 -0
  62. data/test/test_free_image.rb +15 -0
  63. data/test/test_helper.rb +35 -0
  64. data/test/test_information.rb +118 -0
  65. data/test/test_io.rb +53 -0
  66. data/test/test_memory.rb +65 -0
  67. data/test/test_modify.rb +59 -0
  68. data/test/test_palette.rb +45 -0
  69. data/test/test_pixels.rb +62 -0
  70. data/test/test_rgb_quad.rb +26 -0
  71. data/test/test_scanline.rb +65 -0
  72. data/test/test_suite.rb +19 -0
  73. data/test/test_transforms.rb +30 -0
  74. metadata +169 -0
data/HISTORY ADDED
@@ -0,0 +1,5 @@
1
+ = Release History
2
+
3
+ == 0.5.0 / 2011-08-28 Charlie Savage
4
+
5
+ * Initial Commit
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2008-2011 Charlie Savage and contributors
2
+ Copyright (c) 2002-2007 Sean Chittenden and contributors
3
+ Copyright (c) 2001 Wai-Sun "Squidster" Chia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,99 @@
1
+ = FreeImage Ruby Bindings
2
+
3
+ == Overview
4
+ The free-image gem provides Ruby language bindings for the
5
+ FreeImage[http://freeimage.sourceforge.net/] library. It is free software,
6
+ released under the MIT License.
7
+
8
+ FreeImage is an light-weight, open source image manipulation library that
9
+ supports many popular graphics image {formats}[rdoc-ref:FreeImage.formats]
10
+ such as PNG, JPEG, GIF, BMP, and TIFF.
11
+
12
+ We think FreeImage is a great library for applications that need to read, write,
13
+ create and modify images and thumbnails because:
14
+
15
+ * Its easy to use
16
+ * Its supports almost all popular image formats
17
+ * Its a light-weight alternative to larger libraries such as ImageMagick,
18
+ supporting basic manipulation functions but not advanced functionality
19
+ * Its cross-platform
20
+ * The ruby bindings are implemented using FFI, so work across all Ruby
21
+ implementations and do not have to be compiled
22
+ * Its much more comprehensive than ImageScience
23
+ * Has comprehensive documentation
24
+
25
+ Note that FreeImage is not the right library for you if you need:
26
+ * Advanced image processing operations such as convolution and transforms
27
+ * Bitmap drawing
28
+ * Vector graphics
29
+
30
+ == Installation
31
+ free-image requires Ruby 1.8.7 or higher. The easiest way to install
32
+ free-image is via Ruby Gems. To install:
33
+
34
+ gem install free-image
35
+
36
+
37
+ == Getting Started
38
+ Using free-image is easy. To get you started, refer to the
39
+ \FreeImage cookbook[rdoc-ref:cookbook.rdoc].
40
+
41
+
42
+ == Implementation Status
43
+ The FreeImage API is divided into multiple parts. As summarized below, the Ruby ffi
44
+ bindings currently implement a subset of the available api. Patches are welcome to
45
+ extend the coverage.
46
+
47
+ === Bitmap functions
48
+ * General - FreeImage::Bitmap
49
+ * Bitmap management - FreeImage::Bitmap
50
+ * Bitmap information - FreeImage::Information, FreeImage::Color::Palette
51
+ * Filetype - FreeImage::File, FreeImage::IO, FreeImage::Memory
52
+ * Pixel access - FreeImage::Pixel
53
+ * Conversion - FreeImage::Conversions
54
+ * Tone mapping - Not Implemented
55
+ * ICC profile - FreeImage::ICC
56
+ * Plugin - Not Implemented
57
+ * Multipage - Not Implemented
58
+ * Memory I/O streams - FreeImage::MemoryStream
59
+ * Compression - Not Implemented
60
+ * Helper functions - FreeImage::Helper
61
+
62
+ === Metadata Functions
63
+ * Introduction - Not Implemented
64
+ * Tag creation and destruction - Not Implemented
65
+ * Tag accessors - Not Implemented
66
+ * Metadata iterator - Not Implemented
67
+ * Metadata accessors - Not Implemented
68
+ * Metadata helper functions - Not Implemented
69
+
70
+ === Toolkit Functions
71
+ * Rotation and flipping - FreeImage::Transforms
72
+ * Upsampling / downsampling - FreeImage::Modify
73
+ * Color manipulation - Not Implemented
74
+ * Channel processing - Not Implemented
75
+ * Copy / Paste / Composite routines - FreeImage::Modify
76
+ * Background filling - FreeImage::Modify
77
+ * Miscellaneous algorithms - Not Implemented
78
+
79
+ == Documentation
80
+ Documentation is available via rdoc, and is installed automatically with the
81
+ gem. Note that much of the documentation is directly copied from
82
+ the FreeImage API documentation available
83
+ here[http://downloads.sourceforge.net/freeimage/FreeImage3151.pdf].
84
+
85
+ free-image's online documentation is generated using Hanna. To generate
86
+ documentation from source:
87
+
88
+ gem install hanna-nouveau
89
+ rake rdoc
90
+ - or -
91
+ rdoc -o doc/rdoc -f hanna -m "README.rdoc" lib/**/*.rb README.rdoc
92
+
93
+
94
+ == Support
95
+
96
+ If you have any questions about using free-image, please ?
97
+
98
+ == License
99
+ See LICENSE for license information.
@@ -0,0 +1,47 @@
1
+ # encoding: UTF-8
2
+ # !/usr/bin/env ruby
3
+
4
+ require "rubygems"
5
+ require "rake/testtask"
6
+ require "rubygems/package_task"
7
+ require "rdoc/task"
8
+ require "fileutils"
9
+
10
+ GEM_NAME = "free-image"
11
+
12
+ # Read the spec file
13
+ spec = Gem::Specification.load("#{GEM_NAME}.gemspec")
14
+
15
+ # Setup generic gem
16
+ Gem::PackageTask.new(spec) do |pkg|
17
+ pkg.package_dir = 'pkg'
18
+ pkg.need_tar = false
19
+ end
20
+
21
+ # RDoc Task
22
+ desc "Generate rdoc documentation"
23
+ RDoc::Task.new("rdoc") do |rdoc|
24
+ rdoc.rdoc_dir = 'doc'
25
+ rdoc.title = "FreeImage"
26
+ # Show source inline with line numbers
27
+ rdoc.options << "--line-numbers"
28
+ # Use Hanna - this only works with RDoc 3.1 or greater
29
+ rdoc.generator = 'hanna'
30
+ # Make the readme file the start page for the generated html
31
+ rdoc.main = 'cookbook.rdoc'
32
+ rdoc.rdoc_files = FileList['HISTORY',
33
+ 'LICENSE',
34
+ '*.rdoc',
35
+ 'lib/**/*.rb']
36
+ end
37
+
38
+ desc "Setup Cookbook"
39
+ task :cookbook => :rdoc do
40
+ FileUtils.cp_r("test/images", "doc/cookbook")
41
+ end
42
+
43
+ # Test Task
44
+ Rake::TestTask.new do |t|
45
+ t.libs << "test"
46
+ t.verbose = true
47
+ end
@@ -0,0 +1,239 @@
1
+ = \Getting Started With \FreeImage
2
+ Below are various recipes to get you up and running with \FreeImage as quickly
3
+ as possible. The example images tcan be found in the
4
+ test/images directory. For more general information about \FreeImage, including
5
+ installation instructions, please refer to README.rdoc.
6
+
7
+ == Loading An Image
8
+ The first step in using \FreeImage is to load an image. \FreeImage can load
9
+ images from files[rdoc-ref::FreeImage::File], strings[rdoc-ref::FreeImage::Memory]
10
+ or IO[rdoc-ref::FreeImage::IO] streams. The simplest way to do this is
11
+ via the FreeImage::Bitmap.open method:
12
+
13
+ image = FreeImage::Bitmap.open('images/lena.tiff')
14
+ image = FreeImage::Bitmap.open(io_object)
15
+ image = FreeImage::Bitmap.open(FreeImage::Memory.new(string))
16
+
17
+ The open method also takes two additional optional parameters, format and flags,
18
+ that provide greater control over opening images if needed.
19
+
20
+ The open method works similary to File.open, meaning you can pass it a block.
21
+
22
+ FreeImage::Bitmap.open('images/lena.png') do |image|
23
+ ... do some stuff..
24
+ end
25
+
26
+ Once the block completes, the image will be automatically freed for you. If you don't
27
+ pass block, then the image will be freed by Ruby's Garbage Collector once it goes out
28
+ of scope or you can call the FreeImage::Bitmap#free method. Once you do that though,
29
+ remember the image no longer exists and further usage of it will result in
30
+ segmentation faults.
31
+
32
+ Image[link:cookbook/lena.png]
33
+
34
+ == Saving An Image
35
+ Now let's say you want to save the image to :png format. This is done
36
+ via the FreeImage::Bitmap.save method. The save method takes a destination,
37
+ which can be a file[rdoc-ref::FreeImage::File], string[rdoc-ref::FreeImage::Memory]
38
+ or IO[rdoc-ref::FreeImage::IO] stream, and an image format.
39
+
40
+ image.save('images/lena.png', :png)
41
+
42
+ == Creating a Thumbnail
43
+ Next, let's assume our application needs to show a list of thumbnails for the images
44
+ it stores. This can be done using the make_thumbnail[rdoc-ref:FreeImage::Modify.make_thumbnail]
45
+ method in the Modify[rdoc-ref:FreeImage::Modify] module.
46
+
47
+ thumbnail = image.make_thumbnail(100)
48
+ thumbnail.save('images/lena_thumbnail.png', :png)
49
+
50
+ Thumbnail[link:cookbook/lena_thumbnail.png]
51
+
52
+ == Putting a Border Around a Thumbnail
53
+ Once we have created a thumbnail, let's outline it with a red border. There
54
+ are various approaches to do doing this. In the first approach, we'll use
55
+ the enlarge_canvas[FreeImage::Modify.enlarge_canvas] method.
56
+
57
+ # Border size
58
+ border = 4
59
+
60
+ # Specify the color as red
61
+ color = FreeImage::RGBQuad.create(255, 0, 0)
62
+
63
+ # Add 4 pixel red border around the thumbnail
64
+ thumbnail_border = thumbnail.enlarge_canvas(border, border, border, border, color)
65
+ thumbnail_border.save('images/lena_thumbnail_border_1.png', :png)
66
+
67
+ ThumbnailBorderEnlarge[link:cookbook/lena_thumbnail_border_enlarge.png]
68
+
69
+ In the second approach, let's create a image with a red background
70
+ and then paste it on top of our thumbnail:
71
+
72
+ # Create a red image that is the same size as the thumbnail
73
+ red_image = FreeImage::Bitmap.create(thumbnail.width, thumbnail.height, thumbnail.bits_per_pixel)
74
+ red_image_new.fill_background(color)
75
+
76
+ # Now copy a subimage from the thumbnail that is 2 borders less wide and tall
77
+ subimage = thumbnail.copy(border, border, thumbnail.width - border, thumbnail.height - border)
78
+
79
+ # Now paste the subimage into the red image. Specify an alpha over 255
80
+ # to disable alpha blending
81
+ red_image.paste(subimage, border, border, 300)
82
+ red_image.save('images/test1.png', :png)
83
+ thumbnail_border.save('images/lena_thumbnail_border_2.png', :png)
84
+
85
+ ThumbnailBorderPaste[link:cookbook/lena_thumbnail_border_paste.png]
86
+
87
+ == Resampling An Image
88
+ If you need additional control over how an image is resampled, use the
89
+ FreeImage::Bitmap#rescale method, which lets you specify a filtering
90
+ algorithm. To see how each filter works, let's scale up the thumbnail
91
+ by 400%.
92
+
93
+ thumbnail = FreeImage::Bitmap.open('images/lena_thumbnail.png')
94
+
95
+ FreeImage.enum_type(:filter).symbols.each do |filter|
96
+ rescaled = thumbnail.rescale(thumbnail.width * 4, thumbnail.height * 4, filter)
97
+ rescaled.save("images/lena_rescale_#{filter.to_s}.png", :png)
98
+ end
99
+
100
+ RescaleBox[link:cookbook/lena_rescale_box.png]
101
+ RescaleBicubic[link:cookbook/lena_rescale_bicubic.png]
102
+ RescaleBilinear[link:cookbook/lena_rescale_bilinear.png]
103
+ RescaleBspline[link:cookbook/lena_rescale_bspline.png]
104
+ RescaleCatmullrom[link:cookbook/lena_rescale_catmullrom.png]
105
+ RescaleLanczos3[link:cookbook/lena_rescale_lanczos3.png]
106
+
107
+ == Flipping An Image
108
+ The Transform modules lets you flip or rotate an image. Let's say you want to
109
+ flip your image horizontally:
110
+
111
+ image.flip_horizontal
112
+ image.save('images/lena_flipped.png', :png)
113
+
114
+ Thumbnail[link:cookbook/lena_flipped.png]
115
+
116
+ == Rotating An Image
117
+ Next, let's rotate an image. Two methods are provide, FreeImage::Bitmap#rotate and
118
+ FreeImage::Bitmap#rotate_ex. The #rotate method is simpler to use:
119
+
120
+ image = FreeImage::Bitmap.open('images/lena.png', :png)
121
+
122
+ # Rotate the image 45 degrees using white as the background fill color
123
+ color = FreeImage::RGBQuad.create(255, 255, 255, 0)
124
+ rotated = image.rotate(45, color)
125
+ rotated.save("images/lena_rotate_45.png", :png)
126
+
127
+ Thumbnail[link:cookbook/lena_rotate_45.png]
128
+
129
+ Notice that the image size and geometry has changed? Thus, the #rotate
130
+ function is best for rotating and image 90, 180 or 270 degrees.
131
+
132
+ Let's now rotate the image using the #rotate_ex method while using a mask:
133
+
134
+ rotated = image.rotate_ex(45, 0, 0, image.width/2, image.height/2, true)
135
+ rotated.save("images/lena_rotate_ex_45_masked.png", :png)
136
+
137
+ And now let's rotate the image without a mask, so data is filled in using
138
+ a mirroring algorithm:
139
+
140
+ rotated = image.rotate_ex(45, 0, 0, image.width/2, image.height/2, false)
141
+ rotated.save("images/lena_rotate_ex_45_mirrored.png", :png)
142
+
143
+ Thumbnail[link:cookbook/lena_rotate_ex_45_masked.png]
144
+ Thumbnail[link:cookbook/lena_rotate_ex_45_mirrored.png]
145
+
146
+ Last, lets rotate the image around the top left corner:
147
+
148
+ rotated = image.rotate_ex(45, 0, 0, 0, 0, true)
149
+ rotated.save("images/lena_rotate_ex_45_top_left.png", :png)
150
+
151
+ Thumbnail[link:cookbook/lena_rotate_ex_45_top_left.png]
152
+
153
+ == Compositing An Image
154
+ \FreeImage also lets you composite an image with a background color or another image.
155
+ Here is an example of compositing an image with the color green.
156
+
157
+ image = FreeImage::Bitmap.open('images/sample.png')
158
+ color = FreeImage::RGBQuad.create(0, 255, 0, 0)
159
+ composite = image.composite_with_color(color)
160
+ composite.save("images/sample_composite_color.png", :png)
161
+
162
+ Sample[link:cookbook/sample.png]
163
+ SampleCompositeColor[link:cookbook/sample_composite_color.png]
164
+
165
+ == Manipulating An Image
166
+ \FreeImage also allows you to directly access each pixel in an image.
167
+ As an example, let's create an image that has a gradient from
168
+ blue in the top left corner to green in the bottom right
169
+
170
+ image = FreeImage::Bitmap.create(300, 300, 24)
171
+ color = FreeImage::RGBQuad.new
172
+
173
+ image.width.times do |x|
174
+ image.height.times do |y|
175
+ color[:green] = (x.to_f/image.width) * 255
176
+ color[:blue] = (y.to_f/image.height) * 255
177
+ image.set_pixel_color(x, y, color)
178
+ end
179
+ end
180
+
181
+ image.save('images/gradient.png', :png)
182
+
183
+ Gradient[link:cookbook/gradient.png]
184
+
185
+ You can use a similar technique as another solution to drawing a border around a
186
+ thumbnail as discussed above.
187
+
188
+ == Using Scanlines
189
+ Scanlines[rdoc-ref:FreeImage::Scanline] provide low level access to image data.
190
+ The only lower-level access is working with the actual raw bytes, which you can do
191
+ via the FreeeImage::Bitmap#bytes method, but its not recommended.
192
+
193
+ A scanline represents one row of image data, starting from the bottom. Let's go back
194
+ to our example above of drawing a red border around a thumbnail.
195
+
196
+ # Helper method
197
+ def set_to_red(color)
198
+ color[:red] = 255
199
+ color[:green] = 0
200
+ color[:blue] = 0
201
+ end
202
+
203
+ # Create a thumbnail
204
+ image = FreeImage::Bitmap.open('images/lena.png')
205
+ thumbnail = image.make_thumbnail(100)
206
+
207
+ # Draw bottom border 4 pixels tall
208
+ (0..3).each do |index|
209
+ scanline = thumbnail.scanline(index)
210
+ scanline.each do |color|
211
+ set_to_red(color)
212
+ end
213
+ end
214
+
215
+ # Draw top border 4 pixels tall
216
+ ((thumbnail.height - 5)..(thumbnail.height - 1)).each do |index|
217
+ scanline = thumbnail.scanline(index)
218
+ scanline.each do |color|
219
+ set_to_red(color)
220
+ end
221
+ end
222
+
223
+ # We could skip top and bottom 4 scanlines since
224
+ # already drew them.
225
+ thumbnail.height.each do |index|
226
+ scanline = thumbnail.scanline(index)
227
+ # Draw left and right borders 4 pixels wide
228
+ (0..4).each do |index|
229
+ set_to_red(scanline[index])
230
+ end
231
+
232
+ ((thumbnail.width - 5)..(thumbnail.width - 1)).each do |index|
233
+ set_to_red(scanline[index])
234
+ end
235
+ end
236
+
237
+ thumbnail.save("images/lena_thumbnail_border_scanline.png", :png)
238
+
239
+ ThumbnailBorderScanline[link:cookbook/lena_thumbnail_border_scanline.png]
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'free-image'
5
+ spec.version = '0.5.0'
6
+ spec.summary = 'Ruby Bindings for the Free Image Library'
7
+ spec.description = <<-EOS
8
+ FreeImage is an Open Source library project for developers who would like to support
9
+ popular graphics image formats like PNG, BMP, JPEG, TIFF and others as needed by
10
+ today's multimedia applications. FreeImage is easy to use, fast, multithreading
11
+ safe, compatible with all 32-bit or 64-bit versions of Windows, and
12
+ cross-platform (works both with Linux and Mac OS X).
13
+ EOS
14
+ spec.authors = [ 'Charlie Savage']
15
+ spec.platform = Gem::Platform::RUBY
16
+ spec.files = Dir.glob(['HISTORY',
17
+ 'LICENSE',
18
+ 'free-image.gemspec',
19
+ 'Rakefile',
20
+ '*.rdoc',
21
+ 'lib/**/*.rb',
22
+ 'test/**/*'])
23
+ spec.test_files = Dir.glob("test/test_*.rb")
24
+ spec.required_ruby_version = '>= 1.8.7'
25
+ spec.date = Time.now
26
+
27
+ spec.add_dependency('ffi', '>=1.0.10')
28
+ spec.add_development_dependency('hanna-nouveau')
29
+ spec.add_development_dependency('open4')
30
+ end
@@ -0,0 +1,101 @@
1
+ # encoding: UTF-8
2
+ require 'ffi'
3
+ require 'rbconfig'
4
+
5
+ module FreeImage
6
+ def self.msvc?
7
+ # If this is windows we assume FreeImage was compiled with
8
+ # MSVC since that is the binary distibution provided on
9
+ # the web site. If you have compiled FreeImage yourself
10
+ # on windows using another compiler, set this to false.
11
+ #
12
+ # This is important because FreeImage defines different
13
+ # type sizes for MSVC - see types/ffi.rb
14
+ FFI::Platform.windows?
15
+ end
16
+
17
+ def self.search_paths
18
+ @search_paths ||= begin
19
+ if ENV['FREE_IMAGE_LIBRARY_PATH']
20
+ [ ENV['FREE_IMAGE_LIBRARY_PATH'] ]
21
+ elsif FFI::Platform::IS_WINDOWS
22
+ ENV['PATH'].split(File::PATH_SEPARATOR)
23
+ else
24
+ [ '/usr/local/{lib64,lib32,lib}', '/opt/local/{lib64,lib32,lib}', '/usr/{lib64,lib32,lib}' ]
25
+ end
26
+ end
27
+ end
28
+
29
+ def self.find_lib(lib)
30
+ files = search_paths.inject(Array.new) do |array, path|
31
+ file_name = File.expand_path(File.join(path, "#{lib}.#{FFI::Platform::LIBSUFFIX}"))
32
+ array << Dir.glob(file_name)
33
+ array
34
+ end
35
+ files.flatten.compact.first
36
+ end
37
+
38
+ def self.free_image_library_paths
39
+ @free_image_library_paths ||= begin
40
+ libs = %w{libfreeimage libfreeimage.3 FreeImaged}
41
+
42
+ libs.map do |lib|
43
+ find_lib(lib)
44
+ end.compact
45
+ end
46
+ end
47
+
48
+ extend ::FFI::Library
49
+
50
+ if free_image_library_paths.any?
51
+ ffi_lib(*free_image_library_paths)
52
+ elsif FFI::Platform.windows?
53
+ ffi_lib("FreeImaged")
54
+ else
55
+ ffi_lib("free_image")
56
+ end
57
+
58
+ ffi_convention :stdcall if FFI::Platform.windows?
59
+ end
60
+
61
+
62
+ # Types
63
+ require 'free-image/types/ffi'
64
+ require 'free-image/types/boolean'
65
+
66
+ # More types
67
+ require 'free-image/types/rgb_triple'
68
+ require 'free-image/types/rgb_quad'
69
+ require 'free-image/types/rgb16'
70
+ require 'free-image/types/rgba16'
71
+ require 'free-image/types/rgbf'
72
+ require 'free-image/types/rgbaf'
73
+ require 'free-image/types/complex'
74
+
75
+ # Enums
76
+ require 'free-image/enums/color_types'
77
+ require 'free-image/enums/dithers'
78
+ require 'free-image/enums/filters'
79
+ require 'free-image/enums/formats'
80
+ require 'free-image/enums/image_types'
81
+
82
+ # Sources
83
+ require 'free-image/sources/abstract_source'
84
+ require 'free-image/sources/io'
85
+ require 'free-image/sources/file'
86
+ require 'free-image/sources/memory'
87
+
88
+ # Modules
89
+ require 'free-image/modules/conversions'
90
+ require 'free-image/modules/helper'
91
+ require 'free-image/modules/icc'
92
+ require 'free-image/modules/information'
93
+ require 'free-image/modules/modify'
94
+ require 'free-image/modules/pixels'
95
+ require 'free-image/modules/transforms'
96
+
97
+ # Main classes
98
+ require 'free-image/errors'
99
+ require 'free-image/palette'
100
+ require 'free-image/scanline'
101
+ require 'free-image/bitmap'