Commit 37e9b86d authored by Anakin's avatar Anakin

fixed bug that sometimes alpha channel was not read in,

code improvement = performance,
parent 4342260e
......@@ -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;
}
......@@ -5,7 +5,6 @@
#include "..\Header\OutputDevice.h"
#include <QRegExp>
#include "../Header/Profiler.h"
/////////////////////////////////////////////////////////////////////////
// constructor/destructor
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment