free-image 0.5.0 → 0.6.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.
- data/README.rdoc +25 -4
- data/cookbook.rdoc +3 -4
- data/free-image.gemspec +1 -1
- data/lib/free-image.rb +1 -1
- data/lib/free-image/bitmap.rb +26 -8
- data/lib/free-image/enums/image_types.rb +2 -2
- data/lib/free-image/modules/conversions.rb +110 -22
- data/lib/free-image/modules/modify.rb +52 -13
- data/lib/free-image/modules/transforms.rb +12 -4
- data/test/test_bitmap.rb +12 -0
- metadata +8 -8
    
        data/README.rdoc
    CHANGED
    
    | @@ -33,11 +33,32 @@ free-image is via Ruby Gems.  To install: | |
| 33 33 |  | 
| 34 34 | 
             
             gem install free-image
         | 
| 35 35 |  | 
| 36 | 
            -
             | 
| 37 36 | 
             
            == Getting Started
         | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 37 | 
            +
            Getting started is easy - first work through the examples in the cookbook[rdoc-ref:cookbook.rdoc].
         | 
| 38 | 
            +
            Once you've done that, the refer to rdocs for extensive documentation.
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            == Memory Management
         | 
| 41 | 
            +
            Opening and working with images consumes some memory.  Generally you won't have to
         | 
| 42 | 
            +
            worry about this.  When an image goes out of scope, it will be garbage collected
         | 
| 43 | 
            +
            and the underlying image memory will be freed.
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            Having said that, \FreeImage also lets you control when the memory is freed.
         | 
| 46 | 
            +
            Any method that creates a new image also takes a block.  When the block finishes,
         | 
| 47 | 
            +
            the underlying image memory is freed.  This works the same way as the File.open
         | 
| 48 | 
            +
            method.  For example:
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              FreeImage::Bitmap.open('images/lena.png') do |image|
         | 
| 51 | 
            +
                thumbnail = image.make_thumbail do |thumbail|
         | 
| 52 | 
            +
                  thumbnail.save('images/thumbnail.png', :png)
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
              end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
            When the inner block finishes the thumbnail image is freed and when the outer
         | 
| 57 | 
            +
            block finished the lena image is freed.
         | 
| 40 58 |  | 
| 59 | 
            +
            If you need even more control, you can  use FreeImage::Bitmap#free which frees 
         | 
| 60 | 
            +
            the underlying image.  Be careful though - once the image is freed further usage
         | 
| 61 | 
            +
            of it will result in a segmentation fault.
         | 
| 41 62 |  | 
| 42 63 | 
             
            == Implementation Status
         | 
| 43 64 | 
             
            The FreeImage API is divided into multiple parts.  As summarized below, the Ruby ffi
         | 
| @@ -74,7 +95,7 @@ extend the coverage. | |
| 74 95 | 
             
            * Channel processing - Not Implemented
         | 
| 75 96 | 
             
            * Copy / Paste / Composite routines - FreeImage::Modify
         | 
| 76 97 | 
             
            * Background filling - FreeImage::Modify
         | 
| 77 | 
            -
            * Miscellaneous algorithms -  | 
| 98 | 
            +
            * Miscellaneous algorithms - FreeImage::Helper
         | 
| 78 99 |  | 
| 79 100 | 
             
            == Documentation
         | 
| 80 101 | 
             
            Documentation is available via rdoc, and is installed automatically with the
         | 
    
        data/cookbook.rdoc
    CHANGED
    
    | @@ -17,7 +17,7 @@ via the FreeImage::Bitmap.open method: | |
| 17 17 | 
             
            The open method also takes two additional optional parameters, format and flags,
         | 
| 18 18 | 
             
            that provide greater control over opening images if needed.
         | 
| 19 19 |  | 
| 20 | 
            -
            The open method works similary to File.open, meaning you can pass it a block.
         | 
| 20 | 
            +
            The open method works similary to File.open, meaning you can also pass it a block.
         | 
| 21 21 |  | 
| 22 22 | 
             
              FreeImage::Bitmap.open('images/lena.png') do |image|
         | 
| 23 23 | 
             
                ... do some stuff..
         | 
| @@ -25,9 +25,8 @@ The open method works similary to File.open, meaning you can pass it a block. | |
| 25 25 |  | 
| 26 26 | 
             
            Once the block completes, the image will be automatically freed for you.  If you don't
         | 
| 27 27 | 
             
            pass block, then the image will be freed by Ruby's Garbage Collector once it goes out
         | 
| 28 | 
            -
            of scope  | 
| 29 | 
            -
             | 
| 30 | 
            -
            segmentation faults.
         | 
| 28 | 
            +
            of scope.  For more information about memory management, refer to
         | 
| 29 | 
            +
            the readme [rdoc-ref:README.rdoc].
         | 
| 31 30 |  | 
| 32 31 | 
             
            Image[link:cookbook/lena.png]
         | 
| 33 32 |  | 
    
        data/free-image.gemspec
    CHANGED
    
    | @@ -2,7 +2,7 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            Gem::Specification.new do |spec|
         | 
| 4 4 | 
             
              spec.name        = 'free-image'
         | 
| 5 | 
            -
              spec.version     = '0. | 
| 5 | 
            +
              spec.version     = '0.6.0'
         | 
| 6 6 | 
             
              spec.summary     = 'Ruby Bindings for the Free Image Library'
         | 
