7 Commits

Author SHA1 Message Date
Haik Aslanyan e2a305dcf3 updated pixelThreshold range 2020-04-19 17:22:02 +04:00
Haik Aslanyan fb3fc03fe1 Merge pull request #4 from aslanyanhaik/develop
Develop
2020-04-19 16:56:00 +04:00
Haik Aslanyan 2e45c812b9 Merge branch 'develop' of https://github.com/aslanyanhaik/roundCode into develop 2020-04-19 16:53:45 +04:00
Haik Aslanyan 795bed4c5d updated to 1.1.1 version 2020-04-19 16:53:39 +04:00
Haik Aslanyan 843df78755 updated example project 2020-04-19 16:51:02 +04:00
Haik Aslanyan 5f88ff991e added color color validation for black background 2020-04-19 16:50:14 +04:00
Haik Aslanyan 395f608cee changed pixelThreshold from constant to range 2020-04-19 16:47:53 +04:00
8 changed files with 21 additions and 13 deletions
+1 -1
View File
@@ -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"/>
+1 -6
View File
@@ -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
View File
@@ -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.
+1 -1
View File
@@ -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)
}
+3
View File
@@ -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"
}
}
}
+3 -3
View File
@@ -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
+10
View File
@@ -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 {
+1 -1
View File
@@ -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)