PhotoSlice

public class PhotoSlice : Equatable

Represents a read-only view for on rectangular region of a Photo.

The PhotoSlice enables fast and efficient read operations on sections of a large Photo without creating a copy of any of the underlying photo’s pixel data.

Specification Properties: - photo : Photo - the underlying photo - bounds : Rect - the sub-part of the photo we can access. - pixels : [[Pixel]] - the photo is conceptually a 2d array of pixels

Abstract Invariant: - pixels[x,y] == photo[x,y] for all (x,y) in bounds

  • The bounds of the part of the photo we can safely access.

    Declaration

    Swift

    public let bounds: Rect
  • Access photo[x,y].

    Requires: (x,y) in bounds.

    Declaration

    Swift

    public subscript(x: Int, y: Int) -> Pixel { get }
  • create a new Slice with the given bounds.

    Requires: sliceBounds must be within bounds.

    Declaration

    Swift

    public subscript(sliceBounds: Rect) -> PhotoSlice { get }
  • Two slices are equal if the are for the same Photo and have the same bounds.

    Declaration

    Swift

    public static func == (lhs: PhotoSlice, rhs: PhotoSlice) -> Bool

    Parameters

    lhs

    the first photo

    rhs

    the second photo

    Return Value

    true iff the two PhotoSlices represent the same slice.