Ejemplo 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);
        }
Ejemplo n.º 2
0
        byte[] _output;     /* internal storage of decoded output */
        #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);

            _array = new byte[mappingCols * mappingRows];

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

            _code = new byte[codeSize];

            _output = new byte[10 * codeSize];
        }
Ejemplo n.º 3
0
        internal DmtxImage(byte[] pxl, int width, int height, DmtxPackOrder pack)
        {
            _bitsPerChannel = new int[4];
            _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");
            }
        }
Ejemplo n.º 4
0
        internal void DecodeDataStream(DmtxSymbolSize sizeIdx, byte[] outputStart)
        {
            bool       macro = false;
            DmtxScheme encScheme;
            int        dataEndIndex;

            byte[] ptr;

            this._output    = (outputStart == null) ? this._output : outputStart;
            this._outputIdx = 0;

            ptr          = this._code;
            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;)
            {
                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;

                default:
                    /* error */
                    break;
                }
            }

            /* Print macro trailer if required */
            if (macro)
            {
                PushOutputMacroTrailer();
            }
        }
        internal string EncodeSvgFile(DmtxEncode enc, string format, int moduleSize, int margin, Color foreColor, Color backColor)
        {
            int  col, row, rowInv;
            int  symbolCols, symbolRows;
            int  width, height, module;
            bool defineOnly = false;
            //byte mosaicRed, mosaicGrn, mosaicBlu;
            string idString     = null;
            string style        = "";
            string outputString = "";

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

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

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

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

            symbolCols = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribSymbolCols, enc.Region.SizeIdx);
            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);
                style = "";
            }

            /* Write Data Matrix ON modules */
            for (row = 0; row < enc.Region.SymbolRows; row++)
            {
                rowInv = enc.Region.SymbolRows - row - 1;
                for (col = 0; col < enc.Region.SymbolCols; col++)
                {
                    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);
        }