33 lines
717 B
C++
33 lines
717 B
C++
|
|
#include "qr_encoder.hpp"
|
|
#include <qrencode.h>
|
|
#include <cstring>
|
|
namespace acs
|
|
{
|
|
|
|
bool qr_encoder::encode_url(const std::string& suffix)
|
|
{
|
|
memset(map_, 0, 64 * 64);
|
|
auto url = std::string(base_url) + suffix;
|
|
auto qr_code = QRcode_encodeString(url.c_str(), 8, QR_ECLEVEL_M, QR_MODE_8, true);
|
|
width_ = qr_code->width;
|
|
if (width_ > 64)
|
|
return false;
|
|
for (auto i = 0U; i < width_ * width_; ++i)
|
|
{
|
|
map_[i] = qr_code->data[i] % 2 ? 0 : 1;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
unsigned char* qr_encoder::get_map()
|
|
{
|
|
return map_;
|
|
}
|
|
|
|
unsigned qr_encoder::get_width() const
|
|
{
|
|
return width_;
|
|
}
|
|
}
|