Esempio n. 1
0
 private DmtxEncode(DmtxEncode src)
 {
     this._scheme = src._scheme;
     this._sizeIdxRequest = src._sizeIdxRequest;
     this._marginSize = src._marginSize;
     this._moduleSize = src._moduleSize;
     this._pixelPacking = src._pixelPacking;
     this._imageFlip = src._imageFlip;
     this._rowPadBytes = src._rowPadBytes;
     this._image = src._image;
     this._message = src._message;
     this._method = src._method;
     this._region = src._region;
 }
Esempio n. 2
0
        private List <string> DecodeImage(Bitmap image, int maxResultCount, TimeSpan timeOut, bool isMosaic)
        {
            List <string> result = new List <string>();
            int           stride;

            byte[]    rawImg  = ImageToByteArray(image, out stride);
            DmtxImage dmtxImg = new DmtxImage(rawImg, image.Width, image.Height, DmtxPackOrder.DmtxPack24bppRGB);

            dmtxImg.RowPadBytes = stride % 3;
            DmtxDecode decode    = new DmtxDecode(dmtxImg, 1);
            TimeSpan   timeLeft  = new TimeSpan(timeOut.Ticks);
            Stopwatch  stopWatch = new Stopwatch();

            stopWatch.Start();
            while (true)
            {
                if (stopWatch.Elapsed > timeOut)
                {
                    break;
                }
                DmtxRegion region = decode.RegionFindNext(timeOut);
                if (region != null)
                {
                    DmtxMessage msg     = isMosaic ? decode.MosaicRegion(region, -1) : decode.MatrixRegion(region, -1);
                    string      message = Encoding.ASCII.GetString(msg.Output);
                    message = message.Substring(0, message.IndexOf('\0'));
                    if (!result.Contains(message))
                    {
                        result.Add(message);
                        if (result.Count >= maxResultCount)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    break;
                }
            }
            return(result);
        }
Esempio n. 3
0
        internal DmtxDecode(DmtxImage img, int scale)
        {
            int width = img.Width / scale;
            int height = img.Height / scale;

            this._edgeMin = DmtxConstants.DmtxUndefined;
            this._edgeMax = DmtxConstants.DmtxUndefined;
            this._scanGap = 1;
            this._squareDevn = Math.Cos(50.0 * (Math.PI / 180.0));
            this._sizeIdxExpected = DmtxSymbolSize.DmtxSymbolShapeAuto;
            this._edgeThresh = 10;

            this._xMin = 0;
            this._xMax = width - 1;
            this._yMin = 0;
            this._yMax = height - 1;
            this._scale = scale;

            this._cache = new byte[width * height];

            this._image = img;
            ValidateSettingsAndInitScanGrid();
        }
Esempio n. 4
0
 private List<string> DecodeImage(Bitmap image, int maxResultCount, TimeSpan timeOut, bool isMosaic)
 {
     List<string> result = new List<string>();
     int stride;
     byte[] rawImg = ImageToByteArray(image, out stride);
     DmtxImage dmtxImg = new DmtxImage(rawImg, image.Width, image.Height, DmtxPackOrder.DmtxPack24bppRGB);
     dmtxImg.RowPadBytes = stride % 3;
     DmtxDecode decode = new DmtxDecode(dmtxImg, 1);
     TimeSpan timeLeft = new TimeSpan(timeOut.Ticks);
     Stopwatch stopWatch = new Stopwatch();
     stopWatch.Start();
     while (true)
     {
         if (stopWatch.Elapsed > timeOut)
         {
             break;
         }
         DmtxRegion region = decode.RegionFindNext(timeOut);
         if (region != null)
         {
             DmtxMessage msg = isMosaic ? decode.MosaicRegion(region, -1) : decode.MatrixRegion(region, -1);
             string message = Encoding.ASCII.GetString(msg.Output);
             message = message.Substring(0, message.IndexOf('\0'));
             if (!result.Contains(message))
             {
                 result.Add(message);
                 if (result.Count >= maxResultCount)
                 {
                     break;
                 }
             }
         }
         else
         {
             break;
         }
     }
     return result;
 }
Esempio n. 5
0
        internal bool EncodeDataMatrix(Color? foreColor, Color? backColor, byte[] inputString)
        {
            int padCount;
            int width, height, bitsPerPixel;
            byte[] buf = new byte[4096];
            byte[] pxl;

            /* Encode input string into data codewords */
            DmtxSymbolSize sizeIdx = this._sizeIdxRequest;
            int dataWordCount = EncodeDataCodewords(buf, inputString, ref sizeIdx);
            if (dataWordCount <= 0)
            {
                return false;
            }

            /* EncodeDataCodewords() should have updated any auto sizeIdx to a real one */
            if (sizeIdx == DmtxSymbolSize.DmtxSymbolSquareAuto || sizeIdx == DmtxSymbolSize.DmtxSymbolRectAuto)
            {
                throw new Exception("Invalid symbol size for encoding!");
            }

            /* Add pad characters to match a standard symbol size (whether smallest or requested) */
            padCount = AddPadChars(buf, ref dataWordCount, DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribSymbolDataWords, sizeIdx));

            /* XXX we can remove a lot of this redundant data */
            this._region = new DmtxRegion();
            this._region.SizeIdx = sizeIdx;
            this._region.SymbolRows = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribSymbolRows, sizeIdx);
            this._region.SymbolCols = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribSymbolCols, sizeIdx);
            this._region.MappingRows = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribMappingMatrixRows, sizeIdx);
            this._region.MappingCols = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribMappingMatrixCols, sizeIdx);

            /* Allocate memory for message and array */
            this._message = new DmtxMessage(sizeIdx, DmtxFormat.Matrix);
            this._message.PadCount = padCount;
            for (int i = 0; i < dataWordCount; i++)
            {
                this._message.Code[i] = buf[i];
            }

            /* Generate error correction codewords */
            DmtxCommon.GenReedSolEcc(this._message, this._region.SizeIdx);

            /* Module placement in region */
            DmtxDecode.ModulePlacementEcc200(this._message.Array, this._message.Code,
                  this._region.SizeIdx, DmtxConstants.DmtxModuleOnRGB);

            width = 2 * this._marginSize + (this._region.SymbolCols * this._moduleSize);
            height = 2 * this._marginSize + (this._region.SymbolRows * this._moduleSize);
            bitsPerPixel = DmtxCommon.GetBitsPerPixel(this._pixelPacking);
            if (bitsPerPixel == DmtxConstants.DmtxUndefined)
                return false;
            if (bitsPerPixel % 8 != 0)
            {
                throw new Exception("Invalid color depth for encoding!");
            }

            /* Allocate memory for the image to be generated */
            // pxl = (unsigned char *)malloc(width * height * (bitsPerPixel/8) + enc->rowPadBytes);
            pxl = new byte[width * height * (bitsPerPixel / 8) + this._rowPadBytes];

            this._image = new DmtxImage(pxl, width, height, this._pixelPacking);
            this._image.ImageFlip = this._imageFlip;
            this._image.RowPadBytes = this._rowPadBytes;

            /* Insert finder and aligment pattern modules */
            PrintPattern(foreColor, backColor);

            return true;
        }