コード例 #1
0
ファイル: QRImage.cs プロジェクト: Legoless/QRCode
        /// <summary>
        /// Initializes a new instance of the <see cref="QrImage"/> class.
        /// </summary>
        /// <param name="version">
        /// The version.
        /// </param>
        /// <param name="mask">
        /// The mask.
        /// </param>
        public QrImage(QrVersion version, QrMask mask)
        {
            this.version = version;
            this.mask = mask;

            this.Initialize();
        }
コード例 #2
0
ファイル: QRFormat.cs プロジェクト: Legoless/QRCode
        /// <summary>
        /// Initializes a new instance of the <see cref="QrFormat"/> class.
        /// </summary>
        /// <param name="error">
        /// The error.
        /// </param>
        /// <param name="mask">
        /// The mask.
        /// </param>
        /// <param name="debug">
        /// The debug.
        /// </param>
        public QrFormat(QrError error, QrMask mask, bool debug)
        {
            if (debug)
            {
                this.debugData = new StringBuilder();
            }

            this.CalculateFormat(error, mask);
        }
コード例 #3
0
ファイル: QRCodeCreator.cs プロジェクト: Legoless/QRCode
 /// <summary>
 /// The choose versions.
 /// </summary>
 private void ChooseVersions()
 {
     // Automatic setting
     if ((this.version == null) || (this.mask == null))
     {
         this.type = QrType.AlphaNumeric;
         this.version = new QrVersion(1, QrError.Q);
         this.mask = new QrMask(2);
     }
 }
コード例 #4
0
ファイル: QRCodeCreator.cs プロジェクト: Legoless/QRCode
 /// <summary>
 /// Advanced mode wrapper
 /// </summary>
 /// <param name="t">
 /// <c>QR</c> code type
 /// </param>
 /// <param name="v">
 /// <c>QR</c> code version
 /// </param>
 /// <param name="m">
 /// <c>QR</c> code mask
 /// </param>
 public void SetAdvancedMode(QrType t, QrVersion v, QrMask m)
 {
     this.type = t;
     this.version = v;
     this.mask = m;
 }
コード例 #5
0
ファイル: QRFormat.cs プロジェクト: Legoless/QRCode
 /// <summary>
 /// Initializes a new instance of the <see cref="QrFormat"/> class.
 /// </summary>
 /// <param name="error">
 /// The error.
 /// </param>
 /// <param name="mask">
 /// The mask.
 /// </param>
 public QrFormat(QrError error, QrMask mask)
 {
     this.CalculateFormat(error, mask);
 }
コード例 #6
0
ファイル: QRFormat.cs プロジェクト: Legoless/QRCode
        /// <summary>
        /// Calculate <c>QR</c> code format
        /// </summary>
        /// <param name="error">
        /// The error code information.
        /// </param>
        /// <param name="mask">
        /// The mask.
        /// </param>
        private void CalculateFormat(QrError error, QrMask mask)
        {
            // Get error bits
            if (this.debugData != null)
            {
                this.debugData.Append("- Calculating format bits...\n");
            }

            // Get 5 bits of format information
            int formatInfo = (QrErrorBits.GetBits(error) << 3) | BinaryExtensions.BinToDec(mask.GetBits());

            if (this.debugData != null)
            {
                this.debugData.Append(
                    "- Format information error and mask bits: "
                    + BinaryExtensions.BinaryToString(BinaryExtensions.DecToBin(formatInfo)) + "\n");
                this.debugData.Append("- Calculating BCH (15,5) code for information bits...\n");
            }

            int bchCode = QrBoseChaudhuriHocquenghem.CalculateBch(formatInfo, QrConst.GenPolyFormat);

            if (this.debugData != null)
            {
                this.debugData.Append(
                    "- BCH (15,5) error code: " + BinaryExtensions.BinaryToString(BinaryExtensions.DecToBin(bchCode))
                    + "\n");
            }

            // Append BCH code to format info
            formatInfo = (formatInfo << 10) | bchCode;

            if (this.debugData != null)
            {
                this.debugData.Append(
                    "- Format information with appended BCH: "
                    + BinaryExtensions.BinaryToString(BinaryExtensions.DecToBin(formatInfo)) + "\n");
                this.debugData.Append(
                    "- Calculating XOR with format constant: "
                    + BinaryExtensions.BinaryToString(BinaryExtensions.DecToBin(QrConst.ConstFormatXor)) + "\n");
            }

            formatInfo = formatInfo ^ QrConst.ConstFormatXor;

            if (this.debugData != null)
            {
                this.debugData.Append(
                    "- Final format: " + BinaryExtensions.BinaryToString(BinaryExtensions.DecToBin(formatInfo, 15))
                    + "\n");
            }

            List<bool> formatBits = BinaryExtensions.DecToBin(formatInfo, 15);

            // Reverse, because our QRCode is inserting backwards
            formatBits.Reverse();

            foreach (bool t in formatBits)
            {
                this.output.Enqueue(t);
            }
        }
