Skip to content

Commit

Permalink
move to
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuhikoarase committed Aug 8, 2014
1 parent 4d001a1 commit b541737
Show file tree
Hide file tree
Showing 53 changed files with 7,968 additions and 0 deletions.
59 changes: 59 additions & 0 deletions as3/src/as3/com/d_project/qrcode/BitBuffer.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.d_project.qrcode {

/**
* BitBuffer
* @author Kazuhiko Arase
*/
internal class BitBuffer {

private var buffer : Array;

private var length : int;

public function BitBuffer() {
buffer = new Array();
length = 0;
}

public function getBuffer() : Array {
return buffer;
}

public function getLengthInBits() : int {
return length;
}

private function getBitAt(index : int) : Boolean {
return ( (buffer[Math.floor(index / 8)] >>> (7 - index % 8) ) & 1) == 1;
}

public function put(num : int, length : int) : void {
for (var i : int = 0; i < length; i++) {
putBit( ( (num >>> (length - i - 1) ) & 1) == 1);
}
}

public function putBit(bit : Boolean) : void {

if (length == buffer.length * 8) {
buffer.push(0);
}

if (bit) {
buffer[Math.floor(length / 8)] |= (0x80 >>> (length % 8) );
}

length++;
}

public function toString() : String {
var buffer : String = "";
for (var i : int = 0; i < getLengthInBits(); i++) {
buffer += (getBitAt(i)? '1' : '0');
}
return buffer;
}

}

}
31 changes: 31 additions & 0 deletions as3/src/as3/com/d_project/qrcode/ErrorCorrectLevel.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.d_project.qrcode {

/**
* 誤り訂正レベル.
* @author Kazuhiko Arase
*/
public class ErrorCorrectLevel {

/**
* 復元能力 7%.
* <br>vodafoneで使用不可?
*/
public static const L : int = 1;

/**
* 復元能力 15%.
*/
public static const M : int = 0;

/**
* 復元能力 25%.
*/
public static const Q : int = 3;

/**
* 復元能力 30%.
*/
public static const H : int = 2;

}
}
52 changes: 52 additions & 0 deletions as3/src/as3/com/d_project/qrcode/MaskPattern.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.d_project.qrcode {

/**
* マスクパターン.
* @author Kazuhiko Arase
*/
internal class MaskPattern {

/**
* マスクパターン000
*/
public static const PATTERN000 : int = 0;

/**
* マスクパターン001
*/
public static const PATTERN001 : int = 1;

/**
* マスクパターン010
*/
public static const PATTERN010 : int = 2;

/**
* マスクパターン011
*/
public static const PATTERN011 : int = 3;

/**
* マスクパターン100
*/
public static const PATTERN100 : int = 4;

/**
* マスクパターン101
*/
public static const PATTERN101 : int = 5;

/**
* マスクパターン110
*/
public static const PATTERN110 : int = 6;

/**
* マスクパターン111
*/
public static const PATTERN111 : int = 7;

}


}
35 changes: 35 additions & 0 deletions as3/src/as3/com/d_project/qrcode/Mode.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.d_project.qrcode {

/**
* モード.
* @author Kazuhiko Arase
*/
public class Mode {

/**
* 自動モード
*/
public static const MODE_AUTO : int = 0;

/**
* 数値モード
*/
public static const MODE_NUMBER : int = 1 << 0;

/**
* 英数字モード
*/
public static const MODE_ALPHA_NUM : int = 1 << 1;

/**
* 8ビットバイトモード
*/
public static const MODE_8BIT_BYTE : int = 1 << 2;

/**
* 漢字モード
*/
public static const MODE_KANJI : int = 1 << 3;

}
}
103 changes: 103 additions & 0 deletions as3/src/as3/com/d_project/qrcode/Polynomial.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.d_project.qrcode {

/**
* Polynomial
* @author Kazuhiko Arase
*/
internal class Polynomial {

private var num : Array;

public function Polynomial(num : Array, shift : int = 0) {

var offset : int = 0;

while (offset < num.length && num[offset] == 0) {
offset++;
}

this.num = new Array(num.length - offset + shift);
for (var i : int = 0; i < num.length - offset; i++) {
this.num[i] = num[offset + i];
}
}

public function getAt(index : int) : int {
return num[index];
}

public function getLength() : int {
return num.length;
}

public function toString() : String {

var buffer : String = "";

for (var i : int = 0; i < getLength(); i++) {
if (i > 0) {
buffer += ",";
}
buffer += getAt(i);
}

return buffer;
}

public function toLogString() : String {

var buffer : String = "";

for (var i : int = 0; i < getLength(); i++) {
if (i > 0) {
buffer += ",";
}
buffer += QRMath.glog(getAt(i) );

}

return buffer.toString();
}

public function multiply(e : Polynomial) : Polynomial {

var num : Array = new Array(getLength() + e.getLength() - 1);

for (var i : int = 0; i < getLength(); i++) {
for (var j : int = 0; j < e.getLength(); j++) {
num[i + j] ^= QRMath.gexp(QRMath.glog(getAt(i) ) + QRMath.glog(e.getAt(j) ) );
}
}

return new Polynomial(num);
}

public function mod(e : Polynomial) : Polynomial {

if (getLength() - e.getLength() < 0) {
return this;
}

// 最上位桁の比率
var ratio : int = QRMath.glog(getAt(0) ) - QRMath.glog(e.getAt(0) );

var i : int;

// コピー作成
var num : Array = new Array(getLength() );
for (i = 0; i < getLength(); i++) {
num[i] = getAt(i);
}

// 引き算して余りを計算
for (i = 0; i < e.getLength(); i++) {
num[i] ^= QRMath.gexp(QRMath.glog(e.getAt(i) ) + ratio);
}

// 再帰計算
return new Polynomial(num).mod(e);
}

}

}
26 changes: 26 additions & 0 deletions as3/src/as3/com/d_project/qrcode/QR8BitByte.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.d_project.qrcode {

import flash.utils.ByteArray;

/**
* QR8BitByte
* @author Kazuhiko Arase
*/
internal class QR8BitByte extends QRData {

public function QR8BitByte(data : String) {
super(Mode.MODE_8BIT_BYTE, data);
}

public override function write(buffer : BitBuffer) : void {
var data : ByteArray = StringUtil.getBytes(getData(), QRUtil.getJISEncoding() );
for (var i : int = 0; i < data.length; i++) {
buffer.put(data[i], 8);
}
}

public override function getLength() : int {
return StringUtil.getBytes(getData(), QRUtil.getJISEncoding() ).length;
}
}
}
60 changes: 60 additions & 0 deletions as3/src/as3/com/d_project/qrcode/QRAlphaNum.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.d_project.qrcode {

/**
* QRAlphaNum
* @author Kazuhiko Arase
*/
internal class QRAlphaNum extends QRData {

public function QRAlphaNum(data : String) {
super(Mode.MODE_ALPHA_NUM, data);
}

public override function write(buffer : BitBuffer) : void {

var i : int = 0;
var s : String = getData();

while (i + 1 < s.length) {
buffer.put(getCode(s.charAt(i) ) * 45 + getCode(s.charAt(i + 1) ), 11);
i += 2;
}

if (i < s.length) {
buffer.put(getCode(s.charAt(i) ), 6);
}
}

public override function getLength() : int {
return getData().length;
}

private static function getCode(c : String) : int {
var code : int = c.charCodeAt(0);
if (getCharCode('0') <= code && code <= getCharCode('9') ) {
return code - getCharCode('0');
} else if (getCharCode('A') <= code && code <= getCharCode('Z') ) {
return code - getCharCode('A') + 10;
} else {
switch (c) {
case ' ' : return 36;
case '$' : return 37;
case '%' : return 38;
case '*' : return 39;
case '+' : return 40;
case '-' : return 41;
case '.' : return 42;
case '/' : return 43;
case ':' : return 44;
default :
throw new Error("illegal char :" + c);
}
}
throw new Error();
}

private static function getCharCode(c : String) : int {
return c.charCodeAt(0);
}
}
}
Loading

0 comments on commit b541737

Please sign in to comment.