File indexing completed on 2024-12-08 10:16:30
0001 /* 0002 * SPDX-FileCopyrightText: 2009 Kare Sars <kare dot sars at iki dot fi> 0003 * SPDX-FileCopyrightText: 2014 Gregor Mitsch : port to KDE5 frameworks 0004 * SPDX-FileCopyrightText: 2021 Alexander Stippich <a.stippich@gmx.net> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #ifndef KSANE_SCAN_THREAD_H 0010 #define KSANE_SCAN_THREAD_H 0011 0012 #include "imagebuilder.h" 0013 0014 // Sane includes 0015 extern "C" 0016 { 0017 #include <sane/saneopts.h> 0018 #include <sane/sane.h> 0019 } 0020 0021 #include <QThread> 0022 #include <QMutex> 0023 #include <QByteArray> 0024 #include <QImage> 0025 #include <QTimer> 0026 0027 #define SCAN_READ_CHUNK_SIZE 100000 0028 0029 namespace KSaneCore 0030 { 0031 0032 class ScanThread: public QThread 0033 { 0034 Q_OBJECT 0035 public: 0036 enum ReadStatus { 0037 ReadOngoing, 0038 ReadError, 0039 ReadCancel, 0040 ReadReady 0041 }; 0042 0043 explicit ScanThread(SANE_Handle handle); 0044 void run() override; 0045 void setImageInverted(const QVariant &newValue); 0046 void setImageResolution(const QVariant &newValue); 0047 void cancelScan(); 0048 0049 ReadStatus frameStatus(); 0050 SANE_Status saneStatus(); 0051 0052 void lockScanImage(); 0053 QImage *scanImage(); 0054 void unlockScanImage(); 0055 0056 Q_SIGNALS: 0057 0058 void scanProgressUpdated(int progress); 0059 0060 private: 0061 void readData(); 0062 void updateScanProgress(); 0063 void copyToScanData(int readBytes); 0064 0065 SANE_Byte m_readData[SCAN_READ_CHUNK_SIZE]; 0066 SANE_Handle m_saneHandle; 0067 int m_frameSize = 0; 0068 int m_frameRead = 0; 0069 int m_frame_t_count = 0; 0070 int m_dataSize = 0; 0071 int m_dpi = 0; 0072 SANE_Parameters m_params; 0073 SANE_Status m_saneStatus = SANE_STATUS_GOOD; 0074 ReadStatus m_readStatus = ReadReady; 0075 bool m_announceFirstRead = true; 0076 bool m_invertColors = false; 0077 ImageBuilder m_imageBuilder; 0078 QImage m_image; 0079 QMutex m_imageMutex; 0080 0081 QTimer m_emitProgressUpdateTimer; 0082 }; 0083 0084 } // namespace KSaneCore 0085 0086 #endif // KSANE_SCAN_THREAD_H