| 7 7 | 
             
              spec.description = <<-EOS
         | 
| 8 8 | 
             
                FreeImage is an Open Source library project for developers who would like to support
         | 
    
        data/lib/free-image.rb
    CHANGED
    
    
    
        data/lib/free-image/bitmap.rb
    CHANGED
    
    | @@ -86,14 +86,28 @@ module FreeImage | |
| 86 86 | 
             
                # also be a string which is interpreted as a fully qualified file path.
         | 
| 87 87 | 
             
                def self.open(source)
         | 
| 88 88 | 
             
                  bitmap = figure_source(source).open
         | 
| 89 | 
            -
                   | 
| 90 | 
            -
                     | 
| 89 | 
            +
                  if block_given?
         | 
| 90 | 
            +
                    begin
         | 
| 91 | 
            +
                      yield bitmap
         | 
| 92 | 
            +
                    ensure
         | 
| 93 | 
            +
                      bitmap.free
         | 
| 94 | 
            +
                    end
         | 
| 91 95 | 
             
                  else
         | 
| 96 | 
            +
                    bitmap
         | 
| 97 | 
            +
                  end
         | 
| 98 | 
            +
                end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
                def self.new(ptr, source = nil)
         | 
| 101 | 
            +
                  bitmap = super(ptr, source)
         | 
| 102 | 
            +
             | 
| 103 | 
            +
                  if block_given?
         | 
| 92 104 | 
             
                    begin
         | 
| 93 105 | 
             
                      yield bitmap
         | 
| 94 106 | 
             
                    ensure
         | 
| 95 107 | 
             
                      bitmap.free
         | 
| 96 108 | 
             
                    end
         | 
| 109 | 
            +
                  else
         | 
| 110 | 
            +
                    bitmap
         | 
| 97 111 | 
             
                  end
         | 
| 98 112 | 
             
                end
         | 
| 99 113 |  | 
| @@ -112,11 +126,19 @@ module FreeImage | |
| 112 126 | 
             
                  super(ptr)
         | 
| 113 127 | 
             
                end
         | 
| 114 128 |  | 
| 129 | 
            +
                # :call-seq:
         | 
| 130 | 
            +
                #   image.clone -> bitmap
         | 
| 131 | 
            +
                #   image.clone {|img| block} -> bitmap
         | 
| 132 | 
            +
                # 
         | 
| 115 133 | 
             
                # Creates an exact copy of the current image.
         | 
| 116 | 
            -
                 | 
| 134 | 
            +
                #
         | 
| 135 | 
            +
                # If an optional block is provided, it will be passed the new image as an argument.  The
         | 
| 136 | 
            +
                # image will be automatically closed when the block completes.
         | 
| 137 | 
            +
                #
         | 
| 138 | 
            +
                def clone(&block)
         | 
| 117 139 | 
             
                  ptr = FreeImage.FreeImage_Clone(self)
         | 
| 118 140 | 
             
                  FreeImage.check_last_error
         | 
| 119 | 
            -
                  self.class.new(ptr)
         | 
| 141 | 
            +
                  self.class.new(ptr, &block)
         | 
| 120 142 | 
             
                end
         | 
| 121 143 |  | 
| 122 144 | 
             
                # Save the image to the specified source.
         | 
| @@ -146,9 +168,5 @@ module FreeImage | |
| 146 168 | 
             
                    raise(ArgumentError, "Unknown source type: #{source.class.name}")
         | 
| 147 169 | 
             
                  end
         | 
| 148 170 | 
             
                end
         | 
| 149 | 
            -
             | 
| 150 | 
            -
                def figure_color_klass
         | 
| 151 | 
            -
                  
         | 
| 152 | 
            -
                end
         | 
| 153 171 | 
             
              end
         | 
| 154 172 | 
             
            end
         | 
| @@ -14,9 +14,9 @@ module FreeImage | |
| 14 14 | 
             
              # :double:: Array of double: 64-bit IEEE floating point
         | 
| 15 15 | 
             
              # :complex:: Array of FICOMPLEX: 2 x 64-bit IEEE floating point
         | 
| 16 16 | 
             
              # :rgb16:: 48-bit rgb image: 3 x 16-bit
         | 
| 17 | 
            -
              # :rgba16:: 64-bit  | 
| 17 | 
            +
              # :rgba16:: 64-bit rgba image: 4 x 16-bit
         | 
| 18 18 | 
             
              # :rgbf:: 96-bit rgb float image: 3 x 32-bit IEEE floating point
         | 
| 19 | 
            -
              # :rgbaf:: 128-bit  | 
| 19 | 
            +
              # :rgbaf:: 128-bit rgba float image: 4 x 32-bit IEEE floating point
         | 
| 20 20 | 
             
              #
         | 
| 21 21 | 
             
              # :method: image_types
         | 
| 22 22 |  | 
| @@ -33,6 +33,10 @@ module FreeImage | |
| 33 33 | 
             
              attach_function('FreeImage_ConvertToType', [:pointer, :image_type, FreeImage::Boolean], :pointer)
         | 
| 34 34 |  | 
| 35 35 | 
             
              module Conversions
         | 
| 36 | 
            +
                # :call-seq:
         | 
| 37 | 
            +
                #   image.convert_to_4bits -> bitmap
         | 
| 38 | 
            +
                #   image.convert_to_4bits {|img| block} -> bitmap
         | 
| 39 | 
            +
                #
         | 
