Commit 44e36b8b authored by Anakin's avatar Anakin

trying to fix the 2xEmit bug,

write directly mirrored to the image,
parent 1d5d20cf
......@@ -54,7 +54,7 @@ public:
MainWindow* tmp = dynamic_cast<MainWindow*>(parent->parent()->parent());
if(tmp != NULL)
connect(this, SIGNAL(sendMessage(QString, int)), tmp, SLOT(showMessage(QString, int)));
connect(this, SIGNAL(sendMessage(QString, int)), tmp, SLOT(printMessage(QString, int)));
};
......
......@@ -21,7 +21,7 @@ private slots:
void aboutTool();
public slots:
void showMessage(QString message, int severity);
void printMessage(QString message, int severity);
signals:
void loadFile(const char*);
......
......@@ -22,19 +22,14 @@ QImage loadTga(const char* filePath, bool &success)
return img;
}
// some variables
std::vector<std::uint8_t>* vui8Pixels;
std::uint32_t ui32BpP;
std::uint32_t ui32Width;
std::uint32_t ui32Height;
// read in the header
std::uint8_t ui8x18Header[19] = { 0 };
fsPicture.read(reinterpret_cast<char*>(&ui8x18Header), sizeof(ui8x18Header) - 1);
//get variables
vui8Pixels = new std::vector<std::uint8_t>;
bool bCompressed;
std::uint32_t ui32BpP;
std::uint32_t ui32Width;
std::uint32_t ui32Height;
std::uint32_t ui32IDLength;
std::uint32_t ui32PicType;
std::uint32_t ui32PaletteLength;
......@@ -50,22 +45,38 @@ QImage loadTga(const char* filePath, bool &success)
// calculate some more information
ui32Size = ui32Width * ui32Height * ui32BpP / 8;
bCompressed = ui32PicType == 9 || ui32PicType == 10;
vui8Pixels->resize(ui32Size);
// 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);
// uncompressed
if (ui32PicType == 2 && (ui32BpP == 24 || ui32BpP == 32))
{
fsPicture.read(reinterpret_cast<char*>(vui8Pixels->data()), ui32Size);
std::vector<std::uint8_t> vui8Pixels;
vui8Pixels.resize(ui32Size);
fsPicture.read(reinterpret_cast<char*>(vui8Pixels.data()), ui32Size);
for (unsigned int y = 0; y < ui32Height; y++)
{
for (unsigned int x = 0; x < ui32Width; x++)
{
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);
QColor value(valr, valg, valb);
img.setPixelColor(x, ui32Width - 1 - y, value);
}
}
}
// else if compressed 24 or 32 bit
else if (ui32PicType == 10 && (ui32BpP == 24 || ui32BpP == 32)) // compressed
{
std::uint8_t tempChunkHeader;
std::uint8_t tempData[5];
unsigned int tempByteIndex = 0;
unsigned int tmp_pixelIndex = 0;
do {
fsPicture.read(reinterpret_cast<char*>(&tempChunkHeader), sizeof(tempChunkHeader));
......@@ -79,10 +90,15 @@ QImage loadTga(const char* filePath, bool &success)
for (int i = 0; i <= tempChunkHeader; i++)
{
vui8Pixels->at(tempByteIndex++) = tempData[0];
vui8Pixels->at(tempByteIndex++) = tempData[1];
vui8Pixels->at(tempByteIndex++) = tempData[2];
if (ui32BpP == 32) vui8Pixels->at(tempByteIndex++) = tempData[3];
QColor color;
if (ui32BpP == 32)
color.setRgba(qRgba(tempData[2], tempData[1], tempData[0], tempData[3]));
else
color.setRgb(qRgb(tempData[2], tempData[1], tempData[0]));
img.setPixelColor(tmp_pixelIndex % ui32Width, ui32Height - 1 - (tmp_pixelIndex / ui32Width), color);
tmp_pixelIndex++;
}
}
else // data count
......@@ -94,13 +110,18 @@ QImage loadTga(const char* filePath, bool &success)
{
fsPicture.read(reinterpret_cast<char*>(&tempData), ui32BpP / 8);
vui8Pixels->at(tempByteIndex++) = tempData[0];
vui8Pixels->at(tempByteIndex++) = tempData[1];
vui8Pixels->at(tempByteIndex++) = tempData[2];
if (ui32BpP == 32) vui8Pixels->at(tempByteIndex++) = tempData[3];
QColor color;
if (ui32BpP == 32)
color.setRgba(qRgba(tempData[2], tempData[1], tempData[0], tempData[3]));
else
color.setRgb(qRgb(tempData[2], tempData[1], tempData[0]));
img.setPixelColor(tmp_pixelIndex % ui32Width, ui32Height - 1 - (tmp_pixelIndex / ui32Width), color);
tmp_pixelIndex++;
}
}
} while (tempByteIndex < ui32Size);
} while (tmp_pixelIndex < (ui32Width * ui32Height));
}
// not useable format
else
......@@ -113,26 +134,6 @@ QImage loadTga(const char* filePath, bool &success)
}
fsPicture.close();
img = QImage(ui32Width, ui32Height, QImage::Format_RGB888);
int pixelSize = ui32BpP == 32 ? 4 : 3;
//TODO: write direct into img
for (unsigned int x = 0; x < ui32Width; x++)
{
for (unsigned int y = 0; y < ui32Height; y++)
{
int valr = vui8Pixels->at(y * ui32Width * pixelSize + x * pixelSize + 2);
int valg = vui8Pixels->at(y * ui32Width * pixelSize + x * pixelSize + 1);
int valb = vui8Pixels->at(y * ui32Width * pixelSize + x * pixelSize);
QColor value(valr, valg, valb);
img.setPixelColor(x, y, value);
}
}
img = img.mirrored();
}
success = true;
return img;
......
......@@ -100,6 +100,8 @@ void GeometryEngine::loadFile(const char* filePath)
for(auto& it : *textureNames)
loadTexture(path.c_str(), it.c_str());
loadTexture("", "");
emit requestUpdate();
emit sendMessage("done..", 0);
}
......@@ -114,12 +116,13 @@ void GeometryEngine::loadTexture(const char* filePath, const char* fileName)
bool loadSuccess(false);
QImage img;
//if (!strcmp(fileName, ""))
//{
// img = QImage(1, 1, QImage::Format_RGB32);
// img.fill(Qt::red);
//}
//else
if (!strcmp(fileName, ""))
{
loadSuccess = true;
img = QImage(1, 1, QImage::Format_RGB32);
img.fill(Qt::red);
}
else
img = loadTga((std::string(filePath) + std::string(fileName)).c_str(), loadSuccess);
//TODO: emit if not successfull
......
......@@ -74,7 +74,7 @@ void MainWindow::aboutTool()
dialog->exec();
}
void MainWindow::showMessage(QString message, int severity)
void MainWindow::printMessage(QString message, int severity)
{
if (severity < m_curSeverity)
return;
......
......@@ -197,7 +197,7 @@ void OglViewerWidget::setConnections()
connect(m_dataEngine, &GeometryEngine::requestResetView, this, &OglViewerWidget::resetView);
connect(parentWidget(), SIGNAL(loadFile(const char*)), m_dataEngine, SLOT(loadFile(const char*)));
connect(this, SIGNAL(loadFile(const char*)), m_dataEngine, SLOT(loadFile(const char*)));
connect(m_dataEngine, SIGNAL(sendMessage(QString, int)), parentWidget(), SLOT(showMessage(QString, int)));
connect(m_dataEngine, SIGNAL(sendMessage(QString, int)), parentWidget(), SLOT(printMessage(QString, int)));
connect(m_dataEngine, SIGNAL(requestUpdate()), this, SLOT(update()));
}
......
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