Add support for 16 bit PNG images
This commit is contained in:
@@ -25,8 +25,9 @@ const RawImageType rawImageTypes[] = {
|
|||||||
{QOpenGLTexture::Red, QOpenGLTexture::R16_UNorm, QOpenGLTexture::UInt16, true},
|
{QOpenGLTexture::Red, QOpenGLTexture::R16_UNorm, QOpenGLTexture::UInt16, true},
|
||||||
{QOpenGLTexture::Red, QOpenGLTexture::R32F, QOpenGLTexture::Float32, true},
|
{QOpenGLTexture::Red, QOpenGLTexture::R32F, QOpenGLTexture::Float32, true},
|
||||||
{QOpenGLTexture::RGB, QOpenGLTexture::RGB8_UNorm, QOpenGLTexture::UInt8, false},
|
{QOpenGLTexture::RGB, QOpenGLTexture::RGB8_UNorm, QOpenGLTexture::UInt8, false},
|
||||||
{QOpenGLTexture::BGRA,QOpenGLTexture::RGB8_UNorm, QOpenGLTexture::UInt8, false},
|
{QOpenGLTexture::RGBA,QOpenGLTexture::RGB8_UNorm, QOpenGLTexture::UInt8, false},
|
||||||
{QOpenGLTexture::RGB, QOpenGLTexture::RGB16_UNorm, QOpenGLTexture::UInt16, false},
|
{QOpenGLTexture::RGB, QOpenGLTexture::RGB16_UNorm, QOpenGLTexture::UInt16, false},
|
||||||
|
{QOpenGLTexture::RGBA, QOpenGLTexture::RGB16_UNorm, QOpenGLTexture::UInt16, false},
|
||||||
{QOpenGLTexture::RGB, QOpenGLTexture::RGB32F, QOpenGLTexture::Float32, false}
|
{QOpenGLTexture::RGB, QOpenGLTexture::RGB32F, QOpenGLTexture::Float32, false}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+30
-5
@@ -16,6 +16,8 @@ RawImage::ImgType CV2Type(int cvtype)
|
|||||||
return RawImage::UINT8C4;
|
return RawImage::UINT8C4;
|
||||||
case CV_16UC3:
|
case CV_16UC3:
|
||||||
return RawImage::UINT16C3;
|
return RawImage::UINT16C3;
|
||||||
|
case CV_16UC4:
|
||||||
|
return RawImage::UINT16C4;
|
||||||
case CV_32FC3:
|
case CV_32FC3:
|
||||||
return RawImage::FLOAT32C3;
|
return RawImage::FLOAT32C3;
|
||||||
default:
|
default:
|
||||||
@@ -39,6 +41,8 @@ int Type2CV(RawImage::ImgType type)
|
|||||||
return CV_8UC4;
|
return CV_8UC4;
|
||||||
case RawImage::UINT16C3:
|
case RawImage::UINT16C3:
|
||||||
return CV_16UC3;
|
return CV_16UC3;
|
||||||
|
case RawImage::UINT16C4:
|
||||||
|
return CV_16UC4;
|
||||||
case RawImage::FLOAT32C3:
|
case RawImage::FLOAT32C3:
|
||||||
return CV_32FC3;
|
return CV_32FC3;
|
||||||
case RawImage::UNKNOWN:
|
case RawImage::UNKNOWN:
|
||||||
@@ -84,6 +88,27 @@ RawImage::RawImage(const QImage &img)
|
|||||||
m_img.create(img.height(), img.width(), CV_8UC4);
|
m_img.create(img.height(), img.width(), CV_8UC4);
|
||||||
for(int i=0; i<img.height(); i++)
|
for(int i=0; i<img.height(); i++)
|
||||||
std::memcpy(m_img.ptr(i), img.scanLine(i), img.width()*4);
|
std::memcpy(m_img.ptr(i), img.scanLine(i), img.width()*4);
|
||||||
|
cv::cvtColor(m_img, m_img, cv::COLOR_BGRA2RGB);
|
||||||
|
}
|
||||||
|
else if(img.format() == QImage::Format_ARGB32)
|
||||||
|
{
|
||||||
|
m_img.create(img.height(), img.width(), CV_8UC4);
|
||||||
|
for(int i=0; i<img.height(); i++)
|
||||||
|
std::memcpy(m_img.ptr(i), img.scanLine(i), img.width()*4);
|
||||||
|
cv::cvtColor(m_img, m_img, cv::COLOR_BGRA2RGBA);
|
||||||
|
}
|
||||||
|
else if(img.format() == QImage::Format_RGBX64)
|
||||||
|
{
|
||||||
|
m_img.create(img.height(), img.width(), CV_16UC4);
|
||||||
|
for(int i=0; i<img.height(); i++)
|
||||||
|
std::memcpy(m_img.ptr(i), img.scanLine(i), img.width()*8);
|
||||||
|
cv::cvtColor(m_img, m_img, cv::COLOR_RGBA2RGB);
|
||||||
|
}
|
||||||
|
else if(img.format() == QImage::Format_RGBA64)
|
||||||
|
{
|
||||||
|
m_img.create(img.height(), img.width(), CV_16UC4);
|
||||||
|
for(int i=0; i<img.height(); i++)
|
||||||
|
std::memcpy(m_img.ptr(i), img.scanLine(i), img.width()*8);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -284,7 +309,7 @@ void RawImage::convertToThumbnail()
|
|||||||
if(m_img.channels() == 1)
|
if(m_img.channels() == 1)
|
||||||
cv::cvtColor(m_img, m_img, cv::COLOR_GRAY2RGB);
|
cv::cvtColor(m_img, m_img, cv::COLOR_GRAY2RGB);
|
||||||
if(m_img.channels() == 4)
|
if(m_img.channels() == 4)
|
||||||
cv::cvtColor(m_img, m_img, cv::COLOR_BGRA2RGB);
|
cv::cvtColor(m_img, m_img, cv::COLOR_RGBA2RGB);
|
||||||
cv::Size dsize(THUMB_SIZE, THUMB_SIZE);
|
cv::Size dsize(THUMB_SIZE, THUMB_SIZE);
|
||||||
cv::resize(m_img, m_img, dsize, 0, 0, cv::INTER_NEAREST);
|
cv::resize(m_img, m_img, dsize, 0, 0, cv::INTER_NEAREST);
|
||||||
}
|
}
|
||||||
@@ -326,25 +351,25 @@ bool RawImage::pixel(int x, int y, QVector3D &rgb) const
|
|||||||
case CV_8UC3:
|
case CV_8UC3:
|
||||||
{
|
{
|
||||||
cv::Vec3b v = m_img.at<cv::Vec3b>(y, x);
|
cv::Vec3b v = m_img.at<cv::Vec3b>(y, x);
|
||||||
rgb = QVector3D(v[2], v[1], v[0]);
|
rgb = QVector3D(v[0], v[1], v[2]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CV_8UC4:
|
case CV_8UC4:
|
||||||
{
|
{
|
||||||
cv::Vec4b v = m_img.at<cv::Vec4b>(y, x);
|
cv::Vec4b v = m_img.at<cv::Vec4b>(y, x);
|
||||||
rgb = QVector3D(v[2], v[1], v[0]);
|
rgb = QVector3D(v[0], v[1], v[2]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CV_16UC3:
|
case CV_16UC3:
|
||||||
{
|
{
|
||||||
cv::Vec3w v = m_img.at<cv::Vec3w>(y, x);
|
cv::Vec3w v = m_img.at<cv::Vec3w>(y, x);
|
||||||
rgb = QVector3D(v[2], v[1], v[0]);
|
rgb = QVector3D(v[0], v[1], v[2]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CV_32FC3:
|
case CV_32FC3:
|
||||||
{
|
{
|
||||||
cv::Vec3f v = m_img.at<cv::Vec3f>(y, x);
|
cv::Vec3f v = m_img.at<cv::Vec3f>(y, x);
|
||||||
rgb = QVector3D(v[2], v[1], v[0]);
|
rgb = QVector3D(v[0], v[1], v[2]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ public:
|
|||||||
UINT8C3,
|
UINT8C3,
|
||||||
UINT8C4,
|
UINT8C4,
|
||||||
UINT16C3,
|
UINT16C3,
|
||||||
|
UINT16C4,
|
||||||
FLOAT32C3,
|
FLOAT32C3,
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user