Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e2a305dcf3 | |||
| fb3fc03fe1 | |||
| 2e45c812b9 | |||
| 795bed4c5d | |||
| 843df78755 | |||
| 5f88ff991e | |||
| 395f608cee |
@@ -43,7 +43,7 @@
|
||||
<rect key="frame" x="20" y="93" width="374" height="32"/>
|
||||
<segments>
|
||||
<segment title="Orange"/>
|
||||
<segment title="Magenta"/>
|
||||
<segment title="Red"/>
|
||||
<segment title="Green"/>
|
||||
<segment title="Brown"/>
|
||||
<segment title="Cyan"/>
|
||||
|
||||
@@ -30,17 +30,12 @@ class ViewController: UIViewController {
|
||||
@IBOutlet weak var messageLabel: UILabel!
|
||||
var coder = RCCoder()
|
||||
var image = RCImage(message: "")
|
||||
let colors: [[UIColor]] = [[.orange, .gray], [.orange, .magenta], [.systemGreen, .systemBlue], [.orange, .brown], [.purple, .cyan]]
|
||||
let colors: [[UIColor]] = [[.orange, .magenta], [.systemPink, .systemTeal], [.systemTeal, .systemGreen], [.orange, .brown], [.purple, .cyan]]
|
||||
var isScanningFromLibrary = false
|
||||
}
|
||||
|
||||
extension ViewController {
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
image.isTransparent = true
|
||||
}
|
||||
|
||||
@IBAction func scanImage(_ sender: Any) {
|
||||
isScanningFromLibrary = true
|
||||
let vc = UIImagePickerController()
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'RoundCode'
|
||||
s.version = '1.1.0'
|
||||
s.version = '1.1.1'
|
||||
s.summary = 'Facebook messenger style custom barcode.'
|
||||
s.description = <<-DESC
|
||||
Encode and decode data into custom stylish barcode.
|
||||
|
||||
@@ -28,5 +28,5 @@ struct RCConstants {
|
||||
static let dotSizeScale: CGFloat = 0.08
|
||||
static let dotPatterns: [CGFloat] = [6, 4, 2]
|
||||
static let dotPointRange = (Float(1.3)...Float(2.5))
|
||||
static let pixelThreshold = 180
|
||||
static let pixelThreshold = (0...180)
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ public enum RCError: String, LocalizedError {
|
||||
case longText
|
||||
case decoding
|
||||
case wrongImageSize
|
||||
case wrongColors
|
||||
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
@@ -38,6 +39,8 @@ public enum RCError: String, LocalizedError {
|
||||
return "Error decoding"
|
||||
case .wrongImageSize:
|
||||
return "Error decoding. Image width and height must be a equal"
|
||||
case .wrongColors:
|
||||
return "The tint colors should be in a range of \(RCConstants.pixelThreshold) grayscale with 1.0 alpha"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ extension RCImageDecoder {
|
||||
let transform = calculateTransform(from: points)
|
||||
let mapper = RCPointMapper(transform: transform, size: size)
|
||||
let locations = mapper.map(points: calculateBitLocations())
|
||||
let bits = locations.map { data[Int($0.x), Int($0.y)] > RCConstants.pixelThreshold ? RCBit.zero : RCBit.one }
|
||||
let bits = locations.map { RCConstants.pixelThreshold.contains(Int(data[Int($0.x), Int($0.y)])) ? RCBit.one : RCBit.zero }
|
||||
return bits
|
||||
}
|
||||
|
||||
@@ -75,13 +75,13 @@ extension RCImageDecoder {
|
||||
private func scanControlPoint(for data: PixelContainer, region: (x: Int, y: Int), side: Side) throws -> CGPoint {
|
||||
|
||||
func scan(region: (x: Int, y: Int, size: Int), data: PixelContainer, coordinate: (Int) -> (x: Int, y: Int), comparison: (PixelPattern, (x: Int, y: Int)) -> Bool) -> [PixelPattern] {
|
||||
var lastPattern = PixelPattern(bit: data[region.x, region.y] > RCConstants.pixelThreshold ? RCBit.zero : RCBit.one, x: region.x, y: region.y, count: 0)
|
||||
var lastPattern = PixelPattern(bit: RCConstants.pixelThreshold.contains(Int(data[region.x, region.y])) ? RCBit.one : RCBit.zero, x: region.x, y: region.y, count: 0)
|
||||
var pixelPatterns = [lastPattern]
|
||||
var count = 0
|
||||
let maxSize = region.size * region.size
|
||||
while count < maxSize {
|
||||
let coordinate = coordinate(count)
|
||||
let bit = data[coordinate.x, coordinate.y] > RCConstants.pixelThreshold ? RCBit.zero : RCBit.one
|
||||
let bit = RCConstants.pixelThreshold.contains(Int(data[coordinate.x, coordinate.y])) ? RCBit.one : RCBit.zero
|
||||
if comparison(lastPattern, coordinate), lastPattern.bit == bit {
|
||||
lastPattern.count += 1
|
||||
pixelPatterns[pixelPatterns.count - 1] = lastPattern
|
||||
|
||||
@@ -54,6 +54,16 @@ public extension RCCoder {
|
||||
func validate(_ text: String) -> Bool {
|
||||
configuration.validate(text)
|
||||
}
|
||||
|
||||
func validateForBlackBackground(colors: [UIColor]) -> Bool {
|
||||
colors.allSatisfy { color in
|
||||
var white: CGFloat = 0
|
||||
var alpha: CGFloat = 0
|
||||
guard color.getWhite(&white, alpha: &alpha) else { return false }
|
||||
guard alpha == 1.0 else { return false }
|
||||
return RCConstants.pixelThreshold.contains(Int(white * 255))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension RCCoder {
|
||||
|
||||
@@ -28,7 +28,7 @@ public struct RCImage {
|
||||
public var size = CGFloat(300)
|
||||
public var tintColors: [UIColor] = [.orange, .magenta]
|
||||
public var attachmentImage: UIImage?
|
||||
public var isTransparent = false
|
||||
public var isTransparent = true
|
||||
public var gradientType = GradientType.linear(angle: CGFloat.pi / 4)
|
||||
public var contentInsets = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user