Class: Hornetseye::RGB_

Inherits:
Composite show all
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

Instance Method Summary collapse

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

#align, #fit

Methods included from FLOAT_::Match

#align, #fit

Methods included from OBJECT::Match

#align, #fit

Methods included from COMPLEX_::Match

#align, #fit

Methods included from BOOL::Match

#fit

Methods included from Match

#align, #fit

Methods included from INT_::Match

#fit

Constructor Details

#initialize(value = self.class.default) ⇒ RGB_

Constructor for native RGB value

Parameters:

  • value (RGB) (defaults to: self.class.default)

    Initial 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

Parameters:

  • other (Object)

    Object to compare with.

Returns:

  • (Boolean)

    Boolean indicating whether classes are equal.



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

Parameters:

  • other (Class)

    Other type to coerce with.

Returns:

  • (Array<Class>)

    Result of coercion.



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

Parameters:

  • other (Class)

    Other native datatype to coerce with.

Returns:

  • (Class)

    Result of coercion.



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

Parameters:

  • r (Object)

    Value for red channel.

  • g (Object)

    Value for green channel.

  • b (Object)

    Value for blue channel.

Returns:

  • (RGB)

    New object of this type.



260
261
262
# File 'lib/multiarray/rgb.rb', line 260

def construct( r, g, b )
  new RGB.new( r, g, b )
end

.defaultObject

Get default value for elements of this type

Returns:

  • (Object)

    Returns RGB( 0, 0, 0 ).



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

Parameters:

  • other (Object)

    Object to compare with.

Returns:

  • (Boolean)

    Returns true if objects are equal.



376
377
378
# File 'lib/multiarray/rgb.rb', line 376

def eql?(other)
  self == other
end

.floatClass

Convert to type based on floating point numbers

Returns:

  • (Class)

    Corresponding type based on floating point numbers.



312
313
314
# File 'lib/multiarray/rgb.rb', line 312

def float
  Hornetseye::RGB element_type.float
end

.hashFixnum

Compute hash value for this class

Returns:



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.

Parameters:

  • subclass (Class)

    The class inheriting from RGB_.

Returns:

  • The return value should be ignored.



241
242
243
# File 'lib/multiarray/rgb.rb', line 241

def inherited(subclass)
  subclass.num_elements = 3
end

.inspectString

Diplay information about this class

Returns:

  • (String)

    Text with information about this class (e.g. “DFLOATRGB”).



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

.maxintClass

Get corresponding maximum integer type

Returns:

  • (Class)

    Returns RGB type based on integers.



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

Returns:

  • (Boolean)

    Returns true.



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

Parameters:

  • value (Object)

    New value for this object.

Returns:



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

#dupRGB_

Duplicate object

Returns:

  • (RGB_)

    Duplicate of self.



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

#valuesArray<Object>

Get values of composite number

Returns:

  • (Array<Object>)

    Returns array with red, green, and blue component.



453
454
455
# File 'lib/multiarray/rgb.rb', line 453

def values
  [ @value.r, @value.g, @value.b ]
end