Usable OpenGL ES
This commit is contained in:
+44
-10
@@ -2,12 +2,16 @@
|
||||
#include <QDebug>
|
||||
#include <cstring>
|
||||
#include <QElapsedTimer>
|
||||
#include <QFloat16>
|
||||
|
||||
using F16 = qfloat16;
|
||||
|
||||
int THUMB_SIZE = 128;
|
||||
int THUMB_SIZE_BORDER = 138;
|
||||
int THUMB_SIZE_BORDER_Y = 158;
|
||||
double SATURATION = 0.95;
|
||||
bool QUALITY_RESIZE = true;
|
||||
extern bool OpenGLES;
|
||||
|
||||
#ifdef __SSE2__
|
||||
template<typename T, int ch>
|
||||
@@ -21,6 +25,7 @@ size_t RawImage::typeSize(RawImage::DataType type)
|
||||
case RawImage::UINT8:
|
||||
return 1;
|
||||
case RawImage::UINT16:
|
||||
case RawImage::FLOAT16:
|
||||
return 2;
|
||||
case RawImage::UINT32:
|
||||
case RawImage::FLOAT32:
|
||||
@@ -338,7 +343,7 @@ RawImage::DataType RawImage::type() const
|
||||
|
||||
uint32_t RawImage::norm() const
|
||||
{
|
||||
switch(m_type)
|
||||
switch(m_origType)
|
||||
{
|
||||
case UINT8:
|
||||
return UINT8_MAX;
|
||||
@@ -404,10 +409,10 @@ void RawImage::convertToThumbnail()
|
||||
|
||||
if(m_thumbAspect == 0.0f)
|
||||
m_thumbAspect = (float)width() / height();
|
||||
std::unique_ptr<PixelType[]> outptr = std::make_unique<PixelType[]>(THUMB_SIZE * THUMB_SIZE * 4 * sizeof(uint16_t));
|
||||
uint16_t *out = reinterpret_cast<uint16_t*>(outptr.get());
|
||||
std::unique_ptr<PixelType[]> outptr = std::make_unique<PixelType[]>(THUMB_SIZE * THUMB_SIZE * 4 * sizeof(qfloat16));
|
||||
F16 *out = reinterpret_cast<F16*>(outptr.get());
|
||||
|
||||
auto loop = [&](uint16_t *out, auto *in, auto scale)
|
||||
auto loop = [&](F16 *out, auto *in, float scale)
|
||||
{
|
||||
for(int i=0; i<THUMB_SIZE; i++)
|
||||
{
|
||||
@@ -426,7 +431,7 @@ void RawImage::convertToThumbnail()
|
||||
out[idx + 1] = in[idx2 + 1] * scale;;
|
||||
out[idx + 2] = in[idx2 + 2] * scale;;
|
||||
}
|
||||
out[idx + 3] = UINT16_MAX;
|
||||
out[idx + 3] = 1.0f;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -434,16 +439,19 @@ void RawImage::convertToThumbnail()
|
||||
switch(m_type)
|
||||
{
|
||||
case UINT8:
|
||||
loop(out, reinterpret_cast<uint8_t*>(m_pixels.get()), 256);
|
||||
loop(out, reinterpret_cast<uint8_t*>(m_pixels.get()), 1.0f/UINT8_MAX);
|
||||
break;
|
||||
case UINT16:
|
||||
loop(out, reinterpret_cast<uint16_t*>(m_pixels.get()), 1);
|
||||
loop(out, reinterpret_cast<uint16_t*>(m_pixels.get()), 1.0f/UINT16_MAX);
|
||||
break;
|
||||
case UINT32:
|
||||
loop(out, reinterpret_cast<uint32_t*>(m_pixels.get()), UINT16_MAX/(float)UINT32_MAX);
|
||||
loop(out, reinterpret_cast<uint32_t*>(m_pixels.get()), (float)(1.0/UINT32_MAX));
|
||||
break;
|
||||
case FLOAT16:
|
||||
loop(out, reinterpret_cast<F16*>(m_pixels.get()), 1.0f);
|
||||
break;
|
||||
case FLOAT32:
|
||||
loop(out, reinterpret_cast<float*>(m_pixels.get()), 65535.0);
|
||||
loop(out, reinterpret_cast<float*>(m_pixels.get()), 1.0f);
|
||||
break;
|
||||
default:
|
||||
qWarning() << "FLOAT64 should not happend";
|
||||
@@ -455,7 +463,7 @@ void RawImage::convertToThumbnail()
|
||||
m_height = THUMB_SIZE;
|
||||
m_ch = 4;
|
||||
m_channels = 3;
|
||||
m_type = UINT16;
|
||||
m_type = FLOAT16;
|
||||
}
|
||||
|
||||
void RawImage::convertToGLFormat()
|
||||
@@ -483,6 +491,17 @@ void RawImage::convertToGLFormat()
|
||||
for(size_t i = 0; i < s; i++)
|
||||
dst[i] = src[i];
|
||||
}
|
||||
else if(OpenGLES && m_type == UINT16)
|
||||
{
|
||||
m_original = std::move(m_pixels);
|
||||
allocate(m_width, m_height, m_channels, FLOAT16);
|
||||
m_origType = UINT16;
|
||||
F16 *dst = reinterpret_cast<F16*>(m_pixels.get());
|
||||
uint16_t *src = reinterpret_cast<uint16_t*>(m_original.get());
|
||||
|
||||
for(size_t i = 0; i < s; i++)
|
||||
dst[i] = src[i] / (float)UINT16_MAX;
|
||||
}
|
||||
}
|
||||
|
||||
float RawImage::thumbAspect() const
|
||||
@@ -571,6 +590,21 @@ bool RawImage::pixel(int x, int y, double &r, double &g, double &b) const
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FLOAT16:
|
||||
{
|
||||
const F16 *v = static_cast<const F16*>(origData(y, x));
|
||||
if(m_channels == 1)
|
||||
{
|
||||
r = g = b = *v;
|
||||
}
|
||||
else
|
||||
{
|
||||
r = v[0];
|
||||
g = v[1];
|
||||
b = v[2];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user