Skip to content

Commit 9919621

Browse files
committed
Fixed ECC in analyzer
1 parent 289a0f6 commit 9919621

4 files changed

Lines changed: 31 additions & 1 deletion

File tree

Demo-QRCode-Variety/Program.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ internal static void Main()
4141
DoBasicDemo();
4242
DoVarietyDemo();
4343
DoEncodingDemo();
44+
DoEmojiDemo();
4445
DoBinaryDemo();
4546
}
4647

@@ -88,6 +89,13 @@ private static void DoEncodingDemo()
8889
}
8990

9091

92+
private static void DoEmojiDemo()
93+
{
94+
var qr = QrCode.EncodeText("🎲 😇 🤒 🏌 ⏭ 🚍", QrCode.Ecc.Quartile);
95+
SaveAsSvg(qr, "emojis-QR.svg", 4);
96+
}
97+
98+
9199

92100
private static void DoBinaryDemo()
93101
{

QrCodeAnalyzer/MainWindow.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
<Label Content="Error Correction:" HorizontalAlignment="Left" VerticalAlignment="Center" Padding="0,5,12,5"/>
6161
<ComboBox x:Name="ErrorCorrectionCombo" HorizontalAlignment="Left" VerticalAlignment="Center" Width="100" Margin="0,6,24,6"
6262
ItemsSource="{Binding Path=ErrorCorrectionLevels, Mode=OneTime}" DisplayMemberPath="Item1" SelectedValuePath="Item2" SelectedValue="{Binding Path=ErrorCorrection}"/>
63+
<CheckBox x:Name="BoostEccCheckBox" Content="Fixed ECC" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,6,24,6"
64+
IsChecked="{Binding Path=FixedEcc, UpdateSourceTrigger=PropertyChanged}"/>
6365
<Label Content="Border Width:" HorizontalAlignment="Left" VerticalAlignment="Center" Padding="0,5,12,5"/>
6466
<TextBox x:Name="BorderWidthTextBox" Text="{Binding Path=BorderWidth, UpdateSourceTrigger=PropertyChanged}"
6567
HorizontalAlignment="Left" VerticalAlignment="Center" Width="60" Margin="0,6" Padding="5,3"/>

QrCodeAnalyzer/MainWindowViewModel.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public sealed class MainWindowViewModel : INotifyPropertyChanged
2424
private string _text = "QR code text";
2525
private int _borderWidth = 4;
2626
private QrCode.Ecc _errorCorrection = QrCode.Ecc.Medium;
27+
private bool fixedEcc = false;
2728
private int _dataMaskPattern = -1;
2829
private QrCodeBuilder.PenaltyInfo _penaltyDetails;
2930
private ImageSource? _qrCodeImage;
@@ -98,6 +99,18 @@ public QrCode.Ecc ErrorCorrection
9899
}
99100
}
100101

102+
public bool FixedEcc
103+
{
104+
get => fixedEcc;
105+
set
106+
{
107+
if (fixedEcc == value) return;
108+
fixedEcc = value;
109+
UpdateQrCode();
110+
OnPropertyChanged();
111+
}
112+
}
113+
101114
public int DataMaskPattern
102115
{
103116
get => _dataMaskPattern;
@@ -162,7 +175,7 @@ public BitmapSource CreateClipboardBitmap()
162175
private void UpdateQrCode()
163176
{
164177
_debugInfo.ForcedDataMask = _dataMaskPattern;
165-
var qrCode = QrCode.EncodeText(_text, _errorCorrection);
178+
var qrCode = QrCode.EncodeTextAdvanced(_text, _errorCorrection, boostEcl: !fixedEcc);
166179
_currentQrCode = qrCode;
167180
SelectedDataMaskPattern = qrCode.Mask;
168181
PenaltyDetails = _debugInfo.Penalties[qrCode.Mask];

QrCodeGenerator/QrCodeBuilder.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ static class QrCodeBuilder
3333

3434
internal static QrCode Build(List<DataSegment> dataSegments, int ecc, int minVersion = 1, int maxVersion = 40, bool boostEcc = true)
3535
{
36+
#if DEBUG
37+
if (DebugAccess != null)
38+
{
39+
DebugAccess.DataSegments = dataSegments;
40+
}
41+
#endif
3642
var result = FindVersionAndEcc(dataSegments, ecc, minVersion, maxVersion, boostEcc);
3743
var version = result.Item1;
3844
ecc = result.Item2;
@@ -1006,6 +1012,7 @@ public class DebugInfo
10061012
{
10071013
public PenaltyInfo[] Penalties { get; } = new PenaltyInfo[8];
10081014
public int ForcedDataMask { get; set; } = -1;
1015+
public List<DataSegment> DataSegments { get; set; }
10091016
}
10101017

10111018
public static DebugInfo DebugAccess { get; set; }

0 commit comments

Comments
 (0)