Class: Magick::Image::View

Inherits:
Object
  • Object
show all
Defined in:
lib/RMagick.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.



965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
# File 'lib/RMagick.rb', line 965

def initialize(img, x, y, width, height)
    if width <= 0 || height <= 0
        Kernel.raise ArgumentError, "invalid geometry (#{width}x#{height}+#{x}+#{y})"
    end
    if x < 0 || y < 0 || (x+width) > img.columns || (y+height) > img.rows
        Kernel.raise RangeError, "geometry (#{width}x#{height}+#{x}+#{y}) exceeds image boundary"
    end
    @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.



963
964
965
# File 'lib/RMagick.rb', line 963

def dirty
  @dirty
end

#heightObject (readonly)

Returns the value of attribute height.



962
963
964
# File 'lib/RMagick.rb', line 962

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



962
963
964
# File 'lib/RMagick.rb', line 962

def width
  @width
end

#xObject (readonly)

Returns the value of attribute x.



962
963
964
# File 'lib/RMagick.rb', line 962

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



962
963
964
# File 'lib/RMagick.rb', line 962

def y
  @y
end

Instance Method Details

#[](*args) ⇒ Object



981
982
983
984
985
# File 'lib/RMagick.rb', line 981

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

#sync(force = false) ⇒ Object

Store changed pixels back to image



988
989
990
991
# File 'lib/RMagick.rb', line 988

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

#update(rows) ⇒ Object

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



995
996
997
998
999
# File 'lib/RMagick.rb', line 995

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