Exemplo n.º 1
0
        internal int SymbolModuleStatus(DmtxSymbolSize sizeIdx, int symbolRow, int symbolCol)
        {
            int dataRegionRows = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribDataRegionRows, sizeIdx);
            int dataRegionCols = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribDataRegionCols, sizeIdx);
            int symbolRows     = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribSymbolRows, sizeIdx);
            int mappingCols    = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribMappingMatrixCols, sizeIdx);

            int symbolRowReverse = symbolRows - symbolRow - 1;
            int mappingRow       = symbolRowReverse - 1 - 2 * (symbolRowReverse / (dataRegionRows + 2));
            int mappingCol       = symbolCol - 1 - 2 * (symbolCol / (dataRegionCols + 2));

            /* Solid portion of alignment patterns */
            if (symbolRow % (dataRegionRows + 2) == 0 || symbolCol % (dataRegionCols + 2) == 0)
            {
                return(DmtxConstants.DmtxModuleOnRGB | (DmtxConstants.DmtxModuleData == 0 ? 1 : 0));  // check if unary not is correct
            }

            /* Horinzontal calibration bars */
            if ((symbolRow + 1) % (dataRegionRows + 2) == 0)
            {
                return((((symbolCol & 0x01) != 0) ? 0 : DmtxConstants.DmtxModuleOnRGB) | (DmtxConstants.DmtxModuleData == 0 ? 1 : 0));
            }

            /* Vertical calibration bars */
            if ((symbolCol + 1) % (dataRegionCols + 2) == 0)
            {
                return((((symbolRow & 0x01) != 0) ? 0 : DmtxConstants.DmtxModuleOnRGB) | (DmtxConstants.DmtxModuleData == 0 ? 1 : 0));
            }

            /* Data modules */
            return(this.Array[mappingRow * mappingCols + mappingCol] | DmtxConstants.DmtxModuleData);
        }
Exemplo n.º 2
0
        internal void DecodeDataStream(DmtxSymbolSize sizeIdx, byte[] outputStart)
        {
            bool macro = false;

            this.Output     = outputStart ?? this.Output;
            this._outputIdx = 0;

            byte[] ptr          = this.Code;
            int    dataEndIndex = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribSymbolDataWords, sizeIdx);

            /* Print macro header if first codeword triggers it */
            if (ptr[0] == DmtxConstants.DmtxChar05Macro || ptr[0] == DmtxConstants.DmtxChar06Macro)
            {
                PushOutputMacroHeader(ptr[0]);
                macro = true;
            }

            for (int codeIter = 0; codeIter < dataEndIndex;)
            {
                DmtxScheme encScheme = GetEncodationScheme(this.Code[codeIter]);
                if (encScheme != DmtxScheme.DmtxSchemeAscii)
                {
                    codeIter++;
                }

                switch (encScheme)
                {
                case DmtxScheme.DmtxSchemeAscii:
                    codeIter = DecodeSchemeAscii(codeIter, dataEndIndex);
                    break;

                case DmtxScheme.DmtxSchemeC40:
                case DmtxScheme.DmtxSchemeText:
                    codeIter = DecodeSchemeC40Text(codeIter, dataEndIndex, encScheme);
                    break;

                case DmtxScheme.DmtxSchemeX12:
                    codeIter = DecodeSchemeX12(codeIter, dataEndIndex);
                    break;

                case DmtxScheme.DmtxSchemeEdifact:
                    codeIter = DecodeSchemeEdifact(codeIter, dataEndIndex);
                    break;

                case DmtxScheme.DmtxSchemeBase256:
                    codeIter = DecodeSchemeBase256(codeIter, dataEndIndex);
                    break;
                }
            }

            /* Print macro trailer if required */
            if (macro)
            {
                PushOutputMacroTrailer();
            }
        }
