free-image 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/HISTORY +30 -19
  3. data/LICENSE +20 -20
  4. data/README.rdoc +120 -120
  5. data/Rakefile +51 -47
  6. data/cookbook.rdoc +248 -237
  7. data/free-image.gemspec +30 -29
  8. data/lib/free-image.rb +1 -2
  9. data/lib/free-image/bitmap.rb +2 -2
  10. data/lib/free-image/enums/filters.rb +11 -11
  11. data/lib/free-image/errors.rb +43 -43
  12. data/lib/free-image/modules/conversions.rb +253 -253
  13. data/lib/free-image/modules/helper.rb +41 -41
  14. data/lib/free-image/modules/information.rb +20 -2
  15. data/lib/free-image/modules/modify.rb +299 -299
  16. data/lib/free-image/modules/pixels.rb +134 -134
  17. data/lib/free-image/modules/transforms.rb +90 -90
  18. data/lib/free-image/sources/abstract_source.rb +178 -178
  19. data/lib/free-image/sources/file.rb +114 -114
  20. data/lib/free-image/sources/io.rb +153 -153
  21. data/lib/free-image/sources/memory.rb +188 -188
  22. data/lib/free-image/types/boolean.rb +13 -13
  23. data/lib/free-image/types/ffi.rb +13 -13
  24. data/lib/free-image/types/info_header.rb +36 -0
  25. data/lib/free-image/types/rgb16.rb +31 -0
  26. data/test/cookbook.rb +45 -46
  27. data/test/images/sample_composite.png +0 -0
  28. data/test/images/test16.bmp +0 -0
  29. data/test/images/test16bf555.bmp +0 -0
  30. data/test/images/test16bf565.bmp +0 -0
  31. data/test/test_bitmap.rb +61 -63
  32. data/test/test_conversions.rb +85 -86
  33. data/test/test_file.rb +68 -69
  34. data/test/test_free_image.rb +14 -15
  35. data/test/test_helper.rb +14 -0
  36. data/test/test_information.rb +145 -117
  37. data/test/test_io.rb +73 -74
  38. data/test/test_memory.rb +83 -84
  39. data/test/test_modify.rb +75 -58
  40. data/test/test_palette.rb +44 -45
  41. data/test/test_pixels.rb +61 -62
  42. data/test/test_rgb_quad.rb +24 -25
  43. data/test/test_scanline.rb +64 -65
  44. data/test/test_suite.rb +12 -17
  45. data/test/test_transforms.rb +28 -29
  46. metadata +58 -31
@@ -1,42 +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
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
42
  end
@@ -47,6 +47,12 @@ module FreeImage
47
47
  #DLL_API unsigned DLL_CALLCONV FreeImage_GetGreenMask(FIBITMAP *dib);
48
48
  attach_function('FreeImage_GetGreenMask', [:pointer], :ulong)
49
49
 
50
+ #DLL_API BITMAPINFOHEADER DLL_CALLCONV FreeImage_GetInfoHeader(FIBITMAP *dib);
51
+ attach_function('FreeImage_GetInfoHeader', [:pointer], FreeImage::InfoHeader)
52
+
53
+ #DLL_API BOOL DLL_CALLCONV FreeImage_hasRGBMasks(FIBITMAP *dib);
54
+ attach_function('FreeImage_HasRGBMasks', [:pointer], FreeImage::Boolean)
55
+
50
56
  #DLL_API unsigned DLL_CALLCONV FreeImage_GetTransparencyCount(FIBITMAP *dib);
51
57
  attach_function('FreeImage_GetTransparencyCount', [:pointer], :ulong)
52
58
 
@@ -186,7 +192,13 @@ module FreeImage
186
192
  FreeImage.check_last_error
187
193
  result
188
194
  end
189
-
195
+
196
+ def has_rgb_masks
197
+ result = FreeImage.FreeImage_HasRGBMasks(self)
198
+ FreeImage.check_last_error
199
+ result
200
+ end
201
+
190
202
  # Returns the height of the bitmap in pixel units
191
203
  def height
192
204
  result = FreeImage.FreeImage_GetHeight(self)
