Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ There are a few different ways to approach filtering an image. The easiest are t
```swift
let testImage = UIImage(named:"WID-small.jpg")!
let toonFilter = SmoothToonFilter()
let filteredImage = testImage.filterWithOperation(toonFilter)
let filteredImage = try! testImage.filterWithOperation(toonFilter)
```

for a more complex pipeline:
Expand All @@ -161,7 +161,7 @@ for a more complex pipeline:
let testImage = UIImage(named:"WID-small.jpg")!
let toonFilter = SmoothToonFilter()
let luminanceFilter = Luminance()
let filteredImage = testImage.filterWithPipeline{input, output in
let filteredImage = try! testImage.filterWithPipeline{input, output in
input --> toonFilter --> luminanceFilter --> output
}
```
Expand All @@ -173,7 +173,7 @@ Both of these convenience methods wrap several operations. To feed a picture int
```swift
let toonFilter = SmoothToonFilter()
let testImage = UIImage(named:"WID-small.jpg")!
let pictureInput = PictureInput(image:testImage)
let pictureInput = try! PictureInput(image:testImage)
let pictureOutput = PictureOutput()
pictureOutput.imageAvailableCallback = {image in
// Do something with image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ let filterOperations: Array<FilterOperationInterface> = [
sliderUpdateCallback: nil,
filterOperationType:.custom(filterSetupFunction:{(camera, filter, outputView) in
let castFilter = filter as! Luminance
let maskImage = PictureInput(imageName:"Mask.png")
let maskImage = try! PictureInput(imageName:"Mask.png")
castFilter.drawUnmodifiedImageOutsideOfMask = false
castFilter.mask = maskImage
maskImage.processImage()
Expand Down Expand Up @@ -297,7 +297,7 @@ let filterOperations: Array<FilterOperationInterface> = [
titleName:"Histogram",
sliderConfiguration:.enabled(minimumValue:4.0, maximumValue:32.0, initialValue:16.0),
sliderUpdateCallback: {(filter, sliderValue) in
filter.downsamplingFactor = UInt(round(sliderValue))
filter.downsamplingFactor = UInt(roundf(sliderValue))
},
filterOperationType:.custom(filterSetupFunction: {(camera, filter, outputView) in
let castFilter = filter as! Histogram
Expand Down Expand Up @@ -684,7 +684,7 @@ let filterOperations: Array<FilterOperationInterface> = [
titleName:"Posterize",
sliderConfiguration:.enabled(minimumValue:1.0, maximumValue:20.0, initialValue:10.0),
sliderUpdateCallback: {(filter, sliderValue) in
filter.colorLevels = round(sliderValue)
filter.colorLevels = roundf(sliderValue)
},
filterOperationType:.singleInput
),
Expand Down Expand Up @@ -739,7 +739,7 @@ let filterOperations: Array<FilterOperationInterface> = [
let blendFilter = AlphaBlend()
blendFilter.mix = 1.0

let inputImage = PictureInput(imageName:blendImageName)
let inputImage = try! PictureInput(imageName:blendImageName)

inputImage --> blendFilter
camera --> castFilter --> blendFilter --> outputView
Expand All @@ -753,7 +753,7 @@ let filterOperations: Array<FilterOperationInterface> = [
titleName:"Kuwahara",
sliderConfiguration:.enabled(minimumValue:3.0, maximumValue:9.0, initialValue:3.0),
sliderUpdateCallback: {(filter, sliderValue) in
filter.radius = Int(round(sliderValue))
filter.radius = Int(roundf(sliderValue))
},
filterOperationType:.singleInput
),
Expand Down
6 changes: 4 additions & 2 deletions examples/iOS/FilterShowcase/FilterShowcase.xcodeproj/project.pbxproj
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
TargetAttributes = {
BC0037B6195CA11B00B9D651 = {
CreatedOnToolsVersion = 6.0;
DevelopmentTeam = FQ7WDPMYNA;
LastSwiftMigration = 0940;
ProvisioningStyle = Automatic;
};
Expand All @@ -219,6 +220,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -442,7 +444,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = FQ7WDPMYNA;
INFOPLIST_FILE = FilterShowcaseSwift/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.sunsetlakesoftware.${PRODUCT_NAME:rfc1034identifier}";
Expand All @@ -460,7 +462,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = FQ7WDPMYNA;
INFOPLIST_FILE = FilterShowcaseSwift/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.sunsetlakesoftware.${PRODUCT_NAME:rfc1034identifier}";
Expand Down
Empty file.
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion examples/iOS/FilterShowcase/FilterShowcaseSwift/FilterDisplayViewController.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class FilterDisplayViewController: UIViewController, UISplitViewControllerDelega
currentFilterConfiguration.filter.addTarget(view)
case .blend:
videoCamera.addTarget(currentFilterConfiguration.filter)
self.blendImage = PictureInput(imageName:blendImageName)
self.blendImage = try? PictureInput(imageName:blendImageName)
self.blendImage?.addTarget(currentFilterConfiguration.filter)
self.blendImage?.processImage()
currentFilterConfiguration.filter.addTarget(view)
Expand Down
Empty file.
Empty file modified examples/iOS/FilterShowcase/FilterShowcaseSwift/Info.plist
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified examples/iOS/SimpleImageFilter/SimpleImageFilter/Info.plist
100644 → 100755
Empty file.
17 changes: 15 additions & 2 deletions examples/iOS/SimpleImageFilter/SimpleImageFilter/ViewController.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ class ViewController: UIViewController {
// Filtering image for saving
let testImage = UIImage(named:"WID-small.jpg")!
let toonFilter = SmoothToonFilter()
let filteredImage = testImage.filterWithOperation(toonFilter)

let filteredImage:UIImage
do {
filteredImage = try testImage.filterWithOperation(toonFilter)
} catch {
print("Couldn't filter image with error: \(error)")
return
}

let pngImage = UIImagePNGRepresentation(filteredImage)!
do {
Expand All @@ -25,8 +32,14 @@ class ViewController: UIViewController {
print("Couldn't write to file with error: \(error)")
}


// Filtering image for display
picture = PictureInput(image:UIImage(named:"WID-small.jpg")!)
do {
picture = try PictureInput(image:UIImage(named:"WID-small.jpg")!)
} catch {
print("Couldn't create PictureInput with error: \(error)")
return
}
filter = SaturationAdjustment()
picture --> filter --> renderView
picture.processImage()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -14,16 +18,18 @@
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="mTz-kJ-GVc">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" verticalCompressionResistancePriority="250" ambiguous="YES" misplaced="YES" preservesSuperviewLayoutMargins="YES" translatesAutoresizingMaskIntoConstraints="NO" id="TZG-4E-PsH" customClass="RenderView" customModule="GPUImage">
<rect key="frame" x="0.0" y="28" width="600" height="572"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<view contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" verticalCompressionResistancePriority="250" preservesSuperviewLayoutMargins="YES" translatesAutoresizingMaskIntoConstraints="NO" id="TZG-4E-PsH" customClass="RenderView" customModule="GPUImage">
<rect key="frame" x="0.0" y="28" width="375" height="572"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="TZG-4E-PsH" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="8" id="CSH-6h-Dfk"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="TZG-4E-PsH" secondAttribute="bottom" constant="67" id="Zxr-89-xw6"/>
<constraint firstAttribute="trailing" secondItem="TZG-4E-PsH" secondAttribute="trailing" id="eaB-aM-y2J"/>
<constraint firstItem="TZG-4E-PsH" firstAttribute="leading" secondItem="mTz-kJ-GVc" secondAttribute="leading" id="j8T-4u-Tsw"/>
</constraints>
Expand Down
43 changes: 21 additions & 22 deletions framework/Source/BasicOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import Foundation

public func defaultVertexShaderForInputs(_ inputCount:UInt) -> String {
switch inputCount {
case 1: return OneInputVertexShader
case 2: return TwoInputVertexShader
case 3: return ThreeInputVertexShader
case 4: return FourInputVertexShader
case 5: return FiveInputVertexShader
default: return OneInputVertexShader
case 1: return OneInputVertexShader
case 2: return TwoInputVertexShader
case 3: return ThreeInputVertexShader
case 4: return FourInputVertexShader
case 5: return FiveInputVertexShader
default: return OneInputVertexShader
}
}

Expand Down Expand Up @@ -35,14 +35,14 @@ open class BasicOperation: ImageProcessingOperation {
}
public var activatePassthroughOnNextFrame:Bool = false
public var uniformSettings = ShaderUniformSettings()

// MARK: -
// MARK: Internal

public let targets = TargetContainer()
public let sources = SourceContainer()
var shader:ShaderProgram
var inputFramebuffers = [UInt:Framebuffer]()
public var inputFramebuffers = [UInt:Framebuffer]()
var renderFramebuffer:Framebuffer!
var outputFramebuffer:Framebuffer { get { return renderFramebuffer } }
let usesAspectRatio:Bool
Expand All @@ -51,7 +51,7 @@ open class BasicOperation: ImageProcessingOperation {

// MARK: -
// MARK: Initialization and teardown

public init(shader:ShaderProgram, numberOfInputs:UInt = 1) {
self.maximumInputs = numberOfInputs
self.shader = shader
Expand All @@ -64,7 +64,7 @@ open class BasicOperation: ImageProcessingOperation {
self.shader = compiledShader
usesAspectRatio = shader.uniformIndex("aspectRatio") != nil
}

public init(vertexShaderFile:URL? = nil, fragmentShaderFile:URL, numberOfInputs:UInt = 1, operationName:String = #file) throws {
let compiledShader:ShaderProgram
if let vertexShaderFile = vertexShaderFile {
Expand All @@ -78,7 +78,7 @@ open class BasicOperation: ImageProcessingOperation {
}

deinit {
debugPrint("Deallocating operation: \(self)")
//debugPrint("Deallocating operation: \(self)")
}

// MARK: -
Expand All @@ -89,7 +89,7 @@ open class BasicOperation: ImageProcessingOperation {
previousFramebuffer.unlock()
}
inputFramebuffers[fromSourceIndex] = framebuffer

guard (!activatePassthroughOnNextFrame) else { // Use this to allow a bootstrap of cyclical processing, like with a low pass filter
activatePassthroughOnNextFrame = false
updateTargetsWithFramebuffer(framebuffer)
Expand All @@ -103,7 +103,7 @@ open class BasicOperation: ImageProcessingOperation {
}
}

func renderFrame() {
open func renderFrame() {
renderFramebuffer = sharedImageProcessingContext.framebufferCache.requestFramebufferWithProperties(orientation:.portrait, size:sizeOfInitialStageBasedOnFramebuffer(inputFramebuffers[0]!), stencil:mask != nil)

let textureProperties = initialTextureProperties()
Expand All @@ -123,7 +123,7 @@ open class BasicOperation: ImageProcessingOperation {
}
}

func internalRenderFunction(_ inputFramebuffer:Framebuffer, textureProperties:[InputTextureProperties]) {
open func internalRenderFunction(_ inputFramebuffer:Framebuffer, textureProperties:[InputTextureProperties]) {
renderQuadWithShader(shader, uniformSettings:uniformSettings, vertexBufferObject:sharedImageProcessingContext.standardImageVBO, inputTextures:textureProperties)
releaseIncomingFramebuffers()
}
Expand Down Expand Up @@ -175,19 +175,18 @@ open class BasicOperation: ImageProcessingOperation {
return inputTextureProperties
}

func configureFramebufferSpecificUniforms(_ inputFramebuffer:Framebuffer) {
open func configureFramebufferSpecificUniforms(_ inputFramebuffer:Framebuffer) {
if usesAspectRatio {
let outputRotation = overriddenOutputRotation ?? inputFramebuffer.orientation.rotationNeededForOrientation(.portrait)
uniformSettings["aspectRatio"] = inputFramebuffer.aspectRatioForRotation(outputRotation)
}
}

public func transmitPreviousImage(to target:ImageConsumer, atIndex:UInt) {
sharedImageProcessingContext.runOperationAsynchronously{
guard let renderFramebuffer = self.renderFramebuffer, (!renderFramebuffer.timingStyle.isTransient()) else { return }

renderFramebuffer.lock()
target.newFramebufferAvailable(renderFramebuffer, fromSourceIndex:atIndex)
}
//guard let renderFramebuffer = self.renderFramebuffer, (!renderFramebuffer.timingStyle.isTransient()) else { return }

//renderFramebuffer.lock()
//target.newFramebufferAvailable(renderFramebuffer, fromSourceIndex:atIndex)
}
}

Loading