Class: Axon::AlphaStripper

Inherits:
Object
  • Object
show all
Defined in:
lib/axon/alpha_stripper.rb

Overview

Strips the Alpha Channel from an Image

Axon::AlphaStripper Removes the Alpha Channel from an Image.

Example

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ AlphaStripper

:call-seq:

AlphaStripper.new(image_in)

Removes the alpha channel from image_in.



17
18
19
# File 'lib/axon/alpha_stripper.rb', line 17

def initialize(source)
  @source = source
end

Instance Method Details

#componentsObject

Gets the components in the image.



35
36
37
38
39
40
41
# File 'lib/axon/alpha_stripper.rb', line 35

def components
  case @source.components
  when 2 then 1
  when 4 then 3
  else @source.components
  end
end

#getsObject

Gets the next scanline from the image.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/axon/alpha_stripper.rb', line 51

def gets
  sl = @source.gets
  return unless sl

  # This should probably be done in C, but not seeing alpha stripping
  # performance as terribly important right now.
  case @source.components
  when 2
    (sl.size / 2).times{ |i| sl.slice!(1) }
    sl
  when 4
    (sl.size / 4).times{ |i| sl.slice!(3) }
    sl
  else
    sl
  end
end

#heightObject

Gets the height of the image. Same as the height of the source image.



23
24
25
# File 'lib/axon/alpha_stripper.rb', line 23

def height
  @source.height
end

#linenoObject

Gets the line number of the next scanline.



45
46
47
# File 'lib/axon/alpha_stripper.rb', line 45

def lineno
  @source.lineno
end

#widthObject

Gets the width of the image. Same as the width of the source image.



29
30
31
# File 'lib/axon/alpha_stripper.rb', line 29

def width
  @source.width
end