KSaneCore

scanthread.h
1/*
2 * SPDX-FileCopyrightText: 2009 Kare Sars <kare dot sars at iki dot fi>
3 * SPDX-FileCopyrightText: 2014 Gregor Mitsch : port to KDE5 frameworks
4 * SPDX-FileCopyrightText: 2021 Alexander Stippich <a.stippich@gmx.net>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#ifndef KSANE_SCAN_THREAD_H
10#define KSANE_SCAN_THREAD_H
11
12#include "imagebuilder.h"
13
14// Sane includes
15extern "C"
16{
17#include <sane/saneopts.h>
18#include <sane/sane.h>
19}
20
21#include <QThread>
22#include <QMutex>
23#include <QByteArray>
24#include <QImage>
25#include <QTimer>
26
27#define SCAN_READ_CHUNK_SIZE 100000
28
29namespace KSaneCore
30{
31
32class ScanThread: public QThread
33{
35public:
36 enum ReadStatus {
37 ReadOngoing,
38 ReadError,
39 ReadCancel,
40 ReadReady
41 };
42
43 explicit ScanThread(SANE_Handle handle);
44 void run() override;
45 void setImageInverted(const QVariant &newValue);
46 void setImageResolution(const QVariant &newValue);
47 void cancelScan();
48
49 ReadStatus frameStatus();
50 SANE_Status saneStatus();
51
52 void lockScanImage();
53 QImage *scanImage();
54 void unlockScanImage();
55
57
58 void scanProgressUpdated(int progress);
59
60private:
61 void readData();
62 void updateScanProgress();
63 void copyToScanData(int readBytes);
64
65 SANE_Byte m_readData[SCAN_READ_CHUNK_SIZE];
66 SANE_Handle m_saneHandle;
67 int m_frameSize = 0;
68 int m_frameRead = 0;
69 int m_frame_t_count = 0;
70 int m_dataSize = 0;
71 int m_dpi = 0;
72 SANE_Parameters m_params;
73 SANE_Status m_saneStatus = SANE_STATUS_GOOD;
74 ReadStatus m_readStatus = ReadReady;
75 bool m_announceFirstRead = true;
76 bool m_invertColors = false;
77 ImageBuilder m_imageBuilder;
78 QImage m_image;
79 QMutex m_imageMutex;
80
81 QTimer m_emitProgressUpdateTimer;
82};
83
84} // namespace KSaneCore
85
86#endif // KSANE_SCAN_THREAD_H
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:49:00 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.