Skip to content
Snippets Groups Projects
Commit 95c526b2 authored by Nicolas Jager's avatar Nicolas Jager
Browse files

qrcode : add quick response code

source : https://github.com/BlueDragon747/qrencode-win32

Change-Id: I0fbe4f37100afcfa761b0cef90e34b4198fccf0e
Tuleap: #1233
parent 7cb18bce
No related branches found
No related tags found
No related merge requests found
Showing
with 33430 additions and 12 deletions
Assets/qrCodeIcon.png

291 B

......@@ -199,7 +199,6 @@
Foreground="Crimson"
Margin="10,5,10,0"
FontSize="14"
IsTextSelectionEnabled="True"
TextTrimming="CharacterEllipsis"
Text="{x:Bind ringID_}"/>
</Grid>
......@@ -384,14 +383,16 @@
Checked="_accountsMenuButton__Checked"
Unchecked="_accountsMenuButton__Unchecked"
Style="{StaticResource ToggleButtonStyle1}"/>
<!-- _shareMenuButton_ collapsed on purpose -->
<!-- _shareMenuButton_ -->
<ToggleButton x:Name="_shareMenuButton_"
VerticalAlignment="Bottom"
Visibility="Collapsed"
Content="&#xE72D;"
Checked="_shareMenuButton__Checked"
Unchecked="_shareMenuButton__Unchecked"
Style="{StaticResource ToggleButtonStyle1}"/>
Style="{StaticResource ToggleButtonStyle1}">
<Image Source="Assets/qrCodeIcon.png"
Stretch="Uniform"/>
</ToggleButton>
<!-- _devicesMenuButton_ -->
<ToggleButton x:Name="_devicesMenuButton_"
VerticalAlignment="Bottom"
Content="&#xE836;"
......@@ -514,20 +515,33 @@
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid Background="white"
Margin="10"
MaxHeight="150"
MaxWidth="140"
Padding="5">
<Image x:Name="_selectedAccountQrCode_"
Source="Assets\TESTS\qrcode.png"
Width="200"
Margin="5"
Grid.Row="0"
Stretch="None"
Height="200"/>
<TextBlock Text="RingId:"
</Grid>
<TextBlock x:Name="_ringId_"
Padding="5"
Style="{StaticResource TextStyle4}"
Text=""
Grid.Row="1"
IsTextSelectionEnabled="True"
HorizontalAlignment="Center"/>
<TextBox Style="{StaticResource TextBoxStyle2}"
HorizontalAlignment="Center"
Text="c4fc649aed8b2497a5e98fd2d856222f07020044"
Grid.Row="2"/>
</Grid>
<Button x:Name="_shareMenuDone_"
Grid.Row="1"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Content="&#xE081;"
Click="_shareMenuDone__Click"
Style="{StaticResource ButtonStyle6}"/>
</Grid>
<!-- devices menu. -->
<Grid x:Name="_devicesMenuGrid_"
......
......@@ -19,6 +19,8 @@
#include "pch.h"
#include <string> // move it
#include "SmartPanel.xaml.h"
#include "qrencode.h"
#include <MemoryBuffer.h> // IMemoryBufferByteAccess
using namespace Platform;
......@@ -34,6 +36,10 @@ using namespace Windows::UI::Xaml::Shapes;
using namespace Windows::UI::Xaml::Media;
using namespace Concurrency;
using namespace Windows::Foundation;
using namespace Windows::Graphics::Imaging;
using namespace Windows::Foundation;
using namespace Concurrency;
using namespace Windows::ApplicationModel::Core;
using namespace Windows::Storage;
......@@ -147,6 +153,10 @@ RingClientUWP::Views::SmartPanel::updatePageContent()
_devicesMenuButton_->Visibility = (account->accountType_ == "RING")
? Windows::UI::Xaml::Visibility::Visible
: Windows::UI::Xaml::Visibility::Collapsed;
_shareMenuButton_->Visibility = (account->accountType_ == "RING")
? Windows::UI::Xaml::Visibility::Visible
: Windows::UI::Xaml::Visibility::Collapsed;
}
void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e)
......@@ -207,6 +217,8 @@ void RingClientUWP::Views::SmartPanel::_shareMenuButton__Checked(Platform::Objec
_addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountsMenuButton_->IsChecked = false;
_devicesMenuButton_->IsChecked = false;
generateQRcode();
}
void RingClientUWP::Views::SmartPanel::_shareMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
......@@ -418,6 +430,75 @@ void RingClientUWP::Views::SmartPanel::_contactItem__PointerReleased(Platform::O
}
void RingClientUWP::Views::SmartPanel::generateQRcode()
{
auto ringId = AccountsViewModel::instance->selectedAccount->ringID_;
auto ringId2 = Utils::toString(ringId);
_ringId_->Text = ringId;
auto qrcode = QRcode_encodeString(ringId2.c_str(),
0, //Let the version be decided by libqrencode
QR_ECLEVEL_L, // Lowest level of error correction
QR_MODE_8, // 8-bit data mode
1);
if (!qrcode) {
WNG_("Failed to generate QR code: ");
return;
}
const int STRETCH_FACTOR = 4;
const int widthQrCode = qrcode->width;
const int widthBitmap = STRETCH_FACTOR * widthQrCode;
unsigned char* qrdata = qrcode->data;
auto frame = ref new SoftwareBitmap(BitmapPixelFormat::Bgra8, widthBitmap, widthBitmap, BitmapAlphaMode::Premultiplied);
const int BYTES_PER_PIXEL = 4;
BitmapBuffer^ buffer = frame->LockBuffer(BitmapBufferAccessMode::ReadWrite);
IMemoryBufferReference^ reference = buffer->CreateReference();
Microsoft::WRL::ComPtr<IMemoryBufferByteAccess> byteAccess;
if (SUCCEEDED(reinterpret_cast<IUnknown*>(reference)->QueryInterface(IID_PPV_ARGS(&byteAccess))))
{
byte* data;
unsigned capacity;
byteAccess->GetBuffer(&data, &capacity);
auto desc = buffer->GetPlaneDescription(0);
unsigned char* row, * p;
p = qrcode->data;
for (int u = 0 ; u < widthBitmap ; u++) {
for (int v = 0; v < widthBitmap; v++) {
int x = (float)u / (float)widthBitmap * (float)widthQrCode;
int y = (float)v / (float)widthBitmap * (float)widthQrCode;
auto currPixelRow = desc.StartIndex + desc.Stride * u + BYTES_PER_PIXEL * v;
row = (p + (y * widthQrCode));
if (*(row + x) & 0x1) {
data[currPixelRow + 3] = 255;
}
}
}
}
delete reference;
delete buffer;
auto sbSource = ref new Media::Imaging::SoftwareBitmapSource();
sbSource->SetBitmapAsync(frame);
_selectedAccountQrCode_->Source = sbSource;
}
Object ^ RingClientUWP::Views::IncomingVisibility::Convert(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
auto state = static_cast<CallStatus>(value);
......@@ -578,3 +659,11 @@ void RingClientUWP::Views::SmartPanel::_closePin__Click(Platform::Object^ sender
// refacto : do something better...
_waitingAndResult_->Text = "Exporting account on the Ring...";
}
void RingClientUWP::Views::SmartPanel::_shareMenuDone__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
_shareMenuButton_->IsChecked = false;
_shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
}
......@@ -93,6 +93,7 @@ private:
void Grid_PointerEntered(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e);
void Grid_PointerExited(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e);
void _contactItem__PointerReleased(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e);
void generateQRcode();
/* members */
void _devicesMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
......@@ -103,6 +104,7 @@ private:
void _pinGeneratorNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OnexportOnRingEnded(Platform::String ^accountId, Platform::String ^pin);
void _closePin__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _shareMenuDone__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
}
}
\ No newline at end of file
......@@ -56,6 +56,17 @@
<Setter Property="Foreground"
Value="White"/>
</Style>
<Style x:Key="TextStyle4"
TargetType="TextBlock">
<Setter Property="FontSize"
Value="12"/>
<Setter Property="HorizontalAlignment"
Value="Center"/>
<Setter Property="VerticalAlignment"
Value="Center"/>
<Setter Property="Foreground"
Value="Black"/>
</Style>
<Style x:Key="TextSegoeStyle1"
TargetType="TextBlock">
<Setter Property="FontFamily"
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
AUTOMAKE_OPTIONS = foreign
ACLOCAL_AMFLAGS=-I m4
SUBDIRS = .
if BUILD_TESTS
SUBDIRS += tests
endif
lib_LTLIBRARIES = libqrencode.la
libqrencode_la_SOURCES = qrencode.c qrencode_inner.h \
qrinput.c qrinput.h \
bitstream.c bitstream.h \
qrspec.c qrspec.h \
rscode.c rscode.h \
split.c split.h \
mask.c mask.h \
mqrspec.c mqrspec.h \
mmask.c mmask.h
libqrencode_la_LDFLAGS = -version-number $(MAJOR_VERSION):$(MINOR_VERSION):$(MICRO_VERSION)
include_HEADERS = qrencode.h
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libqrencode.pc
EXTRA_DIST = libqrencode.pc.in autogen.sh configure.ac acinclude.m4 \
Makefile.am tests/Makefile.am qrencode.spec.in qrencode.spec \
qrencode.1.in Doxyfile tests/test_all.sh
if BUILD_TOOLS
bin_PROGRAMS = qrencode
qrencode_SOURCES = qrenc.c
qrencode_CFLAGS = $(png_CFLAGS)
qrencode_LDADD = libqrencode.la $(png_LIBS)
man1_MANS = qrencode.1
endif
This diff is collapsed.
This diff is collapsed.
libqrencode 3.4.4 - QR Code encoding library
GENERAL INFORMATION
===================
Libqrencode is a library for encoding data in a QR Code symbol, a 2D symbology
that can be scanned by handy terminals such as a mobile phone with CCD. The
capacity of QR Code is up to 7000 digits or 4000 characters and has high
robustness.
Libqrencode accepts a string or a list of data chunks then encodes in a QR Code
symbol as a bitmap array. While other QR Code applications generate an image
file, using libqrencode allows applications to render QR Code symbols from raw
bitmap data directly. This library also contains a command-line utility outputs
a QR Code symbol as a PNG image.
SPECIFICATION
=============
Libqrencode supports QR Code model 2, described in JIS (Japanese Industrial
Standards) X0510:2004 or ISO/IEC 18004. Most of features in the specification
are implemented such as:
- Numeric, alphabet, Japanese kanji (Shift-JIS) or any 8 bit code can be
embedded
- Optimized encoding of a string
- Structured-append of symbols
- Micro QR Code (experimental)
Currently the following features are not supported:
- ECI and FNC1 mode
- QR Code model 1 (deprecated)
INSTALL
=======
Requirements
------------
Some test programs or utility tools uses SDL or PNG, but the library itself
has no dependencies. You can skip compiling those tools if you want not to
install programs using SDL or PNG.
Compile & install
-----------------
Just try
./configure
make
make install
This compiles and installs the library and header file to the appropriate
directories. By default, /usr/local/lib and /usr/local/include. You can change
the destination directory by passing some options to the configure script.
Run "./configure --help" to see the list of options.
It also installs a binary "qrencode" to /usr/local/bin. If you want not to
install it, give "--without-tools" option to the configure script.
When you downloaded a development tree from github, it is required to run
"autogen.sh" at first to generate configure script.
USAGE
=====
Basic usages of this library are written in the header file (qrencode.h).
You can generate a manual of the library by using Doxygen.
WARNINGS
========
The library is distributed WITHOUT ANY WRRANTY.
Micro QR Code support is EXPERIMENTAL.
Be careful to use the command line tool (qrencode) if it is used by a web
application (e.g. CGI script). For example, giving "-s" option with a large
number to qrencode may cause DoS. The parameters should be checked by the
application.
LICENSING INFORMATION
=====================
Copyright (C) 2006-2012 Kentaro Fukuchi
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this library; if not, write to the Free Software Foundation, Inc., 51
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
CONTACT
=======
Visit the homepage at:
http://fukuchi.org/works/qrencode/
for new releases. The git repository is available at:
https://github.com/fukuchi/libqrencode
Please mail any bug reports, suggestions, comments, and questions to:
Kentaro Fukuchi <kentaro@fukuchi.org>
or submit issues to:
https://github.com/fukuchi/libqrencode/issues
Questions of license compliance are also welcome.
ACKNOWLEDGMENTS
===============
QR Code is registered trademarks of DENSO WAVE INCORPORATED in JAPAN and other
countries.
Reed-Solomon encoder is written by Phil Karn, KA9Q.
Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q
BlueDragon747 - made changes for VS 2015 compatability
NANKI Haruo - improved lower-case characteres encoding
Philippe Delcroix - improved mask evaluation
Yusuke Mihara - structured-append support
David Dahl - DPI and SVG support patch
Adam Shepherd - bug fix patch of the mask evaluation
Josef Eisl (zapster) - EPS support patch
Colin (moshen) - ANSI support patch
Ralf Ertzinger - ASCII support patch
Yutaka Niibe (gniibe) - various bug fix patches
Dan Storm (Repox) - SVG support patch
Lennart Poettering (mezcalero)
- improved text art patch
Yann Droneaud - improved input validation patch
Viona - bug fix patch for string splitting
Daniel Dörrhöfer - RLE option
Shigeyuki Hirai, Paul Janssens, wangsai, Gavan Fantom, Matthew Baker, Rob Ryan,
Fred Steinhaeuser, Terry Burton, chisj, vlad417, Petr, Hassan Hajji,
Emmanuel Blot, ßlúèÇhîp, win32asm, Antenore, Yoshimichi Inoue
- bug report / suggestion
Micro QR code encoding is not tested well.
Documents (not only the README, but also the manual of the library) needs
revision of grammer, spell or to resolve ambiguity or incomplete descriptions.
Feel really free to send us your revision.
This diff is collapsed.
#!/bin/sh
set -e
if [ `uname -s` = Darwin ]; then
LIBTOOLIZE=glibtoolize
else
LIBTOOLIZE=libtoolize
fi
ACLOCAL_OPT=""
if [ -d /usr/local/share/aclocal ]; then
ACLOCAL_OPT="-I /usr/local/share/aclocal"
elif [ -d /opt/local/share/aclocal ]; then
ACLOCAL_OPT="-I /opt/local/share/aclocal"
elif [ -d /usr/share/aclocal ]; then
ACLOCAL_OPT="-I /usr/share/aclocal"
fi
if [ ! -d use ]; then
mkdir use
fi
autoheader
aclocal $ACLOCAL_OPT
$LIBTOOLIZE --automake --copy
automake --add-missing --copy
autoconf
This diff is collapsed.
/*
* qrencode - QR Code encoder
*
* Binary sequence class.
* Copyright (C) 2006-2011 Kentaro Fukuchi <kentaro@fukuchi.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __BITSTREAM_H__
#define __BITSTREAM_H__
typedef struct {
int length;
unsigned char *data;
} BitStream;
extern BitStream *BitStream_new(void);
extern int BitStream_append(BitStream *bstream, BitStream *arg);
extern int BitStream_appendNum(BitStream *bstream, int bits, unsigned int num);
extern int BitStream_appendBytes(BitStream *bstream, int size, unsigned char *data);
#define BitStream_size(__bstream__) (__bstream__->length)
extern unsigned char *BitStream_toByte(BitStream *bstream);
extern void BitStream_free(BitStream *bstream);
#endif /* __BITSTREAM_H__ */
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment