Class: Hornetseye::RGB_
- Defined in:
- lib/multiarray/rgb.rb
Overview
Class for representing native RGB values
Defined Under Namespace
Modules: Match
Constant Summary collapse
- IDENTIFIER =
Identifier array used internally
{ BYTE => 'BYTERGB', UBYTE => 'UBYTERGB', SINT => 'SINTRGB', USINT => 'USINTRGB', INT => 'INTRGB', UINT => 'UINTRGB', LONG => 'LONGRGB', ULONG => 'ULONGRGB', SFLOAT => 'SFLOATRGB', DFLOAT => 'DFLOATRGB' }
Class Method Summary collapse
-
.==(other) ⇒ Boolean
Test equality of classes.
-
.coerce(other) ⇒ Array<Class>
Type coercion for native elements.
-
.coercion(other) ⇒ Class
Compute balanced type for binary operation.
-
.construct(r, g, b) ⇒ RGB
Construct new object from arguments.
-
.default ⇒ Object
Get default value for elements of this type.
-
.eql?(other) ⇒ Boolean
Equality for hash operations.
-
.float ⇒ Class
Convert to type based on floating point numbers.
-
.hash ⇒ Fixnum
Compute hash value for this class.
- .inherit(element_type) ⇒ Object
-
.inherited(subclass) ⇒ Object
Set base class attribute.
-
.inspect ⇒ String
Diplay information about this class.
-
.maxint ⇒ Class
Get corresponding maximum integer type.
-
.rgb? ⇒ Boolean
Check whether this object is an RGB value.
Instance Method Summary collapse
-
#assign(value) ⇒ Object
Store new value in this object.
-
#dup ⇒ RGB_
Duplicate object.
-
#initialize(value = self.class.default) ⇒ RGB_
constructor
Constructor for native RGB value.
-
#values ⇒ Array<Object>
Get values of composite number.
Methods inherited from Composite
basetype, #decompose, descriptor, directive, memory_type, scalar, storage_size, typecodes
Methods inherited from Element
#compilable?, #descriptor, fetch, #get, #skip, #strip, #write
Methods inherited from Node
#+@, #<=>, ===, #[], #[]=, #allocate, #b=, #b_with_decompose, basetype, #basetype, #between?, bool, byte, #check_shape, #clip, #coerce, coercion_bool, coercion_byte, coercion_maxint, #collect, #compilable?, compilable?, #components, cond, #conditional, #convolve, #decompose, define_binary_op, define_unary_op, #demand, #descriptor, descriptor, #diagonal, #dilate, dimension, #dimension, #downsample, #each, #empty?, #eq_with_multiarray, #erode, #fill!, finalised?, #finalised?, #flip, float_scalar, floating, #fmod_with_float, #force, #g=, #g_with_decompose, #gauss_blur, #gauss_gradient, #get, #height, #histogram, #histogram_with_rgb, identity, #if, #if_else, #imag=, #imag_with_decompose, indgen, #inject, #inspect, #integral, #lut, #lut_with_rgb, #malloc, #mask, match, #matched?, #max, #mean, #memorise, #memory, #min, #normalise, #prod, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #reshape, #rgb?, #roll, scalar, #shape, shape, #shift, #simplify, #size, #sobel, #stretch, #stride, #strides, #strip, strip, #subst, subst, #sum, #swap_rgb_with_scalar, #table, #to_a, #to_s, to_s, #to_type, to_type, #to_type_with_identity, #to_type_with_rgb, #transpose, #typecode, typecode, typecodes, #unmask, #unroll, #variables, variables, #warp, #width
Methods included from Field_::Match
Methods included from FLOAT_::Match
Methods included from OBJECT::Match
Methods included from COMPLEX_::Match
Methods included from BOOL::Match
Methods included from Match
Methods included from INT_::Match
Constructor Details
#initialize(value = self.class.default) ⇒ RGB_
Constructor for native RGB value
392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/multiarray/rgb.rb', line 392 def initialize( value = self.class.default ) if Thread.current[ :function ].nil? or [ value.r, value.g, value.b ].all? { |c| c.is_a? GCCValue } @value = value else r = GCCValue.new Thread.current[ :function ], value.r.to_s g = GCCValue.new Thread.current[ :function ], value.g.to_s b = GCCValue.new Thread.current[ :function ], value.b.to_s @value = RGB.new r, g, b end end |
Class Method Details
.==(other) ⇒ Boolean
Test equality of classes
355 356 357 358 |
# File 'lib/multiarray/rgb.rb', line 355 def ==(other) other.is_a? Class and other < RGB_ and element_type == other.element_type end |
.coerce(other) ⇒ Array<Class>
Type coercion for native elements
340 341 342 343 344 345 346 347 348 |
# File 'lib/multiarray/rgb.rb', line 340 def coerce(other) if other < RGB_ return other, self elsif other < INT_ or other < FLOAT_ return Hornetseye::RGB(other), self else super other end end |
.coercion(other) ⇒ Class
Compute balanced type for binary operation
323 324 325 326 327 328 329 330 331 |
# File 'lib/multiarray/rgb.rb', line 323 def coercion(other) if other < RGB_ Hornetseye::RGB element_type.coercion( other.element_type ) elsif other < INT_ or other < FLOAT_ Hornetseye::RGB element_type.coercion(other) else super other end end |
.construct(r, g, b) ⇒ RGB
Construct new object from arguments
260 261 262 |
# File 'lib/multiarray/rgb.rb', line 260 def construct( r, g, b ) new RGB.new( r, g, b ) end |
.default ⇒ Object
Get default value for elements of this type
269 270 271 |
# File 'lib/multiarray/rgb.rb', line 269 def default RGB.new 0, 0, 0 end |
.eql?(other) ⇒ Boolean
Equality for hash operations
376 377 378 |
# File 'lib/multiarray/rgb.rb', line 376 def eql?(other) self == other end |
.float ⇒ Class
Convert to type based on floating point numbers
312 313 314 |
# File 'lib/multiarray/rgb.rb', line 312 def float Hornetseye::RGB element_type.float end |
.hash ⇒ Fixnum
Compute hash value for this class
365 366 367 |
# File 'lib/multiarray/rgb.rb', line 365 def hash [ :RGB_, element_type ].hash end |
.inherit(element_type) ⇒ Object
245 246 247 248 249 |
# File 'lib/multiarray/rgb.rb', line 245 def inherit(element_type) retval = Class.new self retval.element_type = element_type retval end |
.inherited(subclass) ⇒ Object
Set base class attribute
Sets number of elements to three.
241 242 243 |
# File 'lib/multiarray/rgb.rb', line 241 def inherited(subclass) subclass.num_elements = 3 end |
.inspect ⇒ String
Diplay information about this class
290 291 292 293 294 295 296 |
# File 'lib/multiarray/rgb.rb', line 290 def inspect unless element_type.nil? IDENTIFIER[ element_type ] || "RGB(#{element_type.inspect})" else super end end |
.maxint ⇒ Class
Get corresponding maximum integer type
303 304 305 |
# File 'lib/multiarray/rgb.rb', line 303 def maxint Hornetseye::RGB element_type.maxint end |
.rgb? ⇒ Boolean
Check whether this object is an RGB value
383 384 385 |
# File 'lib/multiarray/rgb.rb', line 383 def rgb? true end |
Instance Method Details
#assign(value) ⇒ Object
Store new value in this object
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'lib/multiarray/rgb.rb', line 428 def assign(value) value = value.simplify if @value.r.respond_to? :assign @value.r.assign value.get.r else @value.r = value.get.r end if @value.g.respond_to? :assign @value.g.assign value.get.g else @value.g = value.get.g end if @value.b.respond_to? :assign @value.b.assign value.get.b else @value.b = value.get.b end value end |
#dup ⇒ RGB_
Duplicate object
407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/multiarray/rgb.rb', line 407 def dup if Thread.current[ :function ] r = Thread.current[ :function ].variable self.class.element_type, 'v' g = Thread.current[ :function ].variable self.class.element_type, 'v' b = Thread.current[ :function ].variable self.class.element_type, 'v' r.assign @value.r g.assign @value.g b.assign @value.b self.class.new RGB.new( r, g, b ) else self.class.new get end end |