public void SaveBuffer(string filePath, ImageType imageType, ScannedSide side, BufferSize bufferSize) { var res = _scanner.SaveBuffer(filePath, imageType, side, bufferSize); if (res) // OK Logger.LogVerbose(Message.ScannerManagerBufferSaved, imageType, bufferSize, side, filePath); else // Error Logger.LogError(Message.ScannerManagerBufferSaveError, imageType, bufferSize, side, filePath, res); }
public bool GetHalftoneBuffer(ScannedSide side, short xCoord, short yCoord, short width, short height, MemoryBlock image) { short absX = xCoord; short absY = yCoord; if (side == 0) { absX += _scannerConfig.WorkZone.SideTopX; absY += _scannerConfig.WorkZone.SideTopY; } else { absX += _scannerConfig.WorkZone.SideBottomX; absY += _scannerConfig.WorkZone.SideBottomY; } short bufferId; _scanner.GetHalftoneBuffer(side, absX, absY, width, height, image, out bufferId); Logger.LogVerbose(Message.ScannerManagerGetHalftone, side, xCoord, yCoord, width, height, bufferId); return true; }
public void SetWorkZone(ScannedSide side, short x, short y) { if (side == ScannedSide.Undefined) throw new ArgumentException("Сторона не определена"); var sideIndex = (int)side; _x[sideIndex] = x; _y[sideIndex] = y; }
public unsafe void GetHalftoneBuffer( ScannedSide side, short x, short y, short w, short h, MemoryBlock iMemory, out short id) { if (side == ScannedSide.Undefined) throw new ArgumentException("Сторона не определена"); var sideIndex = (int)side; var ptr = _sh.HalftoneBuffer[sideIndex]; if (side == ScannedSide.Top) { ptr = HalfToneBuffer0.ToPointer(); } else if (side == ScannedSide.Bottom) { ptr = HalfToneBuffer1.ToPointer(); } var sourceBuffer = (byte*)ptr.ToPointer(); x -= _x[sideIndex]; y -= _y[sideIndex]; if (x < 0) { throw new Exception("недопустимое значение левой границы"); } if (y < 0) { throw new Exception("недопустимое значение верхней границы"); } if (h < 0) { throw new Exception("отрицательная высота"); } if (w < 0) { throw new Exception("отрицательная ширина"); } if (x + w > _currentConfiguration.DotsOneSide || y + h > _currentConfiguration.MaxLines) { throw new Exception("запрашиваемое изображение выходит за границы отсканированной области"); } if (x % DOTS_PER_BYTE_HALFTONE != 0) { throw new Exception("начальная координата не попадает на границу байта!"); } if (w % DOTS_PER_BYTE_HALFTONE != 0) { throw new Exception("ширина запрошенной области содерит не целое число байт!"); } ptr = iMemory.ToPointer(); if (ptr == IntPtr.Zero) { throw new Exception("нет буфера для записи изображения!"); } var destination = (byte*)ptr.ToPointer(); var lengthLine = _currentConfiguration.DotsOneSide / DOTS_PER_BYTE_HALFTONE; var lengthCopy = w / DOTS_PER_BYTE_HALFTONE; var shift = (side == 0 ? 0 : _currentConfiguration.DotsOneSide); if (x == y && y == 0 && lengthCopy == lengthLine) { if (!WhiteCoeffApplyed[sideIndex]) { var wcPtr = _whiteCoeffU.ToPointer(); if ((_currentConfiguration.Options & HardwareOptions.RightToLeftHalftone) > 0) { if (!_halftoneFlipped[sideIndex]) { FlipBufferVertically(sourceBuffer, lengthCopy, h); _halftoneFlipped[sideIndex] = true; } applyWhiteCoeffs(sourceBuffer, destination, (byte*)wcPtr.ToPointer() + shift, lengthCopy, h); } else { applyWhiteCoeffs(sourceBuffer, destination, (byte*)wcPtr.ToPointer() + shift, lengthCopy, h); } } else { } } else { int wcX = x; var wcInc = 1; if (!_halftoneFlipped[sideIndex] && (_currentConfiguration.Options & HardwareOptions.RightToLeftHalftone) > 0) { wcX = x + w - 1; wcInc = -1; x = (short)(_currentConfiguration.DotsOneSide - x - w); } var startLine = sourceBuffer + // начало буфера y * lengthLine + // число байт в первых y-строках x / BaseSharedMemory.DotsPerByteHalftone; // число байт в первых x-точках var p = destination; for (var i = 0; i < h; i++) { var source = startLine; for (int j = 0, wcJ = wcX; j < lengthCopy; j++, wcJ += wcInc) { *p++ = whiteCoeffTable.whiteCoeff[(*source++ << 8) + _whiteCoeff[shift + wcJ]]; } startLine += lengthLine; } if (!_halftoneFlipped[sideIndex] && (_currentConfiguration.Options & HardwareOptions.RightToLeftHalftone) > 0) { FlipBufferVertically(destination, w, h); } } id = 0; }
public unsafe bool SaveBuffer(string fileName, ImageType imageType, ScannedSide side, BufferSize bufferSize) { try { if (/*WhiteCoeff > 0 && */imageType == ImageType.Halftone) { IntPtr wcPtr = _whiteCoeffU.ToPointer(); int shift = (side == 0 ? 0 : _currentConfiguration.DotsOneSide); if ((_currentConfiguration.Options & HardwareOptions.RightToLeftHalftone) > 0) { if ((_currentConfiguration.Options & HardwareOptions.OneSide) == 0) { if ((side == ScannedSide.Top || side == ScannedSide.Undefined) && !_halftoneFlipped[(int)ScannedSide.Top]) { IntPtr p0 = HalfToneBuffer0.ToPointer(); FlipBufferVertically((byte*)p0.ToPointer(), _currentConfiguration.DotsOneSide, _linesCount); _halftoneFlipped[(int)ScannedSide.Top] = true; } } if ((side == ScannedSide.Bottom || side == ScannedSide.Undefined) && !_halftoneFlipped[(int)ScannedSide.Bottom]) { IntPtr p1 = HalfToneBuffer1.ToPointer(); FlipBufferVertically((byte*)p1.ToPointer(), _currentConfiguration.DotsOneSide, _linesCount); _halftoneFlipped[(int)ScannedSide.Bottom] = true; } } if ((_currentConfiguration.Options & HardwareOptions.OneSide) == 0) { if ((side == ScannedSide.Top || side == ScannedSide.Undefined) && !WhiteCoeffApplyed[(int)ScannedSide.Top]) { IntPtr p0 = HalfToneBuffer0.ToPointer(); applyWhiteCoeffs( (byte*)p0.ToPointer(), (byte*)p0.ToPointer(), (byte*)wcPtr.ToPointer() + shift, _currentConfiguration.DotsOneSide, _linesCount); WhiteCoeffApplyed[(int)ScannedSide.Top] = true; } } if ((side == ScannedSide.Bottom || side == ScannedSide.Undefined) && !WhiteCoeffApplyed[(int)ScannedSide.Bottom]) { IntPtr p1 = HalfToneBuffer1.ToPointer(); applyWhiteCoeffs( (byte*)p1.ToPointer(), (byte*)p1.ToPointer(), (byte*)wcPtr.ToPointer() + shift, _currentConfiguration.DotsOneSide, _linesCount); WhiteCoeffApplyed[(int)ScannedSide.Bottom] = true; } } if (side == ScannedSide.Top || side == ScannedSide.Undefined) { TiffImageHelper.SaveToFile(fileName + "_0.tif", imageType, imageType == ImageType.Binary ? WorkBufferTop : HalfToneBuffer0, _currentConfiguration.DotsOneSide, bufferSize == BufferSize.Scanned ? _linesCount : _currentConfiguration.MaxLines); } if (side == ScannedSide.Bottom || side == ScannedSide.Undefined) { TiffImageHelper.SaveToFile(fileName + "_1.tif", imageType, imageType == ImageType.Binary ? WorkBufferBottom : HalfToneBuffer1, _currentConfiguration.DotsOneSide, bufferSize == BufferSize.Scanned ? _linesCount : _currentConfiguration.MaxLines); } return true; } catch { return false; } }