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,135 +1,135 @@
1
- module FreeImage
2
- #DLL_API BYTE *DLL_CALLCONV FreeImage_GetBits(FIBITMAP *dib);
3
- attach_function('FreeImage_GetBits', [:pointer], :pointer)
4
-
5
- #DLL_API BYTE *DLL_CALLCONV FreeImage_GetScanLine(FIBITMAP *dib, int scanline);
6
- attach_function('FreeImage_GetScanLine', [:pointer, :int], :pointer)
7
-
8
- #DLL_API BOOL DLL_CALLCONV FreeImage_GetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value);
9
- attach_function('FreeImage_GetPixelIndex', [:pointer, :uint, :uint, :pointer], FreeImage::Boolean)
10
-
11
- #DLL_API BOOL DLL_CALLCONV FreeImage_SetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value);
12
- attach_function('FreeImage_SetPixelIndex', [:pointer, :uint, :uint, :pointer], FreeImage::Boolean)
13
-
14
- #DLL_API BOOL DLL_CALLCONV FreeImage_GetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value);
15
- attach_function('FreeImage_GetPixelColor', [:pointer, :uint, :uint, :pointer], FreeImage::Boolean)
16
-
17
- #DLL_API BOOL DLL_CALLCONV FreeImage_SetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value);
18
- attach_function('FreeImage_SetPixelColor', [:pointer, :uint, :uint, :pointer], FreeImage::Boolean)
19
-
20
- # == Summary
21
- #
22
- # The \Pixel module provides methods that allow you to read, write and work pixel-by-pixel
23
- # with image data. \FreeImage not only can work with standard bitmap data
24
- # (e.g. 1-, 4-, 8-, 16-, 24- and 32-bit) but also with scientific data such as
25
- # 16-bit greyscale images, or images made up of long, double or complex values
26
- # (often used in signal and image processing algorithms).
27
- #
28
- # The \FreeImage coordinate system is upside down relative to usual graphics
29
- # conventions. Thus, the scanlines are stored upside down, with the first
30
- # scan in memory being the bottommost scan in the image.
31
- #
32
- # For additional information, please refer to the FreeImage::Scanline documentation.
33
- #
34
- module Pixels
35
- # Returns the data-bits of the bitmap. It is up to you to interpret these bytes
36
- # correctly, according to the results of Information#bits_per_pixel, Information#red_mask,
37
- # Information#green_mask and Information#blue_mask.
38
- #
39
- # If the bitmap does not contain pixel data (see Information#has_pixels),
40
- # nil will be returned.
41
- #
42
- # For a performance reason, the address returned by FreeImage_GetBits is aligned on
43
- # a 16 bytes alignment boundary
44
- #
45
- def bits
46
- ptr = FreeImage.FreeImage_GetBits(self)
47
- FreeImage.check_last_error
48
- ptr.read_string
49
- end
50
-
51
- # Returns the requested row of image data as a FreeImage::Scanline instance.
52
- #
53
- # If the bitmap does not contain pixel data (see Information#has_pixels),
54
- # nil will be returned.
55
- def scanline(index)
56
- unless (0...self.height).include?(index)
57
- raise(RangeError, "Index must be between 0 and #{self.height - 1}")
58
- end
59
- ptr = FreeImage.FreeImage_GetScanLine(self, index)
60
- FreeImage.check_last_error
61
-
62
- ptr ? Scanline.new(self, index, ptr) : nil
63
- end
64
-
65
- # Gets the pixel index of a palettized image at the specified coordinate.
66
- #
67
- # == Parameters
68
- # x:: The pixel position in horizontal direction
69
- # y:: The pixel position in vertical direction.
70
- #
71
- def pixel_index(x, y)
72
- byte_type = FreeImage.find_type(:byte)
73
- ptr = FFI::MemoryPointer.new(byte_type)
74
- result = FreeImage.FreeImage_GetPixelIndex(self, x, y, ptr)
75
- FreeImage.check_last_error
76
- return nil unless result
77
-
78
- data = ptr.read_bytes(byte_type.size)
79
- if byte_type.size == 1
80
- data.ord
81
- else
82
- data
83
- end
84
- end
85
-
86
- # Sets the pixel index of a palettized image at the specified coordinate.
87
- #
88
- # == Parameters
89
- # x:: The pixel position in horizontal direction
90
- # y:: The pixel position in vertical direction.
91
- #
92
- # The function returns true on success and false otherwise.
93
- #
94
- def set_pixel_index(x, y, index)
95
- byte_type = FreeImage.find_type(:byte)
96
- ptr = FFI::MemoryPointer.new(byte_type.size)
97
- if byte_type.size == 1
98
- ptr.put_bytes(0, index.chr, 0, byte_type.size)
99
- else
100
- ptr.put_bytes(0, index.to_s, 0, byte_type.size)
101
- end
102
- result = FreeImage.FreeImage_SetPixelIndex(self, x, y, ptr)
103
- FreeImage.check_last_error
104
- result
105
- end
106
-
107
- # Gets the pixel color of a 16-, 24- or 32-bit image at the specified coordinate.
108
- #
109
- # == Parameters
110
- # x:: The pixel position in horizontal direction
111
- # y:: The pixel position in vertical direction.
112
- #
113
- def pixel_color(x, y)
114
- color = RGBQuad.new
115
- result = FreeImage.FreeImage_GetPixelColor(self, x, y, color)
116
- FreeImage.check_last_error
117
- result ? color : nil
118
- end
119
-
120
- # Sets the pixel color of a 16-, 24- or 32-bit image at the specified coordinate.
121
- #
122
- # == Parameters
123
- # x:: The pixel position in horizontal direction
124
- # y:: The pixel position in vertical direction.
125
- # color:: The new color as a RGBAQuad instance.
126
- #
127
- # The function returns true on success and false otherwise.
128
- #
129
- def set_pixel_color(x, y, color)
130
- result = FreeImage.FreeImage_SetPixelColor(self, x, y, color)
131
- FreeImage.check_last_error
132
- result
133
- end
134
- end
1
+ module FreeImage
2
+ #DLL_API BYTE *DLL_CALLCONV FreeImage_GetBits(FIBITMAP *dib);
3
+ attach_function('FreeImage_GetBits', [:pointer], :pointer)
4
+
5
+ #DLL_API BYTE *DLL_CALLCONV FreeImage_GetScanLine(FIBITMAP *dib, int scanline);
6
+ attach_function('FreeImage_GetScanLine', [:pointer, :int], :pointer)
7
+
8
+ #DLL_API BOOL DLL_CALLCONV FreeImage_GetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value);
9
+ attach_function('FreeImage_GetPixelIndex', [:pointer, :uint, :uint, :pointer], FreeImage::Boolean)
10
+
11
+ #DLL_API BOOL DLL_CALLCONV FreeImage_SetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value);
12
+ attach_function('FreeImage_SetPixelIndex', [:pointer, :uint, :uint, :pointer], FreeImage::Boolean)
13
+
14
+ #DLL_API BOOL DLL_CALLCONV FreeImage_GetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value);
15
+ attach_function('FreeImage_GetPixelColor', [:pointer, :uint, :uint, :pointer], FreeImage::Boolean)
16
+
17
+ #DLL_API BOOL DLL_CALLCONV FreeImage_SetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value);
18
+ attach_function('FreeImage_SetPixelColor', [:pointer, :uint, :uint, :pointer], FreeImage::Boolean)
19
+
20
+ # == Summary
21
+ #
22
+ # The \Pixel module provides methods that allow you to read, write and work pixel-by-pixel
23
+ # with image data. \FreeImage not only can work with standard bitmap data
24
+ # (e.g. 1-, 4-, 8-, 16-, 24- and 32-bit) but also with scientific data such as
25
+ # 16-bit greyscale images, or images made up of long, double or complex values
26
+ # (often used in signal and image processing algorithms).
27
+ #
28
+ # The \FreeImage coordinate system is upside down relative to usual graphics
29
+ # conventions. Thus, the scanlines are stored upside down, with the first
30
+ # scan in memory being the bottommost scan in the image.
31
+ #
32
+ # For additional information, please refer to the FreeImage::Scanline documentation.
33
+ #
34
+ module Pixels
35
+ # Returns the data-bits of the bitmap. It is up to you to interpret these bytes
36
+ # correctly, according to the results of Information#bits_per_pixel, Information#red_mask,
37
+ # Information#green_mask and Information#blue_mask.
38
+ #
39
+ # If the bitmap does not contain pixel data (see Information#has_pixels),
40
+ # nil will be returned.
41
+ #
42
+ # For a performance reason, the address returned by FreeImage_GetBits is aligned on
43
+ # a 16 bytes alignment boundary
44
+ #
45
+ def bits
46
+ ptr = FreeImage.FreeImage_GetBits(self)
47
+ FreeImage.check_last_error
48
+ ptr.read_string
49
+ end
50
+
51
+ # Returns the requested row of image data as a FreeImage::Scanline instance.
52
+ #
53
+ # If the bitmap does not contain pixel data (see Information#has_pixels),
54
+ # nil will be returned.
55
+ def scanline(index)
56
+ unless (0...self.height).include?(index)
57
+ raise(RangeError, "Index must be between 0 and #{self.height - 1}")
58
+ end
59
+ ptr = FreeImage.FreeImage_GetScanLine(self, index)
60
+ FreeImage.check_last_error
61
+
62
+ ptr ? Scanline.new(self, index, ptr) : nil
63
+ end
64
+
65
+ # Gets the pixel index of a palettized image at the specified coordinate.
66
+ #
67
+ # == Parameters
68
+ # x:: The pixel position in horizontal direction
69
+ # y:: The pixel position in vertical direction.
70
+ #
71
+ def pixel_index(x, y)
72
+ byte_type = FreeImage.find_type(:byte)
73
+ ptr = FFI::MemoryPointer.new(byte_type)
74
+ result = FreeImage.FreeImage_GetPixelIndex(self, x, y, ptr)
75
+ FreeImage.check_last_error
76
+ return nil unless result
77
+
78
+ data = ptr.read_bytes(byte_type.size)
79
+ if byte_type.size == 1
80
+ data.ord
81
+ else
82
+ data
83
+ end
84
+ end
85
+
86
+ # Sets the pixel index of a palettized image at the specified coordinate.
87
+ #
88
+ # == Parameters
89
+ # x:: The pixel position in horizontal direction
90
+ # y:: The pixel position in vertical direction.
91
+ #
92
+ # The function returns true on success and false otherwise.
93
+ #
94
+ def set_pixel_index(x, y, index)
95
+ byte_type = FreeImage.find_type(:byte)
96
+ ptr = FFI::MemoryPointer.new(byte_type.size)
97
+ if byte_type.size == 1
98
+ ptr.put_bytes(0, index.chr, 0, byte_type.size)
99
+ else
100
+ ptr.put_bytes(0, index.to_s, 0, byte_type.size)
101
+ end
102
+ result = FreeImage.FreeImage_SetPixelIndex(self, x, y, ptr)
103
+ FreeImage.check_last_error
104
+ result
105
+ end
106
+
107
+ # Gets the pixel color of a 16-, 24- or 32-bit image at the specified coordinate.
108
+ #
109
+ # == Parameters
110
+ # x:: The pixel position in horizontal direction
111
+ # y:: The pixel position in vertical direction.
112
+ #
113
+ def pixel_color(x, y)
114
+ color = RGBQuad.new
115
+ result = FreeImage.FreeImage_GetPixelColor(self, x, y, color)
116
+ FreeImage.check_last_error
117
+ result ? color : nil
118
+ end
119
+
120
+ # Sets the pixel color of a 16-, 24- or 32-bit image at the specified coordinate.
121
+ #
122
+ # == Parameters
123
+ # x:: The pixel position in horizontal direction
124
+ # y:: The pixel position in vertical direction.
125
+ # color:: The new color as a RGBAQuad instance.
126
+ #
127
+ # The function returns true on success and false otherwise.
128
+ #
129
+ def set_pixel_color(x, y, color)
130
+ result = FreeImage.FreeImage_SetPixelColor(self, x, y, color)
131
+ FreeImage.check_last_error
132
+ result
133
+ end
134
+ end
135
135
  end
