Class RS::Converter::RSILRMagickConverter
In: rsil/converter/rsilrmagickconverter.rb
Parent: RS::Converter::RSAbstractConverter
RSTripel RSRectangle RSObjcWrapper RSImageUnit RSImageList RSILRMagickConverter RSILTkConverter RSConverter RSProperties RSImageProperties RSPoint RSDimension Array RSVector RSFilter RSColor RSImage\n[rsil/extension/rsimageextension.rb\nrsil/graphics/rsimage.rb] RSImageX Comparable RSAbstractConverter Enumerable Test::Unit::TestCase RSTestPoint RSTestFilter RSTestImage RSTestExtension RSTestDimension RSTestVector RSTestImageUnit RSTestImageProperties RSTestColor RSTestRectangle RSTestProperties RSTestImageList RSTestConverter RSTestComparison RSTestStress RSTestUseCases RSTestTripel RSTestScenarios MonitorMixin Benchmark StandardError Assertion RSEXIFProperties RSTests rsil/geometry/rsdimension.rb rsil/geometry/rspoint.rb rsil/geometry/rsvector.rb rsil/geometry/rsrectangle.rb rsil/geometry/rstripel.rb Geometry rsil/graphics/rsfilter.rb rsil/graphics/rsimagelist.rb rsil/graphics/rscolor.rb rsil/graphics/rsimageunit.rb rsil/extension/rsimagex.rb rsil/graphics/rsimage.rb Graphics rsil/converter/rsconverter.rb rsil/converter/rsabstractconverter.rb rsil/converter/rsiltkconverter.rb rsil/converter/rsilrmagickconverter.rb Converter rsil/test/rstestusecases.rb rsil/test/rstestcolor.rb rsil/test/rstestdimension.rb rsil/test/rstestfilter.rb rsil/test/rstestpoint.rb rsil/test/rstestconverter.rb rsil/test/rstestimagelist.rb rsil/test/rstestimageproperties.rb rsil/test/rstestscenarios.rb rsil/test/rstestvector.rb rsil/test/rstesttripel.rb rsil/test/rstestproperties.rb rsil/test/rstestimageunit.rb rsil/test/rstestextension.rb rsil/test/rstestimage.rb rsil/test/rsteststress.rb rsil/test/rstestcomparison.rb rsil/test/rstestrectangle.rb rsil/test/rstests.rb Test rsil/extension/rsextension.rb Extension rsil/utils/rsimageproperties.rb rsil/utils/rsobjcwrapper.rb rsil/utils/rsproperties.rb rsil/utils/rsexifproperties.rb Utils RS Module: RS

Class:RSILRMagickConverter
File:rsilrmagickconverter.rb
Purpose:RSILRMagickConverter includes functions to convert objects of RSIL classes to object of RMagick classes.
Created by:Mario Pehle, 2006/04/28
Required modules:Magick
Offers functions:converting objects, managing of converters

Methods

Included Modules

RS::Extension

Public Class methods

Description:Converts an object to an object of specified class.
Precondition:-
Postcondition:-
Exceptions:-
Uses:RSILRMagickConverter#converts?
Returns:Object if valid arguments, else nil
Parameters:Name | i/o/io | default | Meaning
:object | i | - | The object to convert from
:klass | o | - | The class the converted object should be from

[Source]

    # File rsil/converter/rsilrmagickconverter.rb, line 79
79:   def self::convert object, klass
80:     if self.converts? object, klass
81:       case object
82:         when Magick::Image, Magick::ImageList, Magick::Pixel
83:           return self.rmagick_convert(object, klass)
84:         when RS::Graphics::RSImage, RS::Graphics::RSImageList, RS::Graphics::RSColor
85:           return self.rsil_convert(object, klass)
86:       end
87:     end
88:     nil
89:   end
Description:Checks, whether it is possible to convert a given object to an object of the given class.
Precondition:-
Postcondition:-
Exceptions:-
Uses:@@sources
Returns:true if object can be converted, else false
Parameters:Name | i/o/io | default | Meaning
:object | i | - | Object, the object to convert
:klass | o | - | Class, the class to convert object

[Source]

     # File rsil/converter/rsilrmagickconverter.rb, line 259
259:   def self::converts? object, klass
260:     converts = false
261:     ocn = object.class
262:     kn  = klass
263:     @@sources.each do |pair|
264:       converts = ((pair.first==ocn) and (pair.last==kn)) unless converts
265:     end
266:     converts
267:   end
Description:Converts an object to an object of specified class. Call this method if you want to convert a RMagick object to an RSIL object.
Precondition:-
Postcondition:-
Exceptions:-
Uses:RSILRMagickConverter#converts?, Magick::Image, Magick::ImageList, Magick::Pixel, RSImage, RSImageList, RSColor
Returns:Object if converted and nil if no convertion possible.
Parameters:Name | i/o/io | default | Meaning
:object | i | - | The object to convert from
:klass | o | - | The class the converted object should be from

[Source]

     # File rsil/converter/rsilrmagickconverter.rb, line 123
