Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Commit

Permalink
Ensure we use a RGB color before we get it's components
Browse files Browse the repository at this point in the history
  • Loading branch information
djbe committed May 30, 2017
1 parent 3956e97 commit 0c0e9b1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions Sources/Parsers/ColorsFileParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,13 @@ extension NSColor {
}

var hexValue: UInt32 {
let hexRed = UInt32(round(redComponent * 0xFF)) << 24
let hexGreen = UInt32(round(greenComponent * 0xFF)) << 16
let hexBlue = UInt32(round(blueComponent * 0xFF)) << 8
let hexAlpha = UInt32(round(alphaComponent * 0xFF))
guard let rgb = rgbColor else { return 0 }

let hexRed = UInt32(round(rgb.redComponent * 0xFF)) << 24
let hexGreen = UInt32(round(rgb.greenComponent * 0xFF)) << 16
let hexBlue = UInt32(round(rgb.blueComponent * 0xFF)) << 8
let hexAlpha = UInt32(round(rgb.alphaComponent * 0xFF))

return hexRed | hexGreen | hexBlue | hexAlpha
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class ColorsCLRFileParser: ColorsFileTypeParser {
var colors = [String: UInt32]()

for colorName in colorsList.allKeys {
colors[colorName] = colorsList.color(withKey: colorName)?.rgbColor?.hexValue
colors[colorName] = colorsList.color(withKey: colorName)?.hexValue
}

return colors
Expand Down
2 changes: 1 addition & 1 deletion Tests/Resources
Submodule Resources updated 1 files
+3 −1 CHANGELOG.md

0 comments on commit 0c0e9b1

Please sign in to comment.