Skip to content

Commit

Permalink
Expand formatting to tests and examples, ease up some of the lint che…
Browse files Browse the repository at this point in the history
…cks.
  • Loading branch information
BradLarson committed Feb 18, 2024
1 parent 1e4d64b commit bb11cba
Show file tree
Hide file tree
Showing 25 changed files with 1,152 additions and 1,118 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: Install
run: brew install swift-format
- name: Run linting
run: swift-format lint --recursive --parallel --strict --configuration .swift-format.json Package.swift Sources
run: swift-format lint --recursive --parallel --strict --configuration .swift-format.json Package.swift Sources Tests examples
10 changes: 5 additions & 5 deletions .swift-format.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : false,
"AlwaysUseLowerCamelCase" : true,
"AlwaysUseLowerCamelCase" : false,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
Expand All @@ -38,7 +38,7 @@
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : true,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : true,
"NoBlockComments" : false,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
Expand All @@ -53,9 +53,9 @@
"OrderedImports" : true,
"ReplaceForEachWithForLoop" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"TypeNamesShouldBeCapitalized" : true,
"TypeNamesShouldBeCapitalized" : false,
"UseEarlyExits" : false,
"UseLetInEveryBoundCaseVariable" : true,
"UseLetInEveryBoundCaseVariable" : false,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : true,
"UseSynthesizedInitializer" : true,
Expand All @@ -66,4 +66,4 @@
"spacesAroundRangeFormationOperators" : false,
"tabWidth" : 4,
"version" : 1
}
}
3 changes: 2 additions & 1 deletion Sources/GPUImage/BasicOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ open class BasicOperation: ImageProcessingOperation {
width: outputWidth, height: outputHeight, timingStyle: firstInputTexture.timingStyle
)