123:   def self::rmagick_convert object, klass
124:     if self.converts? object, klass
125:       case object
126:         when Magick::Image
127:           if klass == Magick::ImageList
128:             il = Magick::ImageList.new
129:             il << object.dup
130:             return il
131:           elsif klass == RS::Graphics::RSImage
132:             ri = RS::Graphics::RSImage.new
133:             ri.bytes = object.to_blob
134:             return ri
135:           elsif klass == RS::Graphics::RSImageList
136:             ri = RS::Graphics::RSImage.new
137:             ri.bytes = object.to_blob
138:             return RS::Graphics::RSImageList.new(ri)
139:           end
140:         when Magick::ImageList
141:           if klass == RS::Graphics::RSImageList
142:             rl = RS::Graphics::RSImageList.new
143:             object.each do |im|
144:               ri = RS::Graphics::RSImage.new
145:               ri.bytes = im.to_blob
146:               rl << ri
147:             end
148:             return rl
149:           end
150:         when Magick::Pixel
151:           if klass == RS::Graphics::RSColor
152:             r = object.red.to_f   * 100.0 / Magick::MaxRGB.to_f
153:             g = object.green.to_f * 100.0 / Magick::MaxRGB.to_f
154:             b = object.blue.to_f  * 100.0 / Magick::MaxRGB.to_f
155:             a = object.alpha.to_f * 100.0 / Magick::MaxRGB.to_f
156:             return RS::Graphics::RSColor.new(r, g, b, a)
157:           end
158:       end
159:     end
160:     nil
161:   end
Description:Converts an object to an object of specified class. Call this method if you want to convert a RSIL object to an RMagick object.
Precondition:-
Postcondition:-
Exceptions:-
Uses:RSILRMagickConverter#converts?, Magick::Image, Magick::ImageList, Magick::Pixel, RSImage, RSImageList, RSColor
Returns:Object if converted and nil if no convertion possible.
Parameters:Name | i/o/io | default | Meaning
:object | i | - | The object to convert from
:klass | o | - | The class the converted object should be from

[Source]

     # File rsil/converter/rsilrmagickconverter.rb, line 195
195:   def self::rsil_convert object, klass
196:     if self.converts? object, klass
197:       case object
198:         when RS::Graphics::RSImage
199:           if klass == RS::Graphics::RSImageList
200:             rl = RS::Graphics::RSImageList.new
201:             rl.add object
202:             return rl
203:           elsif klass == Magick::Image
204:             return Magick::Image.from_blob(object.bytes)
205:           elsif klass == Magick::ImageList
206:             return Magick::ImageList.new.from_blob(object.bytes)
207:           end
208:         when RS::Graphics::RSImageList
209:           if klass == Magick::ImageList
210:             il = Magick::ImageList.new
211:             object.each { |im| il.from_blob im.bytes }
212:             return il
213:           end
214:         when RS::Graphics::RSColor
215:           if klass == Magick::Pixel
216:             r = object.red.to_f   * Magick::MaxRGB.to_f
217:             g = object.green.to_f * Magick::MaxRGB.to_f
218:             b = object.blue.to_f  * Magick::MaxRGB.to_f
219:             a = object.alpha.to_f * Magick::MaxRGB.to_f
220:             return Magick::Pixel.new(r, g, b, a)
221:           end
222:       end
223:     end
224:     nil
225:   end

Public Instance methods

Description:Converts an object to an object of specified class.
Precondition:-
Postcondition:-
Exceptions:-
Uses:RSILRMagickConverter#convert
Returns:Object if valid arguments, else nil
Parameters:Name | i/o/io | default | Meaning
:object | i | - | The object to convert from
:klass | o | - | The class the converted object should be from

[Source]

    # File rsil/converter/rsilrmagickconverter.rb, line 61
61:   def convert object, klass
62:     self.class.convert object, klass
63:   end
Description:Checks, whether it is possible to convert a given object to an object of the given class.
Precondition:-
Postcondition:-
Exceptions:-
Uses:RSILRMagickConverter#converts?
Returns:true if object can be converted, else false
Parameters:Name | i/o/io | default | Meaning
:object | i | - | Object, the object to convert
:klass | o | - | Class, the class to convert object

[Source]

     # File rsil/converter/rsilrmagickconverter.rb, line 241
241:   def converts? object, klass
242:     self.class.converts? object, klass
243:   end
Description:Converts an object to an object of specified class. Call this method if you want to convert a RMagick object to an RSIL object.
Precondition:-
Postcondition:-
Exceptions:-
Uses:RSILRMagickConverter#rmagick_convert
Returns:Object if converted and nil if no convertion possible.
Parameters:Name | i/o/io | default | Meaning
:object | i | - | The object to convert from
:klass | o | - | The class the converted object should be from

[Source]

     # File rsil/converter/rsilrmagickconverter.rb, line 105
105:   def rmagick_convert object, klass
106:     self.class.rmagick_convert object, klass
107:   end
Description:Converts an object to an object of specified class. Call this method if you want to convert a RSIL object to an RMagick object.
Precondition:-
Postcondition:-
Exceptions:-
Uses:RSILRMagickConverter#rsil_convert
Returns:Object if converted and nil if no convertion possible.
Parameters:Name | i/o/io | default | Meaning
:object | i | - | The object to convert from
:klass | o | - | The class the converted object should be from

[Source]

     # File rsil/converter/rsilrmagickconverter.rb, line 177
177:   def rsil_convert object, klass
178:     self.class.rsil_convert object, klass
179:   end

[Validate]