| 36 40 | 
             
                # Converts a bitmap to 4 bits. If the bitmap is a high-color (16, 24 or 32-bit),
         | 
| 37 41 | 
             
                # monochrome or greyscale bitmap (1 or 8-bit) the end result will be a greyscale bitmap.
         | 
| 38 42 | 
             
                # A 1-bit bitmap will become a palletized bitmap. 
         | 
| @@ -40,12 +44,20 @@ module FreeImage | |
| 40 44 | 
             
                # Note that "greyscale" means that the resulting bitmap will have grey colors,
         | 
| 41 45 | 
             
                # but the palette won't be a linear greyscale palette. Thus, FreeImage::Bitmap.color_type
         | 
| 42 46 | 
             
                # will return a :palette.
         | 
| 43 | 
            -
                 | 
| 47 | 
            +
                #
         | 
| 48 | 
            +
                # If an optional block is provided, it will be passed the new image as an argument.  The
         | 
| 49 | 
            +
                # image will be automatically closed when the block completes.
         | 
| 50 | 
            +
                #
         | 
| 51 | 
            +
                def convert_to_4bits(&block)
         | 
| 44 52 | 
             
                  ptr = FreeImage.FreeImage_ConvertTo4Bits(self)
         | 
| 45 53 | 
             
                  FreeImage.check_last_error
         | 
| 46 | 
            -
                  self.class.new(ptr)
         | 
| 54 | 
            +
                  self.class.new(ptr, &block)
         | 
| 47 55 | 
             
                end
         | 
| 48 56 |  | 
| 57 | 
            +
                # :call-seq:
         | 
| 58 | 
            +
                #   image.convert_to_8bits -> bitmap
         | 
| 59 | 
            +
                #   image.convert_to_8bits {|img| block} -> bitmap
         | 
| 60 | 
            +
                #
         | 
| 49 61 | 
             
                # Converts a bitmap to 8 bits. If the bitmap is a high-color (16, 24 or 32-bit),
         | 
| 50 62 | 
             
                # monochrome or greyscale bitmap (1 or 4-bit) the end result will be a greyscale bitmap.
         | 
| 51 63 | 
             
                # A 1-bit or 4-bit bitmap will become a palletized bitmap.
         | 
| @@ -53,59 +65,107 @@ module FreeImage | |
| 53 65 | 
             
                # For 16-bit greyscale images (images whose type is :uint16), conversion is done by
         | 
| 54 66 | 
             
                # dividing the 16-bit channel by 256 (see also FreeImage::Bitmap.ConvertToStandardType).
         | 
| 55 67 | 
             
                # A nil value is returned for other non-standard bitmap types.
         | 
| 56 | 
            -
                 | 
| 68 | 
            +
                #
         | 
| 69 | 
            +
                # If an optional block is provided, it will be passed the new image as an argument.  The
         | 
| 70 | 
            +
                # image will be automatically closed when the block completes.
         | 
| 71 | 
            +
                #
         | 
| 72 | 
            +
                def convert_to_8bits(&block)
         | 
| 57 73 | 
             
                  ptr = FreeImage.FreeImage_ConvertTo8Bits(self)
         | 
| 58 74 | 
             
                  FreeImage.check_last_error
         | 
| 59 | 
            -
                  self.class.new(ptr)
         | 
| 75 | 
            +
                  self.class.new(ptr, &block)
         | 
| 60 76 | 
             
                end
         | 
| 61 77 |  | 
| 78 | 
            +
                # :call-seq:
         | 
| 79 | 
            +
                #   image.convert_to_greyscale -> bitmap
         | 
| 80 | 
            +
                #   image.convert_to_greyscale {|img| block} -> bitmap
         | 
| 81 | 
            +
                #
         | 
| 62 82 | 
             
                # Converts a bitmap to a 8-bit greyscale image with a linear ramp. Contrary to
         | 
| 63 83 | 
             
                # the FreeImage::Conversions#convert_to_8bits function, 1-, 4- and 8-bit palletized
         | 
| 64 84 | 
             
                # bitmaps are correctly converted, as well as images with a :minis_white color type.
         | 
| 65 | 
            -
                 | 
| 85 | 
            +
                #
         | 
| 86 | 
            +
                # If an optional block is provided, it will be passed the new image as an argument.  The
         | 
| 87 | 
            +
                # image will be automatically closed when the block completes.
         | 
| 88 | 
            +
                #
         | 
| 89 | 
            +
                def convert_to_greyscale(&block)
         | 
| 66 90 | 
             
                  ptr = FreeImage.FreeImage_ConvertToGreyscale(self)
         | 
| 67 91 | 
             
                  FreeImage.check_last_error
         | 
| 68 | 
            -
                  self.class.new(ptr)
         | 
| 92 | 
            +
                  self.class.new(ptr, &block)
         | 
| 69 93 | 
             
                end
         | 
| 70 94 |  | 
| 95 | 
            +
                # :call-seq:
         | 
| 96 | 
            +
                #   image.convert_to_16bits_555 -> bitmap
         | 
| 97 | 
            +
                #   image.convert_to_16bits_555 {|img| block} -> bitmap
         | 
| 98 | 
            +
                #
         | 
| 71 99 | 
             
                # Converts a bitmap to 16 bits, where each pixel has a color pattern of
         | 
| 72 100 | 
             
                # 5 bits red, 5 bits green and 5 bits blue. One bit in each pixel is
         | 
