diff --git a/src/ksanepreviewthread.h b/src/ksanepreviewthread.h --- a/src/ksanepreviewthread.h +++ b/src/ksanepreviewthread.h @@ -73,17 +73,17 @@ void copyToPreviewImg(int readBytes); SANE_Byte m_readData[PREVIEW_READ_CHUNK_SIZE]; + SANE_Handle m_saneHandle; int m_frameSize; int m_frameRead; - int m_dataSize; int m_frame_t_count; + int m_dataSize; SANE_Parameters m_params; - SANE_Handle m_saneHandle; - bool m_invertColors; SANE_Status m_saneStatus; ReadStatus m_readStatus; // int m_scanProgress; bool m_saneStartDone; + bool m_invertColors; KSanePreviewImageBuilder m_imageBuilder; }; } diff --git a/src/ksanepreviewthread.cpp b/src/ksanepreviewthread.cpp --- a/src/ksanepreviewthread.cpp +++ b/src/ksanepreviewthread.cpp @@ -36,16 +36,16 @@ { KSanePreviewThread::KSanePreviewThread(SANE_Handle handle, QImage *img): QThread(), + m_saneHandle(handle), m_frameSize(0), m_frameRead(0), - m_dataSize(0), m_frame_t_count(0), - m_saneHandle(handle), - m_invertColors(false), + m_dataSize(0), m_saneStatus(SANE_STATUS_GOOD), m_readStatus(READ_READY), // m_scanProgress(0), m_saneStartDone(false), + m_invertColors(false), m_imageBuilder(img) { } @@ -183,24 +183,29 @@ copyToPreviewImg(readBytes); } -void KSanePreviewThread::copyToPreviewImg(int read_bytes) +void KSanePreviewThread::copyToPreviewImg(int readBytes) { QMutexLocker locker(&imgMutex); if (m_invertColors) { - if (m_params.depth >= 8) { - for (int i = 0; i < read_bytes; i++) { - m_readData[i] = 255 - m_readData[i]; + if (m_params.depth == 16) { + //if (readBytes%2) qDebug() << "readBytes=" << readBytes; + quint16 *u16ptr = reinterpret_cast(m_readData); + for (int i = 0; i < readBytes / 2; i++) { + u16ptr[i] = 0xFFFF - u16ptr[i]; } - } - if (m_params.depth == 1) { - for (int i = 0; i < read_bytes; i++) { + } else if (m_params.depth == 8) { + for (int i = 0; i < readBytes; i++) { + m_readData[i] = 0xFF - m_readData[i]; + } + } else if (m_params.depth == 1) { + for (int i = 0; i < readBytes; i++) { m_readData[i] = ~m_readData[i]; } } } - if (m_imageBuilder.copyToImage(m_readData, read_bytes)) { - m_frameRead += read_bytes; + if (m_imageBuilder.copyToImage(m_readData, readBytes)) { + m_frameRead += readBytes; } else { m_readStatus = READ_ERROR; } diff --git a/src/ksanescanthread.h b/src/ksanescanthread.h --- a/src/ksanescanthread.h +++ b/src/ksanescanthread.h @@ -72,15 +72,15 @@ SANE_Byte m_readData[SCAN_READ_CHUNK_SIZE]; QByteArray *m_data; SANE_Handle m_saneHandle; - SANE_Parameters m_params; int m_frameSize; int m_frameRead; int m_frame_t_count; int m_dataSize; + SANE_Parameters m_params; SANE_Status m_saneStatus; ReadStatus m_readStatus; - bool m_invertColors; bool m_saneStartDone; + bool m_invertColors; }; } diff --git a/src/ksanescanthread.cpp b/src/ksanescanthread.cpp --- a/src/ksanescanthread.cpp +++ b/src/ksanescanthread.cpp @@ -43,8 +43,8 @@ m_dataSize(0), m_saneStatus(SANE_STATUS_GOOD), m_readStatus(READ_READY), - m_invertColors(false), - m_saneStartDone(false) + m_saneStartDone(false), + m_invertColors(false) {} void KSaneScanThread::setImageInverted(bool inverted) @@ -67,22 +67,6 @@ m_readStatus = READ_CANCEL; } -int KSaneScanThread::scanProgress() -{ - if (m_dataSize == 0) { - return 0; - } - - int bytesRead; - - if (m_frameSize < m_dataSize) { - bytesRead = m_frameRead + (m_frameSize * m_frame_t_count); - } else { - bytesRead = m_frameRead; - } - return (int)(((float)bytesRead * 100.0) / m_dataSize); -} - SANE_Parameters KSaneScanThread::saneParameters() { return m_params; @@ -142,6 +126,22 @@ } } +int KSaneScanThread::scanProgress() +{ + if (m_dataSize == 0) { + return 0; + } + + int bytesRead; + + if (m_frameSize < m_dataSize) { + bytesRead = m_frameRead + (m_frameSize * m_frame_t_count); + } else { + bytesRead = m_frameRead; + } + return (int)(((float)bytesRead * 100.0) / m_dataSize); +} + void KSaneScanThread::readData() { SANE_Int readBytes = 0;