internal DmtxScanGrid(DmtxDecode dec) { int scale = dec.Scale; int smallestFeature = dec.ScanGap; this._xMin = dec.XMin; this._xMax = dec.XMax; this._yMin = dec.YMin; this._yMax = dec.YMax; /* Values that get set once */ int xExtent = this._xMax - this._xMin; int yExtent = this._yMax - this._yMin; int maxExtent = (xExtent > yExtent) ? xExtent : yExtent; if (maxExtent < 1) { throw new ArgumentException("Invalid max extent for Scan Grid: Must be greater than 0"); } int extent = 1; this._minExtent = extent; for (; extent < maxExtent; extent = ((extent + 1) * 2) - 1) { if (extent <= smallestFeature) { _minExtent = extent; } } this._maxExtent = extent ; this._xOffset = (this._xMin + this._xMax - this._maxExtent) / 2; this._yOffset = (this._yMin + this._yMax - this._maxExtent) / 2; /* Values that get reset for every level */ this._total = 1; this._extent = this._maxExtent; this._jumpSize = this._extent + 1; this._pixelTotal = 2 * this._extent - 1; this._startPos = this._extent / 2; this._pixelCount = 0; this._xCenter = this._yCenter = this._startPos; SetDerivedFields(); }
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; }