@@ -1,91 +1,91 @@
1
- module FreeImage
2
- # DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Rotate(FIBITMAP *dib, double angle, const void *bkcolor FI_DEFAULT(NULL));
3
- attach_function('FreeImage_Rotate', [:pointer, :double, :pointer], :pointer)
4
-
5
- # DLL_API FIBITMAP *DLL_CALLCONV FreeImage_RotateEx(FIBITMAP *dib, double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask);
6
- attach_function('FreeImage_RotateEx', [:pointer, :double, :double, :double, :double, :double, FreeImage::Boolean], :pointer)
7
-
8
- # DLL_API BOOL DLL_CALLCONV FreeImage_FlipHorizontal(FIBITMAP *dib);
9
- attach_function('FreeImage_FlipHorizontal', [:pointer], FreeImage::Boolean)
10
-
11
- # DLL_API BOOL DLL_CALLCONV FreeImage_FlipVertical(FIBITMAP *dib);
12
- attach_function('FreeImage_FlipVertical', [:pointer], FreeImage::Boolean)
13
-
14
- module Transforms
15
- # call-seq:
16
- # bitmap.rotate(angle, bk_color) -> bitmap
17
- # bitmap.rotate(angle, bk_color) -> {|img| block} -> bitmap
18
- #
19
- # Rotates an image around the center of the image area by means of 3 shears.
20
- # The rotated image retains the same size and aspect ratio of source image
21
- # (the resulting image size is usually bigger), so that this function should
22
- # be used when rotating an image by 90°, 180° or 270°.
23
- #
24
- # When the angle value isn’t an integer multiple of 90°, the background is
25
- # filled with the supplied bkcolor parameter. When bkcolor is nil, the
26
- # default value, the background is filled with a black.
27
- #
28
- # == Parameters
29
- #
30
- # angle:: Specifies the angle of rotation in degrees
31
- # bk_color:: The color used to fill the background.
32
- #
33
- # If an optional block is provided, it will be passed the new image as an argument. The
34
- # image will be automatically closed when the block completes.
35
- #
36
- def rotate(angle, bk_color = nil, &block)
37
- ptr = FreeImage.FreeImage_Rotate(self, angle, bk_color)
38
- FreeImage.check_last_error
39
- self.class.new(ptr, &block)
40
- end
41
-
42
- # call-seq:
43
- # bitmap.rotate_ex(aangle, x_shift, y_shift, x_origin, y_origin, use_mask = false) -> bitmap
44
- # bitmap.rotate_ex(aangle, x_shift, y_shift, x_origin, y_origin, use_mask = false) {|img| block} -> bitmap
45
- #
46
- # Rotates an image using a 3rd order (cubic) B-Spline. The rotated image will have
47
- # the same width and height as the source image, so that this function is better
48
- # suited for computer vision and robotics.
49
- #
50
- # == Parameters:
51
- #
52
- # angle:: Specifies the angle of rotation in degrees
53
- # x_shift:: Specifies horizonal image translation
54
- # y_shift:: Specifies vertical image translation
55
- # x_origin:: Specifies the x coordinate of the center of rotation
56
- # y_origin:: Specifies the y coordinate of the center of rotation
57
- # use_mask:: When true, irrelevant parts of the image are set to black,
58
- # otherwise, a mirroring technique is used to fill irrelevant pixels.
59
- #
60
- # If an optional block is provided, it will be passed the new image as an argument. The
61
- # image will be automatically closed when the block completes.
62
- #
63
- def rotate_ex(angle, x_shift, y_shift, x_origin, y_origin, use_mask = false, &block)
64
- ptr = FreeImage.FreeImage_RotateEx(self, angle, x_shift, y_shift, x_origin, y_origin, use_mask)
65
- FreeImage.check_last_error
66
- self.class.new(ptr, &block)
67
- end
68
-
69
- # call-seq:
70
- # bitmap.flip_horizontal -> boolean
71
- #
72
- # Flip the input image horizontally along the vertical axis.
73
- #
74
- def flip_horizontal!
75
- result = FreeImage.FreeImage_FlipHorizontal(self)
76
- FreeImage.check_last_error
77
- result
78
- end
79
-
80
- # call-seq:
81
- # bitmap.flip_vertical -> boolean
82
- #
83
- # Flip the input image vertically horizontally along the horizontal axis.
84
- #
85
- def flip_vertical!
86
- result = FreeImage.FreeImage_FlipHorizontal(self)
87
- FreeImage.check_last_error
88
- result
89
- end
90
- end
1
+ module FreeImage
2
+ # DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Rotate(FIBITMAP *dib, double angle, const void *bkcolor FI_DEFAULT(NULL));
3
+ attach_function('FreeImage_Rotate', [:pointer, :double, :pointer], :pointer)
4
+
5
+ # DLL_API FIBITMAP *DLL_CALLCONV FreeImage_RotateEx(FIBITMAP *dib, double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask);
6
+ attach_function('FreeImage_RotateEx', [:pointer, :double, :double, :double, :double, :double, FreeImage::Boolean], :pointer)
7
+
8
+ # DLL_API BOOL DLL_CALLCONV FreeImage_FlipHorizontal(FIBITMAP *dib);
9
+ attach_function('FreeImage_FlipHorizontal', [:pointer], FreeImage::Boolean)
10
+
11
+ # DLL_API BOOL DLL_CALLCONV FreeImage_FlipVertical(FIBITMAP *dib);
12
+ attach_function('FreeImage_FlipVertical', [:pointer], FreeImage::Boolean)
13
+
14
+ module Transforms
15
+ # call-seq:
16
+ # bitmap.rotate(angle, bk_color) -> bitmap
17
+ # bitmap.rotate(angle, bk_color) -> {|img| block} -> bitmap
18
+ #
19
+ # Rotates an image around the center of the image area by means of 3 shears.
20
+ # The rotated image retains the same size and aspect ratio of source image
21
+ # (the resulting image size is usually bigger), so that this function should
22
+ # be used when rotating an image by 90°, 180° or 270°.
23
+ #
24
+ # When the angle value isn’t an integer multiple of 90°, the background is
25
+ # filled with the supplied bkcolor parameter. When bkcolor is nil, the
26
+ # default value, the background is filled with a black.
27
+ #
28
+ # == Parameters
29
+ #
30
+ # angle:: Specifies the angle of rotation in degrees
31
+ # bk_color:: The color used to fill the background.
32
+ #
33
+ # If an optional block is provided, it will be passed the new image as an argument. The
34
+ # image will be automatically closed when the block completes.
35
+ #
36
+ def rotate(angle, bk_color = nil, &block)
37
+ ptr = FreeImage.FreeImage_Rotate(self, angle, bk_color)
38
+ FreeImage.check_last_error
39
+ self.class.new(ptr, &block)
40
+ end
41
+
42
+ # call-seq:
43
+ # bitmap.rotate_ex(aangle, x_shift, y_shift, x_origin, y_origin, use_mask = false) -> bitmap
44
+ # bitmap.rotate_ex(aangle, x_shift, y_shift, x_origin, y_origin, use_mask = false) {|img| block} -> bitmap
45
+ #
46
+ # Rotates an image using a 3rd order (cubic) B-Spline. The rotated image will have
47
+ # the same width and height as the source image, so that this function is better
48
+ # suited for computer vision and robotics.
49
+ #
50
+ # == Parameters:
51
+ #
52
+ # angle:: Specifies the angle of rotation in degrees
53
+ # x_shift:: Specifies horizonal image translation
54
+ # y_shift:: Specifies vertical image translation
55
+ # x_origin:: Specifies the x coordinate of the center of rotation
56
+ # y_origin:: Specifies the y coordinate of the center of rotation
57
+ # use_mask:: When true, irrelevant parts of the image are set to black,
58
+ # otherwise, a mirroring technique is used to fill irrelevant pixels.
59
+ #
60
+ # If an optional block is provided, it will be passed the new image as an argument. The
61
+ # image will be automatically closed when the block completes.
62
+ #
63
+ def rotate_ex(angle, x_shift, y_shift, x_origin, y_origin, use_mask = false, &block)
64
+ ptr = FreeImage.FreeImage_RotateEx(self, angle, x_shift, y_shift, x_origin, y_origin, use_mask)
65
+ FreeImage.check_last_error
66
+ self.class.new(ptr, &block)
67
+ end
68
+
69
+ # call-seq:
70
+ # bitmap.flip_horizontal -> boolean
71
+ #
72
+ # Flip the input image horizontally along the vertical axis.
73
+ #
74
+ def flip_horizontal!
75
+ result = FreeImage.FreeImage_FlipHorizontal(self)
76
+ FreeImage.check_last_error
77
+ result
78
+ end
79
+
80
+ # call-seq:
81
+ # bitmap.flip_vertical -> boolean
82
+ #
83
+ # Flip the input image vertically along the horizontal axis.
84
+ #
85
+ def flip_vertical!
86
+ result = FreeImage.FreeImage_FlipVertical(self)
87
+ FreeImage.check_last_error
88
+ result
89
+ end
90
+ end
91
91
  end
