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.
- 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/free-image.gemspec
CHANGED
@@ -1,30 +1,31 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
Gem::Specification.new do |spec|
|
4
|
-
spec.name = 'free-image'
|
5
|
-
spec.version = '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('
|
29
|
-
spec.add_development_dependency('
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'free-image'
|
5
|
+
spec.version = '0.7.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('rake')
|
29
|
+
spec.add_development_dependency('hanna-nouveau')
|
30
|
+
spec.add_development_dependency('open4')
|
30
31
|
end
|
data/lib/free-image.rb
CHANGED
@@ -49,8 +49,6 @@ module FreeImage
|
|
49
49
|
|
50
50
|
if free_image_library_paths.any?
|
51
51
|
ffi_lib(*free_image_library_paths)
|
52
|
-
elsif FFI::Platform.windows?
|
53
|
-
ffi_lib("FreeImaged")
|
54
52
|
else
|
55
53
|
ffi_lib("freeimage")
|
56
54
|
end
|
@@ -71,6 +69,7 @@ require 'free-image/types/rgba16'
|
|
71
69
|
require 'free-image/types/rgbf'
|
72
70
|
require 'free-image/types/rgbaf'
|
73
71
|
require 'free-image/types/complex'
|
72
|
+
require 'free-image/types/info_header'
|
74
73
|
|
75
74
|
# Enums
|
76
75
|
require 'free-image/enums/color_types'
|
data/lib/free-image/bitmap.rb
CHANGED
@@ -153,8 +153,8 @@ module FreeImage
|
|
153
153
|
# dst:: The destination where the image will be saved.
|
154
154
|
# format:: The format[rdoc-ref:FreeImage.formats] to save the image to.
|
155
155
|
# flags:: Format specific flags that control how a bitmap is saved. These flags are defined
|
156
|
-
#
|
157
|
-
#
|
156
|
+
# as constants on the AbstractSource[rdoc-ref:FreeImage::AbstractSource::Encoder] class.
|
157
|
+
# Flags can be combined using Ruby's bitwise or operator (|)
|
158
158
|
#
|
159
159
|
def save(source, format, flags = 0)
|
160
160
|
self.class.figure_source(source).save(self, format, flags)
|
@@ -1,12 +1,12 @@
|
|
1
|
-
module FreeImage
|
2
|
-
##
|
3
|
-
#FreeImage supports the following rescaling filters:
|
4
|
-
#
|
5
|
-
# :method: filters
|
6
|
-
enum :filter, [:box, 0,
|
7
|
-
:bicubic, 1,
|
8
|
-
:bilinear, 2,
|
9
|
-
:bspline, 3,
|
10
|
-
:catmullrom, 4,
|
11
|
-
:lanczos3, 5]
|
1
|
+
module FreeImage
|
2
|
+
##
|
3
|
+
#FreeImage supports the following rescaling filters:
|
4
|
+
#
|
5
|
+
# :method: filters
|
6
|
+
enum :filter, [:box, 0,
|
7
|
+
:bicubic, 1,
|
8
|
+
:bilinear, 2,
|
9
|
+
:bspline, 3,
|
10
|
+
:catmullrom, 4,
|
11
|
+
:lanczos3, 5]
|
12
12
|
end
|
data/lib/free-image/errors.rb
CHANGED
@@ -1,44 +1,44 @@
|
|
1
|
-
module FreeImage
|
2
|
-
LAST_ERROR = 'free_image_error'
|
3
|
-
|
4
|
-
#typedef void (*FreeImage_OutputMessageFunction)(FREE_IMAGE_FORMAT fif, const char *msg);
|
5
|
-
#typedef void (DLL_CALLCONV *FreeImage_OutputMessageFunctionStdCall)(FREE_IMAGE_FORMAT fif, const char *msg);
|
6
|
-
callback(:output_message_callback, [:format, :pointer], :void)
|
7
|
-
|
8
|
-
if FFI::Platform.windows?
|
9
|
-
#DLL_API void DLL_CALLCONV FreeImage_SetOutputMessageStdCall(FreeImage_OutputMessageFunctionStdCall omf);
|
10
|
-
attach_function('FreeImage_SetOutputMessage', 'FreeImage_SetOutputMessageStdCall', [:output_message_callback], :void)
|
11
|
-
else
|
12
|
-
#DLL_API void DLL_CALLCONV FreeImage_SetOutputMessage(FreeImage_OutputMessageFunction omf);
|
13
|
-
attach_function('FreeImage_SetOutputMessage', [:output_message_callback], :void)
|
14
|
-
end
|
15
|
-
|
16
|
-
class Error < StandardError
|
17
|
-
attr_reader :format
|
18
|
-
|
19
|
-
def initialize(format, message)
|
20
|
-
@format = format
|
21
|
-
super(message)
|
22
|
-
end
|
23
|
-
|
24
|
-
# def to_s
|
25
|
-
# "#{self.message} Format: #{self.format}"
|
26
|
-
# end
|
27
|
-
end
|
28
|
-
|
29
|
-
CALLBACK = Proc.new do |format, ptr|
|
30
|
-
# Create an exception object and stash it away. We can't raise it here
|
31
|
-
# because FreeImage won't be able to clean up any resources it needs to.
|
32
|
-
# Instead, the calling code must call check_last_error.
|
33
|
-
message = ptr.get_string(0)
|
34
|
-
Thread.current[LAST_ERROR] = Error.new(format, message)
|
35
|
-
end
|
36
|
-
FreeImage_SetOutputMessage(CALLBACK)
|
37
|
-
|
38
|
-
def check_last_error
|
39
|
-
error = Thread.current[LAST_ERROR]
|
40
|
-
Thread.current[LAST_ERROR] = nil
|
41
|
-
raise(error) if error
|
42
|
-
end
|
43
|
-
module_function :check_last_error
|
1
|
+
module FreeImage
|
2
|
+
LAST_ERROR = 'free_image_error'
|
3
|
+
|
4
|
+
#typedef void (*FreeImage_OutputMessageFunction)(FREE_IMAGE_FORMAT fif, const char *msg);
|
5
|
+
#typedef void (DLL_CALLCONV *FreeImage_OutputMessageFunctionStdCall)(FREE_IMAGE_FORMAT fif, const char *msg);
|
6
|
+
callback(:output_message_callback, [:format, :pointer], :void)
|
7
|
+
|
8
|
+
if FFI::Platform.windows?
|
9
|
+
#DLL_API void DLL_CALLCONV FreeImage_SetOutputMessageStdCall(FreeImage_OutputMessageFunctionStdCall omf);
|
10
|
+
attach_function('FreeImage_SetOutputMessage', 'FreeImage_SetOutputMessageStdCall', [:output_message_callback], :void)
|
11
|
+
else
|
12
|
+
#DLL_API void DLL_CALLCONV FreeImage_SetOutputMessage(FreeImage_OutputMessageFunction omf);
|
13
|
+
attach_function('FreeImage_SetOutputMessage', [:output_message_callback], :void)
|
14
|
+
end
|
15
|
+
|
16
|
+
class Error < StandardError
|
17
|
+
attr_reader :format
|
18
|
+
|
19
|
+
def initialize(format, message)
|
20
|
+
@format = format
|
21
|
+
super(message)
|
22
|
+
end
|
23
|
+
|
24
|
+
# def to_s
|
25
|
+
# "#{self.message} Format: #{self.format}"
|
26
|
+
# end
|
27
|
+
end
|
28
|
+
|
29
|
+
CALLBACK = Proc.new do |format, ptr|
|
30
|
+
# Create an exception object and stash it away. We can't raise it here
|
31
|
+
# because FreeImage won't be able to clean up any resources it needs to.
|
32
|
+
# Instead, the calling code must call check_last_error.
|
33
|
+
message = ptr.get_string(0)
|
34
|
+
Thread.current[LAST_ERROR] = Error.new(format, message)
|
35
|
+
end
|
36
|
+
FreeImage_SetOutputMessage(CALLBACK)
|
37
|
+
|
38
|
+
def check_last_error
|
39
|
+
error = Thread.current[LAST_ERROR]
|
40
|
+
Thread.current[LAST_ERROR] = nil
|
41
|
+
raise(error) if error
|
42
|
+
end
|
43
|
+
module_function :check_last_error
|
44
44
|
end
|
@@ -1,254 +1,254 @@
|
|
1
|
-
module FreeImage
|
2
|
-
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo4Bits(FIBITMAP *dib);
|
3
|
-
attach_function('FreeImage_ConvertTo4Bits', [:pointer], :pointer)
|
4
|
-
|
5
|
-
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo8Bits(FIBITMAP *dib);
|
6
|
-
attach_function('FreeImage_ConvertTo8Bits', [:pointer], :pointer)
|
7
|
-
|
8
|
-
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToGreyscale(FIBITMAP *dib);
|
9
|
-
attach_function('FreeImage_ConvertToGreyscale', [:pointer], :pointer)
|
10
|
-
|
11
|
-
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo16Bits555(FIBITMAP *dib);
|
12
|
-
attach_function('FreeImage_ConvertTo16Bits555', [:pointer], :pointer)
|
13
|
-
|
14
|
-
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo16Bits565(FIBITMAP *dib);
|
15
|
-
attach_function('FreeImage_ConvertTo16Bits565', [:pointer], :pointer)
|
16
|
-
|
17
|
-
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo24Bits(FIBITMAP *dib);
|
18
|
-
attach_function('FreeImage_ConvertTo24Bits', [:pointer], :pointer)
|
19
|
-
|
20
|
-
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo32Bits(FIBITMAP *dib);
|
21
|
-
attach_function('FreeImage_ConvertTo32Bits', [:pointer], :pointer)
|
22
|
-
|
23
|
-
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Dither(FIBITMAP *dib, FREE_IMAGE_DITHER algorithm);
|
24
|
-
attach_function('FreeImage_Dither', [:pointer, :dither], :pointer)
|
25
|
-
|
26
|
-
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Threshold(FIBITMAP *dib, BYTE T);
|
27
|
-
attach_function('FreeImage_Threshold', [:pointer, :byte], :pointer)
|
28
|
-
|
29
|
-
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToStandardType(FIBITMAP *src, BOOL scale_linear FI_DEFAULT(TRUE));
|
30
|
-
attach_function('FreeImage_ConvertToStandardType', [:pointer, FreeImage::Boolean], :pointer)
|
31
|
-
|
32
|
-
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToType(FIBITMAP *src, FREE_IMAGE_TYPE dst_type, BOOL scale_linear FI_DEFAULT(TRUE));
|
33
|
-
attach_function('FreeImage_ConvertToType', [:pointer, :image_type, FreeImage::Boolean], :pointer)
|
34
|
-
|
35
|
-
module Conversions
|
36
|
-
# :call-seq:
|
37
|
-
# image.convert_to_4bits -> bitmap
|
38
|
-
# image.convert_to_4bits {|img| block} -> bitmap
|
39
|
-
#
|
40
|
-
# Converts a bitmap to 4 bits. If the bitmap is a high-color (16, 24 or 32-bit),
|
41
|
-
# monochrome or greyscale bitmap (1 or 8-bit) the end result will be a greyscale bitmap.
|
42
|
-
# A 1-bit bitmap will become a palletized bitmap.
|
43
|
-
#
|
44
|
-
# Note that "greyscale" means that the resulting bitmap will have grey colors,
|
45
|
-
# but the palette won't be a linear greyscale palette. Thus, FreeImage::Bitmap.color_type
|
46
|
-
# will return a :palette.
|
47
|
-
#
|
48
|
-
# If an optional block is provided, it will be passed the new image as an argument. The
|
49
|
-
# image will be automatically closed when the block completes.
|
50
|
-
#
|
51
|
-
def convert_to_4bits(&block)
|
52
|
-
ptr = FreeImage.FreeImage_ConvertTo4Bits(self)
|
53
|
-
FreeImage.check_last_error
|
54
|
-
self.class.new(ptr, &block)
|
55
|
-
end
|
56
|
-
|
57
|
-
# :call-seq:
|
58
|
-
# image.convert_to_8bits -> bitmap
|
59
|
-
# image.convert_to_8bits {|img| block} -> bitmap
|
60
|
-
#
|
61
|
-
# Converts a bitmap to 8 bits. If the bitmap is a high-color (16, 24 or 32-bit),
|
62
|
-
# monochrome or greyscale bitmap (1 or 4-bit) the end result will be a greyscale bitmap.
|
63
|
-
# A 1-bit or 4-bit bitmap will become a palletized bitmap.
|
64
|
-
#
|
65
|
-
# For 16-bit greyscale images (images whose type is :uint16), conversion is done by
|
66
|
-
# dividing the 16-bit channel by 256 (see also FreeImage::Bitmap.ConvertToStandardType).
|
67
|
-
# A nil value is returned for other non-standard bitmap types.
|
68
|
-
#
|
69
|
-
# If an optional block is provided, it will be passed the new image as an argument. The
|
70
|
-
# image will be automatically closed when the block completes.
|
71
|
-
#
|
72
|
-
def convert_to_8bits(&block)
|
73
|
-
ptr = FreeImage.FreeImage_ConvertTo8Bits(self)
|
74
|
-
FreeImage.check_last_error
|
75
|
-
self.class.new(ptr, &block)
|
76
|
-
end
|
77
|
-
|
78
|
-
# :call-seq:
|
79
|
-
# image.convert_to_greyscale -> bitmap
|
80
|
-
# image.convert_to_greyscale {|img| block} -> bitmap
|
81
|
-
#
|
82
|
-
# Converts a bitmap to a 8-bit greyscale image with a linear ramp. Contrary to
|
83
|
-
# the FreeImage::Conversions#convert_to_8bits function, 1-, 4- and 8-bit palletized
|
84
|
-
# bitmaps are correctly converted, as well as images with a :minis_white color type.
|
85
|
-
#
|
86
|
-
# If an optional block is provided, it will be passed the new image as an argument. The
|
87
|
-
# image will be automatically closed when the block completes.
|
88
|
-
#
|
89
|
-
def convert_to_greyscale(&block)
|
90
|
-
ptr = FreeImage.FreeImage_ConvertToGreyscale(self)
|
91
|
-
FreeImage.check_last_error
|
92
|
-
self.class.new(ptr, &block)
|
93
|
-
end
|
94
|
-
|
95
|
-
# :call-seq:
|
96
|
-
# image.convert_to_16bits_555 -> bitmap
|
97
|
-
# image.convert_to_16bits_555 {|img| block} -> bitmap
|
98
|
-
#
|
99
|
-
# Converts a bitmap to 16 bits, where each pixel has a color pattern of
|
100
|
-
# 5 bits red, 5 bits green and 5 bits blue. One bit in each pixel is
|
101
|
-
# unused.
|
102
|
-
#
|
103
|
-
# If an optional block is provided, it will be passed the new image as an argument. The
|
104
|
-
# image will be automatically closed when the block completes.
|
105
|
-
#
|
106
|
-
def convert_to_16bits_555(&block)
|
107
|
-
ptr = FreeImage.FreeImage_ConvertTo16Bits555(self)
|
108
|
-
FreeImage.check_last_error
|
109
|
-
self.class.new(ptr, &block)
|
110
|
-
end
|
111
|
-
|
112
|
-
# :call-seq:
|
113
|
-
# image.convert_to_16bits_565 -> bitmap
|
114
|
-
# image.convert_to_16bits_565 {|img| block} -> bitmap
|
115
|
-
#
|
116
|
-
# Converts a bitmap to 16 bits, where each pixel has a color pattern of
|
117
|
-
# 5 bits red, 6 bits green and 5 bits blue. One bit in each pixel is
|
118
|
-
# unused.
|
119
|
-
#
|
120
|
-
# If an optional block is provided, it will be passed the new image as an argument. The
|
121
|
-
# image will be automatically closed when the block completes.
|
122
|
-
#
|
123
|
-
def convert_to_16bits_565(&block)
|
124
|
-
ptr = FreeImage.FreeImage_ConvertTo16Bits565(self)
|
125
|
-
FreeImage.check_last_error
|
126
|
-
self.class.new(ptr, &block)
|
127
|
-
end
|
128
|
-
|
129
|
-
# :call-seq:
|
130
|
-
# image.convert_to_24bits -> bitmap
|
131
|
-
# image.convert_to_24bits {|img| block} -> bitmap
|
132
|
-
#
|
133
|
-
# Converts a bitmap to 24 bits. For 48-bit RGB images, conversion is done
|
134
|
-
# by dividing each 16-bit channel by 256. A nil value is returned for
|
135
|
-
# other non-standard bitmap types.
|
136
|
-
#
|
137
|
-
# If an optional block is provided, it will be passed the new image as an argument. The
|
138
|
-
# image will be automatically closed when the block completes.
|
139
|
-
#
|
140
|
-
def convert_to_24bits(&block)
|
141
|
-
ptr = FreeImage.FreeImage_ConvertTo24Bits(self)
|
142
|
-
FreeImage.check_last_error
|
143
|
-
self.class.new(ptr, &block)
|
144
|
-
end
|
145
|
-
|
146
|
-
# :call-seq:
|
147
|
-
# image.convert_to_32bits -> bitmap
|
148
|
-
# image.convert_to_32bits {|img| block} -> bitmap
|
149
|
-
#
|
150
|
-
# Converts a bitmap to 32 bits. For 48-bit RGB images, conversion is done
|
151
|
-
# by dividing each 16-bit channel by 256 and by setting the alpha channel
|
152
|
-
# to an opaque value (0xFF). For 64-bit RGBA images, conversion is done
|
153
|
-
# by dividing each 16-bit channel by 256. A nil value is returned for
|
154
|
-
# other non-standard bitmap types.
|
155
|
-
#
|
156
|
-
# If an optional block is provided, it will be passed the new image as an argument. The
|
157
|
-
# image will be automatically closed when the block completes.
|
158
|
-
#
|
159
|
-
def convert_to_32bits(&block)
|
160
|
-
ptr = FreeImage.FreeImage_ConvertTo32Bits(self)
|
161
|
-
FreeImage.check_last_error
|
162
|
-
self.class.new(ptr, &block)
|
163
|
-
end
|
164
|
-
|
165
|
-
# :call-seq:
|
166
|
-
# image.convert_to_standard_type(scale_linear = true) -> bitmap
|
167
|
-
# image.convert_to_standard_type(scale_linear = true) {|img| block} -> bitmap
|
168
|
-
#
|
169
|
-
# Converts a non standard image whose color type is :minis_black to a
|
170
|
-
# standard 8-bit greyscale image. When the scale_linear parameter is
|
171
|
-
# true, conversion is done by scaling linearly each pixel value from [min, max]
|
172
|
-
# to an integer value between [0..255], where min and max are the minimum
|
173
|
-
# and maximum pixel values in the image. When scale_linear is false, conversion
|
174
|
-
# is done by rounding each pixel value to an integer between [0..255]. Rounding
|
175
|
-
# is done using the following formula:
|
176
|
-
#
|
177
|
-
# dst_pixel = (BYTE) MIN(255, MAX(0, q)) where int q = int(src_pixel + 0.5)
|
178
|
-
#
|
179
|
-
# For standard bitmaps, a clone of the original bitmap is returned.
|
180
|
-
# For complex images, the magnitude is extracted as a double image and then converted
|
181
|
-
# according to the scale parameter.
|
182
|
-
#
|
183
|
-
# If an optional block is provided, it will be passed the new image as an argument. The
|
184
|
-
# image will be automatically closed when the block completes.
|
185
|
-
#
|
186
|
-
def convert_to_standard_type(scale_linear = true, &block)
|
187
|
-
ptr = FreeImage.FreeImage_ConvertToStandardType(self, scale_linear)
|
188
|
-
FreeImage.check_last_error
|
189
|
-
self.class.new(ptr, &block)
|
190
|
-
end
|
191
|
-
|
192
|
-
# :call-seq:
|
193
|
-
# image.convert_to_type(dst_image_type, scale_linear = true) -> bitmap
|
194
|
-
# image.convert_to_type(dst_image_type, scale_linear = true) {|img| block} -> bitmap
|
195
|
-
#
|
196
|
-
# Converts a bitmap to the specified destination image type. When the image_type
|
197
|
-
# is equal to :bitmap, the function calls FreeImage::Converstions#convert_to_standard_type.
|
198
|
-
# Otherwise, conversion is done using standard C language casting conventions. When
|
199
|
-
# a conversion is not allowed, a nil value is returned and an error is thrown.
|
200
|
-
# Please refer to the FreeImage documentation for allowed conversions.
|
201
|
-
#
|
202
|
-
# If an optional block is provided, it will be passed the new image as an argument. The
|
203
|
-
# image will be automatically closed when the block completes.
|
204
|
-
#
|
205
|
-
def convert_to_type(dst_image_type, scale_linear = true, &block)
|
206
|
-
ptr = FreeImage.FreeImage_ConvertToType(self, dst_image_type, scale_linear)
|
207
|
-
FreeImage.check_last_error
|
208
|
-
self.class.new(ptr, &block)
|
209
|
-
end
|
210
|
-
|
211
|
-
# :call-seq:
|
212
|
-
# image.dither(algorithm) -> bitmap
|
213
|
-
# image.dither(algorithm) {|img| block} -> bitmap
|
214
|
-
#
|
215
|
-
# Converts a bitmap to 1-bit monochrome bitmap using the specified
|
216
|
-
# {dithering}[rdoc-ref:FreeImage.dithers] algorithm. For 1-bit input
|
217
|
-
# bitmaps, the function clones the input bitmap and builds a
|
218
|
-
# monochrome palette. Otherwise the function first converts the
|
219
|
-
# bitmap to a 8-bit greyscale bitmap.
|
220
|
-
#
|
221
|
-
# If an optional block is provided, it will be passed the new image as an argument. The
|
222
|
-
# image will be automatically closed when the block completes.
|
223
|
-
#
|
224
|
-
def dither(algorithm, &block)
|
225
|
-
ptr = FreeImage.FreeImage_Dither(self, algorithm)
|
226
|
-
FreeImage.check_last_error
|
227
|
-
self.class.new(ptr, &block)
|
228
|
-
end
|
229
|
-
|
230
|
-
# :call-seq:
|
231
|
-
# image.threshold(value) -> bitmap
|
232
|
-
# image.threshold(value) {|img| block} -> bitmap
|
233
|
-
#
|
234
|
-
# Converts a bitmap to 1-bit monochrome bitmap using a threshold value
|
235
|
-
# between 0 and 255. The function first converts the bitmap to a 8-bit
|
236
|
-
# greyscale bitmap. Then any brightness level that is less than the
|
237
|
-
# threshold is set to zero and any value above is set to 1.
|
238
|
-
# For 1-bit input bitmaps, the function clones the input bitmap and
|
239
|
-
# builds a monochrome palette.
|
240
|
-
#
|
241
|
-
# If an optional block is provided, it will be passed the new image as an argument. The
|
242
|
-
# image will be automatically closed when the block completes.
|
243
|
-
#
|
244
|
-
def threshold(value, &block)
|
245
|
-
value = Integer(value)
|
246
|
-
unless (0..255).include?(value)
|
247
|
-
raise(RangeError, "Value is out of range 0..255. Value: #{value}")
|
248
|
-
end
|
249
|
-
ptr = FreeImage.FreeImage_Threshold(self, value)
|
250
|
-
FreeImage.check_last_error
|
251
|
-
self.class.new(ptr, &block)
|
252
|
-
end
|
253
|
-
end
|
1
|
+
module FreeImage
|
2
|
+
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo4Bits(FIBITMAP *dib);
|
3
|
+
attach_function('FreeImage_ConvertTo4Bits', [:pointer], :pointer)
|
4
|
+
|
5
|
+
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo8Bits(FIBITMAP *dib);
|
6
|
+
attach_function('FreeImage_ConvertTo8Bits', [:pointer], :pointer)
|
7
|
+
|
8
|
+
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToGreyscale(FIBITMAP *dib);
|
9
|
+
attach_function('FreeImage_ConvertToGreyscale', [:pointer], :pointer)
|
10
|
+
|
11
|
+
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo16Bits555(FIBITMAP *dib);
|
12
|
+
attach_function('FreeImage_ConvertTo16Bits555', [:pointer], :pointer)
|
13
|
+
|
14
|
+
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo16Bits565(FIBITMAP *dib);
|
15
|
+
attach_function('FreeImage_ConvertTo16Bits565', [:pointer], :pointer)
|
16
|
+
|
17
|
+
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo24Bits(FIBITMAP *dib);
|
18
|
+
attach_function('FreeImage_ConvertTo24Bits', [:pointer], :pointer)
|
19
|
+
|
20
|
+
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo32Bits(FIBITMAP *dib);
|
21
|
+
attach_function('FreeImage_ConvertTo32Bits', [:pointer], :pointer)
|
22
|
+
|
23
|
+
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Dither(FIBITMAP *dib, FREE_IMAGE_DITHER algorithm);
|
24
|
+
attach_function('FreeImage_Dither', [:pointer, :dither], :pointer)
|
25
|
+
|
26
|
+
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Threshold(FIBITMAP *dib, BYTE T);
|
27
|
+
attach_function('FreeImage_Threshold', [:pointer, :byte], :pointer)
|
28
|
+
|
29
|
+
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToStandardType(FIBITMAP *src, BOOL scale_linear FI_DEFAULT(TRUE));
|
30
|
+
attach_function('FreeImage_ConvertToStandardType', [:pointer, FreeImage::Boolean], :pointer)
|
31
|
+
|
32
|
+
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToType(FIBITMAP *src, FREE_IMAGE_TYPE dst_type, BOOL scale_linear FI_DEFAULT(TRUE));
|
33
|
+
attach_function('FreeImage_ConvertToType', [:pointer, :image_type, FreeImage::Boolean], :pointer)
|
34
|
+
|
35
|
+
module Conversions
|
36
|
+
# :call-seq:
|
37
|
+
# image.convert_to_4bits -> bitmap
|
38
|
+
# image.convert_to_4bits {|img| block} -> bitmap
|
39
|
+
#
|
40
|
+
# Converts a bitmap to 4 bits. If the bitmap is a high-color (16, 24 or 32-bit),
|
41
|
+
# monochrome or greyscale bitmap (1 or 8-bit) the end result will be a greyscale bitmap.
|
42
|
+
# A 1-bit bitmap will become a palletized bitmap.
|
43
|
+
#
|
44
|
+
# Note that "greyscale" means that the resulting bitmap will have grey colors,
|
45
|
+
# but the palette won't be a linear greyscale palette. Thus, FreeImage::Bitmap.color_type
|
46
|
+
# will return a :palette.
|
47
|
+
#
|
48
|
+
# If an optional block is provided, it will be passed the new image as an argument. The
|
49
|
+
# image will be automatically closed when the block completes.
|
50
|
+
#
|
51
|
+
def convert_to_4bits(&block)
|
52
|
+
ptr = FreeImage.FreeImage_ConvertTo4Bits(self)
|
53
|
+
FreeImage.check_last_error
|
54
|
+
self.class.new(ptr, &block)
|
55
|
+
end
|
56
|
+
|
57
|
+
# :call-seq:
|
58
|
+
# image.convert_to_8bits -> bitmap
|
59
|
+
# image.convert_to_8bits {|img| block} -> bitmap
|
60
|
+
#
|
61
|
+
# Converts a bitmap to 8 bits. If the bitmap is a high-color (16, 24 or 32-bit),
|
62
|
+
# monochrome or greyscale bitmap (1 or 4-bit) the end result will be a greyscale bitmap.
|
63
|
+
# A 1-bit or 4-bit bitmap will become a palletized bitmap.
|
64
|
+
#
|
65
|
+
# For 16-bit greyscale images (images whose type is :uint16), conversion is done by
|
66
|
+
# dividing the 16-bit channel by 256 (see also FreeImage::Bitmap.ConvertToStandardType).
|
67
|
+
# A nil value is returned for other non-standard bitmap types.
|
68
|
+
#
|
69
|
+
# If an optional block is provided, it will be passed the new image as an argument. The
|
70
|
+
# image will be automatically closed when the block completes.
|
71
|
+
#
|
72
|
+
def convert_to_8bits(&block)
|
73
|
+
ptr = FreeImage.FreeImage_ConvertTo8Bits(self)
|
74
|
+
FreeImage.check_last_error
|
75
|
+
self.class.new(ptr, &block)
|
76
|
+
end
|
77
|
+
|
78
|
+
# :call-seq:
|
79
|
+
# image.convert_to_greyscale -> bitmap
|
80
|
+
# image.convert_to_greyscale {|img| block} -> bitmap
|
81
|
+
#
|
82
|
+
# Converts a bitmap to a 8-bit greyscale image with a linear ramp. Contrary to
|
83
|
+
# the FreeImage::Conversions#convert_to_8bits function, 1-, 4- and 8-bit palletized
|
84
|
+
# bitmaps are correctly converted, as well as images with a :minis_white color type.
|
85
|
+
#
|
86
|
+
# If an optional block is provided, it will be passed the new image as an argument. The
|
87
|
+
# image will be automatically closed when the block completes.
|
88
|
+
#
|
89
|
+
def convert_to_greyscale(&block)
|
90
|
+
ptr = FreeImage.FreeImage_ConvertToGreyscale(self)
|
91
|
+
FreeImage.check_last_error
|
92
|
+
self.class.new(ptr, &block)
|
93
|
+
end
|
94
|
+
|
95
|
+
# :call-seq:
|
96
|
+
# image.convert_to_16bits_555 -> bitmap
|
97
|
+
# image.convert_to_16bits_555 {|img| block} -> bitmap
|
98
|
+
#
|
99
|
+
# Converts a bitmap to 16 bits, where each pixel has a color pattern of
|
100
|
+
# 5 bits red, 5 bits green and 5 bits blue. One bit in each pixel is
|
101
|
+
# unused.
|
102
|
+
#
|
103
|
+
# If an optional block is provided, it will be passed the new image as an argument. The
|
104
|
+
# image will be automatically closed when the block completes.
|
105
|
+
#
|
106
|
+
def convert_to_16bits_555(&block)
|
107
|
+
ptr = FreeImage.FreeImage_ConvertTo16Bits555(self)
|
108
|
+
FreeImage.check_last_error
|
109
|
+
self.class.new(ptr, &block)
|
110
|
+
end
|
111
|
+
|
112
|
+
# :call-seq:
|
113
|
+
# image.convert_to_16bits_565 -> bitmap
|
114
|
+
# image.convert_to_16bits_565 {|img| block} -> bitmap
|
115
|
+
#
|
116
|
+
# Converts a bitmap to 16 bits, where each pixel has a color pattern of
|
117
|
+
# 5 bits red, 6 bits green and 5 bits blue. One bit in each pixel is
|
118
|
+
# unused.
|
119
|
+
#
|
120
|
+
# If an optional block is provided, it will be passed the new image as an argument. The
|
121
|
+
# image will be automatically closed when the block completes.
|
122
|
+
#
|
123
|
+
def convert_to_16bits_565(&block)
|
124
|
+
ptr = FreeImage.FreeImage_ConvertTo16Bits565(self)
|
125
|
+
FreeImage.check_last_error
|
126
|
+
self.class.new(ptr, &block)
|
127
|
+
end
|
128
|
+
|
129
|
+
# :call-seq:
|
130
|
+
# image.convert_to_24bits -> bitmap
|
131
|
+
# image.convert_to_24bits {|img| block} -> bitmap
|
132
|
+
#
|
133
|
+
# Converts a bitmap to 24 bits. For 48-bit RGB images, conversion is done
|
134
|
+
# by dividing each 16-bit channel by 256. A nil value is returned for
|
135
|
+
# other non-standard bitmap types.
|
136
|
+
#
|
137
|
+
# If an optional block is provided, it will be passed the new image as an argument. The
|
138
|
+
# image will be automatically closed when the block completes.
|
139
|
+
#
|
140
|
+
def convert_to_24bits(&block)
|
141
|
+
ptr = FreeImage.FreeImage_ConvertTo24Bits(self)
|
142
|
+
FreeImage.check_last_error
|
143
|
+
self.class.new(ptr, &block)
|
144
|
+
end
|
145
|
+
|
146
|
+
# :call-seq:
|
147
|
+
# image.convert_to_32bits -> bitmap
|
148
|
+
# image.convert_to_32bits {|img| block} -> bitmap
|
149
|
+
#
|
150
|
+
# Converts a bitmap to 32 bits. For 48-bit RGB images, conversion is done
|
151
|
+
# by dividing each 16-bit channel by 256 and by setting the alpha channel
|
152
|
+
# to an opaque value (0xFF). For 64-bit RGBA images, conversion is done
|
153
|
+
# by dividing each 16-bit channel by 256. A nil value is returned for
|
154
|
+
# other non-standard bitmap types.
|
155
|
+
#
|
156
|
+
# If an optional block is provided, it will be passed the new image as an argument. The
|
157
|
+
# image will be automatically closed when the block completes.
|
158
|
+
#
|
159
|
+
def convert_to_32bits(&block)
|
160
|
+
ptr = FreeImage.FreeImage_ConvertTo32Bits(self)
|
161
|
+
FreeImage.check_last_error
|
162
|
+
self.class.new(ptr, &block)
|
163
|
+
end
|
164
|
+
|
165
|
+
# :call-seq:
|
166
|
+
# image.convert_to_standard_type(scale_linear = true) -> bitmap
|
167
|
+
# image.convert_to_standard_type(scale_linear = true) {|img| block} -> bitmap
|
168
|
+
#
|
169
|
+
# Converts a non standard image whose color type is :minis_black to a
|
170
|
+
# standard 8-bit greyscale image. When the scale_linear parameter is
|
171
|
+
# true, conversion is done by scaling linearly each pixel value from [min, max]
|
172
|
+
# to an integer value between [0..255], where min and max are the minimum
|
173
|
+
# and maximum pixel values in the image. When scale_linear is false, conversion
|
174
|
+
# is done by rounding each pixel value to an integer between [0..255]. Rounding
|
175
|
+
# is done using the following formula:
|
176
|
+
#
|
177
|
+
# dst_pixel = (BYTE) MIN(255, MAX(0, q)) where int q = int(src_pixel + 0.5)
|
178
|
+
#
|
179
|
+
# For standard bitmaps, a clone of the original bitmap is returned.
|
180
|
+
# For complex images, the magnitude is extracted as a double image and then converted
|
181
|
+
# according to the scale parameter.
|
182
|
+
#
|
183
|
+
# If an optional block is provided, it will be passed the new image as an argument. The
|
184
|
+
# image will be automatically closed when the block completes.
|
185
|
+
#
|
186
|
+
def convert_to_standard_type(scale_linear = true, &block)
|
187
|
+
ptr = FreeImage.FreeImage_ConvertToStandardType(self, scale_linear)
|
188
|
+
FreeImage.check_last_error
|
189
|
+
self.class.new(ptr, &block)
|
190
|
+
end
|
191
|
+
|
192
|
+
# :call-seq:
|
193
|
+
# image.convert_to_type(dst_image_type, scale_linear = true) -> bitmap
|
194
|
+
# image.convert_to_type(dst_image_type, scale_linear = true) {|img| block} -> bitmap
|
195
|
+
#
|
196
|
+
# Converts a bitmap to the specified destination image type. When the image_type
|
197
|
+
# is equal to :bitmap, the function calls FreeImage::Converstions#convert_to_standard_type.
|
198
|
+
# Otherwise, conversion is done using standard C language casting conventions. When
|
199
|
+
# a conversion is not allowed, a nil value is returned and an error is thrown.
|
200
|
+
# Please refer to the FreeImage documentation for allowed conversions.
|
201
|
+
#
|
202
|
+
# If an optional block is provided, it will be passed the new image as an argument. The
|
203
|
+
# image will be automatically closed when the block completes.
|
204
|
+
#
|
205
|
+
def convert_to_type(dst_image_type, scale_linear = true, &block)
|
206
|
+
ptr = FreeImage.FreeImage_ConvertToType(self, dst_image_type, scale_linear)
|
207
|
+
FreeImage.check_last_error
|
208
|
+
self.class.new(ptr, &block)
|
209
|
+
end
|
210
|
+
|
211
|
+
# :call-seq:
|
212
|
+
# image.dither(algorithm) -> bitmap
|
213
|
+
# image.dither(algorithm) {|img| block} -> bitmap
|
214
|
+
#
|
215
|
+
# Converts a bitmap to 1-bit monochrome bitmap using the specified
|
216
|
+
# {dithering}[rdoc-ref:FreeImage.dithers] algorithm. For 1-bit input
|
217
|
+
# bitmaps, the function clones the input bitmap and builds a
|
218
|
+
# monochrome palette. Otherwise the function first converts the
|
219
|
+
# bitmap to a 8-bit greyscale bitmap.
|
220
|
+
#
|
221
|
+
# If an optional block is provided, it will be passed the new image as an argument. The
|
222
|
+
# image will be automatically closed when the block completes.
|
223
|
+
#
|
224
|
+
def dither(algorithm, &block)
|
225
|
+
ptr = FreeImage.FreeImage_Dither(self, algorithm)
|
226
|
+
FreeImage.check_last_error
|
227
|
+
self.class.new(ptr, &block)
|
228
|
+
end
|
229
|
+
|
230
|
+
# :call-seq:
|
231
|
+
# image.threshold(value) -> bitmap
|
232
|
+
# image.threshold(value) {|img| block} -> bitmap
|
233
|
+
#
|
234
|
+
# Converts a bitmap to 1-bit monochrome bitmap using a threshold value
|
235
|
+
# between 0 and 255. The function first converts the bitmap to a 8-bit
|
236
|
+
# greyscale bitmap. Then any brightness level that is less than the
|
237
|
+
# threshold is set to zero and any value above is set to 1.
|
238
|
+
# For 1-bit input bitmaps, the function clones the input bitmap and
|
239
|
+
# builds a monochrome palette.
|
240
|
+
#
|
241
|
+
# If an optional block is provided, it will be passed the new image as an argument. The
|
242
|
+
# image will be automatically closed when the block completes.
|
243
|
+
#
|
244
|
+
def threshold(value, &block)
|
245
|
+
value = Integer(value)
|
246
|
+
unless (0..255).include?(value)
|
247
|
+
raise(RangeError, "Value is out of range 0..255. Value: #{value}")
|
248
|
+
end
|
249
|
+
ptr = FreeImage.FreeImage_Threshold(self, value)
|
250
|
+
FreeImage.check_last_error
|
251
|
+
self.class.new(ptr, &block)
|
252
|
+
end
|
253
|
+
end
|
254
254
|
end
|