Class: Pixels::Targa24

Inherits:
TargaBase show all
Includes:
NoAlphaChannel
Defined in:
lib/pixels.rb

Instance Attribute Summary

Attributes inherited from TargaBase

#alpha_depth, #bpp, #color_depth, #height, #origin, #width

Instance Method Summary collapse

Methods included from NoAlphaChannel

#color_from_rgba, #has_alpha?, #rgba_from_color

Methods inherited from TargaBase

#close, #each_row_rgb, #each_row_rgba, #get_row_rgb, #get_row_rgba, #initialize, #put_row_rgb, #put_row_rgba, #read_row_bytes, #spec, #write_row_bytes

Constructor Details

This class inherits a constructor from Pixels::TargaBase

Instance Method Details

#color_from_rgb(r, g, b) ⇒ Object

Return a 24-bit integer pixel value given separate red, green, and blue values.

Each r, g, b value is an integer between 0 and 255.



583
584
585
586
587
588
# File 'lib/pixels.rb', line 583

def color_from_rgb(r, g, b)
  # Pack 8-bit-per-channel values
  return ((r.to_i & 0xff) << 16) |
         ((g.to_i & 0xff) << 8) |
         (b.to_i & 0xff)
end

#get_row(y) ⇒ Object

You probably want to use TargaBase#get_row_rgb or TargaBase#get_row_rgba instead.



553
554
555
556
557
558
559
560
561
# File 'lib/pixels.rb', line 553

def get_row(y)
  bytes = read_row_bytes(y)
  row = []
  for offset in (0..@width*@bytes_per_pixel-1).step(@bytes_per_pixel)
    v, = (bytes[offset,3] + "\x00").unpack("V")
    row << (v & 0x00ffffff)
  end
  return row
end

#put_row(y, row) ⇒ Object

You probably want to use TargaBase#put_row_rgb or TargaBase#put_row_rgba instead.



564
565
566
567
# File 'lib/pixels.rb', line 564

def put_row(y, row)
  bytes = row.map{|v| [v].pack("V")[0..2]}.join
  write_row_bytes(y, bytes)
end

#rgb_from_color(color) ⇒ Object

Given a 24-bit integer colour value, return separate [r, g, b] values.

Each r, g, b value is an integer between 0 and 255.



572
573
574
575
576
577
578
# File 'lib/pixels.rb', line 572

def rgb_from_color(color)
  # Extract 8-bit-per-channel values
  b = color & 0xff
  g = (color >> 8) & 0xff
  r = (color >> 16) & 0xff
  return [r, g, b]
end