Class: Pruim::Page

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#frameObject (readonly)

Returns the value of attribute frame.



16
17
18
# File 'lib/pruim/page.rb', line 16

def frame
  @frame
end

#hObject (readonly)

Returns the value of attribute h.



14
15
16
# File 'lib/pruim/page.rb', line 14

def h
  @h
end

#imageObject (readonly)

Returns the value of attribute image.



12
13
14
# File 'lib/pruim/page.rb', line 12

def image
  @image
end

#infoObject (readonly)

Extra information data hash table.



21
22
23
# File 'lib/pruim/page.rb', line 21

def info
  @info
end

#layerObject (readonly)

Returns the value of attribute layer.



15
16
17
# File 'lib/pruim/page.rb', line 15

def layer
  @layer
end

#wObject (readonly)

Returns the value of attribute w.



13
14
15
# File 'lib/pruim/page.rb', line 13

def w
  @w
end

#xObject (readonly)

Returns the value of attribute x.



17
18
19
# File 'lib/pruim/page.rb', line 17

def x
  @x
end

#yObject (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.

Returns:

  • (Boolean)


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

#pixelsObject



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