Classes
The following classes are available globally.
-
TODO: Document Me
See moreDeclaration
Swift
public class FeatureVector
-
A general class to represent an image that may require some work to create or load. You create an ImageSource by passing to the initializer a generating function, a closure that returns the UIImage of interest.
The generation function may do any work necessary to create the UIImage object, and the ImageSource
image
property is lazy initialized with the value returned from the generator the first time it is accessed.The use case for URL images is thus the following:
See morelet url = URL(...) let imageSource = ImageSource() { if let urlContents = try? Data(contentsOf: url) { return UIImage(data: urlContents) } else { return nil } }
Declaration
Swift
public class ImageSource : Equatable
-
An ImageViewController presents an image within a UIScrollView. The controller avoids blocking the UI thread by running the code to get the UIImage to show on the global dispatch queue.
It also is able to handle images from sources other than a URL. It supports images from any source by have the client provide an ImageSource object rather than a URL. That object is responsible for providing an image when asked.
Given an imageViewController, the use case for URL images is the following:
let url = URL(...) let imageSource = ImageSource() { if let urlContents = try? Data(contentsOf: url) { return UIImage(data: urlContents) } else { return nil } } imageViewController.imageSource = imageSource
This version also extends the lecture version with:
an action for sharing the shown image with other apps. You may connect that handler to a UIBarButton in your UI.
a spinng activity indicator that displays when getting the image. You may connect that handler to a UIActivityViewer.
Declaration
Swift
public class ImageViewController : UIViewController, UIScrollViewDelegate
-
Represents an image in a way amenable to the processing we will do on them.
Specification Properties:
- image : UIImage - the underlying image the photo captures
- name : String? - The optional name of the photo
- size : Size - the width and height of the photo
- pixels : [[Pixel]] - the photo is conceptually a 2d array of pixels
Abstract Invariant:
- size is the same as image.size, but truncated to integral dimensions.
- pixels[x,y] is a Pixel with the same color as the image and point (x,y)
This is an immutable class.
See moreDeclaration
Swift
public class Photo : Hashable, CustomStringConvertible
-
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
See moreDeclaration
Swift
public class PhotoSlice : Equatable
-
A PhotoCollection represents a group of Photos that are all the same size. Collections are stored in a folder in the app bundle and loaded by the static methods provided in this class. A PhotoCollection is a sequence. Thus you can iterator over collections. Example:
// get names of all folders in "Photo Collections" let collectionNames = PhotoCollection.namesOfCollections(inFolder: "Photo Collections") // create collection for "swatches" subfolder and iterate over the photos // in that collection let collection = PhotoCollection.collection(named: "swatches", inFolder: "Photo Collections") for photo in collection { ... }
Specification Properties:
- name : String - The name of the collection
- self : Sequence - The photos in the collecton
- photoSize : Size - the size of each photo
Abstract Invariant:
- all photos stored in the collection has size photoSize.
Declaration
Swift
public class PhotoCollection : Sequence
-
A 2-d matrix of photos that can be rendered as a UIImage.
Specification Properties:
- photos[col,row] : the possibly-nil photo stored at the given column and row.
- columns : Int - the number of columns
- rows : Int - the nubmer of rows
- tileSize : Size - the size to render each photo stored in the matrix
Abstract Invariant:
- all photos stored in the matrix must have size == tileSize.
- For all photo, count[photo] == number of times photo appears in photos.
Declaration
Swift
public class PhotoMatrix