| 73 101 | 
             
                # unused.
         | 
| 74 | 
            -
                 | 
| 102 | 
            +
                #
         | 
| 103 | 
            +
                # If an optional block is provided, it will be passed the new image as an argument.  The
         | 
| 104 | 
            +
                # image will be automatically closed when the block completes.
         | 
| 105 | 
            +
                #
         | 
| 106 | 
            +
                def convert_to_16bits_555(&block)
         | 
| 75 107 | 
             
                  ptr = FreeImage.FreeImage_ConvertTo16Bits555(self)
         | 
| 76 108 | 
             
                  FreeImage.check_last_error
         | 
| 77 | 
            -
                  self.class.new(ptr)
         | 
| 109 | 
            +
                  self.class.new(ptr, &block)
         | 
| 78 110 | 
             
                end
         | 
| 79 111 |  | 
| 112 | 
            +
                # :call-seq:
         | 
| 113 | 
            +
                #   image.convert_to_16bits_565 -> bitmap
         | 
| 114 | 
            +
                #   image.convert_to_16bits_565 {|img| block} -> bitmap
         | 
| 115 | 
            +
                #
         | 
| 80 116 | 
             
                # Converts a bitmap to 16 bits, where each pixel has a color pattern of
         | 
| 81 117 | 
             
                # 5 bits red, 6 bits green and 5 bits blue. One bit in each pixel is
         | 
| 82 118 | 
             
                # unused.
         | 
| 83 | 
            -
                 | 
| 119 | 
            +
                #
         | 
| 120 | 
            +
                # If an optional block is provided, it will be passed the new image as an argument.  The
         | 
| 121 | 
            +
                # image will be automatically closed when the block completes.
         | 
| 122 | 
            +
                #
         | 
| 123 | 
            +
                def convert_to_16bits_565(&block)
         | 
| 84 124 | 
             
                  ptr = FreeImage.FreeImage_ConvertTo16Bits565(self)
         | 
| 85 125 | 
             
                  FreeImage.check_last_error
         | 
| 86 | 
            -
                  self.class.new(ptr)
         | 
| 126 | 
            +
                  self.class.new(ptr, &block)
         | 
| 87 127 | 
             
                end
         | 
| 88 128 |  | 
| 129 | 
            +
                # :call-seq:
         | 
| 130 | 
            +
                #   image.convert_to_24bits -> bitmap
         | 
| 131 | 
            +
                #   image.convert_to_24bits {|img| block} -> bitmap
         | 
| 132 | 
            +
                #
         | 
| 89 133 | 
             
                # Converts a bitmap to 24 bits. For 48-bit RGB images, conversion is done
         | 
| 90 134 | 
             
                # by dividing each 16-bit channel by 256. A nil value is returned for
         | 
| 91 135 | 
             
                # other non-standard bitmap types.
         | 
| 92 | 
            -
                 | 
| 136 | 
            +
                #
         | 
| 137 | 
            +
                # If an optional block is provided, it will be passed the new image as an argument.  The
         | 
| 138 | 
            +
                # image will be automatically closed when the block completes.
         | 
| 139 | 
            +
                #
         | 
| 140 | 
            +
                def convert_to_24bits(&block)
         | 
| 93 141 | 
             
                  ptr = FreeImage.FreeImage_ConvertTo24Bits(self)
         | 
| 94 142 | 
             
                  FreeImage.check_last_error
         | 
| 95 | 
            -
                  self.class.new(ptr)
         | 
| 143 | 
            +
                  self.class.new(ptr, &block)
         | 
| 96 144 | 
             
                end
         | 
| 97 145 |  | 
| 146 | 
            +
                # :call-seq:
         | 
| 147 | 
            +
                #   image.convert_to_32bits -> bitmap
         | 
| 148 | 
            +
                #   image.convert_to_32bits {|img| block} -> bitmap
         | 
| 149 | 
            +
                #
         | 
| 98 150 | 
             
                # Converts a bitmap to 32 bits. For 48-bit RGB images, conversion is done
         | 
| 99 151 | 
             
                # by dividing each 16-bit channel by 256 and by setting the alpha channel
         | 
| 100 152 | 
             
                # to an opaque value (0xFF). For 64-bit RGBA images, conversion is done
         | 
| 101 153 | 
             
                # by dividing each 16-bit channel by 256. A nil value is returned for
         | 
| 102 154 | 
             
                # other non-standard bitmap types.
         | 
| 103 | 
            -
                 | 
| 155 | 
            +
                #
         | 
| 156 | 
            +
                # If an optional block is provided, it will be passed the new image as an argument.  The
         | 
| 157 | 
            +
                # image will be automatically closed when the block completes.
         | 
| 158 | 
            +
                #
         | 
| 159 | 
            +
                def convert_to_32bits(&block)
         | 
| 104 160 | 
             
                  ptr = FreeImage.FreeImage_ConvertTo32Bits(self)
         | 
| 105 161 | 
             
                  FreeImage.check_last_error
         | 
| 106 | 
            -
                  self.class.new(ptr)
         | 
| 162 | 
            +
                  self.class.new(ptr, &block)
         | 
| 107 163 | 
             
                end
         | 
| 108 164 |  | 
| 165 | 
            +
                # :call-seq:
         | 
| 166 | 
            +
                #   image.convert_to_standard_type(scale_linear = true) -> bitmap
         | 
