This repository has been archived on 2018-05-28. You can view files and clone it, but cannot push or open issues or pull requests.
BBB-Simple-ACS/client/qr_encoder.cpp

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_;
}
}