-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #257 from vktr/f/qr-code-generator
Add QR code generator to support apps.
- Loading branch information
Showing
24 changed files
with
1,812 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
namespace picotorrent | ||
{ | ||
namespace client | ||
{ | ||
namespace qr | ||
{ | ||
class bit_buffer | ||
{ | ||
public: | ||
bit_buffer(); | ||
|
||
std::vector<char> get_buffer(); | ||
int get_length_in_bits(); | ||
void put(int num, int length); | ||
void put(bool bit); | ||
|
||
private: | ||
std::vector<char> buffer_; | ||
int inclements_; | ||
int length_; | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace picotorrent | ||
{ | ||
namespace client | ||
{ | ||
namespace qr | ||
{ | ||
class polynomial | ||
{ | ||
public: | ||
polynomial(const std::vector<int> &num); | ||
polynomial(const std::vector<int> &num, int shift); | ||
|
||
int get(int index) const; | ||
int get_length() const; | ||
polynomial multiply(const polynomial &other); | ||
polynomial mod(const polynomial &other); | ||
std::string to_string(); | ||
std::string to_log_string(); | ||
|
||
private: | ||
std::vector<int> num_; | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include <picotorrent/client/qr/qr_data.hpp> | ||
|
||
namespace picotorrent | ||
{ | ||
namespace client | ||
{ | ||
namespace qr | ||
{ | ||
class qr_8bit_byte : public qr_data | ||
{ | ||
public: | ||
qr_8bit_byte(const std::string &data); | ||
|
||
int get_length(); | ||
void write(bit_buffer &buffer); | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include <picotorrent/client/qr/qr_data.hpp> | ||
|
||
#define MODE_NUMBER (1<<0) | ||
#define MODE_ALPHA_NUM (1<<1) | ||
#define MODE_8BIT_BYTE (1<<2) | ||
#define MODE_KANJI (1<<3) | ||
|
||
namespace picotorrent | ||
{ | ||
namespace client | ||
{ | ||
namespace qr | ||
{ | ||
class bit_buffer; | ||
class qr_8bit_byte; | ||
class rs_block; | ||
|
||
class qr_code | ||
{ | ||
public: | ||
qr_code(); | ||
|
||
int get_type_number(); | ||
void set_type_number(int type_number); | ||
int get_error_correct_level(); | ||
void set_error_correct_level(int error_correct_level); | ||
void add_data(const std::string &data); | ||
void add_data(const std::string &data, int mode); | ||
void clear_data(); | ||
bool is_dark(int row, int col); | ||
int get_module_count(); | ||
void make(); | ||
|
||
static std::vector<char> create_data(int type_number, int error_correct_level, std::vector<std::shared_ptr<qr_data>> &data); | ||
|
||
protected: | ||
void add_data(const std::shared_ptr<qr_data> &data); | ||
int get_data_count(); | ||
qr_data& get_data(int index); | ||
|
||
private: | ||
struct module_val | ||
{ | ||
bool value; | ||
bool has_value; | ||
}; | ||
|
||
int get_best_mask_pattern(); | ||
void make(bool test, int mask_pattern); | ||
void map_data(const std::vector<char> &data, int mask_pattern); | ||
void setup_position_adjust_pattern(); | ||
void setup_position_probe_pattern(int row, int col); | ||
void setup_timing_pattern(); | ||
void setup_type_number(bool test); | ||
void setup_type_info(bool test, int mask_pattern); | ||
|
||
static std::vector<char> create_bytes(bit_buffer &buffer, std::vector<rs_block> &blocks); | ||
|
||
int type_number_; | ||
std::vector<std::vector<module_val>> modules_; | ||
int module_count_; | ||
int error_correct_level_; | ||
std::vector<std::shared_ptr<qr_data>> qr_data_list_; | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
namespace picotorrent | ||
{ | ||
namespace client | ||
{ | ||
namespace qr | ||
{ | ||
class bit_buffer; | ||
|
||
class qr_data | ||
{ | ||
public: | ||
std::string get_data(); | ||
virtual int get_length() = 0; | ||
int get_length_in_bits(int type); | ||
int get_mode(); | ||
virtual void write(bit_buffer &buffer) = 0; | ||
|
||
protected: | ||
qr_data(int mode, const std::string &data); | ||
|
||
private: | ||
int mode_; | ||
std::string data_; | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
namespace picotorrent | ||
{ | ||
namespace client | ||
{ | ||
namespace qr | ||
{ | ||
class qr_math | ||
{ | ||
public: | ||
static int gexp(int n); | ||
static int glog(int n); | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include <picotorrent/client/qr/polynomial.hpp> | ||
|
||
namespace picotorrent | ||
{ | ||
namespace client | ||
{ | ||
namespace qr | ||
{ | ||
class qr_code; | ||
|
||
class qr_util | ||
{ | ||
public: | ||
static std::string get_jis_encoding(); | ||
static std::vector<int> get_pattern_position(int type_number); | ||
static int get_max_length(int type_number, int mode, int error_correct_level); | ||
static polynomial get_error_correct_polynomial(int error_correct_length); | ||
static bool get_mask(int mask_pattern, int i, int j); | ||
static int get_lost_point(qr_code &qr); | ||
static int get_mode(const std::string &m); | ||
static int get_bch_type_info(int data); | ||
static int get_bch_type_number(int data); | ||
static int get_bch_digit(int data); | ||
|
||
private: | ||
qr_util() {} | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
namespace picotorrent | ||
{ | ||
namespace client | ||
{ | ||
namespace qr | ||
{ | ||
class rs_block | ||
{ | ||
public: | ||
rs_block(int total_count, int data_count); | ||
|
||
int get_data_count(); | ||
int get_total_count(); | ||
|
||
static std::vector<rs_block> get_rs_blocks(int type_number, int error_correct_level); | ||
|
||
private: | ||
static std::vector<int> get_rs_block_table(int type_number, int error_correct_level); | ||
|
||
int data_count_; | ||
int total_count_; | ||
}; | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
include/picotorrent/client/ui/dialogs/remote_qr_dialog.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include <picotorrent/client/ui/dialogs/dialog_base.hpp> | ||
|
||
namespace picotorrent | ||
{ | ||
namespace client | ||
{ | ||
namespace qr | ||
{ | ||
class qr_code; | ||
} | ||
namespace ui | ||
{ | ||
namespace dialogs | ||
{ | ||
class remote_qr_dialog : public dialog_base | ||
{ | ||
public: | ||
remote_qr_dialog(); | ||
~remote_qr_dialog(); | ||
|
||
void set_data(const std::string &data); | ||
|
||
protected: | ||
BOOL on_command(int, WPARAM, LPARAM); | ||
BOOL on_init_dialog(); | ||
BOOL on_notify(LPARAM); | ||
|
||
private: | ||
std::shared_ptr<qr::qr_code> qr_; | ||
}; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.