Giter Club home page Giter Club logo

roundcode's Introduction

RoundCode for iOS

License Swift 5 Twitter: @aslanyanhaik

RoundCode is custom circular QR code with lots of customization. Similar to Facebook messenger and Apple's App Clip Codes the RoundCode includes convenient camera scanner and decoder.

Different styles of RoundCode for iOS

Installation

Cocoapods:

pod 'RoundCode'

Swift Package Manager:

File > Swift Packages > Add Package Dependency

https://github.com/aslanyanhaik/RoundCode

Usage example

import framework

import RoundCode

Encoding

create coder and encode

let image = RCImage(message: "Hello World")
let coder = RCCoder()
do {
  imageView.image = try coder.encode(image)
} catch {
  //handle errors
}

You can also validate the messsage before encoding

let coder = RCCoder()
let isValidText = coder.validate("Hello world")

Decoding

Create instane of RCCameraViewController and handle the delegate

class ViewController: UIViewController, RCCameraViewControllerDelegate {
  
  func scan() {
    let cameraController = RCCameraViewController()
    cameraController.delegate = self
    present(cameraController, animated: true)
  }
  
  func cameraViewController(didFinishScanning message: String) {
    messageLabel.text = message
  }
}

You can also decode a UIImage like this

let coder = RCCoder()
do {
  messageLabel.text = try coder.decode(UIImage(named: code)!)
} catch {
  //handle errors
}

Appearance

You can change the appearance like this

var image = RCImage(message: "Hello world")
image.contentInsets = UIEdgeInsets(top: 8, left: 10, bottom: 4, right: 10)
image.attachmentImage = UIImage(named: "Profile")
image.size = 300
image.gradientType = .linear(angle: CGFloat.pi)
image.tintColors = [.red, .black]

If image is on dark background you should change scanning mode to darkBackground

let coder = RCCoder()
coder.scanningMode = .darkBackground

Advanced coding configuration

You can provide custom coding configuration in order to encode long text by reducing number of characters

let configuration = RCCoderConfiguration.shortConfiguration
let coder = RCCoder(configuration: configuration)
let configuration = RCCoderConfiguration(characters: " -abcdefghijklmnopqrstuvwxyz0123456789")
let coder = RCCoder(configuration: configuration)

⚠️ If you are encoding with custom configuration, then you should change the RCCameraViewController configuration ⚠️

let configuration = RCCoderConfiguration(characters: " -abcdefghijklmnopqrstuvwxyz0123456789")
let coder = RCCoder(configuration: configuration)
let camera = RCCameraViewController()
camera.coder = coder

Compatibility

Written in Swift 5 and requires Xcode 11.0

RoundCode is compatible with iOS 13.0+.

Screenshot of RoundCode for iOS

Author

License

Copyright 2020 Haik Aslanyan.

Licensed under MIT License: https://opensource.org/licenses/MIT

roundcode's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

roundcode's Issues

Impressive! Some suggestion how to improve

I never thought that something that possible to do in Swift. Well done! 👍

Here some ideas to improve performance of your algo:

  1. The slowest part of your algo it control point detector. If you will use simplest structure here, you will have better performance and it will be possible to process full image.
  static let lightBackgroundRange = UInt8(0)...UInt8(180) // simple compare better: pixel < 180 
  static let darkBackgroundRange = UInt8(100)...UInt8(255) // simple compare better: pixel > 100 

I recommend to perform threshold separately. Accelerate framework can help


let bit = pixelThreshold.contains(data[x, y]) ? RCBit.one : RCBit.zero

You probably don't need RCBit abstraction. typealias around bool will works better and pretty informative


pixelPatterns[pixelPatterns.count - 1] = lastPattern

This operation call lot of times. Just with change struct to class and you can remove this line


2) Reed Solomon codes. Additional you will get error restoration. You have interesting idea with something like `hash` with `RCMatrix` (if I understand it right). To make orientation working, you can try 4 possible orientation on decode bits. It's stupid and simple solution.

You awesome! =)

Custom background color?

Very nice library, is there a way to change the background color in the source code? It must be possible right?

Does the detection have to be on a white BG?

Seems like it only works on the output generated image (White Background), not while on a black BG (using the example app). Could this be made configurable?

I tried to apply a CIFilter(name: "CIColorInvert") to the pixelBuffer with not much luck.

Limitation

Hi!

I know that it isn't issue per se but I have a question directly connected with the code encoder/decoder. May I ask for some data about limitation (especially in terms of character amount) and the "regen" level for damaged codes?

Android Clone

Hi, Do you know if one Android repo exists, like a clone of your project ?

I want to use your code for one project, but i need to have the same with the android app, only to read it

Thanks

Character limitation.

Could we have a way to increase character count?
Current character limit is so small.

Why is RoundCodes only compatible with iOS 13.0+?

The README states that RoundCodes is written in Swift 5, requires Xcode 11 and is compatible with iOS 13.0+. Does it not work below iOS 13? Which APIs do you use that are not available on, say, iOS 11?

Decode not working from camera roll

Love the package. Great work. I'm not able to get it working with codes generated by the package that are then loaded from my camera roll. I tested the example project in the repo which also failed with a generic decode error.

if let message = try? coder.decode(camImage) {
  messageLabel.text = message
  messageLabel.isHidden = false
  DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
    self.messageLabel.isHidden = true
  }
}

Increase number of accepted characters in textfield input

Hey,

I would like to know if it possible to increase the number of input characters in the textfield where you put your string with the default configuration. I want to pass firebase UID but I can because they are too long.

Thanks.

darkBackground not working for iOS 14

I am trying to decode a Round code with a white tint and black background and an image in the middle. I am running on iOS 14 . Regardless of what scanning mode I put It on, It only works for a dark Roundcode on a white background.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.