| 167 | 
            +
                #   image.convert_to_standard_type(scale_linear = true) {|img| block} -> bitmap
         | 
| 168 | 
            +
                #
         | 
| 109 169 | 
             
                # Converts a non standard image whose color type is :minis_black to a
         | 
| 110 170 | 
             
                # standard 8-bit greyscale image.  When the scale_linear parameter is
         | 
| 111 171 | 
             
                # true, conversion is done by scaling linearly each pixel value from [min, max]
         | 
| @@ -119,48 +179,76 @@ module FreeImage | |
| 119 179 | 
             
                # For standard bitmaps, a clone of the original bitmap is returned.
         | 
| 120 180 | 
             
                # For complex images, the magnitude is extracted as a double image and then converted
         | 
| 121 181 | 
             
                # according to the scale parameter.
         | 
| 122 | 
            -
                 | 
| 182 | 
            +
                #
         | 
| 183 | 
            +
                # If an optional block is provided, it will be passed the new image as an argument.  The
         | 
| 184 | 
            +
                # image will be automatically closed when the block completes.
         | 
| 185 | 
            +
                #
         | 
| 186 | 
            +
                def convert_to_standard_type(scale_linear = true, &block)
         | 
| 123 187 | 
             
                  ptr = FreeImage.FreeImage_ConvertToStandardType(self, scale_linear)
         | 
| 124 188 | 
             
                  FreeImage.check_last_error
         | 
| 125 | 
            -
                  self.class.new(ptr)
         | 
| 189 | 
            +
                  self.class.new(ptr, &block)
         | 
| 126 190 | 
             
                end
         | 
| 127 191 |  | 
| 192 | 
            +
                # :call-seq:
         | 
| 193 | 
            +
                #   image.convert_to_type(dst_image_type, scale_linear = true) -> bitmap
         | 
| 194 | 
            +
                #   image.convert_to_type(dst_image_type, scale_linear = true) {|img| block} -> bitmap
         | 
| 195 | 
            +
                #
         | 
| 128 196 | 
             
                # Converts a bitmap to the specified destination image type.  When the image_type
         | 
| 129 197 | 
             
                # is equal to :bitmap, the function calls FreeImage::Converstions#convert_to_standard_type.
         | 
| 130 198 | 
             
                # Otherwise, conversion is done using standard C language casting conventions. When
         | 
| 131 199 | 
             
                # a conversion is not allowed, a nil value is returned and an error is thrown.
         | 
| 132 200 | 
             
                # Please refer to the FreeImage documentation for allowed conversions.
         | 
| 133 | 
            -
                 | 
| 201 | 
            +
                #
         | 
| 202 | 
            +
                # If an optional block is provided, it will be passed the new image as an argument.  The
         | 
| 203 | 
            +
                # image will be automatically closed when the block completes.
         | 
| 204 | 
            +
                #
         | 
| 205 | 
            +
                def convert_to_type(dst_image_type, scale_linear = true, &block)
         | 
| 134 206 | 
             
                  ptr = FreeImage.FreeImage_ConvertToType(self, dst_image_type, scale_linear)
         | 
| 135 207 | 
             
                  FreeImage.check_last_error
         | 
| 136 | 
            -
                  self.class.new(ptr)
         | 
| 208 | 
            +
                  self.class.new(ptr, &block)
         | 
| 137 209 | 
             
                end
         | 
| 138 210 |  | 
| 211 | 
            +
                # :call-seq:
         | 
| 212 | 
            +
                #   image.dither(algorithm) -> bitmap
         | 
| 213 | 
            +
                #   image.dither(algorithm) {|img| block} -> bitmap
         | 
| 214 | 
            +
                #
         | 
| 139 215 | 
             
                # Converts a bitmap to 1-bit monochrome bitmap using the specified
         | 
| 140 216 | 
             
                # {dithering}[rdoc-ref:FreeImage.dithers] algorithm. For 1-bit input
         | 
| 141 217 | 
             
                # bitmaps, the function clones the input bitmap and builds a
         | 
| 142 218 | 
             
                # monochrome palette.  Otherwise the function first converts the
         | 
| 143 219 | 
             
                # bitmap to a 8-bit greyscale bitmap.
         | 
| 144 | 
            -
                 | 
| 220 | 
            +
                #
         | 
| 221 | 
            +
                # If an optional block is provided, it will be passed the new image as an argument.  The
         | 
| 222 | 
            +
                # image will be automatically closed when the block completes.
         | 
| 223 | 
            +
                #
         | 
| 224 | 
            +
                def dither(algorithm, &block)
         | 
| 145 225 | 
             
                  ptr = FreeImage.FreeImage_Dither(self, algorithm)
         | 
| 146 226 | 
             
                  FreeImage.check_last_error
         | 
| 147 | 
            -
                  self.class.new(ptr)
         | 
| 227 | 
            +
                  self.class.new(ptr, &block)
         | 
| 148 228 | 
             
                end
         | 
| 149 229 |  | 
| 230 | 
            +
                # :call-seq:
         | 
| 231 | 
            +
                #   image.threshold(value) -> bitmap
         | 
| 232 | 
            +
                #   image.threshold(value) {|img| block} -> bitmap
         | 
| 233 | 
            +
                #
         | 
| 150 234 | 
             
                # Converts a bitmap to 1-bit monochrome bitmap using a threshold value
         | 
| 151 235 | 
             
                # between 0 and 255.  The function first converts the bitmap to a 8-bit
         | 
