Class: Hornetseye::RGB_

Inherits:
Composite show all
Defined in:
lib/multiarray/rgb.rb

Defined Under Namespace

Modules: Match

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Composite

basetype, descriptor, directive, memory, scalar, storage_size, typecodes

Methods inherited from Element

#compilable?, #descriptor, fetch, #get, #skip, #strip, #write

Methods inherited from Node

===, #[], #[]=, #array_type, array_type, basetype, #basetype, bool, byte, #check_shape, #coerce, coercion_bool, coercion_byte, coercion_maxint, #compilable?, compilable?, cond, contiguous, #decompose, #demand, #descriptor, descriptor, dimension, #dimension, empty?, #empty?, finalised?, #finalised?, float_scalar, floating, #force, #get, height, #height, indgen, #inspect, match, #memory, pointer_type, #pointer_type, #rgb?, scalar, #shape, shape, #simplify, #size, size, #storage_size, strip, #strip, subst, #subst, #to_a, to_s, #to_s, to_type, #typecode, typecode, typecodes, variables, #variables, #width, width

Methods included from FLOAT_::Match

#align, #fit

Methods included from OBJECT::Match

#align, #fit

Methods included from COMPLEX_::Match

#align, #fit

Methods included from Sequence_::Match

#align, #fit

Methods included from BOOL::Match

#fit

Methods included from Match

#align, #fit

Methods included from INT_::Match

#fit

Methods included from Operations

#+@, #<=>, #b=, #b_with_decompose, #collect, #conditional, #convolve, define_binary_op, define_unary_op, #diagonal, #eq_with_multiarray, #fill!, #g=, #g_with_decompose, #histogram, #histogram_with_composite, #imag=, #imag_with_decompose, #inject, #integral, #lut, #lut_with_composite, #max, #min, #normalise, #product, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #roll, #sum, #to_type, #to_type_with_rgb, #transpose, #unroll

Constructor Details

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

Returns a new instance of RGB_.



324
325
326
327
328
329
330
331
332
333
334
# File 'lib/multiarray/rgb.rb', line 324

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.



293
294
295
296
# File 'lib/multiarray/rgb.rb', line 293

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.



278
279
280
281
282
283
284
285
286
# File 'lib/multiarray/rgb.rb', line 278

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.



261
262
263
264
265
266
267
268
269
# File 'lib/multiarray/rgb.rb', line 261

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.



202
203
204
# File 'lib/multiarray/rgb.rb', line 202

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 ).



211
212
213
# File 'lib/multiarray/rgb.rb', line 211

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.



314
315
316
# File 'lib/multiarray/rgb.rb', line 314

def eql?( other )
  self == other
end

.floatClass

Convert to type based on floating point numbers

Returns:

  • (Class)

    Corresponding type based on floating point numbers.



250
251
252
# File 'lib/multiarray/rgb.rb', line 250

def float
  Hornetseye::RGB element_type.float
end

.hashFixnum

Compute hash value for this class.

Returns:



303
304
305
# File 'lib/multiarray/rgb.rb', line 303

def hash
  [ :RGB_, element_type ].hash
end

.inherited(subclass) ⇒ Object

Set base class attribute

Sets number of elements to three.



189
190
191
# File 'lib/multiarray/rgb.rb', line 189

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”).



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/multiarray/rgb.rb', line 218

def inspect
  unless element_type.nil?
    { BYTE    => 'BYTERGB',
      UBYTE   => 'UBYTERGB',
      SINT    => 'SINTRGB',
      USINT   => 'USINTRGB',
      INT     => 'INTRGB',
      UINT    => 'UINTRGB',
      LONG    => 'LONGRGB',
      ULONG   => 'ULONGRGB',
      SFLOAT  => 'SFLOATRGB',
      DFLOAT  => 'DFLOATRGB' }[ element_type ] ||
      "RGB(#{element_type.inspect})"
  else
    super
  end
end

.maxintClass

Get corresponding maximum integer type

Returns:

  • (Class)

    Returns RGB type based on integers.



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

def maxint
  Hornetseye::RGB element_type.maxint
end

.rgb?Boolean

Returns:

  • (Boolean)


318
319
320
# File 'lib/multiarray/rgb.rb', line 318

def rgb?
  true
end

Instance Method Details

#dupRGB_

Duplicate object

Returns:

  • (RGB_)

    Duplicate of self.



339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/multiarray/rgb.rb', line 339

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.store @value.r
    g.store @value.g
    b.store @value.b
    self.class.new RGB.new( r, g, b )
  else
    self.class.new get
  end
end

#store(value) ⇒ Object

Store new value in this object

Parameters:

  • value (Object)

    New value for this object.

Returns:



360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/multiarray/rgb.rb', line 360

def store( value )
  value = value.simplify
  if @value.r.respond_to? :store
    @value.r.store value.get.r
  else
    @value.r = value.get.r
  end
  if @value.g.respond_to? :store
    @value.g.store value.get.g
  else
    @value.g = value.get.g
  end
  if @value.b.respond_to? :store
    @value.b.store value.get.b
  else
    @value.b = value.get.b
  end
  value
end

#valuesArray<Object>

Get values of composite number

Returns:

  • (Array<Object>)

    Returns array with red, green, and blue component.



385
386
387
# File 'lib/multiarray/rgb.rb', line 385

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