File tree Expand file tree Collapse file tree 1 file changed +14
-16
lines changed Expand file tree Collapse file tree 1 file changed +14
-16
lines changed Original file line number Diff line number Diff line change @@ -524,23 +524,21 @@ private static void ConvertToDecNotationInPlace(Polynom poly)
524
524
/// <returns>The minimum version of the QR code that can accommodate the given data and settings.</returns>
525
525
private static int GetVersion ( int length , EncodingMode encMode , ECCLevel eccLevel )
526
526
{
527
+ // capacity table is already sorted by version number ascending, so the smallest version that can hold the data is the first one found
528
+ foreach ( var x in capacityTable )
529
+ {
530
+ // find the requested ECC level and encoding mode in the capacity table
531
+ foreach ( var y in x . Details )
532
+ {
533
+ if ( y . ErrorCorrectionLevel == eccLevel && y . CapacityDict [ encMode ] >= length )
534
+ {
535
+ // if the capacity of the current version is enough, return the version number
536
+ return x . Version ;
537
+ }
538
+ }
539
+ }
527
540
528
- var fittingVersions = capacityTable . Where (
529
- x => x . Details . Any (
530
- y => ( y . ErrorCorrectionLevel == eccLevel
531
- && y . CapacityDict [ encMode ] >= Convert . ToInt32 ( length )
532
- )
533
- )
534
- ) . Select ( x => new
535
- {
536
- version = x . Version ,
537
- capacity = x . Details . Single ( y => y . ErrorCorrectionLevel == eccLevel )
538
- . CapacityDict [ encMode ]
539
- } ) ;
540
-
541
- if ( fittingVersions . Any ( ) )
542
- return fittingVersions . Min ( x => x . version ) ;
543
-
541
+ // if no version was found, throw an exception
544
542
var maxSizeByte = capacityTable . Where (
545
543
x => x . Details . Any (
546
544
y => ( y . ErrorCorrectionLevel == eccLevel ) )
You can’t perform that action at this time.
0 commit comments