| 152 236 | 
             
                # greyscale bitmap. Then any brightness level that is less than the
         | 
| 153 237 | 
             
                # threshold is set to zero and any value above is set to 1.
         | 
| 154 238 | 
             
                # For 1-bit input bitmaps, the function clones the input bitmap and
         | 
| 155 239 | 
             
                # builds a monochrome palette.
         | 
| 156 | 
            -
                 | 
| 240 | 
            +
                #
         | 
| 241 | 
            +
                # If an optional block is provided, it will be passed the new image as an argument.  The
         | 
| 242 | 
            +
                # image will be automatically closed when the block completes.
         | 
| 243 | 
            +
                #
         | 
| 244 | 
            +
                def threshold(value, &block)
         | 
| 157 245 | 
             
                  value = Integer(value)
         | 
| 158 246 | 
             
                  unless (0..255).include?(value)
         | 
| 159 247 | 
             
                    raise(RangeError, "Value is out of range 0..255. Value: #{value}")
         | 
| 160 248 | 
             
                  end
         | 
| 161 249 | 
             
                  ptr = FreeImage.FreeImage_Threshold(self, value)
         | 
| 162 250 | 
             
                  FreeImage.check_last_error
         | 
| 163 | 
            -
                  self.class.new(ptr)
         | 
| 251 | 
            +
                  self.class.new(ptr, &block)
         | 
| 164 252 | 
             
                end
         | 
| 165 253 | 
             
              end
         | 
| 166 254 | 
             
            end
         | 
| @@ -45,6 +45,10 @@ module FreeImage | |
| 45 45 | 
             
              # filling background colors.
         | 
| 46 46 | 
             
              #
         | 
| 47 47 | 
             
              module Modify
         | 
| 48 | 
            +
                # :call-seq:
         | 
| 49 | 
            +
                #   image.composite(background_bitmap) -> bitmap
         | 
| 50 | 
            +
                #   image.composite(background_bitmap) {|img| block} -> bitmap
         | 
| 51 | 
            +
                #
         | 
| 48 52 | 
             
                # Composites a transparent foreground image against a background image.
         | 
| 49 53 | 
             
                # The equation for computing a composited sample value is:
         | 
| 50 54 | 
             
                #
         | 
| @@ -53,12 +57,20 @@ module FreeImage | |
| 53 57 | 
             
                # Where alpha and the input and output sample values are expressed as fractions
         | 
| 54 58 | 
             
                # in the range 0 to 1. For color images, the computation is done separately
         | 
| 55 59 | 
             
                # for R, G, and B samples.
         | 
| 56 | 
            -
                 | 
| 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)
         | 
| 57 65 | 
             
                  ptr = FreeImage.FreeImage_Composite(self, false, nil, background_bitmap)
         | 
| 58 66 | 
             
                  FreeImage.check_last_error
         | 
| 59 | 
            -
                  self.class.new(ptr)
         | 
| 67 | 
            +
                  self.class.new(ptr, &block)
         | 
| 60 68 | 
             
                end
         | 
| 61 69 |  | 
| 70 | 
            +
                # :call-seq:
         | 
| 71 | 
            +
                #   image.composite_with_color(background_color) -> bitmap
         | 
| 72 | 
            +
                #   image.composite_with_color(background_color) {|img| block} -> bitmap
         | 
| 73 | 
            +
                #
         | 
| 62 74 | 
             
                # Composites a transparent foreground image against a background color.
         | 
| 63 75 | 
             
                # The equation for computing a composited sample value is:
         | 
| 64 76 | 
             
                #
         | 
| @@ -67,25 +79,41 @@ module FreeImage | |
| 67 79 | 
             
                # Where alpha and the input and output sample values are expressed as fractions
         | 
| 68 80 | 
             
                # in the range 0 to 1. For color images, the computation is done separately
         | 
| 69 81 | 
             
                # for R, G, and B samples.
         | 
| 70 | 
            -
                 | 
| 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)
         | 
| 71 87 | 
             
                  ptr = FreeImage.FreeImage_Composite(self, false, background_color, nil)
         | 
| 72 88 | 
             
                  FreeImage.check_last_error
         | 
| 73 | 
            -
                  self.class.new(ptr)
         | 
| 89 | 
            +
                  self.class.new(ptr, &block)
         | 
| 74 90 | 
             
                end
         | 
| 75 91 |  | 
| 92 | 
            +
                # :call-seq:
         | 
| 93 | 
            +
                #   image.copy(left, top, right, bottom) -> bitmap
         | 
| 94 | 
            +
                #   image.copy(left, top, right, bottom) {|img| block} -> bitmap
         | 
| 95 | 
            +
                #
         | 
| 76 96 | 
             
                # Copy a subpart of the current image. The rectangle defined by the
         | 
| 77 97 | 
             
                # left, top, right, bottom parameters is first normalized such that the
         | 
| 78 98 | 
             
                # value of the left coordinate is less than the right and the top is less
         | 
| 79 99 | 
             
                # than the bottom. Then, the returned bitmap is defined by a width equal to
         | 
| 80 100 | 
             
                # (right - left) and a height equal to (bottom - top).
         | 
| 81 101 | 
             
                #
         | 
| 82 | 
            -
                #  | 
| 83 | 
            -
                 | 
| 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)
         | 
| 84 108 | 
             
                  ptr = FreeImage.FreeImage_Copy(self, left, top, right, bottom)
         | 