Exemplo n.º 3
0
        int _outputIdx;     /* Internal index used to store output progress */

        #endregion

        #region Constructors
        internal DmtxMessage(DmtxSymbolSize sizeIdx, DmtxFormat symbolFormat)
        {
            if (symbolFormat != DmtxFormat.Matrix && symbolFormat != DmtxFormat.Mosaic)
            {
                throw new ArgumentException("Only DmtxFormats Matrix and Mosaic are currently supported");
            }
            int mappingRows = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribMappingMatrixRows, sizeIdx);
            int mappingCols = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribMappingMatrixCols, sizeIdx);

            this.Array = new byte[mappingCols * mappingRows];

            int codeSize = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribSymbolDataWords, sizeIdx) + DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribSymbolErrorWords, sizeIdx);

            this.Code = new byte[codeSize];

            this.Output = new byte[10 * codeSize];
        }
Exemplo n.º 4
0
        internal DmtxImage(byte[] pxl, int width, int height, DmtxPackOrder pack)
        {
            this.BitsPerChannel = new int[4];
            this.ChannelStart = new int[4];
            if (pxl == null || width < 1 || height < 1)
            {
                throw new ArgumentException("Cannot create image of size null");
            }

            this.Pxl = pxl;
            this.Width = width;
            this.Height = height;
            this.PixelPacking = pack;
            this.BitsPerPixel = DmtxCommon.GetBitsPerPixel(pack);
            this.BytesPerPixel = this.BitsPerPixel / 8;
            this._rowPadBytes = 0;
            this.RowSizeBytes = this.Width * this.BytesPerPixel + this._rowPadBytes;
            this.ImageFlip = DmtxFlip.DmtxFlipNone;

            /* Leave channelStart[] and bitsPerChannel[] with zeros from calloc */
            this.ChannelCount = 0;

            switch (pack)
            {
                case DmtxPackOrder.DmtxPackCustom:
                    break;
                case DmtxPackOrder.DmtxPack1bppK:
                    throw new ArgumentException("Cannot create image: not supported pack order!");
                case DmtxPackOrder.DmtxPack8bppK:
                    SetChannel(0, 8);
                    break;
                case DmtxPackOrder.DmtxPack16bppRGB:
                case DmtxPackOrder.DmtxPack16bppBGR:
                case DmtxPackOrder.DmtxPack16bppYCbCr:
                    SetChannel(0, 5);
                    SetChannel(5, 5);
                    SetChannel(10, 5);
                    break;
                case DmtxPackOrder.DmtxPack24bppRGB:
                case DmtxPackOrder.DmtxPack24bppBGR:
                case DmtxPackOrder.DmtxPack24bppYCbCr:
                case DmtxPackOrder.DmtxPack32bppRGBX:
                case DmtxPackOrder.DmtxPack32bppBGRX:
                    SetChannel(0, 8);
                    SetChannel(8, 8);
                    SetChannel(16, 8);
                    break;
                case DmtxPackOrder.DmtxPack16bppRGBX:
                case DmtxPackOrder.DmtxPack16bppBGRX:
                    SetChannel(0, 5);
                    SetChannel(5, 5);
                    SetChannel(10, 5);
                    break;
                case DmtxPackOrder.DmtxPack16bppXRGB:
                case DmtxPackOrder.DmtxPack16bppXBGR:
                    SetChannel(1, 5);
                    SetChannel(6, 5);
                    SetChannel(11, 5);
                    break;
                case DmtxPackOrder.DmtxPack32bppXRGB:
                case DmtxPackOrder.DmtxPack32bppXBGR:
                    SetChannel(8, 8);
                    SetChannel(16, 8);
                    SetChannel(24, 8);
                    break;
                case DmtxPackOrder.DmtxPack32bppCMYK:
                    SetChannel(0, 8);
                    SetChannel(8, 8);
                    SetChannel(16, 8);
                    SetChannel(24, 8);
                    break;
                default:
                    throw new ArgumentException("Cannot create image: Invalid Pack Order");
            }
        }