コード例 #7
0
ファイル: QRImage.cs プロジェクト: Legoless/QRCode
        /// <summary>
        /// Initializes a new instance of the <see cref="QrImage"/> class.
        /// </summary>
        /// <param name="codeVersion">
        /// The version.
        /// </param>
        /// <param name="codeMask">
        /// The mask.
        /// </param>
        /// <param name="codeBreakPoint">
        /// The breakpoint to stop image generation.
        /// </param>
        public QrImage(QrVersion codeVersion, QrMask codeMask, QrBreakPoint codeBreakPoint)
        {
            this.debugData = new StringBuilder();

            this.breakPoint = codeBreakPoint;

            this.version = codeVersion;
            this.mask = codeMask;

            this.Initialize();
        }
コード例 #8
0
ファイル: QRImage.cs プロジェクト: Legoless/QRCode
        /// <summary>
        /// Method writes format to picture.
        /// </summary>
        /// <param name="error">
        /// The error code information.
        /// </param>
        /// <param name="codeMask">
        /// The mask mask information.
        /// </param>
        private void WriteFormat(QrError error, QrMask codeMask)
        {
            QrFormat format;

            if (this.debugData != null)
            {
                this.debugData.Append("------------------ Step 10 ------------------\n- Writing format ...\n");

                format = new QrFormat(error, codeMask, true);

                this.debugData.Append(format.GetDebugData());
            }
            else
            {
                format = new QrFormat(error, codeMask);
            }

            List<bool> bits = new List<bool>(format.GetFormatBits().ToArray());

            // Write format vertically
            int y = 0;

            for (int i = 0; i < bits.Count; i++)
            {
                if (this.picture[8, y] == QrPixel.Format)
                {
                    this.picture[8, y] = bits[i] ? QrPixel.Black : QrPixel.White;
                }
                else
                {
                    y++;
                    i--;
                }
            }

            // Write format horizontally
            int x = this.picture.GetLength(0) - 1;

            for (int i = 0; i < bits.Count; i++)
            {
                if (this.picture[x, 8] == QrPixel.Format)
                {
                    this.picture[x, 8] = bits[i] ? QrPixel.Black : QrPixel.White;
                }
                else
                {
                    x--;
                    i--;
                }
            }

            if (this.debugData != null)
            {
                this.debugData.Append("- Format successfully written.\n\n");
            }
        }
コード例 #9
0
ファイル: QRImage.cs プロジェクト: Legoless/QRCode
        /// <summary>
        /// The do mask.
        /// </summary>
        /// <param name="codeMask">
        /// The mask.
        /// </param>
        private void DoMask(QrMask codeMask)
        {
            if (this.debugData != null)
            {
                this.debugData.Append(
                    "------------------ Step 9 ------------------\n- Executing mask on data pixels: "
                    + BinaryExtensions.BinaryToString(codeMask.GetBits()) + "\n");
            }

            int counter = 0;

            for (int i = 0; i < this.picture.GetLength(0); i++)
            {
                for (int j = 0; j < this.picture.GetLength(1); j++)
                {
                    int x = this.picture.GetLength(0) - i - 1;
                    int y = this.picture.GetLength(1) - j - 1;

                    if (codeMask.Test(y, x) && (this.staticData[x, y] == false) && (this.picture[x, y] != QrPixel.Empty))
                    {
                        this.picture[x, y] = (this.picture[x, y] == QrPixel.White) ? QrPixel.Black : QrPixel.White;

                        counter++;

                        if ((this.breakPoint == QrBreakPoint.Mask) && (this.debugData != null))
                        {
                            this.picture[x, y] = QrPixel.Mask;
                        }
                    }
                }
            }

            if (this.debugData != null)
            {
                this.debugData.Append("- Mask (" + codeMask + ") written to: " + counter + " pixels.\n\n");
            }
        }