| 85 109 | 
             
                  FreeImage.check_last_error
         | 
| 86 | 
            -
                  self.class.new(ptr)
         | 
| 110 | 
            +
                  self.class.new(ptr, &block)
         | 
| 87 111 | 
             
                end
         | 
| 88 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 | 
            +
                #
         | 
| 89 117 | 
             
                # Enlarges or shrinks an image selectively per side and fills newly added areas with the
         | 
| 90 118 | 
             
                # specified background color.  The common use case is to add borders to an image.
         | 
| 91 119 | 
             
                #
         | 
| @@ -117,12 +145,15 @@ module FreeImage | |
| 117 145 | 
             
                # options:: Used to control color search process for palletized images. See
         | 
| 118 146 | 
             
                #           #fill_background for more details.
         | 
| 119 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 | 
            +
                # 
         | 
| 120 151 | 
             
                # Returns a new image on success or nil.
         | 
| 121 152 | 
             
                #
         | 
| 122 | 
            -
                def enlarge_canvas(left, top, right, bottom, color, options = 0)
         | 
| 153 | 
            +
                def enlarge_canvas(left, top, right, bottom, color, options = 0, &block)
         | 
| 123 154 | 
             
                  ptr = FreeImage.FreeImage_EnlargeCanvas(self, left, top, right, bottom, color, options)
         | 
| 124 155 | 
             
                  FreeImage.check_last_error
         | 
| 125 | 
            -
                  self.class.new(ptr)
         | 
| 156 | 
            +
                  self.class.new(ptr, &block)
         | 
| 126 157 | 
             
                end
         | 
| 127 158 |  | 
| 128 159 | 
             
                # Sets all pixels of an image to the specified color.
         | 
| @@ -161,6 +192,7 @@ module FreeImage | |
| 161 192 |  | 
| 162 193 | 
             
                # :call-seq:
         | 
| 163 194 | 
             
                #   bitmap.make_thumbnail(max_pixel_size, convert = true) -> bitmap
         | 
| 195 | 
            +
                #   bitmap.make_thumbnail(max_pixel_size, convert = true) {|img| block} -> bitmap
         | 
| 164 196 | 
             
                #
         | 
| 165 197 | 
             
                # Creates a thumbnail image that fits inside a square of size max_pixel_size,
         | 
| 166 198 | 
             
                # keeping the original aspect ratio intact.  Downsampling is done using a bilinear
         | 
| @@ -174,10 +206,13 @@ module FreeImage | |
| 174 206 | 
             
                #           to standard images (i.e. 8-, 24 or 32-bit images).  The
         | 
| 175 207 | 
             
                #           default value is true.
         | 
| 176 208 | 
             
                #
         | 
| 177 | 
            -
                 | 
| 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)
         | 
| 178 213 | 
             
                  ptr = FreeImage.FreeImage_MakeThumbnail(self, max_pixel_size, convert)
         | 
| 179 214 | 
             
                  FreeImage.check_last_error
         | 
| 180 | 
            -
                  self.class.new(ptr)
         | 
| 215 | 
            +
                  self.class.new(ptr, &block)
         | 
| 181 216 | 
             
                end
         | 
| 182 217 |  | 
| 183 218 | 
             
                # Combines or blends a subpart of another image with the current image.
         | 
| @@ -201,6 +236,7 @@ module FreeImage | |
| 201 236 |  | 
| 202 237 | 
             
                # :call-seq:
         | 
| 203 238 | 
             
                #   bitmap.rescale(width, height, filter) -> bitmap
         | 
| 239 | 
            +
                #   bitmap.rescale(width, height, filter) {|img| block} -> bitmap -> bitmap
         | 
| 204 240 | 
             
                #
         | 
| 205 241 | 
             
                # Resamples an image to the desired width and height. Resampling changes the
         | 
| 206 242 | 
             
                # pixel dimensions (and therefore display size) of an image.
         | 
| @@ -252,10 +288,13 @@ module FreeImage | |
| 252 288 | 
             
                #             rare applications using band-limited photographic images with
         | 
| 253 289 | 
             
                #             no sharp edges.
         | 
| 254 290 | 
             
                #
         | 
| 255 | 
            -
                 | 
| 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)
         | 
| 256 295 | 
             
                  ptr = FreeImage.FreeImage_Rescale(self, width, height, filter)
         | 
| 257 296 | 
             
                  FreeImage.check_last_error
         | 
| 258 | 
            -
                  self.class.new(ptr)
         | 
| 297 | 
            +
                  self.class.new(ptr, &block)
         | 
| 259 298 | 
             
                end
         | 
| 260 299 | 
             
              end
         | 
| 261 300 | 
             
            end
         | 
| @@ -14,6 +14,7 @@ module FreeImage | |
| 14 14 | 
             
              module Transforms
         | 
| 15 15 | 
             
                # call-seq:
         | 
| 16 16 | 
             
                #   bitmap.rotate(angle, bk_color) -> bitmap
         | 
| 17 | 
            +
                #   bitmap.rotate(angle, bk_color) -> {|img| block} -> bitmap
         | 
| 17 18 | 
             
                #
         | 
| 18 19 | 
             
                # Rotates an image around the center of the image area by means of 3 shears.
         | 
| 19 20 | 
             
                # The rotated image retains the same size and aspect ratio of source image
         | 
