Class: Pixels::Targa15
- 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
-
#color_from_rgb(r, g, b) ⇒ Object
Return a 15-bit integer pixel value given separate red, green, and blue values.
-
#get_row(y) ⇒ Object
You probably want to use TargaBase#get_row_rgb or TargaBase#get_row_rgba instead.
-
#put_row(y, row) ⇒ Object
You probably want to use TargaBase#put_row_rgb or TargaBase#put_row_rgba instead.
-
#rgb_from_color(color) ⇒ Object
Given a 15-bit integer colour value, return separate [r, g, b] values.
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 15-bit integer pixel value given separate red, green, and blue values.
Each r, g, b value is an integer between 0 and 255.
489 490 491 492 493 494 495 |
# File 'lib/pixels.rb', line 489 def color_from_rgb(r, g, b) # Convert 8 bits-per-channel to 5 bits-per-channel r5 = (r.to_i >> 3) & 0x1f g5 = (g.to_i >> 3) & 0x1f b5 = (b.to_i >> 3) & 0x1f return (b5 << 10) | (g5 << 5) | r5 end |
#get_row(y) ⇒ Object
You probably want to use TargaBase#get_row_rgb or TargaBase#get_row_rgba instead.
454 455 456 457 458 459 460 461 462 |
# File 'lib/pixels.rb', line 454 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,2].unpack("v") row << (v & 0x7fff) end return row end |
#put_row(y, row) ⇒ Object
You probably want to use TargaBase#put_row_rgb or TargaBase#put_row_rgba instead.
465 466 467 468 |
# File 'lib/pixels.rb', line 465 def put_row(y, row) bytes = row.pack("v" * row.length) write_row_bytes(y, bytes) end |
#rgb_from_color(color) ⇒ Object
Given a 15-bit integer colour value, return separate [r, g, b] values.
Each r, g, b value is an integer between 0 and 255.
473 474 475 476 477 478 479 480 481 482 483 484 |
# File 'lib/pixels.rb', line 473 def rgb_from_color(color) # Extract 5 bits-per-channel values b5 = color & 0x1f g5 = (color >> 5) & 0x1f r5 = (color >> 10) & 0x1f # Convert 5 bits-per-channel to 8 bits-per-channel r8 = r5 * 255 / 31 g8 = g5 * 255 / 31 b8 = b5 * 255 / 31 return [r, g, b] end |