Class: Magick::Image::View

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

Overview

Magick::Image::View class

Defined Under Namespace

Classes: Pixels, Rows

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(img, x, y, width, height) ⇒ View

Returns a new instance of View.



1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
# File 'lib/rmagick_internal.rb', line 1080

def initialize(img, x, y, width, height)
  img.check_destroyed
  Kernel.raise ArgumentError, "invalid geometry (#{width}x#{height}+#{x}+#{y})" if width <= 0 || height <= 0
  Kernel.raise RangeError, "geometry (#{width}x#{height}+#{x}+#{y}) exceeds image boundary" if x < 0 || y < 0 || (x + width) > img.columns || (y + height) > img.rows
  @view = img.get_pixels(x, y, width, height)
  @img = img
  @x = x
  @y = y
  @width = width
  @height = height
  @dirty = false
end

Instance Attribute Details

#dirtyObject

Returns the value of attribute dirty.



1078
1079
1080
# File 'lib/rmagick_internal.rb', line 1078

def dirty
  @dirty
end

#heightObject (readonly)

Returns the value of attribute height.



1077
1078
1079
# File 'lib/rmagick_internal.rb', line 1077

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



1077
1078
1079
# File 'lib/rmagick_internal.rb', line 1077

def width
  @width
end

#xObject (readonly)

Returns the value of attribute x.



1077
1078
1079
# File 'lib/rmagick_internal.rb', line 1077

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



1077
1078
1079
# File 'lib/rmagick_internal.rb', line 1077

def y
  @y
end

Instance Method Details

#[](*args) ⇒ Object



1093
1094
1095
1096
1097
# File 'lib/rmagick_internal.rb', line 1093

def [](*args)
  rows = Rows.new(@view, @width, @height, args)
  rows.add_observer(self)
  rows
end

#sync(force = false) ⇒ Object

Store changed pixels back to image



1100
1101
1102
1103
# File 'lib/rmagick_internal.rb', line 1100

def sync(force = false)
  @img.store_pixels(x, y, width, height, @view) if @dirty || force
  @dirty || force
end

#update(rows) ⇒ Object

Get update from Rows - if @dirty ever becomes true, don’t change it back to false!



1107
1108
1109
1110
1111
# File 'lib/rmagick_internal.rb', line 1107

def update(rows)
  @dirty = true
  rows.delete_observer(self) # No need to tell us again.
  nil
end