mirror of https://github.com/status-im/qzxing.git
progressing port of QR Encoder
This commit is contained in:
parent
3ecb2fa8d8
commit
e6e82548ab
File diff suppressed because it is too large
Load Diff
|
@ -1,148 +1,133 @@
|
||||||
//#ifndef ENCODER_H
|
#ifndef ENCODER_H
|
||||||
//#define ENCODER_H
|
#define ENCODER_H
|
||||||
////package com.google.zxing.qrcode.encoder;
|
|
||||||
|
|
||||||
////import com.google.zxing.EncodeHintType;
|
#include <vector>
|
||||||
////import com.google.zxing.WriterException;
|
#include <zxing/common/CharacterSetECI.h>
|
||||||
////import com.google.zxing.common.BitArray;
|
#include <zxing/qrcode/ErrorCorrectionLevel.h>
|
||||||
////import com.google.zxing.common.CharacterSetECI;
|
#include <zxing/qrcode/encoder/QRCode.h>
|
||||||
////import com.google.zxing.common.reedsolomon.GenericGF;
|
#include <zxing/EncodeHint.h>
|
||||||
////import com.google.zxing.common.reedsolomon.ReedSolomonEncoder;
|
|
||||||
////import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
|
||||||
////import com.google.zxing.qrcode.decoder.Mode;
|
|
||||||
////import com.google.zxing.qrcode.decoder.Version;
|
|
||||||
|
|
||||||
////import java.io.UnsupportedEncodingException;
|
#include <vector>
|
||||||
////import java.util.ArrayList;
|
#include <QString>
|
||||||
////import java.util.Collection;
|
|
||||||
////import java.util.Map;
|
|
||||||
|
|
||||||
//#include <string>
|
namespace zxing {
|
||||||
//#include <vector>
|
namespace qrcode {
|
||||||
//#include <zxing/common/CharacterSetECI.h>
|
|
||||||
//#include <zxing/qrcode/ErrorCorrectionLevel.h>
|
|
||||||
//#include <zxing/qrcode/encoder/QRCode.h>
|
|
||||||
|
|
||||||
//namespace zxing {
|
class Encoder {
|
||||||
//namespace qrcode {
|
|
||||||
|
|
||||||
//class Encoder {
|
private:
|
||||||
|
static const int ALPHANUMERIC_TABLE_SIZE;
|
||||||
|
static const int ALPHANUMERIC_TABLE[];
|
||||||
|
static const QString DEFAULT_BYTE_MODE_ENCODING;
|
||||||
|
|
||||||
//private:
|
/**
|
||||||
// static const int ALPHANUMERIC_TABLE[];
|
* The mask penalty calculation is complicated. See Table 21 of JISX0510:2004 (p.45) for details.
|
||||||
// static const std::string DEFAULT_BYTE_MODE_ENCODING;
|
* Basically it applies four rules and summate all penalties.
|
||||||
|
*/
|
||||||
|
static int calculateMaskPenalty(const ByteMatrix& matrix);
|
||||||
|
|
||||||
// Encoder() {}
|
/**
|
||||||
|
* Encode "bytes" with the error correction level "ecLevel". The encoding mode will be chosen
|
||||||
|
* internally by chooseMode(). On success, store the result in "qrCode".
|
||||||
|
*
|
||||||
|
* We recommend you to use QRCode.EC_LEVEL_L (the lowest level) for
|
||||||
|
* "getECLevel" since our primary use is to show QR code on desktop screens. We don't need very
|
||||||
|
* strong error correction for this purpose.
|
||||||
|
*
|
||||||
|
* Note that there is no way to encode bytes in MODE_KANJI. We might want to add EncodeWithMode()
|
||||||
|
* with which clients can specify the encoding mode. For now, we don't need the functionality.
|
||||||
|
*/
|
||||||
|
public:
|
||||||
|
static QRCode* encode(const QString& content, const ErrorCorrectionLevel* ecLevel);
|
||||||
|
|
||||||
// /**
|
static QRCode* encode(const QString& content, const ErrorCorrectionLevel* ecLevel, const EncodeHint* hints);
|
||||||
// * The mask penalty calculation is complicated. See Table 21 of JISX0510:2004 (p.45) for details.
|
|
||||||
// * Basically it applies four rules and summate all penalties.
|
|
||||||
// */
|
|
||||||
// static int calculateMaskPenalty(ByteMatrix matrix);
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Encode "bytes" with the error correction level "ecLevel". The encoding mode will be chosen
|
* @return the code point of the table used in alphanumeric mode or
|
||||||
// * internally by chooseMode(). On success, store the result in "qrCode".
|
* -1 if there is no corresponding code in the table.
|
||||||
// *
|
*/
|
||||||
// * We recommend you to use QRCode.EC_LEVEL_L (the lowest level) for
|
static int getAlphanumericCode(int code);
|
||||||
// * "getECLevel" since our primary use is to show QR code on desktop screens. We don't need very
|
|
||||||
// * strong error correction for this purpose.
|
|
||||||
// *
|
|
||||||
// * Note that there is no way to encode bytes in MODE_KANJI. We might want to add EncodeWithMode()
|
|
||||||
// * with which clients can specify the encoding mode. For now, we don't need the functionality.
|
|
||||||
// */
|
|
||||||
//public:
|
|
||||||
// static QRCode encode(std::string content, ErrorCorrectionLevel ecLevel);
|
|
||||||
|
|
||||||
// static QRCode encode(String content, ErrorCorrectionLevel ecLevel/*,
|
static Mode* chooseMode(const QString& content);
|
||||||
// Map<EncodeHintType,?> hints*/);
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * @return the code point of the table used in alphanumeric mode or
|
* Choose the best mode by examining the content. Note that 'encoding' is used as a hint;
|
||||||
// * -1 if there is no corresponding code in the table.
|
* if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}.
|
||||||
// */
|
*/
|
||||||
// static int getAlphanumericCode(int code);
|
private:
|
||||||
|
static Mode* chooseMode(const QString& content, const QString& encoding);
|
||||||
|
|
||||||
// static Mode chooseMode(String content);
|
//static bool isOnlyDoubleByteKanji(const QString& content);
|
||||||
|
|
||||||
// /**
|
static int chooseMaskPattern(BitArray bits,
|
||||||
// * Choose the best mode by examining the content. Note that 'encoding' is used as a hint;
|
ErrorCorrectionLevel ecLevel,
|
||||||
// * if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}.
|
Version version,
|
||||||
// */
|
ByteMatrix matrix);
|
||||||
//private:
|
|
||||||
// static Mode chooseMode(std::string content, std::string encoding);
|
|
||||||
|
|
||||||
// static boolean isOnlyDoubleByteKanji(std::string content);
|
static Version chooseVersion(int numInputBits, ErrorCorrectionLevel &ecLevel) ;
|
||||||
|
|
||||||
// static int chooseMaskPattern(BitArray bits,
|
/**
|
||||||
// ErrorCorrectionLevel ecLevel,
|
* Terminate bits as described in 8.4.8 and 8.4.9 of JISX0510:2004 (p.24).
|
||||||
// Version version,
|
*/
|
||||||
// ByteMatrix matrix);
|
protected:
|
||||||
|
static void terminateBits(int numDataBytes, BitArray& bits);
|
||||||
|
|
||||||
// static Version chooseVersion(int numInputBits, ErrorCorrectionLevel ecLevel) ;
|
/**
|
||||||
|
* Get number of data bytes and number of error correction bytes for block id "blockID". Store
|
||||||
|
* the result in "numDataBytesInBlock", and "numECBytesInBlock". See table 12 in 8.5.1 of
|
||||||
|
* JISX0510:2004 (p.30)
|
||||||
|
*/
|
||||||
|
static void getNumDataBytesAndNumECBytesForBlockID(int numTotalBytes,
|
||||||
|
int numDataBytes,
|
||||||
|
int numRSBlocks,
|
||||||
|
int blockID,
|
||||||
|
std::vector<int>& numDataBytesInBlock,
|
||||||
|
std::vector<int>& numECBytesInBlock);
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Terminate bits as described in 8.4.8 and 8.4.9 of JISX0510:2004 (p.24).
|
* Interleave "bits" with corresponding error correction bytes. On success, store the result in
|
||||||
// */
|
* "result". The interleave rule is complicated. See 8.6 of JISX0510:2004 (p.37) for details.
|
||||||
//protected:
|
*/
|
||||||
// static void terminateBits(int numDataBytes, BitArray bits);
|
static BitArray* interleaveWithECBytes(const BitArray& bits,
|
||||||
|
int numTotalBytes,
|
||||||
|
int numDataBytes,
|
||||||
|
int numRSBlocks);
|
||||||
|
|
||||||
// /**
|
static ArrayRef<char> generateECBytes(const std::vector<char>& dataBytes, int numEcBytesInBlock);
|
||||||
// * Get number of data bytes and number of error correction bytes for block id "blockID". Store
|
|
||||||
// * the result in "numDataBytesInBlock", and "numECBytesInBlock". See table 12 in 8.5.1 of
|
|
||||||
// * JISX0510:2004 (p.30)
|
|
||||||
// */
|
|
||||||
// static void getNumDataBytesAndNumECBytesForBlockID(int numTotalBytes,
|
|
||||||
// int numDataBytes,
|
|
||||||
// int numRSBlocks,
|
|
||||||
// int blockID,
|
|
||||||
// int numDataBytesInBlock[],
|
|
||||||
// int numECBytesInBlock[]);
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Interleave "bits" with corresponding error correction bytes. On success, store the result in
|
* Append mode info. On success, store the result in "bits".
|
||||||
// * "result". The interleave rule is complicated. See 8.6 of JISX0510:2004 (p.37) for details.
|
*/
|
||||||
// */
|
static void appendModeInfo(const Mode& mode, BitArray& bits);
|
||||||
// static BitArray interleaveWithECBytes(BitArray bits,
|
|
||||||
// int numTotalBytes,
|
|
||||||
// int numDataBytes,
|
|
||||||
// int numRSBlocks);
|
|
||||||
|
|
||||||
// static std::vector<char> generateECBytes(const std::vector<char>& dataBytes[], int numEcBytesInBlock);
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Append mode info. On success, store the result in "bits".
|
|
||||||
// */
|
|
||||||
// static void appendModeInfo(Mode mode, BitArray bits);
|
|
||||||
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Append length info. On success, store the result in "bits".
|
* Append length info. On success, store the result in "bits".
|
||||||
// */
|
*/
|
||||||
// static void appendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits);
|
static void appendLengthInfo(int numLetters, const Version& version, const Mode& mode, BitArray& bits);
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
|
* Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
|
||||||
// */
|
*/
|
||||||
// static void appendBytes(std::string content,
|
static void appendBytes(const QString& content,
|
||||||
// Mode mode,
|
const Mode& mode,
|
||||||
// BitArray bits,
|
BitArray& bits,
|
||||||
// std::string encoding);
|
const QString& encoding);
|
||||||
|
|
||||||
// static void appendNumericBytes( const std::vector<char>& content, BitArray bits);
|
static void appendNumericBytes( const std::vector<char>& content, BitArray& bits);
|
||||||
|
|
||||||
// static void appendAlphanumericBytes(const std::vector<char>& content, BitArray bits);
|
static void appendAlphanumericBytes(const std::vector<char>& content, BitArray& bits);
|
||||||
|
|
||||||
// static void append8BitBytes(std::string content, BitArray bits, std::string encoding);
|
static void append8BitBytes(const QString& content, BitArray& bits, const QString& encoding);
|
||||||
|
|
||||||
// static void appendKanjiBytes(std::string content, BitArray bits);
|
static void appendKanjiBytes(const QString& content, BitArray& bits);
|
||||||
|
|
||||||
//private:
|
private:
|
||||||
// static void appendECI(zxing::common::CharacterSetECI eci, BitArray bits);
|
static void appendECI(const zxing::common::CharacterSetECI& eci, BitArray& bits);
|
||||||
|
|
||||||
//}
|
};
|
||||||
|
|
||||||
//}
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
//#endif // ENCODER_H
|
#endif // ENCODER_H
|
||||||
|
|
Loading…
Reference in New Issue