free-image 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +5 -0
- data/LICENSE +21 -0
- data/README.rdoc +99 -0
- data/Rakefile +47 -0
- data/cookbook.rdoc +239 -0
- data/free-image.gemspec +30 -0
- data/lib/free-image.rb +101 -0
- data/lib/free-image/bitmap.rb +154 -0
- data/lib/free-image/enums/color_types.rb +24 -0
- data/lib/free-image/enums/dithers.rb +24 -0
- data/lib/free-image/enums/filters.rb +12 -0
- data/lib/free-image/enums/formats.rb +84 -0
- data/lib/free-image/enums/image_types.rb +36 -0
- data/lib/free-image/errors.rb +44 -0
- data/lib/free-image/modules/conversions.rb +166 -0
- data/lib/free-image/modules/helper.rb +42 -0
- data/lib/free-image/modules/icc.rb +41 -0
- data/lib/free-image/modules/information.rb +305 -0
- data/lib/free-image/modules/modify.rb +261 -0
- data/lib/free-image/modules/pixels.rb +135 -0
- data/lib/free-image/modules/transforms.rb +83 -0
- data/lib/free-image/palette.rb +44 -0
- data/lib/free-image/scanline.rb +151 -0
- data/lib/free-image/sources/abstract_source.rb +172 -0
- data/lib/free-image/sources/file.rb +115 -0
- data/lib/free-image/sources/io.rb +154 -0
- data/lib/free-image/sources/memory.rb +189 -0
- data/lib/free-image/types/boolean.rb +14 -0
- data/lib/free-image/types/complex.rb +9 -0
- data/lib/free-image/types/ffi.rb +14 -0
- data/lib/free-image/types/rgb16.rb +11 -0
- data/lib/free-image/types/rgb_quad.rb +82 -0
- data/lib/free-image/types/rgb_triple.rb +42 -0
- data/lib/free-image/types/rgba16.rb +12 -0
- data/lib/free-image/types/rgbaf.rb +12 -0
- data/lib/free-image/types/rgbf.rb +11 -0
- data/test/cookbook.rb +46 -0
- data/test/images/gradient.png +0 -0
- data/test/images/lena.png +0 -0
- data/test/images/lena.tiff +0 -0
- data/test/images/lena_flipped.png +0 -0
- data/test/images/lena_rescale_bicubic.png +0 -0
- data/test/images/lena_rescale_bilinear.png +0 -0
- data/test/images/lena_rescale_box.png +0 -0
- data/test/images/lena_rescale_bspline.png +0 -0
- data/test/images/lena_rescale_catmullrom.png +0 -0
- data/test/images/lena_rescale_lanczos3.png +0 -0
- data/test/images/lena_rotate_45.png +0 -0
- data/test/images/lena_rotate_ex_45_masked.png +0 -0
- data/test/images/lena_rotate_ex_45_mirrored.png +0 -0
- data/test/images/lena_rotate_ex_45_top_left.png +0 -0
- data/test/images/lena_thumbnail.png +0 -0
- data/test/images/lena_thumbnail_border_enlarge.png +0 -0
- data/test/images/lena_thumbnail_border_paste.png +0 -0
- data/test/images/lena_thumbnail_border_scanline.png +0 -0
- data/test/images/not_an_image.txt +0 -0
- data/test/images/sample.png +0 -0
- data/test/images/sample_composite_color.png +0 -0
- data/test/test_bitmap.rb +43 -0
- data/test/test_conversions.rb +86 -0
- data/test/test_file.rb +51 -0
- data/test/test_free_image.rb +15 -0
- data/test/test_helper.rb +35 -0
- data/test/test_information.rb +118 -0
- data/test/test_io.rb +53 -0
- data/test/test_memory.rb +65 -0
- data/test/test_modify.rb +59 -0
- data/test/test_palette.rb +45 -0
- data/test/test_pixels.rb +62 -0
- data/test/test_rgb_quad.rb +26 -0
- data/test/test_scanline.rb +65 -0
- data/test/test_suite.rb +19 -0
- data/test/test_transforms.rb +30 -0
- metadata +169 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
module FreeImage
|
2
|
+
#DLL_API const char *DLL_CALLCONV FreeImage_GetVersion(void);
|
3
|
+
attach_function('FreeImage_GetVersion', [], :string)
|
4
|
+
|
5
|
+
#DLL_API const char *DLL_CALLCONV FreeImage_GetCopyrightMessage(void);
|
6
|
+
attach_function('FreeImage_GetCopyrightMessage', [], :string)
|
7
|
+
|
8
|
+
#DLL_API BOOL DLL_CALLCONV FreeImage_IsLittleEndian(void);
|
9
|
+
attach_function('FreeImage_IsLittleEndian', [], FreeImage::Boolean)
|
10
|
+
|
11
|
+
##
|
12
|
+
# :call-seq:
|
13
|
+
# version -> string
|
14
|
+
#
|
15
|
+
# Returns the current version of the FreeImage library
|
16
|
+
#
|
17
|
+
def self.version
|
18
|
+
FreeImage.FreeImage_GetVersion
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# :call-seq:
|
23
|
+
# copyright -> string
|
24
|
+
#
|
25
|
+
# Returns a standard copyright message you can show in your program.
|
26
|
+
#
|
27
|
+
def self.copyright
|
28
|
+
FreeImage.FreeImage_GetCopyrightMessage
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# :call-seq:
|
33
|
+
# is_little_endian? -> boolean
|
34
|
+
#
|
35
|
+
# Returns TRUE if the platform running FreeImage uses the Little Endian
|
36
|
+
# convention (Intel processors) and returns FALSE if it uses the Big Endian
|
37
|
+
# (Motorola processors).
|
38
|
+
#
|
39
|
+
def self.little_endian?
|
40
|
+
FreeImage.FreeImage_IsLittleEndian
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module FreeImage
|
2
|
+
# DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsICCProfiles(FREE_IMAGE_FORMAT fif)
|
3
|
+
attach_function(:icc_supported, 'FreeImage_FIFSupportsICCProfiles', [:format], FreeImage::Boolean)
|
4
|
+
module_function :icc_supported
|
5
|
+
|
6
|
+
module ICC
|
7
|
+
class Profile < FFI::Struct
|
8
|
+
layout :flags, :int,
|
9
|
+
:size, :uint,
|
10
|
+
:data, :pointer
|
11
|
+
end
|
12
|
+
|
13
|
+
# DLL_API FIICCPROFILE *DLL_CALLCONV FreeImage_GetICCProfile(FIBITMAP *dib)
|
14
|
+
FreeImage.attach_function('FreeImage_GetICCProfile', [:pointer], FreeImage::ICC::Profile)
|
15
|
+
|
16
|
+
def icc_profile
|
17
|
+
result = FreeImage.FreeImage_GetICCProfile(self)
|
18
|
+
FreeImage.check_last_error
|
19
|
+
result
|
20
|
+
end
|
21
|
+
|
22
|
+
# DLL_API FIICCPROFILE *DLL_CALLCONV FreeImage_CreateICCProfile(FIBITMAP *dib, void *data, long size);
|
23
|
+
FreeImage.attach_function('FreeImage_CreateICCProfile', [:pointer, :pointer, :long], FreeImage::ICC::Profile)
|
24
|
+
# DLL_API void DLL_CALLCONV FreeImage_DestroyICCProfile(FIBITMAP *dib);
|
25
|
+
FreeImage.attach_function('FreeImage_DestroyICCProfile', [:pointer], :void)
|
26
|
+
|
27
|
+
def icc_profile=(value)
|
28
|
+
result = if value
|
29
|
+
FreeImage.FreeImage_CreateICCProfile(self, value[:data], value[:size])
|
30
|
+
else
|
31
|
+
FreeImage.FreeImage_DestroyICCProfile(self)
|
32
|
+
end
|
33
|
+
FreeImage.check_last_error
|
34
|
+
result
|
35
|
+
end
|
36
|
+
|
37
|
+
def icc_supported?
|
38
|
+
FreeImage.icc_supported(self)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,305 @@
|
|
1
|
+
module FreeImage
|
2
|
+
#DLL_API BOOL DLL_CALLCONV FreeImage_HasPixels(FIBITMAP *dib);
|
3
|
+
attach_function('FreeImage_HasPixels', [:pointer], FreeImage::Boolean)
|
4
|
+
|
5
|
+
#DLL_API FREE_IMAGE_TYPE DLL_CALLCONV FreeImage_GetImageType(FIBITMAP *dib)
|
6
|
+
attach_function('FreeImage_GetImageType', [:pointer], :image_type)
|
7
|
+
|
8
|
+
#DLL_API unsigned DLL_CALLCONV FreeImage_GetHeight(FIBITMAP *dib);
|
9
|
+
attach_function('FreeImage_GetHeight', [:pointer], :uint)
|
10
|
+
|
11
|
+
#DLL_API unsigned DLL_CALLCONV FreeImage_GetWidth(FIBITMAP *dib);
|
12
|
+
attach_function('FreeImage_GetWidth', [:pointer], :uint)
|
13
|
+
|
14
|
+
#DLL_API unsigned DLL_CALLCONV FreeImage_GetBPP(FIBITMAP *dib);
|
15
|
+
attach_function('FreeImage_GetBPP', [:pointer], :ulong)
|
16
|
+
|
17
|
+
#DLL_API unsigned DLL_CALLCONV FreeImage_GetLine(FIBITMAP *dib);
|
18
|
+
attach_function('FreeImage_GetLine', [:pointer], :ulong)
|
19
|
+
|
20
|
+
#DLL_API unsigned DLL_CALLCONV FreeImage_GetPitch(FIBITMAP *dib);
|
21
|
+
attach_function('FreeImage_GetPitch', [:pointer], :ulong)
|
22
|
+
|
23
|
+
#DLL_API unsigned DLL_CALLCONV FreeImage_GetDIBSize(FIBITMAP *dib);
|
24
|
+
attach_function('FreeImage_GetDIBSize', [:pointer], :ulong)
|
25
|
+
|
26
|
+
#DLL_API unsigned DLL_CALLCONV FreeImage_GetDotsPerMeterX(FIBITMAP *dib);
|
27
|
+
attach_function('FreeImage_GetDotsPerMeterX', [:pointer], :ulong)
|
28
|
+
|
29
|
+
#DLL_API unsigned DLL_CALLCONV FreeImage_GetDotsPerMeterY(FIBITMAP *dib);
|
30
|
+
attach_function('FreeImage_GetDotsPerMeterY', [:pointer], :ulong)
|
31
|
+
|
32
|
+
#DLL_API void DLL_CALLCONV FreeImage_SetDotsPerMeterX(FIBITMAP *dib, unsigned res);
|
33
|
+
attach_function('FreeImage_SetDotsPerMeterX', [:pointer, :ulong], :void)
|
34
|
+
|
35
|
+
#DLL_API void DLL_CALLCONV FreeImage_SetDotsPerMeterY(FIBITMAP *dib, unsigned res);
|
36
|
+
attach_function('FreeImage_SetDotsPerMeterY', [:pointer, :ulong], :void)
|
37
|
+
|
38
|
+
#DLL_API FREE_IMAGE_COLOR_TYPE DLL_CALLCONV FreeImage_GetColorType(FIBITMAP *dib);
|
39
|
+
attach_function('FreeImage_GetColorType', [:pointer], :color_type)
|
40
|
+
|
41
|
+
#DLL_API unsigned DLL_CALLCONV FreeImage_GetBlueMask(FIBITMAP *dib);
|
42
|
+
attach_function('FreeImage_GetBlueMask', [:pointer], :ulong)
|
43
|
+
|
44
|
+
#DLL_API unsigned DLL_CALLCONV FreeImage_GetRedMask(FIBITMAP *dib);
|
45
|
+
attach_function('FreeImage_GetRedMask', [:pointer], :ulong)
|
46
|
+
|
47
|
+
#DLL_API unsigned DLL_CALLCONV FreeImage_GetGreenMask(FIBITMAP *dib);
|
48
|
+
attach_function('FreeImage_GetGreenMask', [:pointer], :ulong)
|
49
|
+
|
50
|
+
#DLL_API unsigned DLL_CALLCONV FreeImage_GetTransparencyCount(FIBITMAP *dib);
|
51
|
+
attach_function('FreeImage_GetTransparencyCount', [:pointer], :ulong)
|
52
|
+
|
53
|
+
#DLL_API void DLL_CALLCONV FreeImage_SetTransparent(FIBITMAP *dib, BOOL enabled);
|
54
|
+
attach_function('FreeImage_SetTransparent', [:pointer, FreeImage::Boolean], :void)
|
55
|
+
|
56
|
+
#DLL_API BOOL DLL_CALLCONV FreeImage_IsTransparent(FIBITMAP *dib);
|
57
|
+
attach_function('FreeImage_IsTransparent', [:pointer], FreeImage::Boolean)
|
58
|
+
|
59
|
+
#DLL_API void DLL_CALLCONV FreeImage_SetTransparentIndex(FIBITMAP *dib, int index);
|
60
|
+
attach_function('FreeImage_SetTransparentIndex', [:pointer, :int], :void)
|
61
|
+
|
62
|
+
#DLL_API int DLL_CALLCONV FreeImage_GetTransparentIndex(FIBITMAP *dib);
|
63
|
+
attach_function('FreeImage_GetTransparentIndex', [:pointer], :int)
|
64
|
+
|
65
|
+
#DLL_API BOOL DLL_CALLCONV FreeImage_HasBackgroundColor(FIBITMAP *dib);
|
66
|
+
attach_function('FreeImage_HasBackgroundColor', [:pointer], FreeImage::Boolean)
|
67
|
+
|
68
|
+
#DLL_API BOOL DLL_CALLCONV FreeImage_GetBackgroundColor(FIBITMAP *dib, RGBQUAD *bkcolor);
|
69
|
+
attach_function('FreeImage_GetBackgroundColor', [:pointer, :pointer], FreeImage::Boolean)
|
70
|
+
|
71
|
+
# DLL_API BOOL DLL_CALLCONV FreeImage_SetBackgroundColor(FIBITMAP *dib, RGBQUAD *bkcolor);
|
72
|
+
attach_function('FreeImage_SetBackgroundColor', [:pointer, :pointer], FreeImage::Boolean)
|
73
|
+
|
74
|
+
# Once a bitmap is loaded into memory, you can use the following methods to
|
75
|
+
# retrieve information about is type, dimensions, colors, etc.
|
76
|
+
module Information
|
77
|
+
|
78
|
+
# Returns the background color of a bitmap. For 8-bit images, the color index
|
79
|
+
# in the palette is returned in the rgbReserved member of the bkcolor parameter.
|
80
|
+
def background_color
|
81
|
+
ptr = FFI::MemoryPointer.new(:pointer)
|
82
|
+
FreeImage.FreeImage_GetBackgroundColor(self, ptr)
|
83
|
+
FreeImage.check_last_error
|
84
|
+
RGBQuad.new(ptr)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Set the background color of a bitmap. The color should be an instance
|
88
|
+
# of RGBQuad.
|
89
|
+
#
|
90
|
+
# When saving an image to PNG, this background
|
91
|
+
# color is transparently saved to the PNG file. When the bkcolor parameter is nil,
|
92
|
+
# the background color is removed from the image.
|
93
|
+
def background_color=(value)
|
94
|
+
result = FreeImage.FreeImage_GetBackgroundColor(self, value)
|
95
|
+
FreeImage.check_last_error
|
96
|
+
if !result
|
97
|
+
raise(RuntimeError, "Could not save background color")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Returns the size of one pixel in the bitmap in bits. For example if each
|
102
|
+
# pixel takes 32-bits of space in the bitmap, this function returns 32.
|
103
|
+
# Possible bit depths are 1, 4, 8, 16, 24, 32 for standard bitmaps and
|
104
|
+
# 16-, 32-, 48-, 64-, 96- and 128-bit for non standard bitmaps
|
105
|
+
def bits_per_pixel
|
106
|
+
result = FreeImage.FreeImage_GetBPP(self)
|
107
|
+
FreeImage.check_last_error
|
108
|
+
result
|
109
|
+
end
|
110
|
+
alias :bpp :bits_per_pixel
|
111
|
+
|
112
|
+
# Returns a bit pattern describing the blue color component of a pixel in a bitmap.
|
113
|
+
def blue_mask
|
114
|
+
result = FreeImage.FreeImage_GetBlueMask(self)
|
115
|
+
FreeImage.check_last_error
|
116
|
+
result
|
117
|
+
end
|
118
|
+
|
119
|
+
def color_type
|
120
|
+
result = FreeImage.FreeImage_GetColorType(self)
|
121
|
+
FreeImage.check_last_error
|
122
|
+
result
|
123
|
+
end
|
124
|
+
|
125
|
+
# Returns the size of the DIB-element of a bitmap in memory, which is the
|
126
|
+
# header size + palette size + data bits. Note that this is not the real
|
127
|
+
# size of a bitmap, just the size of its DIB-element.
|
128
|
+
def dib_size
|
129
|
+
result = FreeImage.FreeImage_GetDIBSize(self)
|
130
|
+
FreeImage.check_last_error
|
131
|
+
result
|
132
|
+
end
|
133
|
+
|
134
|
+
# Returns the horizontal resolution, in pixels-per-meter,
|
135
|
+
# of the target device for the bitmap.
|
136
|
+
def dots_per_meter_x
|
137
|
+
result = FreeImage.FreeImage_GetDotsPerMeterX(self)
|
138
|
+
FreeImage.check_last_error
|
139
|
+
result
|
140
|
+
end
|
141
|
+
|
142
|
+
# Sets the horizontal resolution, in pixels-per-meter,
|
143
|
+
# of the target device for the bitmap.
|
144
|
+
def dots_per_meter_x=(value)
|
145
|
+
result = FreeImage.FreeImage_SetDotsPerMeterX(self, value)
|
146
|
+
FreeImage.check_last_error
|
147
|
+
result
|
148
|
+
end
|
149
|
+
|
150
|
+
# Returns the vertical resolution, in pixels-per-meter,
|
151
|
+
# of the target device for the bitmap.
|
152
|
+
def dots_per_meter_y
|
153
|
+
result = FreeImage.FreeImage_GetDotsPerMeterY(self)
|
154
|
+
FreeImage.check_last_error
|
155
|
+
result
|
156
|
+
end
|
157
|
+
|
158
|
+
# Sets the vertical resolution, in pixels-per-meter,
|
159
|
+
# of the target device for the bitmap.
|
160
|
+
def dots_per_meter_y=(value)
|
161
|
+
result = FreeImage.FreeImage_SetDotsPerMeterY(self, value)
|
162
|
+
FreeImage.check_last_error
|
163
|
+
result
|
164
|
+
end
|
165
|
+
|
166
|
+
# Returns a bit pattern describing the green color component of a pixel in a bitmap.
|
167
|
+
def green_mask
|
168
|
+
result = FreeImage.FreeImage_GetGreenMask(self)
|
169
|
+
FreeImage.check_last_error
|
170
|
+
result
|
171
|
+
end
|
172
|
+
|
173
|
+
# Returns true when the image has a file background color, false otherwise
|
174
|
+
def has_background_color
|
175
|
+
result = FreeImage.FreeImage_HasBackgroundColor(self)
|
176
|
+
FreeImage.check_last_error
|
177
|
+
result
|
178
|
+
end
|
179
|
+
|
180
|
+
# Returns true if the bitmap contains pixel data, otherwise false. Bitmaps
|
181
|
+
# can be loaded using the FIF_LOAD_NOPIXELS load flag whic tells the decoder
|
182
|
+
# to read header data and available metadata and skip pixel data decoding.
|
183
|
+
# This reduces memory usage and load speed.
|
184
|
+
def has_pixels
|
185
|
+
result = FreeImage.FreeImage_HasPixels(self)
|
186
|
+
FreeImage.check_last_error
|
187
|
+
result
|
188
|
+
end
|
189
|
+
|
190
|
+
# Returns the height of the bitmap in pixel units
|
191
|
+
def height
|
192
|
+
result = FreeImage.FreeImage_GetHeight(self)
|
193
|
+
FreeImage.check_last_error
|
194
|
+
result
|
195
|
+
end
|
196
|
+
|
197
|
+
# Returns the {image type}[rdoc-ref:FreeImage.image_types] of a bitmap.
|
198
|
+
def image_type
|
199
|
+
result = FreeImage.FreeImage_GetImageType(self)
|
200
|
+
FreeImage.check_last_error
|
201
|
+
result
|
202
|
+
end
|
203
|
+
|
204
|
+
# Returns the width of the bitmap in bytes. See also FreeImage::Information.pitch.
|
205
|
+
# There has been some criticism on the name of this function. Some people expect it to
|
206
|
+
# return a scanline in the pixel data, while it actually returns the width of the bitmap in
|
207
|
+
# bytes. As far as I know the term Line is common terminology for the width of a bitmap
|
208
|
+
# in bytes. It is at least used by Microsoft DirectX.
|
209
|
+
def line
|
210
|
+
result = FreeImage.FreeImage_GetLine(self)
|
211
|
+
FreeImage.check_last_error
|
212
|
+
result
|
213
|
+
end
|
214
|
+
|
215
|
+
# Returns a bitmap's palette. If the bitmap doesn’t have a palette (i.e. when the
|
216
|
+
# pixel bit depth is greater than 8), this return nil.
|
217
|
+
def palette
|
218
|
+
@palette ||= Palette.new(self)
|
219
|
+
end
|
220
|
+
|
221
|
+
# Returns the width of the bitmap in bytes, rounded to the next 32-bit boundary,
|
222
|
+
# also known as pitch or stride or scan width.
|
223
|
+
# In FreeImage each scanline starts at a 32-bit boundary for performance reasons.
|
224
|
+
# This accessor is essential when using low level {pixel manipulation}[rdoc-ref:FreeImage::Pixels]
|
225
|
+
# functions.
|
226
|
+
def pitch
|
227
|
+
result = FreeImage.FreeImage_GetPitch(self)
|
228
|
+
FreeImage.check_last_error
|
229
|
+
result
|
230
|
+
end
|
231
|
+
|
232
|
+
# Returns a bit pattern describing the red color component of a pixel in a bitmap.
|
233
|
+
def red_mask
|
234
|
+
result = FreeImage.FreeImage_GetRedMask(self)
|
235
|
+
FreeImage.check_last_error
|
236
|
+
result
|
237
|
+
end
|
238
|
+
|
239
|
+
# Returns the number of transparent colors in a palletized bitmap,
|
240
|
+
# otherwise returns 0.
|
241
|
+
def transparency_count
|
242
|
+
result = FreeImage.FreeImage_GetTransparencyCount(self)
|
243
|
+
FreeImage.check_last_error
|
244
|
+
result
|
245
|
+
end
|
246
|
+
|
247
|
+
# Returns true if the transparency table is enabled (1-, 4- or 8-bit images) or
|
248
|
+
# when the input dib contains alpha values (32-bit images, RGBA16 or RGBAF images).
|
249
|
+
# Returns false otherwise.
|
250
|
+
def transparent
|
251
|
+
result = FreeImage.FreeImage_IsTransparent(self)
|
252
|
+
FreeImage.check_last_error
|
253
|
+
result
|
254
|
+
end
|
255
|
+
|
256
|
+
# Tells FreeImage if it should make use of the transparency table or the alpha
|
257
|
+
# channel that may accompany a bitmap. When calling this function with a
|
258
|
+
# bitmap whose bitdepth is different from 1-, 4-, 8- or 32-bit, transparency
|
259
|
+
# is disabled whatever the value of the Boolean parameter.
|
260
|
+
def transparent=(value)
|
261
|
+
result = FreeImage.FreeImage_SetTransparent(self, value)
|
262
|
+
FreeImage.check_last_error
|
263
|
+
result
|
264
|
+
end
|
265
|
+
|
266
|
+
# Returns the palette entry used as transparent color for the image specified.
|
267
|
+
# Works for palletised images only and returns -1 for high color images or
|
268
|
+
# if the image has no color set to be transparent.
|
269
|
+
# Although it is possible for palletised images to have more than one transparent
|
270
|
+
# color, this function always returns the index of the first palette entry,
|
271
|
+
# set to be transparent.
|
272
|
+
def transparent_index
|
273
|
+
result = FreeImage.FreeImage_GetTransparentIndex(self)
|
274
|
+
FreeImage.check_last_error
|
275
|
+
result
|
276
|
+
end
|
277
|
+
|
278
|
+
# Sets the index of the palette entry to be used as transparent color for
|
279
|
+
# the image specified. This works on palletised images only and does nothing
|
280
|
+
# for high color images.
|
281
|
+
#
|
282
|
+
# Although it is possible for palletised images to have more than one transparent
|
283
|
+
# color, this method sets the palette entry specified as the single transparent
|
284
|
+
# color for the image. All other colors will be set to be non-transparent by this method.
|
285
|
+
#
|
286
|
+
# As with FreeImage::Bitmap.transparency_table=, this method also sets the
|
287
|
+
# image's transparency property to true for palletised images.
|
288
|
+
def transparent_index=(value)
|
289
|
+
result = FreeImage.FreeImage_SetTransparentIndex(self, value)
|
290
|
+
FreeImage.check_last_error
|
291
|
+
result
|
292
|
+
end
|
293
|
+
|
294
|
+
# #DLL_API BOOL DLL_CALLCONV FreeImage_HasBackgroundColor(FIBITMAP *dib);
|
295
|
+
# attach_function('FreeImage_HasBackgroundColor', [:pointer], FreeImage::Boolean)
|
296
|
+
#
|
297
|
+
|
298
|
+
# Returns the width of the bitmap in pixel units
|
299
|
+
def width
|
300
|
+
result = FreeImage.FreeImage_GetWidth(self)
|
301
|
+
FreeImage.check_last_error
|
302
|
+
result
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
@@ -0,0 +1,261 @@
|
|
1
|
+
module FreeImage
|
2
|
+
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Copy(FIBITMAP *dib, int left, int top, int right, int bottom);
|
3
|
+
attach_function('FreeImage_Copy', [:pointer, :int, :int, :int, :int], :pointer)
|
4
|
+
|
5
|
+
#DLL_API BOOL DLL_CALLCONV FreeImage_Paste(FIBITMAP *dst, FIBITMAP *src, int left, int top, int alpha);
|
6
|
+
attach_function('FreeImage_Paste', [:pointer, :pointer, :int, :int, :int], FreeImage::Boolean)
|
7
|
+
|
8
|
+
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Composite(FIBITMAP *fg, BOOL useFileBkg FI_DEFAULT(FALSE), RGBQUAD *appBkColor FI_DEFAULT(NULL), FIBITMAP *bg FI_DEFAULT(NULL));
|
9
|
+
attach_function('FreeImage_Composite', [:pointer, FreeImage::Boolean, FreeImage::RGBQuad, :pointer], :pointer)
|
10
|
+
|
11
|
+
#DLL_API BOOL DLL_CALLCONV FreeImage_PreMultiplyWithAlpha(FIBITMAP *dib);
|
12
|
+
#attach_function('FreeImage_PreMultiplyWithAlpha', [:pointer, :int, :int, :int, :int], FreeImage::Boolean)
|
13
|
+
|
14
|
+
# DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Rescale(FIBITMAP *dib, int dst_width, int dst_height, FREE_IMAGE_FILTER filter);
|
15
|
+
attach_function('FreeImage_Rescale', [:pointer, :int, :int, :filter], :pointer)
|
16
|
+
|
17
|
+
# DLL_API FIBITMAP *DLL_CALLCONV FreeImage_MakeThumbnail(FIBITMAP *dib, int max_pixel_size, BOOL convert FI_DEFAULT(TRUE));
|
18
|
+
attach_function('FreeImage_MakeThumbnail', [:pointer, :int, FreeImage::Boolean], :pointer)
|
19
|
+
|
20
|
+
#DLL_API BOOL DLL_CALLCONV FreeImage_FillBackground(FIBITMAP *dib, const void *color, int options FI_DEFAULT(0));
|
21
|
+
attach_function('FreeImage_FillBackground', [:pointer, :pointer, :int], FreeImage::Boolean)
|
22
|
+
|
23
|
+
#DLL_API FIBITMAP *DLL_CALLCONV FreeImage_EnlargeCanvas(FIBITMAP *src, int left, int top, int right, int bottom, const void *color, int options FI_DEFAULT(0));
|
24
|
+
attach_function('FreeImage_EnlargeCanvas', [:pointer, :int, :int, :int, :int, :pointer, :int], :pointer)
|
25
|
+
|
26
|
+
# Background Filling Options
|
27
|
+
|
28
|
+
# RGBQUAD color is a RGB color (contains no valid alpha channel)
|
29
|
+
COLOR_IS_RGB_COLOR = 0x00
|
30
|
+
|
31
|
+
# RGBQUAD color is a RGBA color (contains a valid alpha channel)
|
32
|
+
COLOR_IS_RGBA_COLOR = 0x01
|
33
|
+
|
34
|
+
# For palettized images: lookup equal RGB color from palette
|
35
|
+
COLOR_FIND_EQUAL_COLOR = 0x02
|
36
|
+
|
37
|
+
# The color's rgbReserved member (alpha) contains the palette index to be used
|
38
|
+
COLOR_ALPHA_IS_INDEX = 0x04
|
39
|
+
|
40
|
+
# No color lookup is performed
|
41
|
+
COLOR_PALETTE_SEARCH_MASK = (COLOR_FIND_EQUAL_COLOR | COLOR_ALPHA_IS_INDEX)
|
42
|
+
|
43
|
+
# The \Modify module provides methods that can copy, paste, composite,
|
44
|
+
# and enlarge images. It also allows the creation of thumbnails and
|
45
|
+
# filling background colors.
|
46
|
+
#
|
47
|
+
module Modify
|
48
|
+
# Composites a transparent foreground image against a background image.
|
49
|
+
# The equation for computing a composited sample value is:
|
50
|
+
#
|
51
|
+
# output = alpha * foreground + (1-alpha) * background
|
52
|
+
#
|
53
|
+
# Where alpha and the input and output sample values are expressed as fractions
|
54
|
+
# in the range 0 to 1. For color images, the computation is done separately
|
55
|
+
# for R, G, and B samples.
|
56
|
+
def composite(background_bitmap)
|
57
|
+
ptr = FreeImage.FreeImage_Composite(self, false, nil, background_bitmap)
|
58
|
+
FreeImage.check_last_error
|
59
|
+
self.class.new(ptr)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Composites a transparent foreground image against a background color.
|
63
|
+
# The equation for computing a composited sample value is:
|
64
|
+
#
|
65
|
+
# output = alpha * foreground + (1-alpha) * background
|
66
|
+
#
|
67
|
+
# Where alpha and the input and output sample values are expressed as fractions
|
68
|
+
# in the range 0 to 1. For color images, the computation is done separately
|
69
|
+
# for R, G, and B samples.
|
70
|
+
def composite_with_color(background_color)
|
71
|
+
ptr = FreeImage.FreeImage_Composite(self, false, background_color, nil)
|
72
|
+
FreeImage.check_last_error
|
73
|
+
self.class.new(ptr)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Copy a subpart of the current image. The rectangle defined by the
|
77
|
+
# left, top, right, bottom parameters is first normalized such that the
|
78
|
+
# value of the left coordinate is less than the right and the top is less
|
79
|
+
# than the bottom. Then, the returned bitmap is defined by a width equal to
|
80
|
+
# (right - left) and a height equal to (bottom - top).
|
81
|
+
#
|
82
|
+
# The function returns the subimage if successful and returns nil otherwise.
|
83
|
+
def copy(left, top, right, bottom)
|
84
|
+
ptr = FreeImage.FreeImage_Copy(self, left, top, right, bottom)
|
85
|
+
FreeImage.check_last_error
|
86
|
+
self.class.new(ptr)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Enlarges or shrinks an image selectively per side and fills newly added areas with the
|
90
|
+
# specified background color. The common use case is to add borders to an image.
|
91
|
+
#
|
92
|
+
# To add a border to any of the image's sides, a positive integer value must be passed in
|
93
|
+
# any of the parameters left, top, right or bottom. This value represents the border's
|
94
|
+
# width in pixels. Newly created parts of the image (the border areas)
|
95
|
+
# are filled with the specified color.
|
96
|
+
#
|
97
|
+
# Specifying a negative integer value for a certain side, will shrink or crop the image on
|
98
|
+
# this side. Consequently, specifying zero for a certain side will not
|
99
|
+
# change the image's extension on that side.
|
100
|
+
#
|
101
|
+
# For palletized images, the palette of the current image src is transparently
|
102
|
+
# copied to the newly created enlarged or shrunken image, so any color look-ups
|
103
|
+
# are performed on this palette.
|
104
|
+
#
|
105
|
+
# == Parameters:
|
106
|
+
#
|
107
|
+
# left:: The number of pixels the image should be enlarged on its left side. Negative
|
108
|
+
# values shrink the image on its left side.
|
109
|
+
# top:: The number of pixels the image should be enlarged on its top side. Negative
|
110
|
+
# values shrink the image on its top side.
|
111
|
+
# right:: The number of pixels the image should be enlarged on its right side. Negative
|
112
|
+
# values shrink the image on its right side.
|
113
|
+
# bottom:: The number of pixels, the image should be enlarged on its bottom side.
|
114
|
+
# Negative values shrink the image on its bottom side.
|
115
|
+
# color:: The color value to be used for filling the image. See #fill_background for
|
116
|
+
# more details.
|
117
|
+
# options:: Used to control color search process for palletized images. See
|
118
|
+
# #fill_background for more details.
|
119
|
+
#
|
120
|
+
# Returns a new image on success or nil.
|
121
|
+
#
|
122
|
+
def enlarge_canvas(left, top, right, bottom, color, options = 0)
|
123
|
+
ptr = FreeImage.FreeImage_EnlargeCanvas(self, left, top, right, bottom, color, options)
|
124
|
+
FreeImage.check_last_error
|
125
|
+
self.class.new(ptr)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Sets all pixels of an image to the specified color.
|
129
|
+
#
|
130
|
+
# == Parameters:
|
131
|
+
#
|
132
|
+
# color:: The color value to be used for filling the image.
|
133
|
+
#
|
134
|
+
# The type of the color parameter depends on the
|
135
|
+
# {image type}[rdoc-ref:FreeImage.image_types]
|
136
|
+
#
|
137
|
+
# bitmap:: RGBQuad
|
138
|
+
# rgb16:: RGB16
|
139
|
+
# rgba16:: RGBA16
|
140
|
+
# rgbf:: RGBF
|
141
|
+
# rgbaf:: RGBFA
|
142
|
+
# complex:: Complex
|
143
|
+
# others:: A value of the specific type (double, int, etc.).
|
144
|
+
#
|
145
|
+
# options:: Used to control color search process for palletized images.
|
146
|
+
# Allowed values are defined as constants on the FreeImage
|
147
|
+
# module and include:
|
148
|
+
# COLOR_IS_RGB_COLOR = 0x00
|
149
|
+
# COLOR_IS_RGBA_COLOR = 0x01
|
150
|
+
# COLOR_FIND_EQUAL_COLOR = 0x02
|
151
|
+
# COLOR_ALPHA_IS_INDEX = 0x04
|
152
|
+
# COLOR_PALETTE_SEARCH_MASK = (FI_COLOR_FIND_EQUAL_COLOR | FI_COLOR_ALPHA_IS_INDEX)
|
153
|
+
#
|
154
|
+
# Returns true on success, false on failure.
|
155
|
+
#
|
156
|
+
def fill_background!(color, options = 0)
|
157
|
+
result = FreeImage.FreeImage_FillBackground(self, color, options)
|
158
|
+
FreeImage.check_last_error
|
159
|
+
result
|
160
|
+
end
|
161
|
+
|
162
|
+
# :call-seq:
|
163
|
+
# bitmap.make_thumbnail(max_pixel_size, convert = true) -> bitmap
|
164
|
+
#
|
165
|
+
# Creates a thumbnail image that fits inside a square of size max_pixel_size,
|
166
|
+
# keeping the original aspect ratio intact. Downsampling is done using a bilinear
|
167
|
+
# {filter}[rdoc-ref:FreeImage::Sampling.rescale].
|
168
|
+
#
|
169
|
+
# == Parameters:
|
170
|
+
#
|
171
|
+
# max_pixel_size:: The maximum width/height of the returned image
|
172
|
+
# convert:: When set to true, High Dynamic Range images (FIT_UINT16,
|
173
|
+
# FIT_RGB16, FIT_RGBA16, FIT_FLOAT) are transparently converted
|
174
|
+
# to standard images (i.e. 8-, 24 or 32-bit images). The
|
175
|
+
# default value is true.
|
176
|
+
#
|
177
|
+
def make_thumbnail(max_pixel_size, convert = true)
|
178
|
+
ptr = FreeImage.FreeImage_MakeThumbnail(self, max_pixel_size, convert)
|
179
|
+
FreeImage.check_last_error
|
180
|
+
self.class.new(ptr)
|
181
|
+
end
|
182
|
+
|
183
|
+
# Combines or blends a subpart of another image with the current image.
|
184
|
+
#
|
185
|
+
# == Parameters:
|
186
|
+
#
|
187
|
+
# other:: Source subimage
|
188
|
+
# left:: Specifies the left position of the sub image.
|
189
|
+
# top:: Specifies the top position of the sub image.
|
190
|
+
# alpha:: Alpha blend factor. If alpha is 0..255, the other images is
|
191
|
+
# alpha blended withe current image. If alpha > 255, then
|
192
|
+
# the other image is combined to the current image.
|
193
|
+
#
|
194
|
+
# The function returns true if successful, otherwise false.
|
195
|
+
#
|
196
|
+
def paste!(other, left, top, alpha)
|
197
|
+
result = FreeImage.FreeImage_Paste(self, other, left, top, alpha)
|
198
|
+
FreeImage.check_last_error
|
199
|
+
result
|
200
|
+
end
|
201
|
+
|
202
|
+
# :call-seq:
|
203
|
+
# bitmap.rescale(width, height, filter) -> bitmap
|
204
|
+
#
|
205
|
+
# Resamples an image to the desired width and height. Resampling changes the
|
206
|
+
# pixel dimensions (and therefore display size) of an image.
|
207
|
+
# When you downsample (or decrease the number of pixels), information is deleted from
|
208
|
+
# the image. When you upsample (or increase the number of pixels), new pixels are
|
209
|
+
# added based on color values of existing pixels. You can specify an interpolation
|
210
|
+
# filter to determine how pixels are added or deleted using the filter parameter.
|
211
|
+
#
|
212
|
+
# Returns the newly resample image or nil if the image cannot be resampled.
|
213
|
+
#
|
214
|
+
# == Parameters:
|
215
|
+
#
|
216
|
+
# width:: The width of the new image
|
217
|
+
# height:: The height of the new image
|
218
|
+
# filter:: The filter to use when rescaling
|
219
|
+
#
|
220
|
+
# Filter options include:
|
221
|
+
#
|
222
|
+
# :box:: The simplest and fastest of the scaling algorithms. The technique achieves
|
223
|
+
# magnification by pixel replication, and minification by sparse point sampling.
|
224
|
+
# For large-scale changes, box interpolation produces images with a
|
225
|
+
# blocky appearance. In addition, shift errors of up to one-half pixel are
|
226
|
+
# possible. These problems make this technique inappropriate when
|
227
|
+
# sub-pixel accuracy is required.
|
228
|
+
#
|
229
|
+
# :bicubic:: An advanced parameterized scaling filter. It uses a cubic
|
230
|
+
# to produce very smooth output while maintaining dynamic range
|
231
|
+
# and sharpness. Bicubic scaling takes approximately twice the
|
232
|
+
# processing time as Bilinear. This filter can be used for any
|
233
|
+
# scaling application, especially when scaling factors are 2X
|
234
|
+
# or greater.
|
235
|
+
#
|
236
|
+
# :bilinear:: The second-fastest scaling function. It employs linear interpolation
|
237
|
+
# to determine the output image. Bilinear scaling provides reasonably
|
238
|
+
# good results at moderate cost for most applications where scale
|
239
|
+
# factors are relatively small (4X or less).
|
240
|
+
#
|
241
|
+
# :bspline:: Produces the smoothest output, but tends to smooth over fine details.
|
242
|
+
# This function requires the same processing time as :bicubic filter.
|
243
|
+
# It is recommended for applications where the smoothest output is required.
|
244
|
+
#
|
245
|
+
# :catmullrom:: The Catmull-Rom filter is generally accepted as the best cubic interpolant filter.
|
246
|
+
#
|
247
|
+
# :lanczos3:: A sinc based filter. It is the most theoretically correct filter
|
248
|
+
# that produces the best output for photographic images that do not have
|
249
|
+
# sharp transitions in them. However, Lanczos will produce ripple artefacts
|
250
|
+
# especially for block text, due to aliasing. It requires three times the
|
251
|
+
# processing time of Bilinear. Lanczos is not recommended except in very
|
252
|
+
# rare applications using band-limited photographic images with
|
253
|
+
# no sharp edges.
|
254
|
+
#
|
255
|
+
def rescale(width, height, filter = :bilinear)
|
256
|
+
ptr = FreeImage.FreeImage_Rescale(self, width, height, filter)
|
257
|
+
FreeImage.check_last_error
|
258
|
+
self.class.new(ptr)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|