Skip to content

Commit 9ea34da

Browse files
committed
Release 0.1.4
1 parent 81550a3 commit 9ea34da

31 files changed

+218
-117
lines changed

AVPlayerItemHomeOutput.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'AVPlayerItemHomeOutput'
3-
s.version = '0.1.3'
3+
s.version = '0.1.4'
44
s.summary = 'Coordinate the output of content associated with your HomeKit lightbulbs. #Ambilight'
55

66
s.homepage = 'https://github.com/alexruperez/AVPlayerItemHomeOutput'

AVPlayerItemHomeOutput.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@
843843
DEBUG_INFORMATION_FORMAT = dwarf;
844844
DEFINES_MODULE = YES;
845845
DYLIB_COMPATIBILITY_VERSION = 0.1.0;
846-
DYLIB_CURRENT_VERSION = 0.1.3;
846+
DYLIB_CURRENT_VERSION = 0.1.4;
847847
DYLIB_INSTALL_NAME_BASE = "@rpath";
848848
ENABLE_STRICT_OBJC_MSGSEND = YES;
849849
ENABLE_TESTABILITY = YES;
@@ -932,7 +932,7 @@
932932
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
933933
DEFINES_MODULE = YES;
934934
DYLIB_COMPATIBILITY_VERSION = 0.1.0;
935-
DYLIB_CURRENT_VERSION = 0.1.3;
935+
DYLIB_CURRENT_VERSION = 0.1.4;
936936
DYLIB_INSTALL_NAME_BASE = "@rpath";
937937
ENABLE_NS_ASSERTIONS = NO;
938938
ENABLE_STRICT_OBJC_MSGSEND = YES;

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Release 0.1.4
2+
3+
- [x] CodeBeat refactor.
4+
15
# Release 0.1.3
26

37
- [x] Added logo.
@@ -8,4 +12,4 @@
812

913
# Release 0.1.0
1014

11-
- [x] First release
15+
- [x] First release.

Core/HomeManager.swift

+31-18
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,19 @@ class HomeManager {
3434
for j in 0..<colors {
3535
var bitmap = [UInt8](repeating: 0, count: 4)
3636
let context = CIContext()
37-
let inputExtent = CIVector(x: (extent.size.width/CGFloat(colors))*CGFloat(i), y: (extent.size.height/CGFloat(colors))*CGFloat(j), z: extent.size.width/CGFloat(colors), w: extent.size.height/CGFloat(colors))
38-
let filter = CIFilter(name: "CIAreaAverage", withInputParameters: [kCIInputImageKey: image, kCIInputExtentKey: inputExtent])!
39-
let outputImage = filter.outputImage!
37+
let x = (extent.size.width / CGFloat(colors)) * CGFloat(i)
38+
let y = (extent.size.height / CGFloat(colors)) * CGFloat(j)
39+
let width = extent.size.width / CGFloat(colors)
40+
let height = extent.size.height / CGFloat(colors)
41+
let inputExtent = CIVector(x: x, y: y, z: width, w: height)
42+
let inputParameters = [kCIInputImageKey: image, kCIInputExtentKey: inputExtent]
43+
guard let filter = CIFilter(name: "CIAreaAverage", withInputParameters: inputParameters), let outputImage = filter.outputImage else {
44+
break
45+
}
4046
let outputExtent = outputImage.extent
4147
assert(outputExtent.size.width == 1 && outputExtent.size.height == 1)
42-
context.render(outputImage, toBitmap: &bitmap, rowBytes: 4, bounds: CGRect(x: 0, y: 0, width: 1, height: 1), format: kCIFormatRGBA8, colorSpace: CGColorSpaceCreateDeviceRGB())
48+
let bounds = CGRect(x: 0, y: 0, width: 1, height: 1)
49+
context.render(outputImage, toBitmap: &bitmap, rowBytes: 4, bounds: bounds, format: kCIFormatRGBA8, colorSpace: CGColorSpaceCreateDeviceRGB())
4350
samples.append(bitmap)
4451
}
4552
}
@@ -52,26 +59,27 @@ class HomeManager {
5259
}
5360
var colorIndex = 0
5461
for lightbulbService in lightbulbServices {
62+
let color = colors[colorIndex % colors.count]
5563
var HSBA = [CGFloat](repeating: 0, count: 4)
56-
colors[colorIndex % colors.count].getHue(&HSBA[0], saturation: &HSBA[1], brightness: &HSBA[2], alpha: &HSBA[3])
64+
color.getHue(&HSBA[0], saturation: &HSBA[1], brightness: &HSBA[2], alpha: &HSBA[3])
5765
for characteristic in lightbulbService.characteristics {
5866
if updating[characteristic] == nil {
5967
updating[characteristic] = false
6068
}
6169
guard updating[characteristic] == false else {
6270
break
6371
}
64-
if characteristic.characteristicType == HMCharacteristicTypePowerState {
65-
update(characteristic, floatValue: 1)
66-
}
67-
if characteristic.characteristicType == HMCharacteristicTypeBrightness {
68-
update(characteristic, floatValue: Float(HSBA[2]))
69-
}
70-
if characteristic.characteristicType == HMCharacteristicTypeSaturation {
71-
update(characteristic, floatValue: Float(HSBA[1]))
72-
}
73-
if characteristic.characteristicType == HMCharacteristicTypeHue {
74-
update(characteristic, floatValue: Float(HSBA[0]))
72+
switch characteristic.characteristicType {
73+
case HMCharacteristicTypePowerState:
74+
update(characteristic, floatValue: 1)
75+
case HMCharacteristicTypeBrightness:
76+
update(characteristic, floatValue: Float(HSBA[2]))
77+
case HMCharacteristicTypeSaturation:
78+
update(characteristic, floatValue: Float(HSBA[1]))
79+
case HMCharacteristicTypeHue:
80+
update(characteristic, floatValue: Float(HSBA[0]))
81+
default:
82+
break
7583
}
7684
}
7785
colorIndex += 1
@@ -88,7 +96,8 @@ extension HomeManager {
8896
updating[characteristic] = true
8997
characteristic.writeValue(value, completionHandler: { error in
9098
if error != nil {
91-
DispatchQueue.global().asyncAfter(deadline: .now() + .seconds(1), execute: { [weak self] in
99+
let deadline: DispatchTime = .now() + .seconds(1)
100+
DispatchQueue.global().asyncAfter(deadline: deadline, execute: { [weak self] in
92101
self?.updating[characteristic] = false
93102
})
94103
} else {
@@ -112,7 +121,11 @@ extension HomeManager {
112121
let diffRed = abs(CGFloat(components[0]) - CGFloat(diffComponents[0]))
113122
let diffGreen = abs(CGFloat(components[1]) - CGFloat(diffComponents[1]))
114123
let diffBlue = abs(CGFloat(components[2]) - CGFloat(diffComponents[2]))
115-
let color = UIColor(red: CGFloat(components[0]) / 255.0, green: CGFloat(components[1]) / 255.0, blue: CGFloat(components[2]) / 255.0, alpha: CGFloat(components[3]) / 255.0)
124+
let red = CGFloat(components[0]) / 255
125+
let green = CGFloat(components[1]) / 255
126+
let blue = CGFloat(components[2]) / 255
127+
let alpha = CGFloat(components[3]) / 255
128+
let color = UIColor(red: red, green: green, blue: blue, alpha: alpha)
116129
diffColors[color] = (diffColors[color] ?? 0) + diffRed + diffGreen + diffBlue
117130
}
118131
}

Core/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.1.3</string>
18+
<string>0.1.4</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSHomeKitUsageDescription</key>

0 commit comments

Comments
 (0)