Skip to content

Commit

Permalink
Fixed a bug where picture inputs would process themselves twice, lead…
Browse files Browse the repository at this point in the history
…ing to blank red images.
  • Loading branch information
BradLarson committed Jun 20, 2016
1 parent 7c92c75 commit 4991dbe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?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">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
Expand Down
11 changes: 8 additions & 3 deletions framework/Source/Mac/PictureInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import Cocoa
public class PictureInput: ImageSource {
public let targets = TargetContainer()
var imageFramebuffer:Framebuffer!

var hasProcessedImage:Bool = false

public init(image:CGImage, smoothlyScaleOutput:Bool = false, orientation:ImageOrientation = .Portrait) {
// TODO: Dispatch this whole thing asynchronously to move image loading off main thread
let widthOfImage = GLint(CGImageGetWidth(image))
Expand Down Expand Up @@ -129,17 +130,21 @@ public class PictureInput: ImageSource {
sharedImageProcessingContext.runOperationSynchronously{
sharedImageProcessingContext.makeCurrentContext()
self.updateTargetsWithFramebuffer(self.imageFramebuffer)
self.hasProcessedImage = true
}
} else {
sharedImageProcessingContext.runOperationAsynchronously{
sharedImageProcessingContext.makeCurrentContext()
self.updateTargetsWithFramebuffer(self.imageFramebuffer)
self.hasProcessedImage = true
}
}
}

public func transmitPreviousImageToTarget(target:ImageConsumer, atIndex:UInt) {
imageFramebuffer.lock()
target.newFramebufferAvailable(imageFramebuffer, fromSourceIndex:atIndex)
if hasProcessedImage {
imageFramebuffer.lock()
target.newFramebufferAvailable(imageFramebuffer, fromSourceIndex:atIndex)
}
}
}
9 changes: 7 additions & 2 deletions framework/Source/iOS/PictureInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import UIKit
public class PictureInput: ImageSource {
public let targets = TargetContainer()
var imageFramebuffer:Framebuffer!
var hasProcessedImage:Bool = false

public init(image:CGImage, smoothlyScaleOutput:Bool = false, orientation:ImageOrientation = .Portrait) {
// TODO: Dispatch this whole thing asynchronously to move image loading off main thread
Expand Down Expand Up @@ -128,16 +129,20 @@ public class PictureInput: ImageSource {
if synchronously {
sharedImageProcessingContext.runOperationSynchronously{
self.updateTargetsWithFramebuffer(self.imageFramebuffer)
self.hasProcessedImage = true
}
} else {
sharedImageProcessingContext.runOperationAsynchronously{
self.updateTargetsWithFramebuffer(self.imageFramebuffer)
self.hasProcessedImage = true
}
}
}

public func transmitPreviousImageToTarget(target:ImageConsumer, atIndex:UInt) {
imageFramebuffer.lock()
target.newFramebufferAvailable(imageFramebuffer, fromSourceIndex:atIndex)
if hasProcessedImage {
imageFramebuffer.lock()
target.newFramebufferAvailable(imageFramebuffer, fromSourceIndex:atIndex)
}
}
}

0 comments on commit 4991dbe

Please sign in to comment.