guard !activatePassthroughOnNextFrame else { // Use this to allow a bootstrap of cyclical processing, like with a low pass filter
guard !activatePassthroughOnNextFrame else {
// Use this to allow a bootstrap of cyclical processing, like with a low pass filter.
activatePassthroughOnNextFrame = false
// TODO: Render rotated passthrough image here

Expand Down
3 changes: 2 additions & 1 deletion Sources/GPUImage/Operations/BoxBlur.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public class BoxBlur: BasicOperation {
public var blurRadiusInPixels: Float = 2.0 {
didSet {
if self.useMetalPerformanceShaders, #available(iOS 9, macOS 10.13, *) {
let kernelSize = roundToOdd(blurRadiusInPixels) // MPS box blur kernels need to be odd
// MPS box blur kernels need to be odd.
let kernelSize = roundToOdd(blurRadiusInPixels)
internalMPSImageBox = MPSImageBox(
device: sharedMetalRenderingDevice.device, kernelWidth: kernelSize,
kernelHeight: kernelSize)
Expand Down
12 changes: 9 additions & 3 deletions Sources/GPUImage/PictureOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public class PictureOutput: ImageConsumer {
public func saveNextFrameToURL(_ url: URL, format: PictureFileFormat) {
onlyCaptureNextFrame = true
encodedImageFormat = format
self.url = url // Create an intentional short-term retain cycle to prevent deallocation before next frame is captured
self.url = url
// Create an intentional short-term retain cycle to prevent deallocation
// before next frame is captured.
encodedImageAvailableCallback = { imageData in
do {
try imageData.write(to: self.url, options: .atomic)
Expand Down Expand Up @@ -75,8 +77,12 @@ public class PictureOutput: ImageConsumer {
#if canImport(UIKit)
let image = UIImage(cgImage: cgImageFromBytes, scale: 1.0, orientation: .up)
switch encodedImageFormat {
case .png: imageData = image.pngData()! // TODO: Better error handling here
case .jpeg: imageData = image.jpegData(compressionQuality: 0.8)! // TODO: Be able to set image quality
case .png:
// TODO: Better error handling here.
imageData = image.pngData()!
case .jpeg:
// TODO: Be able to set image quality.
imageData = image.jpegData(compressionQuality: 0.8)!
}
#else
let bitmapRepresentation = NSBitmapImageRep(cgImage: cgImageFromBytes)
Expand Down
5 changes: 3 additions & 2 deletions Tests/GPUImageTests/MatrixTests.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import XCTest

@testable import GPUImage

final class MatrixTests: XCTestCase {
func testMatrix3x3() throws {
let newMatrix = Matrix3x3(rowMajorValues: [
1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0
7.0, 8.0, 9.0,
])

XCTAssertEqual(newMatrix.m11, 1.0)
XCTAssertEqual(newMatrix.m23, 6.0)
XCTAssertEqual(newMatrix.m32, 8.0)
Expand Down
6 changes: 3 additions & 3 deletions examples/Mac/FilterShowcase/FilterShowcase/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {

@IBOutlet weak var window: NSWindow!

var windowController:FilterShowcaseWindowController?
var windowController: FilterShowcaseWindowController?

func applicationDidFinishLaunching(_ aNotification: Notification) {
self.windowController = FilterShowcaseWindowController(windowNibName:NSNib.Name(rawValue: "FilterShowcaseWindowController"))
self.windowController = FilterShowcaseWindowController(
windowNibName: NSNib.Name(rawValue: "FilterShowcaseWindowController"))
self.windowController?.showWindow(self)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,63 @@ import GPUImage

enum FilterSliderSetting {
case disabled
case enabled(minimumValue:Float, maximumValue:Float, initialValue:Float)
case enabled(minimumValue: Float, maximumValue: Float, initialValue: Float)
}

typealias FilterSetupFunction = (Camera, ImageProcessingOperation, RenderView) -> ImageSource?

enum FilterOperationType {
case singleInput
case blend
case custom(filterSetupFunction:FilterSetupFunction)
case custom(filterSetupFunction: FilterSetupFunction)
}

protocol FilterOperationInterface {
var filter: ImageProcessingOperation { get }
var secondInput:ImageSource? { get }
var secondInput: ImageSource? { get }
var listName: String { get }
var titleName: String { get }
var sliderConfiguration: FilterSliderSetting { get }
var filterOperationType: FilterOperationType { get }
var sliderConfiguration: FilterSliderSetting { get }
var filterOperationType: FilterOperationType { get }

func configureCustomFilter(_ secondInput:ImageSource?)
func updateBasedOnSliderValue(_ sliderValue:Float)
func configureCustomFilter(_ secondInput: ImageSource?)
func updateBasedOnSliderValue(_ sliderValue: Float)
}

class FilterOperation<FilterClass: GPUImage.ImageProcessingOperation>: FilterOperationInterface {
lazy var internalFilter:FilterClass = {
lazy var internalFilter: FilterClass = {
return self.filterCreationFunction()
}()
let filterCreationFunction:() -> FilterClass
var secondInput:ImageSource?
let listName:String
let titleName:String
let sliderConfiguration:FilterSliderSetting
let filterOperationType:FilterOperationType
let sliderUpdateCallback: ((FilterClass, Float) -> ())?
init(filter:@escaping () -> FilterClass, listName: String, titleName: String, sliderConfiguration: FilterSliderSetting, sliderUpdateCallback:((FilterClass, Float) -> ())?, filterOperationType: FilterOperationType) {
let filterCreationFunction: () -> FilterClass
var secondInput: ImageSource?
let listName: String
let titleName: String
let sliderConfiguration: FilterSliderSetting
let filterOperationType: FilterOperationType
let sliderUpdateCallback: ((FilterClass, Float) -> Void)?
init(
filter: @escaping () -> FilterClass, listName: String, titleName: String,
sliderConfiguration: FilterSliderSetting,
sliderUpdateCallback: ((FilterClass, Float) -> Void)?,
filterOperationType: FilterOperationType
) {
self.listName = listName
self.titleName = titleName
self.sliderConfiguration = sliderConfiguration
self.filterOperationType = filterOperationType
self.sliderUpdateCallback = sliderUpdateCallback
self.filterCreationFunction = filter
}

var filter: ImageProcessingOperation {
return internalFilter
}

func configureCustomFilter(_ secondInput:ImageSource?) {
func configureCustomFilter(_ secondInput: ImageSource?) {
self.secondInput = secondInput
}

func updateBasedOnSliderValue(_ sliderValue:Float) {
func updateBasedOnSliderValue(_ sliderValue: Float) {
sliderUpdateCallback?(internalFilter, sliderValue)
}
}

Loading

0 comments on commit bb11cba

Please sign in to comment.