From 0cb98a539d97a597c9edffa3082ae1ddd55059cb Mon Sep 17 00:00:00 2001 From: masayume_ht <1936714878@qq.com> Date: Mon, 9 Aug 2021 18:42:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=93=E5=AD=98=E6=89=AB?= =?UTF-8?q?=E6=8F=8F=E5=86=85=E5=AD=98=E8=BF=87=E5=A4=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- huagao/Device/GScanO1003399.cpp | 8 +++++++- huagao/Device/ImageMatQueue.h | 31 +++++++++++++++++++++++++++---- huagao/stdafx.h | Bin 12356 -> 12360 bytes 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/huagao/Device/GScanO1003399.cpp b/huagao/Device/GScanO1003399.cpp index 4d916fa2..11ef92b0 100644 --- a/huagao/Device/GScanO1003399.cpp +++ b/huagao/Device/GScanO1003399.cpp @@ -782,8 +782,9 @@ void GScanO1003399::imgproce(std::shared_ptr>& buff) if (m_param.pixtype == 1 && m_param.hsvcorrect) if (mats[i].channels() == 3) cvtColor(mats[i], mats[i], cv::COLOR_BGR2GRAY); - idata = (isbwimg|| m_param.pixtype == 0 || (((m_param.automaticcolortype == 0) && (m_param.automaticcolor == true)) && (mats[i].channels() == 1))) ? (IMat2Bmp)Mat2BmpBw(mats[i], m_param.resolution_dst) : Mat2Bmp(mats[i], m_param.resolution_dst); + idata = (isbwimg|| m_param.pixtype == 0 || (((m_param.automaticcolortype == 0) && (m_param.automaticcolor == true)) && (mats[i].channels() == 1))) ? (IMat2Bmp)Mat2BmpBw(mats[i], m_param.resolution_dst) : (IMat2Bmp)Mat2Bmp(mats[i], m_param.resolution_dst); m_imagedata.Put(idata.getBmpDataBuffer()); + idata.~IMat2Bmp(); } } @@ -882,6 +883,11 @@ void GScanO1003399::proc(bool bcachemode) b_imgprothread = true; while (b_imgprothread) { + if (m_imagedata.Size() > 0) + { + this_thread::sleep_for(chrono::milliseconds(10)); + continue; + } std::shared_ptr> buffer; if (bcachemode) { if (m_paths.Size() < 1) diff --git a/huagao/Device/ImageMatQueue.h b/huagao/Device/ImageMatQueue.h index dc1ea2ec..8b8b4502 100644 --- a/huagao/Device/ImageMatQueue.h +++ b/huagao/Device/ImageMatQueue.h @@ -16,7 +16,10 @@ using namespace std; class IMat2Bmp { public: - virtual ~IMat2Bmp() {} + virtual ~IMat2Bmp() { + if (m_data.get()) + m_data.reset(); + } virtual std::shared_ptr> getBmpDataBuffer() { return m_data; }; @@ -29,13 +32,33 @@ protected: class Mat2Bmp:public IMat2Bmp { public: Mat2Bmp(const cv::Mat& mat,float res) { - m_data =std::shared_ptr>(new std::vector()); + //m_data =std::shared_ptr>(new std::vector()); + m_data.reset(new std::vector()); int headersize = mat.channels() == 3 ? 54 : 1078; - int bmpdatasize = mat.step1() * mat.rows; - m_data->resize(headersize + bmpdatasize); + int step = mat.step; + int bmpdatasize = (step + 3) / 4 * 4 * mat.rows; + int m_datalinesize = (step + 3) / 4 * 4; + int height = mat.rows; + //m_data->resize(headersize + bmpdatasize); + m_data.reset(new std::vector(headersize + bmpdatasize)); + if (mat.channels() == 1) + { + uchar colortable[256 * 4]{ 0 }; + for (int i = 0; i < 256; i++) { + colortable[i*4] = colortable[i*4 + 1] = colortable[i*4 + 2] = i; + } + memcpy(m_data->data() + 54, colortable, 256 * 4); + } cv::imencode(".bmp", mat, *(m_data.get())); setBmpFileHeader(mat); setBmpInfoHeader(mat, res); + //uchar* data = m_data->data() + headersize + bmpdatasize; + //uchar* matdata = mat.data; + //for (int i = 0; i < mat.rows; i++){ + // data -= m_datalinesize; + // memcpy(data, matdata, step); + // matdata += step; + //} } private: void setBmpFileHeader(const cv::Mat& mat) diff --git a/huagao/stdafx.h b/huagao/stdafx.h index e2d49214117a5b1d4166f8c351053f60605ddcea..44f46cf474ab0bfc9fcc18aa1cc0f45ed45824ff 100644 GIT binary patch delta 16 YcmX?-a3W#DEY8W>I7BwD;+&-h07M@LD*ylh delta 16 YcmX?+a3o>FEY8V&90Hryan4c$07Bmf0{{R3