...
 
Commits (4)
import CoreImage
let appendix8: Effect = { originalImage, depthMap in
return try? LineAvereageKernel.apply(
try? LineAvereageKernel.apply(
withExtent: originalImage.extent,
inputs: [originalImage],
arguments: [
......@@ -79,12 +79,12 @@ private class LineAvereageKernel: CIImageProcessorKernel {
override public class func formatForInput(at input: Int32) -> CIFormat {
// Request color values to be of type Float32, to make it easier to read and write values
return .RGBAf
.RGBAf
}
override public class var outputFormat: CIFormat {
// Request color values to be of type Float32, to make it easier to read and write values
return .RGBAf
.RGBAf
}
override public class func roi(forInput input: Int32, arguments: [String : Any]?, outputRect: CGRect) -> CGRect {
......
......@@ -2,6 +2,8 @@ import CoreImage
import GameplayKit
let appendix9: Effect = { originalImage, depthMap in
// Scale down depth map since stereogram kernel is fairly slow
let depthMap = depthMap.transformed(by: .init(scaleX: 0.2, y: 0.2))
return try? StereogramKernel.apply(
withExtent: depthMap.extent,
inputs: [depthMap],
......@@ -36,7 +38,7 @@ public class StereogramKernel: CIImageProcessorKernel {
let valueCount = pixelCount * 4
let inAddress: Float32Pointer = input.baseAddress.bindMemory(to: Float32.self, capacity: valueCount)
let tempOutAdress: Float32MutablePointer = Float32MutablePointer.allocate(capacity: valueCount)
let tempOutAddress: Float32MutablePointer = Float32MutablePointer.allocate(capacity: valueCount)
let outputRegion = output.region
let outputPixelCount = Int(outputRegion.width * outputRegion.height)
......@@ -98,7 +100,7 @@ public class StereogramKernel: CIImageProcessorKernel {
}
}
let outputRow = tempOutAdress.advanced(by: rowIndex * Int(inputRegion.width) * 4)
let outputRow = tempOutAddress.advanced(by: rowIndex * Int(inputRegion.width) * 4)
for _x in 1...Int(inputRegion.width) {
let x = Int(inputRegion.width) - _x
var outPixel = outputRow.advanced(by: x * 4)
......@@ -111,7 +113,7 @@ public class StereogramKernel: CIImageProcessorKernel {
outPixel.a = 1.0
} else {
let sameOffset = (rowIndex * Int(inputRegion.width) + same[x]) * 4
let samePixel = tempOutAdress.advanced(by: sameOffset)
let samePixel = tempOutAddress.advanced(by: sameOffset)
outPixel.r = samePixel.r
outPixel.g = samePixel.g
outPixel.b = samePixel.b
......@@ -124,7 +126,7 @@ public class StereogramKernel: CIImageProcessorKernel {
for x in Int(outputRegion.minX)...Int(outputRegion.maxX) {
let point = CGPoint(x: x, y: y)
if inputRegion.contains(point) {
let samePixel = tempOutAdress.advanced(by: offset(of: point, in: inputRegion) * 4)
let samePixel = tempOutAddress.advanced(by: offset(of: point, in: inputRegion) * 4)
var outPixel = outAddress.advanced(by: offset(of: point, in: outputRegion) * 4)
outPixel.r = samePixel.r
outPixel.g = samePixel.g
......@@ -134,15 +136,15 @@ public class StereogramKernel: CIImageProcessorKernel {
}
}
tempOutAdress.deallocate()
tempOutAddress.deallocate()
}
override public class func formatForInput(at input: Int32) -> CIFormat {
return CIFormat.RGBAf
.RGBAf
}
override public class var outputFormat: CIFormat {
return CIFormat.RGBAf
.RGBAf
}
override public class func roi(forInput input: Int32, arguments: [String : Any]?, outputRect: CGRect) -> CGRect {
......@@ -175,22 +177,22 @@ fileprivate extension Float32Pointer {
fileprivate extension Float32MutablePointer {
var r: Float32 {
get { return self[0] }
get { self[0] }
set { self[0] = newValue }
}
var g: Float32 {
get { return self[1] }
get { self[1] }
set { self[1] = newValue }
}
var b: Float32 {
get { return self[2] }
get { self[2] }
set { self[2] = newValue }
}
var a: Float32 {
get { return self[3] }
get { self[3] }
set { self[3] = newValue }
}
}
......@@ -59,7 +59,7 @@ class BrowserViewController: UIViewController {
collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
])
updateBrowser()
}
......@@ -120,7 +120,7 @@ extension BrowserViewController: UICollectionViewDelegate {
extension BrowserViewController: UICollectionViewDataSource {
func numberOfSections(in collectionView: UICollectionView) -> Int {
return validAssets() == nil ? 1 : 2
validAssets() == nil ? 1 : 2
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
......
......@@ -38,13 +38,13 @@ class EditorViewController: UIViewController {
view.contentMode = .scaleAspectFit
return view
}()
private var inputsStackView: UIStackView = {
private let inputsStackView: UIStackView = {
let stackView = UIStackView()
stackView.axis = .horizontal
stackView.distribution = .fillEqually
return stackView
}()
private var outerStackView: UIStackView = {
private let outerStackView: UIStackView = {
let stackView = UIStackView()
stackView.axis = .vertical
stackView.preservesSuperviewLayoutMargins = true
......@@ -52,6 +52,12 @@ class EditorViewController: UIViewController {
stackView.spacing = 10
return stackView
}()
private let segmentScroll: UIScrollView = {
let scrollView = UIScrollView()
scrollView.showsHorizontalScrollIndicator = false
return scrollView
}()
private var segment: UISegmentedControl = NoSwipeSegmentedControl()
init(image: CIImage, depthMap: CIImage) {
self.image = image
......@@ -91,11 +97,11 @@ class EditorViewController: UIViewController {
outerStackView.addArrangedSubview(resultImageView)
resultImageView.setContentCompressionResistancePriority(.fittingSizeLevel, for: .vertical)
let segment = NoSwipeSegmentedControl(items: effects.enumerated().map {
let title = "\($0.offset + 1)" as NSString
for (index, _) in effects.enumerated() {
let title = "\(index + 1)" as NSString
title.accessibilityLabel = "Task"
return title
})
segment.insertSegment(withTitle: title as String, at: segment.numberOfSegments, animated: false)
}
for (index, _) in appendices.enumerated() {
segment.insertSegment(withTitle: "A\(index + 1)", at: segment.numberOfSegments, animated: false)
}
......@@ -106,18 +112,16 @@ class EditorViewController: UIViewController {
segment.selectedSegmentTintColor = UIColor(displayP3Red: 1, green: 0, blue: 0.1, alpha: 1)
}
let segmentsScroll = UIScrollView()
segmentsScroll.showsHorizontalScrollIndicator = false
segmentsScroll.addSubview(segment)
segmentScroll.addSubview(segment)
segment.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
segment.leadingAnchor.constraint(equalTo: segmentsScroll.contentLayoutGuide.leadingAnchor),
segment.trailingAnchor.constraint(equalTo: segmentsScroll.contentLayoutGuide.trailingAnchor),
segment.topAnchor.constraint(equalTo: segmentsScroll.contentLayoutGuide.topAnchor),
segment.bottomAnchor.constraint(equalTo: segmentsScroll.contentLayoutGuide.bottomAnchor),
segment.heightAnchor.constraint(equalTo: segmentsScroll.heightAnchor),
segment.leadingAnchor.constraint(equalTo: segmentScroll.contentLayoutGuide.leadingAnchor),
segment.trailingAnchor.constraint(equalTo: segmentScroll.contentLayoutGuide.trailingAnchor),
segment.topAnchor.constraint(equalTo: segmentScroll.contentLayoutGuide.topAnchor),
segment.bottomAnchor.constraint(equalTo: segmentScroll.contentLayoutGuide.bottomAnchor),
segment.heightAnchor.constraint(equalTo: segmentScroll.heightAnchor),
])
toolbarItems = [UIBarButtonItem(customView: segmentsScroll)]
toolbarItems = [UIBarButtonItem(customView: segmentScroll)]
let toolbar = UIToolbar()
view.addSubview(toolbar)
......@@ -135,6 +139,11 @@ class EditorViewController: UIViewController {
navigationController?.setToolbarHidden(false, animated: animated)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
scrollToSelection()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setToolbarHidden(true, animated: animated)
......@@ -142,6 +151,7 @@ class EditorViewController: UIViewController {
@objc private func didChangeSegment(segment: UISegmentedControl) {
selectedEffect = segment.selectedSegmentIndex
scrollToSelection()
}
private func effect(at index: Int) -> Effect {
......@@ -168,7 +178,7 @@ class EditorViewController: UIViewController {
originalImageView.image = UIImage(ciImage: image)
depthMapView.image = UIImage(ciImage: depthMap)
guard let result = effect(at: selectedEffect)(image, depthMap) else {
let ac = UIAlertController(title: "No Output", message: "Effect #\(selectedEffect + 1) returned nil.", preferredStyle: .alert)
let ac = UIAlertController(title: "No Output", message: "Effect returned nil.", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default))
present(ac, animated: true)
resultImageView.image = nil
......@@ -176,6 +186,11 @@ class EditorViewController: UIViewController {
}
resultImageView.image = UIImage(ciImage: result)
}
private func scrollToSelection() {
let selectedFrame = segment.frameForSegment(at: segment.selectedSegmentIndex)
segmentScroll.scrollRectToVisible(selectedFrame, animated: true)
}
}
class InputImageView: UIView {
......@@ -222,7 +237,7 @@ class InputImageView: UIView {
stackView.leadingAnchor.constraint(equalTo: leadingAnchor),
stackView.trailingAnchor.constraint(equalTo: trailingAnchor),
stackView.bottomAnchor.constraint(equalTo: bottomAnchor),
])
])
stackView.addArrangedSubview(label)
stackView.addArrangedSubview(imageView)
......@@ -246,8 +261,21 @@ class InputImageView: UIView {
}
private class NoSwipeSegmentedControl: UISegmentedControl {
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
return true
true
}
}
extension UISegmentedControl {
func frameForSegment(at index: Int) -> CGRect {
var left: CGFloat = 0
let width = bounds.width / CGFloat(numberOfSegments)
for i in 0..<numberOfSegments {
if i == index {
return CGRect(x: left, y: bounds.minY, width: width, height: bounds.height)
}
left += width
}
return .zero
}
}
......@@ -4,7 +4,7 @@ class MainViewController: UIViewController {
private let browser = BrowserViewController()
private lazy var navigation = UINavigationController()
override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }
override var preferredStatusBarStyle: UIStatusBarStyle { .lightContent }
override func viewDidLoad() {
super.viewDidLoad()
......