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 e2d49214..44f46cf4 100644 Binary files a/huagao/stdafx.h and b/huagao/stdafx.h differ