Class: Pruim::Page
- Inherits:
-
Object
- Object
- Pruim::Page
- Defined in:
- lib/pruim/page.rb
Overview
A Page can represents both a layer and a frame of animation, for multi-page image formats. Inside a Page, bitmap data is stored in an array as follows: For a monochrome image, true and false are stored, where true is “black” meaning pixel activated, on, say, an LCD screen, and false means white or pixel not activated. For :palette mode images, what is stored are palette indexes. for an RBGA , integers are stored that encode the color in an 8888 bits ABGR way
Instance Attribute Summary collapse
-
#frame ⇒ Object
readonly
Returns the value of attribute frame.
-
#h ⇒ Object
readonly
Returns the value of attribute h.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#info ⇒ Object
readonly
Extra information data hash table.
-
#layer ⇒ Object
readonly
Returns the value of attribute layer.
-
#w ⇒ Object
readonly
Returns the value of attribute w.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #fill(color) ⇒ Object
-
#getpixel(x, y) ⇒ Object
Gets the pixel at coordinates x,y.
-
#getpixel!(x, y) ⇒ Object
Gets the pixel at coordinates x,y.
-
#initialize(image, w, h, extra = {}) ⇒ Page
constructor
A new instance of Page.
-
#outside?(x, y) ⇒ Boolean
Returns true if the coordinates are outside of the limits of this page.
- #pixels ⇒ Object
- #putpixel(x, y, color) ⇒ Object
- #putpixel!(x, y, color) ⇒ Object
-
#row(y) ⇒ Object
Returns a row of pixels with the given y coordinates as an array.
Constructor Details
#initialize(image, w, h, extra = {}) ⇒ Page
Returns a new instance of Page.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pruim/page.rb', line 33 def initialize(image, w, h, extra = {}) @image = image @info = {} @w = w @h = h @frame = extra[:frame] || 0 @layer = extra[:layer] || 0 @x = extra[:x] || 0 @y = extra[:y] || 0 @data = extra[:data] if !@data @data = Array.new(@h * @w, 0) end end |
Instance Attribute Details
#frame ⇒ Object (readonly)
Returns the value of attribute frame.
16 17 18 |
# File 'lib/pruim/page.rb', line 16 def frame @frame end |
#h ⇒ Object (readonly)
Returns the value of attribute h.
14 15 16 |
# File 'lib/pruim/page.rb', line 14 def h @h end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
12 13 14 |
# File 'lib/pruim/page.rb', line 12 def image @image end |
#info ⇒ Object (readonly)
Extra information data hash table.
21 22 23 |
# File 'lib/pruim/page.rb', line 21 def info @info end |
#layer ⇒ Object (readonly)
Returns the value of attribute layer.
15 16 17 |
# File 'lib/pruim/page.rb', line 15 def layer @layer end |
#w ⇒ Object (readonly)
Returns the value of attribute w.
13 14 15 |
# File 'lib/pruim/page.rb', line 13 def w @w end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
17 18 19 |
# File 'lib/pruim/page.rb', line 17 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
18 19 20 |
# File 'lib/pruim/page.rb', line 18 def y @y end |
Instance Method Details
#fill(color) ⇒ Object
74 75 76 77 78 |
# File 'lib/pruim/page.rb', line 74 def fill(color) for i in (0..(@h*@w)) @data[i] = color end end |
#getpixel(x, y) ⇒ Object
Gets the pixel at coordinates x,y. Returns nil if out of bounds.
61 62 63 |
# File 'lib/pruim/page.rb', line 61 def getpixel(x, y) return getpixel!(x, y) end |
#getpixel!(x, y) ⇒ Object
Gets the pixel at coordinates x,y. Returns nil if out of bounds.
56 57 58 |
# File 'lib/pruim/page.rb', line 56 def getpixel!(x, y) @data[y * @w + x] end |
#outside?(x, y) ⇒ Boolean
Returns true if the coordinates are outside of the limits of this page.
49 50 51 52 53 |
# File 'lib/pruim/page.rb', line 49 def outside?(x, y) return true if (x < 0 ) || (y < 0 ) return true if (x >= @w) || (y >= @h) return false end |
#pixels ⇒ Object
29 30 31 |
# File 'lib/pruim/page.rb', line 29 def pixels return @data end |
#putpixel(x, y, color) ⇒ Object
69 70 71 72 |
# File 'lib/pruim/page.rb', line 69 def putpixel(x, y, color) return nil if outside?(x, y) putpixel!(x, y, color) end |
#putpixel!(x, y, color) ⇒ Object
65 66 67 |
# File 'lib/pruim/page.rb', line 65 def putpixel!(x, y, color) @data[y * @w + x] = color end |
#row(y) ⇒ Object
Returns a row of pixels with the given y coordinates as an array
24 25 26 |
# File 'lib/pruim/page.rb', line 24 def row(y) return @data.slice(y * self.w, self.w) end |