Exemplo n.º 5
0
        internal string EncodeSvgFile(DmtxEncode enc, string format, int moduleSize, int margin, Color foreColor, Color backColor)
        {
            bool   defineOnly = false;
            string idString   = null;
            string style;
            string outputString = "";

            if (_dotFormatProvider == null)
            {
                _dotFormatProvider = new NumberFormatInfo {
                    NumberDecimalSeparator = "."
                };
            }

            if (format == "svg:")
            {
                defineOnly = true;
                idString   = format.Substring(4);
            }

            if (string.IsNullOrEmpty(idString))
            {
                idString = "dmtx_0001";
            }

            int width  = 2 * enc.MarginSize + (enc.Region.SymbolCols * enc.ModuleSize);
            int height = 2 * enc.MarginSize + (enc.Region.SymbolRows * enc.ModuleSize);

            int symbolCols = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribSymbolCols, enc.Region.SizeIdx);
            int symbolRows = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribSymbolRows, enc.Region.SizeIdx);

            /* Print SVG Header */
            if (!defineOnly)
            {
                outputString += string.Format(
                    "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
                    "<!-- Created with DataMatrix.net (http://datamatrixnet.sourceforge.net/) -->\n" +
                    "<svg\n" +
                    "xmlns:svg=\"http://www.w3.org/2000/svg\"\n" +
                    "xmlns=\"http://www.w3.org/2000/svg\"\n" +
                    "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n" +
                    "version=\"1.0\"\n" +
                    "width=\"{0}\"\n" +
                    "height=\"{1}\"\n" +
                    "id=\"svg2\">\n" +
                    "<defs>\n" +
                    "<symbol id=\"{2}\">\n" +
                    "    <desc>Layout:{0}x%{1} Symbol:{3}x{4} Data Matrix</desc>\n", width, height, idString, symbolCols, symbolRows);
            }

            if (backColor != Color.White)
            {
                style = string.Format("style=\"fill:#{0}{1}{2};fill-opacity:{3};stroke:none\" ",
                                      backColor.R.ToString("X2"), backColor.G.ToString("X2"), backColor.B.ToString("X2"), ((double)backColor.A / (double)byte.MaxValue).ToString("0.##", _dotFormatProvider));
                outputString += string.Format("    <rect width=\"{0}\" height=\"{1}\" x=\"0\" y=\"0\" {2}/>\n",
                                              width, height, style);
            }

            /* Write Data Matrix ON modules */
            for (int row = 0; row < enc.Region.SymbolRows; row++)
            {
                int rowInv = enc.Region.SymbolRows - row - 1;
                for (int col = 0; col < enc.Region.SymbolCols; col++)
                {
                    int module = enc.Message.SymbolModuleStatus(enc.Region.SizeIdx, row, col);
                    style = string.Format("style=\"fill:#{0}{1}{2};fill-opacity:{3};stroke:none\" ",
                                          foreColor.R.ToString("X2"), foreColor.G.ToString("X2"), foreColor.B.ToString("X2"), ((double)foreColor.A / (double)byte.MaxValue).ToString("0.##", _dotFormatProvider));

                    if ((module & DmtxConstants.DmtxModuleOn) != 0)
                    {
                        outputString += string.Format("    <rect width=\"{0}\" height=\"{1}\" x=\"{2}\" y=\"{3}\" {4}/>\n",
                                                      moduleSize, moduleSize,
                                                      col * moduleSize + margin,
                                                      rowInv * moduleSize + margin, style);
                    }
                }
            }

            outputString += "  </symbol>\n";

            /* Close SVG document */
            if (!defineOnly)
            {
                outputString += string.Format("</defs>\n" +
                                              "<use xlink:href=\"#{0}\" x='0' y='0' style=\"fill:#000000;fill-opacity:1;stroke:none\" />\n" +
                                              "\n</svg>\n", idString);
            }

            return(outputString);
        }