| @@ -29,14 +30,18 @@ module FreeImage | |
| 29 30 | 
             
                #  angle::    Specifies the angle of rotation in degrees
         | 
| 30 31 | 
             
                #  bk_color:: The color used to fill the background.
         | 
| 31 32 | 
             
                #
         | 
| 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)
         | 
| 33 37 | 
             
                  ptr = FreeImage.FreeImage_Rotate(self, angle, bk_color)
         | 
| 34 38 | 
             
                  FreeImage.check_last_error
         | 
| 35 | 
            -
                  self.class.new(ptr)
         | 
| 39 | 
            +
                  self.class.new(ptr, &block)
         | 
| 36 40 | 
             
                end
         | 
| 37 41 |  | 
| 38 42 | 
             
                # call-seq:
         | 
| 39 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
         | 
| 40 45 | 
             
                #
         | 
| 41 46 | 
             
                # Rotates an image using a 3rd order (cubic) B-Spline. The rotated image will have
         | 
| 42 47 | 
             
                # the same width and height as the source image, so that this function is better
         | 
| @@ -52,10 +57,13 @@ module FreeImage | |
| 52 57 | 
             
                #  use_mask:: When true, irrelevant parts of the image are set to black,
         | 
| 53 58 | 
             
                #             otherwise, a mirroring technique is used to fill irrelevant pixels.
         | 
| 54 59 | 
             
                #
         | 
| 55 | 
            -
                 | 
| 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)
         | 
| 56 64 | 
             
                  ptr = FreeImage.FreeImage_RotateEx(self, angle, x_shift, y_shift, x_origin, y_origin, use_mask)
         | 
| 57 65 | 
             
                  FreeImage.check_last_error
         | 
| 58 | 
            -
                  self.class.new(ptr)
         | 
| 66 | 
            +
                  self.class.new(ptr, &block)
         | 
| 59 67 | 
             
                end
         | 
| 60 68 |  | 
| 61 69 | 
             
                # call-seq:
         | 
    
        data/test/test_bitmap.rb
    CHANGED
    
    | @@ -34,6 +34,18 @@ class BitmapTest < Test::Unit::TestCase | |
| 34 34 | 
             
                end
         | 
| 35 35 | 
             
              end
         | 
| 36 36 |  | 
| 37 | 
            +
              def test_clone
         | 
| 38 | 
            +
                image = lena_image
         | 
| 39 | 
            +
                clone = image.clone
         | 
| 40 | 
            +
                assert(!clone.equal?(image))
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
              def test_clone_block
         | 
| 44 | 
            +
                lena_image.clone do |image|
         | 
| 45 | 
            +
                  assert_not_nil(image)
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
             | 
| 37 49 | 
             
              def test_free
         | 
| 38 50 | 
             
                1000.times do
         | 
| 39 51 | 
             
                  image = sample_image
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: free-image
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.6.0
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,11 +9,11 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2011- | 
| 12 | 
            +
            date: 2011-09-02 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: ffi
         | 
| 16 | 
            -
              requirement: & | 
| 16 | 
            +
              requirement: &25091640 !ruby/object:Gem::Requirement
         | 
| 17 17 | 
             
                none: false
         | 
| 18 18 | 
             
                requirements:
         | 
| 19 19 | 
             
                - - ! '>='
         | 
| @@ -21,10 +21,10 @@ dependencies: | |
| 21 21 | 
             
                    version: 1.0.10
         | 
| 22 22 | 
             
              type: :runtime
         | 
| 23 23 | 
             
              prerelease: false
         | 
| 24 | 
            -
              version_requirements: * | 
| 24 | 
            +
              version_requirements: *25091640
         | 
| 25 25 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 26 26 | 
             
              name: hanna-nouveau
         | 
| 27 | 
            -
              requirement: & | 
| 27 | 
            +
              requirement: &25091412 !ruby/object:Gem::Requirement
         | 
| 28 28 | 
             
                none: false
         | 
| 29 29 | 
             
                requirements:
         | 
| 30 30 | 
             
                - - ! '>='
         | 
| @@ -32,10 +32,10 @@ dependencies: | |
| 32 32 | 
             
                    version: '0'
         | 
| 33 33 | 
             
              type: :development
         | 
| 34 34 | 
             
              prerelease: false
         | 
| 35 | 
            -
              version_requirements: * | 
| 35 | 
            +
              version_requirements: *25091412
         | 
| 36 36 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 37 37 | 
             
              name: open4
         | 
| 38 | 
            -
              requirement: & | 
| 38 | 
            +
              requirement: &25091136 !ruby/object:Gem::Requirement
         | 
| 39 39 | 
             
                none: false
         | 
| 40 40 | 
             
                requirements:
         | 
| 41 41 | 
             
                - - ! '>='
         | 
| @@ -43,7 +43,7 @@ dependencies: | |
| 43 43 | 
             
                    version: '0'
         | 
| 44 44 | 
             
              type: :development
         | 
| 45 45 | 
             
              prerelease: false
         | 
| 46 | 
            -
              version_requirements: * | 
| 46 | 
            +
              version_requirements: *25091136
         | 
| 47 47 | 
             
            description: ! "    FreeImage is an Open Source library project for developers who
         | 
| 48 48 | 
             
              would like to support\n    popular graphics image formats like PNG, BMP, JPEG, TIFF
         | 
| 49 49 | 
             
              and others as needed by\n    today's multimedia applications. FreeImage is easy
         |