@@ -200,7 +212,13 @@ module FreeImage
200
212
  FreeImage.check_last_error
201
213
  result
202
214
  end
203
-
215
+
216
+ def info_header
217
+ result = FreeImage::InfoHeader.new(FreeImage.FreeImage_GetInfoHeader(self))
218
+ FreeImage.check_last_error
219
+ result
220
+ end
221
+
204
222
  # Returns the width of the bitmap in bytes. See also FreeImage::Information.pitch.
205
223
  # There has been some criticism on the name of this function. Some people expect it to
206
224
  # return a scanline in the pixel data, while it actually returns the width of the bitmap in
@@ -1,300 +1,300 @@
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
- # :call-seq:
49
- # image.composite(background_bitmap) -> bitmap
50
- # image.composite(background_bitmap) {|img| block} -> bitmap
51
- #
52
- # Composites a transparent foreground image against a background image.
53
- # The equation for computing a composited sample value is:
54
- #
55
- # output = alpha * foreground + (1-alpha) * background
56
- #
57
- # Where alpha and the input and output sample values are expressed as fractions
58
- # in the range 0 to 1. For color images, the computation is done separately
59
- # for R, G, and B samples.
60
- #
61
- # If an optional block is provided, it will be passed the new image as an argument. The
62
- # image will be automatically closed when the block completes.
63
- #
64
- def composite(background_bitmap, &block)
65
- ptr = FreeImage.FreeImage_Composite(self, false, nil, background_bitmap)
66
- FreeImage.check_last_error
67
- self.class.new(ptr, &block)
68
- end
69
-
70
- # :call-seq:
71
- # image.composite_with_color(background_color) -> bitmap
72
- # image.composite_with_color(background_color) {|img| block} -> bitmap
73
- #
74
- # Composites a transparent foreground image against a background color.
75
- # The equation for computing a composited sample value is:
76
- #
77
- # output = alpha * foreground + (1-alpha) * background
78
- #
79
- # Where alpha and the input and output sample values are expressed as fractions
80
- # in the range 0 to 1. For color images, the computation is done separately
81
- # for R, G, and B samples.
82
- #
83
- # If an optional block is provided, it will be passed the new image as an argument. The
84
- # image will be automatically closed when the block completes.
85
- #
86
- def composite_with_color(background_color, &block)
87
- ptr = FreeImage.FreeImage_Composite(self, false, background_color, nil)
88
- FreeImage.check_last_error
89
- self.class.new(ptr, &block)
90
- end
91
-
92
- # :call-seq:
93
- # image.copy(left, top, right, bottom) -> bitmap
94
- # image.copy(left, top, right, bottom) {|img| block} -> bitmap
95
- #
96
- # Copy a subpart of the current image. The rectangle defined by the
97
- # left, top, right, bottom parameters is first normalized such that the
98
- # value of the left coordinate is less than the right and the top is less
99
- # than the bottom. Then, the returned bitmap is defined by a width equal to
100
- # (right - left) and a height equal to (bottom - top).
101
- #
102
- # If an optional block is provided, it will be passed the new image as an argument. The
103
- # image will be automatically closed when the block completes.
104
- #
105
- # The function returns the subimage if successful and othewise it returns nil.
106
- #
107
- def copy(left, top, right, bottom, &block)
108
- ptr = FreeImage.FreeImage_Copy(self, left, top, right, bottom)
109
- FreeImage.check_last_error
110
- self.class.new(ptr, &block)
111
- end
112
-
113
- # :call-seq:
114
- # image.enlarge_canvas(left, top, right, bottom, color, options = 0) -> bitmap
115
- # image.enlarge_canvas(left, top, right, bottom, color, options = 0) {|img| block} -> bitmap
116
- #
117
- # Enlarges or shrinks an image selectively per side and fills newly added areas with the
118
- # specified background color. The common use case is to add borders to an image.
119
- #
120
- # To add a border to any of the image's sides, a positive integer value must be passed in
121
- # any of the parameters left, top, right or bottom. This value represents the border's
122
- # width in pixels. Newly created parts of the image (the border areas)
123
- # are filled with the specified color.
124
- #
125
- # Specifying a negative integer value for a certain side, will shrink or crop the image on
126
- # this side. Consequently, specifying zero for a certain side will not
127
- # change the image's extension on that side.
128
- #
129
- # For palletized images, the palette of the current image src is transparently
130
- # copied to the newly created enlarged or shrunken image, so any color look-ups
131
- # are performed on this palette.
132
- #
133
- # == Parameters:
134
- #
135
- # left:: The number of pixels the image should be enlarged on its left side. Negative
136
- # values shrink the image on its left side.
137
- # top:: The number of pixels the image should be enlarged on its top side. Negative
138
- # values shrink the image on its top side.
139
- # right:: The number of pixels the image should be enlarged on its right side. Negative
140
- # values shrink the image on its right side.
141
- # bottom:: The number of pixels, the image should be enlarged on its bottom side.
142
- # Negative values shrink the image on its bottom side.
143
- # color:: The color value to be used for filling the image. See #fill_background for
144
- # more details.
145
- # options:: Used to control color search process for palletized images. See
146
- # #fill_background for more details.
147
- #
148
- # If an optional block is provided, it will be passed the new image as an argument. The
149
- # image will be automatically closed when the block completes.
150
- #
151
- # Returns a new image on success or nil.
152
- #
153
- def enlarge_canvas(left, top, right, bottom, color, options = 0, &block)
154
- ptr = FreeImage.FreeImage_EnlargeCanvas(self, left, top, right, bottom, color, options)
155
- FreeImage.check_last_error
156
- self.class.new(ptr, &block)
157
- end
158
-
159
- # Sets all pixels of an image to the specified color.
160
- #
161
- # == Parameters:
162
- #
163
- # color:: The color value to be used for filling the image.
164
- #
165
- # The type of the color parameter depends on the
166
- # {image type}[rdoc-ref:FreeImage.image_types]
167
- #
168
- # bitmap:: RGBQuad
169
- # rgb16:: RGB16
170
- # rgba16:: RGBA16
171
- # rgbf:: RGBF
172
- # rgbaf:: RGBFA
173
- # complex:: Complex
174
- # others:: A value of the specific type (double, int, etc.).
175
- #
176
- # options:: Used to control color search process for palletized images.
177
- # Allowed values are defined as constants on the FreeImage
178
- # module and include:
179
- # COLOR_IS_RGB_COLOR = 0x00
180
- # COLOR_IS_RGBA_COLOR = 0x01
181
- # COLOR_FIND_EQUAL_COLOR = 0x02
182
- # COLOR_ALPHA_IS_INDEX = 0x04
183
- # COLOR_PALETTE_SEARCH_MASK = (FI_COLOR_FIND_EQUAL_COLOR | FI_COLOR_ALPHA_IS_INDEX)
184
- #
185
- # Returns true on success, false on failure.
186
- #
187
- def fill_background!(color, options = 0)
188
- result = FreeImage.FreeImage_FillBackground(self, color, options)
189
- FreeImage.check_last_error
190
- result
191
- end
192
-
193
- # :call-seq:
194
- # bitmap.make_thumbnail(max_pixel_size, convert = true) -> bitmap
195
- # bitmap.make_thumbnail(max_pixel_size, convert = true) {|img| block} -> bitmap
196
- #
197
- # Creates a thumbnail image that fits inside a square of size max_pixel_size,
198
- # keeping the original aspect ratio intact. Downsampling is done using a bilinear
199
- # {filter}[rdoc-ref:FreeImage::Sampling.rescale].
200
- #
201
- # == Parameters:
202
- #
203
- # max_pixel_size:: The maximum width/height of the returned image
204
- # convert:: When set to true, High Dynamic Range images (FIT_UINT16,
205
- # FIT_RGB16, FIT_RGBA16, FIT_FLOAT) are transparently converted
206
- # to standard images (i.e. 8-, 24 or 32-bit images). The
207
- # default value is true.
208
- #
209
- # If an optional block is provided, it will be passed the new image as an argument. The
210
- # image will be automatically closed when the block completes.
211
- #
212
- def make_thumbnail(max_pixel_size, convert = true, &block)
213
- ptr = FreeImage.FreeImage_MakeThumbnail(self, max_pixel_size, convert)
214
- FreeImage.check_last_error
215
- self.class.new(ptr, &block)
216
- end
217
-
218
- # Combines or blends a subpart of another image with the current image.
219
- #
220
- # == Parameters:
221
- #
222
- # other:: Source subimage
223
- # left:: Specifies the left position of the sub image.
224
- # top:: Specifies the top position of the sub image.
225
- # alpha:: Alpha blend factor. If alpha is 0..255, the other images is
226
- # alpha blended withe current image. If alpha > 255, then
227
- # the other image is combined to the current image.
228
- #
229
- # The function returns true if successful, otherwise false.
230
- #
231
- def paste!(other, left, top, alpha)
232
- result = FreeImage.FreeImage_Paste(self, other, left, top, alpha)
233
- FreeImage.check_last_error
234
- result
235
- end
236
-
237
- # :call-seq:
238
- # bitmap.rescale(width, height, filter) -> bitmap
239
- # bitmap.rescale(width, height, filter) {|img| block} -> bitmap -> bitmap
240
- #
241
- # Resamples an image to the desired width and height. Resampling changes the
242
- # pixel dimensions (and therefore display size) of an image.
243
- # When you downsample (or decrease the number of pixels), information is deleted from
244
- # the image. When you upsample (or increase the number of pixels), new pixels are
245
- # added based on color values of existing pixels. You can specify an interpolation
246
- # filter to determine how pixels are added or deleted using the filter parameter.
247
- #
248
- # Returns the newly resample image or nil if the image cannot be resampled.
249
- #
250
- # == Parameters:
251
- #
252
- # width:: The width of the new image
253
- # height:: The height of the new image
254
- # filter:: The filter to use when rescaling
255
- #
256
- # Filter options include:
257
- #
258
- # :box:: The simplest and fastest of the scaling algorithms. The technique achieves
259
- # magnification by pixel replication, and minification by sparse point sampling.
260
- # For large-scale changes, box interpolation produces images with a
261
- # blocky appearance. In addition, shift errors of up to one-half pixel are
262
- # possible. These problems make this technique inappropriate when
263
- # sub-pixel accuracy is required.
264
- #
265
- # :bicubic:: An advanced parameterized scaling filter. It uses a cubic
266
- # to produce very smooth output while maintaining dynamic range
267
- # and sharpness. Bicubic scaling takes approximately twice the
268
- # processing time as Bilinear. This filter can be used for any
269
- # scaling application, especially when scaling factors are 2X
270
- # or greater.
271
- #
272
- # :bilinear:: The second-fastest scaling function. It employs linear interpolation
273
- # to determine the output image. Bilinear scaling provides reasonably
274
- # good results at moderate cost for most applications where scale
275
- # factors are relatively small (4X or less).
276
- #
277
- # :bspline:: Produces the smoothest output, but tends to smooth over fine details.
278
- # This function requires the same processing time as :bicubic filter.
279
- # It is recommended for applications where the smoothest output is required.
280
- #
281
- # :catmullrom:: The Catmull-Rom filter is generally accepted as the best cubic interpolant filter.
282
- #
283
- # :lanczos3:: A sinc based filter. It is the most theoretically correct filter
284
- # that produces the best output for photographic images that do not have
285
- # sharp transitions in them. However, Lanczos will produce ripple artefacts
286
- # especially for block text, due to aliasing. It requires three times the
287
- # processing time of Bilinear. Lanczos is not recommended except in very
288
- # rare applications using band-limited photographic images with
289
- # no sharp edges.
290
- #
291
- # If an optional block is provided, it will be passed the new image as an argument. The
292
- # image will be automatically closed when the block completes.
293
- #
294
- def rescale(width, height, filter = :bilinear, &block)
295
- ptr = FreeImage.FreeImage_Rescale(self, width, height, filter)
296
- FreeImage.check_last_error
297
- self.class.new(ptr, &block)
298
- end
299
- end
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
+ # :call-seq:
49
+ # image.composite(background_bitmap) -> bitmap
50
+ # image.composite(background_bitmap) {|img| block} -> bitmap
51
+ #
52
+ # Composites a transparent foreground image against a background image.
53
+ # The equation for computing a composited sample value is:
54
+ #
55
+ # output = alpha * foreground + (1-alpha) * background
56
+ #
57
+ # Where alpha and the input and output sample values are expressed as fractions
58
+ # in the range 0 to 1. For color images, the computation is done separately
59
+ # for R, G, and B samples.
60
+ #
61
+ # If an optional block is provided, it will be passed the new image as an argument. The
62
+ # image will be automatically closed when the block completes.
63
+ #
64
+ def composite(background_bitmap, &block)
65
+ ptr = FreeImage.FreeImage_Composite(self, false, nil, background_bitmap)
66
+ FreeImage.check_last_error
67
+ self.class.new(ptr, &block)
68
+ end
69
+
70
+ # :call-seq:
71
+ # image.composite_with_color(background_color) -> bitmap
72
+ # image.composite_with_color(background_color) {|img| block} -> bitmap
73
+ #
74
+ # Composites a transparent foreground image against a background color.
75
+ # The equation for computing a composited sample value is:
76
+ #
77
+ # output = alpha * foreground + (1-alpha) * background
78
+ #
79
+ # Where alpha and the input and output sample values are expressed as fractions
80
+ # in the range 0 to 1. For color images, the computation is done separately
81
+ # for R, G, and B samples.
82
+ #
83
+ # If an optional block is provided, it will be passed the new image as an argument. The
84
+ # image will be automatically closed when the block completes.
85
+ #
86
+ def composite_with_color(background_color, &block)
87
+ ptr = FreeImage.FreeImage_Composite(self, false, background_color, nil)
88
+ FreeImage.check_last_error
89
+ self.class.new(ptr, &block)
90
+ end
91
+
92
+ # :call-seq:
93
+ # image.copy(left, top, right, bottom) -> bitmap
94
+ # image.copy(left, top, right, bottom) {|img| block} -> bitmap
95
+ #
96
+ # Copy a subpart of the current image. The rectangle defined by the
97
+ # left, top, right, bottom parameters is first normalized such that the
98
+ # value of the left coordinate is less than the right and the top is less
99
+ # than the bottom. Then, the returned bitmap is defined by a width equal to
100
+ # (right - left) and a height equal to (bottom - top).
101
+ #
102
+ # If an optional block is provided, it will be passed the new image as an argument. The
103
+ # image will be automatically closed when the block completes.
104
+ #
105
+ # The function returns the subimage if successful and othewise it returns nil.
106
+ #
107
+ def copy(left, top, right, bottom, &block)
108
+ ptr = FreeImage.FreeImage_Copy(self, left, top, right, bottom)
109
+ FreeImage.check_last_error
110
+ self.class.new(ptr, &block)
111
+ end
112
+
113
+ # :call-seq:
114
+ # image.enlarge_canvas(left, top, right, bottom, color, options = 0) -> bitmap
115
+ # image.enlarge_canvas(left, top, right, bottom, color, options = 0) {|img| block} -> bitmap
116
+ #
117
+ # Enlarges or shrinks an image selectively per side and fills newly added areas with the
118
+ # specified background color. The common use case is to add borders to an image.
119
+ #
120
+ # To add a border to any of the image's sides, a positive integer value must be passed in
121
+ # any of the parameters left, top, right or bottom. This value represents the border's
122
+ # width in pixels. Newly created parts of the image (the border areas)
123
+ # are filled with the specified color.
124
+ #
125
+ # Specifying a negative integer value for a certain side, will shrink or crop the image on
126
+ # this side. Consequently, specifying zero for a certain side will not
127
+ # change the image's extension on that side.
128
+ #
129
+ # For palletized images, the palette of the current image src is transparently
130
+ # copied to the newly created enlarged or shrunken image, so any color look-ups
131
+ # are performed on this palette.
132
+ #
133
+ # == Parameters:
134
+ #
135
+ # left:: The number of pixels the image should be enlarged on its left side. Negative
136
+ # values shrink the image on its left side.
137
+ # top:: The number of pixels the image should be enlarged on its top side. Negative
138
+ # values shrink the image on its top side.
139
+ # right:: The number of pixels the image should be enlarged on its right side. Negative
140
+ # values shrink the image on its right side.
141
+ # bottom:: The number of pixels, the image should be enlarged on its bottom side.
142
+ # Negative values shrink the image on its bottom side.
143
+ # color:: The color value to be used for filling the image. See #fill_background for
144
+ # more details.
145
+ # options:: Used to control color search process for palletized images. See
146
+ # #fill_background for more details.
147
+ #
148
+ # If an optional block is provided, it will be passed the new image as an argument. The
149
+ # image will be automatically closed when the block completes.
150
+ #
151
+ # Returns a new image on success or nil.
152
+ #
153
+ def enlarge_canvas(left, top, right, bottom, color, options = 0, &block)
154
+ ptr = FreeImage.FreeImage_EnlargeCanvas(self, left, top, right, bottom, color, options)
155
+ FreeImage.check_last_error
156
+ self.class.new(ptr, &block)
157
+ end
158
+
159
+ # Sets all pixels of an image to the specified color.
160
+ #
161
+ # == Parameters:
162
+ #
163
+ # color:: The color value to be used for filling the image.
164
+ #
165
+ # The type of the color parameter depends on the
166
+ # {image type}[rdoc-ref:FreeImage.image_types]
167
+ #
168
+ # bitmap:: RGBQuad
169
+ # rgb16:: RGB16
170
+ # rgba16:: RGBA16
171
+ # rgbf:: RGBF
172
+ # rgbaf:: RGBFA
173
+ # complex:: Complex
174
+ # others:: A value of the specific type (double, int, etc.).
175
+ #
176
+ # options:: Used to control color search process for palletized images.
177
+ # Allowed values are defined as constants on the FreeImage
178
+ # module and include:
179
+ # COLOR_IS_RGB_COLOR = 0x00
180
+ # COLOR_IS_RGBA_COLOR = 0x01
181
+ # COLOR_FIND_EQUAL_COLOR = 0x02
182
+ # COLOR_ALPHA_IS_INDEX = 0x04
183
+ # COLOR_PALETTE_SEARCH_MASK = (FI_COLOR_FIND_EQUAL_COLOR | FI_COLOR_ALPHA_IS_INDEX)
184
+ #
185
+ # Returns true on success, false on failure.
186
+ #
187
+ def fill_background!(color, options = 0)
188
+ result = FreeImage.FreeImage_FillBackground(self, color, options)
189
+ FreeImage.check_last_error
190
+ result
191
+ end
192
+
193
+ # :call-seq:
194
+ # bitmap.make_thumbnail(max_pixel_size, convert = true) -> bitmap
195
+ # bitmap.make_thumbnail(max_pixel_size, convert = true) {|img| block} -> bitmap
196
+ #
197
+ # Creates a thumbnail image that fits inside a square of size max_pixel_size,
198
+ # keeping the original aspect ratio intact. Downsampling is done using a bilinear
199
+ # {filter}[rdoc-ref:FreeImage::Sampling.rescale].
200
+ #
201
+ # == Parameters:
202
+ #
203
+ # max_pixel_size:: The maximum width/height of the returned image
204
+ # convert:: When set to true, High Dynamic Range images (FIT_UINT16,
205
+ # FIT_RGB16, FIT_RGBA16, FIT_FLOAT) are transparently converted
206
+ # to standard images (i.e. 8-, 24 or 32-bit images). The
207
+ # default value is true.
208
+ #
209
+ # If an optional block is provided, it will be passed the new image as an argument. The
210
+ # image will be automatically closed when the block completes.
211
+ #
212
+ def make_thumbnail(max_pixel_size, convert = true, &block)
213
+ ptr = FreeImage.FreeImage_MakeThumbnail(self, max_pixel_size, convert)
214
+ FreeImage.check_last_error
215
+ self.class.new(ptr, &block)
216
+ end
217
+
218
+ # Combines or blends a subpart of another image with the current image.
219
+ #
220
+ # == Parameters:
221
+ #
222
+ # other:: Source subimage
223
+ # left:: Specifies the left position of the sub image.
224
+ # top:: Specifies the top position of the sub image.
225
+ # alpha:: Alpha blend factor. If alpha is 0..255, the other images is
226
+ # alpha blended withe current image. If alpha > 255, then
227
+ # the other image is combined to the current image.
228
+ #
229
+ # The function returns true if successful, otherwise false.
230
+ #
231
+ def paste!(other, left, top, alpha)
232
+ result = FreeImage.FreeImage_Paste(self, other, left, top, alpha)
233
+ FreeImage.check_last_error
234
+ result
235
+ end
236
+
237
+ # :call-seq:
238
+ # bitmap.rescale(width, height, filter) -> bitmap
239
+ # bitmap.rescale(width, height, filter) {|img| block} -> bitmap -> bitmap
240
+ #
241
+ # Resamples an image to the desired width and height. Resampling changes the
242
+ # pixel dimensions (and therefore display size) of an image.
243
+ # When you downsample (or decrease the number of pixels), information is deleted from
244
+ # the image. When you upsample (or increase the number of pixels), new pixels are
245
+ # added based on color values of existing pixels. You can specify an interpolation
246
+ # filter to determine how pixels are added or deleted using the filter parameter.
247
+ #
248
+ # Returns the newly resample image or nil if the image cannot be resampled.
249
+ #
250
+ # == Parameters:
251
+ #
252
+ # width:: The width of the new image
253
+ # height:: The height of the new image
254
+ # filter:: The filter to use when rescaling
255
+ #
256
+ # Filter options include:
257
+ #
258
+ # :box:: The simplest and fastest of the scaling algorithms. The technique achieves
259
+ # magnification by pixel replication, and minification by sparse point sampling.
260
+ # For large-scale changes, box interpolation produces images with a
261
+ # blocky appearance. In addition, shift errors of up to one-half pixel are
262
+ # possible. These problems make this technique inappropriate when
263
+ # sub-pixel accuracy is required.
264
+ #
265
+ # :bicubic:: An advanced parameterized scaling filter. It uses a cubic
266
+ # to produce very smooth output while maintaining dynamic range
267
+ # and sharpness. Bicubic scaling takes approximately twice the
268
+ # processing time as Bilinear. This filter can be used for any
269
+ # scaling application, especially when scaling factors are 2X
270
+ # or greater.
271
+ #
272
+ # :bilinear:: The second-fastest scaling function. It employs linear interpolation
273
+ # to determine the output image. Bilinear scaling provides reasonably
274
+ # good results at moderate cost for most applications where scale
275
+ # factors are relatively small (4X or less).
276
+ #
277
+ # :bspline:: Produces the smoothest output, but tends to smooth over fine details.
278
+ # This function requires the same processing time as :bicubic filter.
279
+ # It is recommended for applications where the smoothest output is required.
280
+ #
281
+ # :catmullrom:: The Catmull-Rom filter is generally accepted as the best cubic interpolant filter.
282
+ #
283
+ # :lanczos3:: A sinc based filter. It is the most theoretically correct filter
284
+ # that produces the best output for photographic images that do not have
285
+ # sharp transitions in them. However, Lanczos will produce ripple artefacts
286
+ # especially for block text, due to aliasing. It requires three times the
287
+ # processing time of Bilinear. Lanczos is not recommended except in very
288
+ # rare applications using band-limited photographic images with
289
+ # no sharp edges.
290
+ #
291
+ # If an optional block is provided, it will be passed the new image as an argument. The
292
+ # image will be automatically closed when the block completes.
293
+ #
294
+ def rescale(width, height, filter = :bilinear, &block)
295
+ ptr = FreeImage.FreeImage_Rescale(self, width, height, filter)
296
+ FreeImage.check_last_error
297
+ self.class.new(ptr, &block)
298
+ end
299
+ end
300
300
  end