forked from donjin123/ColorPickerWheel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pixel.swift
44 lines (35 loc) · 986 Bytes
/
Pixel.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// Pixel.swift
// color
//
// Created by Donjin_master on 05/10/2018.
// Copyright © 2018 Donjin. All rights reserved.
//
import Foundation
import UIKit
struct Pixel: Equatable {
private var rgba: UInt32
var red: UInt8 {
return UInt8((rgba >> 24) & 255)
}
var green: UInt8 {
return UInt8((rgba >> 16) & 255)
}
var blue: UInt8 {
return UInt8((rgba >> 8) & 255)
}
var alpha: UInt8 {
return UInt8((rgba >> 0) & 255)
}
init(red: UInt8, green: UInt8, blue: UInt8, alpha: UInt8) {
let red32 = UInt32(red)
let green32 = UInt32(green)
let blue32 = UInt32(blue)
let alpha32 = UInt32(alpha)
rgba = red32 << 24 | green32 << 16 | blue32 << 8 | alpha32
}
static let bitmapInfo = CGImageAlphaInfo.premultipliedLast.rawValue | CGBitmapInfo.byteOrder32Little.rawValue
static func ==(lhs: Pixel, rhs: Pixel) -> Bool {
return lhs.rgba == rhs.rgba
}
}