@@ -1,179 +1,179 @@
1
- module FreeImage
2
- # == Summary
3
- #
4
- # FreeImage can load images from a variety of files,
5
- # memory or streams. For additional details please see:
6
- #
7
- # FreeImage::File:: Use to load images from files
8
- # FreeImage::Memory:: Use to load images from byte strings
9
- # FreeImage::IO:: Use to load images from io streams
10
- #
11
- class AbstractSource
12
- # The Decoder module defines various constants that
13
- # control how various image formats are loaded.
14
- module Decoder
15
- # Load the image header only (not supported by all plugins)
16
- FIF_LOADNOPIXELS = 0x8000
17
- GIF_DEFAULT = 0x0
18
- # Load the image as a 256 color image with ununsed palette entries, if it's 16 or 2 color
19
- GIF_LOAD256 = 0x1
20
- # 'Play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading
21
- GIF_PLAYBACK = 0x2
22
- ICO_DEFAULT = 0x0
23
- # Loading (see JPEG_FAST); saving (see JPEG_QUALITYGOOD|JPEG_SUBSAMPLING_420)
24
- JPEG_DEFAULT = 0x0
25
- # Load the file as fast as possible, sacrificing some quality
26
- JPEG_FAST = 0x1
27
- # Load the file with the best quality, sacrificing some speed
28
- JPEG_ACCURATE = 0x2
29
- # Load separated CMYK "as is" (use | to combine with other load flags)
30
- JPEG_CMYK = 0x4
31
- # Load and rotate according to Exif 'Orientation' tag if available
32
- JPEG_EXIFROTATE =0x8
33
- PCD_DEFAULT = 0x0
34
- # Load the bitmap sized 768 x 512
35
- PCD_BASE = 0x1
36
- # Load the bitmap sized 384 x 256
37
- PCD_BASEDIV4 = 0x2
38
- # Load the bitmap sized 192 x 128
39
- PCD_BASEDIV16 = 0x3
40
- # Loading: avoid gamma correction
41
- PNG_IGNOREGAMMA = 0x1
42
- PSD_DEFAULT = 0x0
43
- # Reads tags for separated CMYK (default is conversion to RGB)
44
- PSD_CMYK = 0x1
45
- # Reads tags for CIELab (default is conversion to RGB)
46
- PSD_LAB = 0x2
47
- # Load the file as linear RGB 48-bit
48
- RAW_DEFAULT = 0x0
49
- # Try to load the embedded JPEG preview with included Exif Data or default to RGB 24-bit
50
- RAW_PREVIEW = 0x1
51
- # Load the file as RGB 24-bit
52
- RAW_DISPLAY = 0x2
53
- # Output a half-size color image
54
- RAW_HALFSIZE = 0x4
55
- # If set the loader converts RGB555 and ARGB8888 -> RGB888.
56
- TARGA_LOAD_RGB888 = 0x1
57
- # Reads/stores tags for separated CMYK (use | to combine with compression flags)
58
- TIFF_CMYK = 0x1
59
- end
60
-
61
- # The Encoder module defines various constants that
62
- # control how various image formats are saved.
63
- module Encoder
64
- BMP_DEFAULT = 0x0
65
- BMP_SAVE_RLE = 0x1
66
- # Save data as half with piz-based wavelet compression
67
- EXR_DEFAULT = 0x0
68
- # Save data as float instead of as half (not recommended)
69
- EXR_FLOAT = 0x0001
70
- # Save with no compression
71
- EXR_NONE = 0x0002
72
- # Save with zlib compression, in blocks of 16 scan lines
73
- EXR_ZIP = 0x0004
74
- # Save with piz-based wavelet compression
75
- EXR_PIZ = 0x0008
76
- # Save with lossy 24-bit float compression
77
- EXR_PXR24 = 0x0010
78
- # Save with lossy 44% float compression - goes to 22% when combined with EXR_LC
79
- EXR_B44 = 0x0020
80
- # Save images with one luminance and two chroma channels, rather than as RGB (lossy compression)
81
- EXR_LC = 0x0040
82
- # Save with a 16:1 rate
83
- J2K_DEFAULT = 0x0
84
- # Save with a 16:1 rate
85
- JP2_DEFAULT = 0x0
86
- # Loading (see JPEG_FAST); saving (see JPEG_QUALITYGOOD|JPEG_SUBSAMPLING_420)
87
- JPEG_DEFAULT = 0x0
88
- # Save with superb quality (100:1)
89
- JPEG_QUALITYSUPERB = 0x80
90
- # Save with good quality (75:1)
91
- JPEG_QUALITYGOOD = 0x0100
92
- # Save with normal quality (50:1)
93
- JPEG_QUALITYNORMAL = 0x0200
94
- # Save with average quality (25:1)
95
- JPEG_QUALITYAVERAGE = 0x0400
96
- # Save with bad quality (10:1)
97
- JPEG_QUALITYBAD = 0x0800
98
- # Save as a progressive-JPEG (use | to combine with other save flags)
99
- JPEG_PROGRESSIVE = 0x2000
100
- # Save with high 4x1 chroma subsampling (4:1:1)
101
- JPEG_SUBSAMPLING_411 = 0x1000
102
- # Save with medium 2x2 medium chroma subsampling (4:2:0) - default value
103
- JPEG_SUBSAMPLING_420 = 0x4000
104
- # Save with low 2x1 chroma subsampling (4:2:2)
105
- JPEG_SUBSAMPLING_422 = 0x8000
106
- # Save with no chroma subsampling (4:4:4)
107
- JPEG_SUBSAMPLING_444 = 0x10000
108
- # On saving, compute optimal Huffman coding tables (can reduce a few percent of file size)
109
- JPEG_OPTIMIZE = 0x20000
110
- # Save basic JPEG, without metadata or any markers
111
- JPEG_BASELINE = 0x40000
112
- PNG_DEFAULT = 0x0
113
- # Save using ZLib level 1 compression flag (default value is 6)
114
- PNG_Z_BEST_SPEED = 0x0001
115
- # Save using ZLib level 6 compression flag (default recommended value)
116
- PNG_Z_DEFAULT_COMPRESSION = 0x0006
117
- # Save using ZLib level 9 compression flag (default value is 6)
118
- PNG_Z_BEST_COMPRESSION = 0x0009
119
- # Save without ZLib compression
120
- PNG_Z_NO_COMPRESSION = 0x0100
121
- # Save using Adam7 interlacing (use | to combine with other save flags)
122
- PNG_INTERLACED = 0x0200
123
- PNM_DEFAULT = 0x0
124
- # If set the writer saves in RAW format (i.e. P4, P5 or P6)
125
- PNM_SAVE_RAW = 0x0
126
- # If set the writer saves in ASCII format (i.e. P1, P2 or P3)
127
- PNM_SAVE_ASCII = 0x1
128
- TARGA_DEFAULT = 0x0
129
- # If set, the writer saves with RLE compression
130
- TARGA_SAVE_RLE = 0x2
131
- TIFF_DEFAULT = 0x0
132
- # Reads/stores tags for separated CMYK (use | to combine with compression flags)
133
- TIFF_CMYK = 0x0001
134
- # Save using PACKBITS compression
135
- TIFF_PACKBITS = 0x0100
136
- # Save using DEFLATE compression (a.k.a. ZLIB compression)
137
- TIFF_DEFLATE = 0x0200
138
- # Save using ADOBE DEFLATE compression
139
- TIFF_ADOBE_DEFLATE = 0x0400
140
- # Save without any compression
141
- TIFF_NONE = 0x0800
142
- # Save using CCITT Group 3 fax encoding
143
- TIFF_CCITTFAX3 = 0x1000
144
- # Save using CCITT Group 4 fax encoding
145
- TIFF_CCITTFAX4 = 0x2000
146
- # Save using LZW compression
147
- TIFF_LZW = 0x4000
148
- # Save using JPEG compression
149
- TIFF_JPEG = 0x8000
150
- # Save using LogLuv compression
151
- TIFF_LOGLUV = 0x10000
152
- end
153
-
154
- # :nodoc: - This method is documented on subclasses
155
- def open(format = nil, flags = 0)
156
- format ||= self.format
157
-
158
- # Do we know the format?
159
- if format == :unknown
160
- raise(Error.new(:unknown, "Cannot load :unknown image format"))
161
- end
162
-
163
- # Can we load the image?
164
- unless FreeImage.FreeImage_FIFSupportsReading(format)
165
- raise(Error.new("Cannot load image"))
166
- end
167
-
168
- ptr = load(format, flags)
169
-
170
- # Make sure we didn't get a null pointer. This can
171
- # happen - see test_file for example#test_corrupt_wrong_format
172
- if ptr.null?
173
- error = Error.new(:unknown, "Could not load the image")
174
- raise(error)
175
- end
176
- Bitmap.new(ptr, self)
177
- end
178
- end
1
+ module FreeImage
2
+ # == Summary
3
+ #
4
+ # FreeImage can load images from a variety of files,
5
+ # memory or streams. For additional details please see:
6
+ #
7
+ # FreeImage::File:: Use to load images from files
8
+ # FreeImage::Memory:: Use to load images from byte strings
9
+ # FreeImage::IO:: Use to load images from io streams
10
+ #
11
+ class AbstractSource
12
+ # The Decoder module defines various constants that
13
+ # control how various image formats are loaded.
14
+ module Decoder
15
+ # Load the image header only (not supported by all plugins)
16
+ FIF_LOADNOPIXELS = 0x8000
17
+ GIF_DEFAULT = 0x0
18
+ # Load the image as a 256 color image with ununsed palette entries, if it's 16 or 2 color
19
+ GIF_LOAD256 = 0x1
20
+ # 'Play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading
21
+ GIF_PLAYBACK = 0x2
22
+ ICO_DEFAULT = 0x0
23
+ # Loading (see JPEG_FAST); saving (see JPEG_QUALITYGOOD|JPEG_SUBSAMPLING_420)
24
+ JPEG_DEFAULT = 0x0
25
+ # Load the file as fast as possible, sacrificing some quality
26
+ JPEG_FAST = 0x1
27
+ # Load the file with the best quality, sacrificing some speed
28
+ JPEG_ACCURATE = 0x2
29
+ # Load separated CMYK "as is" (use | to combine with other load flags)
30
+ JPEG_CMYK = 0x4
31
+ # Load and rotate according to Exif 'Orientation' tag if available
32
+ JPEG_EXIFROTATE =0x8
33
+ PCD_DEFAULT = 0x0
34
+ # Load the bitmap sized 768 x 512
35
+ PCD_BASE = 0x1
36
+ # Load the bitmap sized 384 x 256
37
+ PCD_BASEDIV4 = 0x2
38
+ # Load the bitmap sized 192 x 128
39
+ PCD_BASEDIV16 = 0x3
40
+ # Loading: avoid gamma correction
41
+ PNG_IGNOREGAMMA = 0x1
42
+ PSD_DEFAULT = 0x0
43
+ # Reads tags for separated CMYK (default is conversion to RGB)
44
+ PSD_CMYK = 0x1
45
+ # Reads tags for CIELab (default is conversion to RGB)
46
+ PSD_LAB = 0x2
47
+ # Load the file as linear RGB 48-bit
48
+ RAW_DEFAULT = 0x0
49
+ # Try to load the embedded JPEG preview with included Exif Data or default to RGB 24-bit
50
+ RAW_PREVIEW = 0x1
51
+ # Load the file as RGB 24-bit
52
+ RAW_DISPLAY = 0x2
53
+ # Output a half-size color image
54
+ RAW_HALFSIZE = 0x4
55
+ # If set the loader converts RGB555 and ARGB8888 -> RGB888.
56
+ TARGA_LOAD_RGB888 = 0x1
57
+ # Reads/stores tags for separated CMYK (use | to combine with compression flags)
58
+ TIFF_CMYK = 0x1
59
+ end
60
+
61
+ # The Encoder module defines various constants that
62
+ # control how various image formats are saved.
63
+ module Encoder
64
+ BMP_DEFAULT = 0x0
65
+ BMP_SAVE_RLE = 0x1
66
+ # Save data as half with piz-based wavelet compression
67
+ EXR_DEFAULT = 0x0
68
+ # Save data as float instead of as half (not recommended)
69
+ EXR_FLOAT = 0x0001
70
+ # Save with no compression
71
+ EXR_NONE = 0x0002
72
+ # Save with zlib compression, in blocks of 16 scan lines
73
+ EXR_ZIP = 0x0004
74
+ # Save with piz-based wavelet compression
75
+ EXR_PIZ = 0x0008
76
+ # Save with lossy 24-bit float compression
77
+ EXR_PXR24 = 0x0010
78
+ # Save with lossy 44% float compression - goes to 22% when combined with EXR_LC
79
+ EXR_B44 = 0x0020
80
+ # Save images with one luminance and two chroma channels, rather than as RGB (lossy compression)
81
+ EXR_LC = 0x0040
82
+ # Save with a 16:1 rate
83
+ J2K_DEFAULT = 0x0
84
+ # Save with a 16:1 rate
85
+ JP2_DEFAULT = 0x0
86
+ # Loading (see JPEG_FAST); saving (see JPEG_QUALITYGOOD|JPEG_SUBSAMPLING_420)
87
+ JPEG_DEFAULT = 0x0
88
+ # Save with superb quality (100:1)
89
+ JPEG_QUALITYSUPERB = 0x80
90
+ # Save with good quality (75:1)
91
+ JPEG_QUALITYGOOD = 0x0100
92
+ # Save with normal quality (50:1)
93
+ JPEG_QUALITYNORMAL = 0x0200
94
+ # Save with average quality (25:1)
95
+ JPEG_QUALITYAVERAGE = 0x0400
96
+ # Save with bad quality (10:1)
97
+ JPEG_QUALITYBAD = 0x0800
98
+ # Save as a progressive-JPEG (use | to combine with other save flags)
99
+ JPEG_PROGRESSIVE = 0x2000
100
+ # Save with high 4x1 chroma subsampling (4:1:1)
101
+ JPEG_SUBSAMPLING_411 = 0x1000
102
+ # Save with medium 2x2 medium chroma subsampling (4:2:0) - default value
103
+ JPEG_SUBSAMPLING_420 = 0x4000
104
+ # Save with low 2x1 chroma subsampling (4:2:2)
105
+ JPEG_SUBSAMPLING_422 = 0x8000
106
+ # Save with no chroma subsampling (4:4:4)
107
+ JPEG_SUBSAMPLING_444 = 0x10000
108
+ # On saving, compute optimal Huffman coding tables (can reduce a few percent of file size)
109
+ JPEG_OPTIMIZE = 0x20000
110
+ # Save basic JPEG, without metadata or any markers
111
+ JPEG_BASELINE = 0x40000
112
+ PNG_DEFAULT = 0x0
113
+ # Save using ZLib level 1 compression flag (default value is 6)
114
+ PNG_Z_BEST_SPEED = 0x0001
115
+ # Save using ZLib level 6 compression flag (default recommended value)
116
+ PNG_Z_DEFAULT_COMPRESSION = 0x0006
117
+ # Save using ZLib level 9 compression flag (default value is 6)
118
+ PNG_Z_BEST_COMPRESSION = 0x0009
119
+ # Save without ZLib compression
120
+ PNG_Z_NO_COMPRESSION = 0x0100
121
+ # Save using Adam7 interlacing (use | to combine with other save flags)
122
+ PNG_INTERLACED = 0x0200
123
+ PNM_DEFAULT = 0x0
124
+ # If set the writer saves in RAW format (i.e. P4, P5 or P6)
125
+ PNM_SAVE_RAW = 0x0
126
+ # If set the writer saves in ASCII format (i.e. P1, P2 or P3)
127
+ PNM_SAVE_ASCII = 0x1
128
+ TARGA_DEFAULT = 0x0
129
+ # If set, the writer saves with RLE compression
130
+ TARGA_SAVE_RLE = 0x2
131
+ TIFF_DEFAULT = 0x0
132
+ # Reads/stores tags for separated CMYK (use | to combine with compression flags)
133
+ TIFF_CMYK = 0x0001
134
+ # Save using PACKBITS compression
135
+ TIFF_PACKBITS = 0x0100
136
+ # Save using DEFLATE compression (a.k.a. ZLIB compression)
137
+ TIFF_DEFLATE = 0x0200
138
+ # Save using ADOBE DEFLATE compression
139
+ TIFF_ADOBE_DEFLATE = 0x0400
140
+ # Save without any compression
141
+ TIFF_NONE = 0x0800
142
+ # Save using CCITT Group 3 fax encoding
143
+ TIFF_CCITTFAX3 = 0x1000
144
+ # Save using CCITT Group 4 fax encoding
145
+ TIFF_CCITTFAX4 = 0x2000
146
+ # Save using LZW compression
147
+ TIFF_LZW = 0x4000
148
+ # Save using JPEG compression
149
+ TIFF_JPEG = 0x8000
150
+ # Save using LogLuv compression
151
+ TIFF_LOGLUV = 0x10000
152
+ end
153
+
154
+ # :nodoc: - This method is documented on subclasses
155
+ def open(format = nil, flags = 0)
156
+ format ||= self.format
157
+
158
+ # Do we know the format?
159
+ if format == :unknown
160
+ raise(Error.new(:unknown, "Cannot load :unknown image format"))
161
+ end
162
+
163
+ # Can we load the image?
164
+ unless FreeImage.FreeImage_FIFSupportsReading(format)
165
+ raise(Error.new("Cannot load image"))
166
+ end
167
+
168
+ ptr = load(format, flags)
169
+
170
+ # Make sure we didn't get a null pointer. This can
171
+ # happen - see test_file for example#test_corrupt_wrong_format
172
+ if ptr.null?
173
+ error = Error.new(:unknown, "Could not load the image")
174
+ raise(error)
175
+ end
176
+ Bitmap.new(ptr, self)
177
+ end
178
+ end
179
179
  end