fixed bug that sometimes alpha channel was not read in,

code improvement = performance,
This commit is contained in:
Anakin 2017-01-30 16:54:35 +01:00
parent 4342260e6d
commit 37e9b86daa
3 changed files with 8 additions and 10 deletions

View File

@ -3,7 +3,6 @@
#include <QImage>
#include <QColor>
#include "..\Header\Profiler.h"
QImage loadTga(QString filePath, bool &success)
{
@ -47,7 +46,7 @@ QImage loadTga(QString filePath, bool &success)
// jump to the data block
fsPicture.seekg(ui32IDLength + ui32PaletteLength, std::ios_base::cur);
img = QImage(ui32Width, ui32Height, ui32BpP == 32? QImage::Format_RGBA8888 : QImage::Format_RGB888);
img = QImage(ui32Width, ui32Height, QImage::Format_RGBA8888);
// uncompressed
if (ui32PicType == 2 && (ui32BpP == 24 || ui32BpP == 32))
@ -63,8 +62,11 @@ QImage loadTga(QString filePath, bool &success)
int valr = vui8Pixels.at(y * ui32Width * ui32BpP / 8 + x * ui32BpP / 8 + 2);
int valg = vui8Pixels.at(y * ui32Width * ui32BpP / 8 + x * ui32BpP / 8 + 1);
int valb = vui8Pixels.at(y * ui32Width * ui32BpP / 8 + x * ui32BpP / 8);
int vala = 255;
if (ui32BpP == 32)
vala = vui8Pixels.at(y * ui32Width * ui32BpP / 8 + x * ui32BpP / 8 + 3);
QColor value(valr, valg, valb);
QColor value(valr, valg, valb, vala);
img.setPixel(x, ui32Width - 1 - y, value.rgba());
}
}
@ -93,7 +95,7 @@ QImage loadTga(QString filePath, bool &success)
if (ui32BpP == 32)
color.setRgba(qRgba(tempData[2], tempData[1], tempData[0], tempData[3]));
else
color.setRgb(qRgb(tempData[2], tempData[1], tempData[0]));
color.setRgba(qRgba(tempData[2], tempData[1], tempData[0], 255));
img.setPixel(tmp_pixelIndex % ui32Width, ui32Height - 1 - (tmp_pixelIndex / ui32Width), color.rgba());
tmp_pixelIndex++;
@ -113,7 +115,7 @@ QImage loadTga(QString filePath, bool &success)
if (ui32BpP == 32)
color.setRgba(qRgba(tempData[2], tempData[1], tempData[0], tempData[3]));
else
color.setRgb(qRgb(tempData[2], tempData[1], tempData[0]));
color.setRgba(qRgba(tempData[2], tempData[1], tempData[0], 255));
img.setPixel(tmp_pixelIndex % ui32Width, ui32Height - 1 - (tmp_pixelIndex / ui32Width), color.rgba());
tmp_pixelIndex++;
@ -125,14 +127,12 @@ QImage loadTga(QString filePath, bool &success)
else
{
fsPicture.close();
img = QImage(1, 1, QImage::Format_RGB32);
img.fill(Qt::red);
success = false;
return img;
}
fsPicture.close();
success = true;
return img;
}

View File

@ -5,7 +5,6 @@
#include "..\Header\OutputDevice.h"
#include <QRegExp>
#include "../Header/Profiler.h"
/////////////////////////////////////////////////////////////////////////
// constructor/destructor

View File

@ -3,7 +3,6 @@
#include "..\Header\OutputDevice.h"
#include <QColor>
#include "..\Header\Profiler.h"
// helper function to save data from file to any variable type
#define F2V(variableName) reinterpret_cast<char*>(&variableName)