void CEngine::toLineal2(bool in_bDelay)
{
int i = 0, j = 255;
uint uiR, uiG, uiB;
uint Yarr[256];
for (int t = 0; t < 256; t++) {
Yarr[t] = 0;
}
uint proc;
QImage imgNew(m_Image.width(), m_Image.height(), QImage::Format_RGB32);
uint uiPercent, uiQuantum = m_Image.width() * m_Image.height() / 100;
QRgb rgb = m_Image.pixel(0, 0);
proc = 5 * uiQuantum;
uint Ymin = 0.2125 * qRed(rgb) + 0.7154 * qGreen(rgb) + 0.0721 * qBlue(rgb), Ymax, Y;
Ymax = Ymin;
for (uint y = 0; y < m_Image.height(); ++y)
{
for (uint x = 0; x < m_Image.width(); ++x)
{
QRgb rgb = m_Image.pixel(x, y);
Y = 0.2125 * qRed(rgb) + 0.7154 * qGreen(rgb) + 0.0721 * qBlue(rgb);
Yarr[Y]++;
}
}
uint Summin = 0, Summax = 0;
while (proc > Summin) {
Summin += Yarr[i];
i++;
}
Ymin = Yarr[i - 1];
while (proc > Summax) {
Summax += Yarr[j];
j--;
}
Ymax = Yarr[j++];
Y = Ymax - Ymin;
for (uint y = 0; y < m_Image.height(); ++y)
{
for (uint x = 0; x < m_Image.width(); ++x)
{
QRgb rgb = m_Image.pixel(x, y);
uiR = (qRed(rgb) - Ymin) * 255 / Y;
uiG = (qGreen(rgb) - Ymin) * 255 / Y;
uiB = (qBlue(rgb) - Ymin) * 255 / Y;
if (uiR > 255) {
uiR = 255;
}
if (uiG > 255) {
uiG = 255;
}
if (uiB > 255) {
uiB = 255;
}
QRgb uirgb = qRgb(uiR, uiG, uiB);
imgNew.setPixel(x, y, uirgb);
uiPercent = y * m_Image.width() + x;
if (uiPercent % uiQuantum == 0 && m_fnCallback)
m_fnCallback(uiPercent / uiQuantum, m_pCallbackExtra);
}
if (in_bDelay) Sleep(5); //! only for emulation purposes
}
m_Image = imgNew;
if (m_fnCallback) m_fnCallback(100, m_pCallbackExtra);
}Add a code snippet to your website: www.paste.org