Module: ImageRuby::RubyBitmapModl
- Defined in:
- lib/imageruby/bitmap/rbbitmap.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#alpha_data ⇒ Object
returns the alpha data string with the alpha channel information of the pixels.
-
#dup ⇒ Object
Creates a duplicate of the image.
-
#get_pixel(x, y) ⇒ Object
return a Color object of a given x and y coord.
-
#initialize_bitmap_representation(width_, height_, color = nil) ⇒ Object
Initialize the representation of bitmap with the given width and height (used internally).
- #initialize_dup(orig) ⇒ Object
-
#pixel_data ⇒ Object
returns the pixel data string with the RGB information of the pixels.
-
#set_pixel(x, y, color) ⇒ Object
set a color value for a image.
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
28 29 30 |
# File 'lib/imageruby/bitmap/rbbitmap.rb', line 28 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
27 28 29 |
# File 'lib/imageruby/bitmap/rbbitmap.rb', line 27 def width @width end |
Instance Method Details
#alpha_data ⇒ Object
returns the alpha data string with the alpha channel information of the pixels
To get the color value of a pixel on given x,y coordinates use image.get_pixel(x,y) or image
Examples
bitmap.pixel_data[(12)*bitmap.width+10] # the alpha value at x=12, y=10
bitmap.pixel_data[(12)*bitmap.width+11] # the alpha value at x=12, y=11
bitmap.pixel_data[(12)*bitmap.width+12] # the alpha value at x=12, y=12
103 104 105 106 |
# File 'lib/imageruby/bitmap/rbbitmap.rb', line 103 def alpha_data @alpha = 255.chr*(@height * @width) unless @alpha @alpha end |
#dup ⇒ Object
Creates a duplicate of the image
59 60 61 62 |
# File 'lib/imageruby/bitmap/rbbitmap.rb', line 59 def dup ret = super ret.initialize_dup(self) end |
#get_pixel(x, y) ⇒ Object
return a Color object of a given x and y coord
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/imageruby/bitmap/rbbitmap.rb', line 40 def get_pixel(x,y) index = (y*@width + x) pointindex = index*3 Color.from_rgba( @array[pointindex+2].ord, @array[pointindex+1].ord, @array[pointindex].ord, @alpha ? @alpha[index].ord : 255 ) end |
#initialize_bitmap_representation(width_, height_, color = nil) ⇒ Object
Initialize the representation of bitmap with the given width and height (used internally)
31 32 33 34 35 36 37 38 |
# File 'lib/imageruby/bitmap/rbbitmap.rb', line 31 def initialize_bitmap_representation(width_, height_, color = nil) color ||= Color.from_rgb(0,0,0) @width = width_ @height = height_ @array = color.to_s*@width*@height end |
#initialize_dup(orig) ⇒ Object
52 53 54 55 56 |
# File 'lib/imageruby/bitmap/rbbitmap.rb', line 52 def initialize_dup(orig) @alpha = orig.alpha_data.dup @array = orig.pixel_data.dup self end |
#pixel_data ⇒ Object
returns the pixel data string with the RGB information of the pixels
To get the color value (including alpha) of a pixel on given x,y coordinates use image.get_pixel(x,y) or image
Examples
bitmap.pixel_data[(12)*bitmap.width+10] # the red channel at x=12, y=10
bitmap.pixel_data[(12)*bitmap.width+10+1] # the green channel at x=12, y=10
bitmap.pixel_data[(12)*bitmap.width+10+2] # the blue channel at x=12, y=10
90 91 92 |
# File 'lib/imageruby/bitmap/rbbitmap.rb', line 90 def pixel_data @array end |
#set_pixel(x, y, color) ⇒ Object
set a color value for a image
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/imageruby/bitmap/rbbitmap.rb', line 65 def set_pixel(x,y,color) index = (y*@width + x) pointindex = index*3 @array[pointindex+2] = color.r.chr @array[pointindex+1] = color.g.chr @array[pointindex] = color.b.chr if color.a != 255 then @alpha = 255.chr*(@height * @width) unless @alpha @alpha[index] = color.a.chr end self end |