trying to fix the 2xEmit bug,
write directly mirrored to the image,
This commit is contained in:
parent
1d5d20cfb8
commit
44e36b8b0d
|
@ -54,7 +54,7 @@ public:
|
||||||
|
|
||||||
MainWindow* tmp = dynamic_cast<MainWindow*>(parent->parent()->parent());
|
MainWindow* tmp = dynamic_cast<MainWindow*>(parent->parent()->parent());
|
||||||
if(tmp != NULL)
|
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();
|
void aboutTool();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void showMessage(QString message, int severity);
|
void printMessage(QString message, int severity);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void loadFile(const char*);
|
void loadFile(const char*);
|
||||||
|
|
|
@ -22,19 +22,14 @@ QImage loadTga(const char* filePath, bool &success)
|
||||||
return img;
|
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
|
// read in the header
|
||||||
std::uint8_t ui8x18Header[19] = { 0 };
|
std::uint8_t ui8x18Header[19] = { 0 };
|
||||||
fsPicture.read(reinterpret_cast<char*>(&ui8x18Header), sizeof(ui8x18Header) - 1);
|
fsPicture.read(reinterpret_cast<char*>(&ui8x18Header), sizeof(ui8x18Header) - 1);
|
||||||
|
|
||||||
//get variables
|
//get variables
|
||||||
vui8Pixels = new std::vector<std::uint8_t>;
|
std::uint32_t ui32BpP;
|
||||||
bool bCompressed;
|
std::uint32_t ui32Width;
|
||||||
|
std::uint32_t ui32Height;
|
||||||
std::uint32_t ui32IDLength;
|
std::uint32_t ui32IDLength;
|
||||||
std::uint32_t ui32PicType;
|
std::uint32_t ui32PicType;
|
||||||
std::uint32_t ui32PaletteLength;
|
std::uint32_t ui32PaletteLength;
|
||||||
|
@ -50,22 +45,38 @@ QImage loadTga(const char* filePath, bool &success)
|
||||||
|
|
||||||
// calculate some more information
|
// calculate some more information
|
||||||
ui32Size = ui32Width * ui32Height * ui32BpP / 8;
|
ui32Size = ui32Width * ui32Height * ui32BpP / 8;
|
||||||
bCompressed = ui32PicType == 9 || ui32PicType == 10;
|
|
||||||
vui8Pixels->resize(ui32Size);
|
|
||||||
|
|
||||||
// jump to the data block
|
// jump to the data block
|
||||||
fsPicture.seekg(ui32IDLength + ui32PaletteLength, std::ios_base::cur);
|
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))
|
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 compressed 24 or 32 bit
|
||||||
else if (ui32PicType == 10 && (ui32BpP == 24 || ui32BpP == 32)) // compressed
|
else if (ui32PicType == 10 && (ui32BpP == 24 || ui32BpP == 32)) // compressed
|
||||||
{
|
{
|
||||||
std::uint8_t tempChunkHeader;
|
std::uint8_t tempChunkHeader;
|
||||||
std::uint8_t tempData[5];
|
std::uint8_t tempData[5];
|
||||||
unsigned int tempByteIndex = 0;
|
unsigned int tmp_pixelIndex = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
fsPicture.read(reinterpret_cast<char*>(&tempChunkHeader), sizeof(tempChunkHeader));
|
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++)
|
for (int i = 0; i <= tempChunkHeader; i++)
|
||||||
{
|
{
|
||||||
vui8Pixels->at(tempByteIndex++) = tempData[0];
|
QColor color;
|
||||||
vui8Pixels->at(tempByteIndex++) = tempData[1];
|
|
||||||
vui8Pixels->at(tempByteIndex++) = tempData[2];
|
if (ui32BpP == 32)
|
||||||
if (ui32BpP == 32) vui8Pixels->at(tempByteIndex++) = tempData[3];
|
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
|
else // data count
|
||||||
|
@ -94,13 +110,18 @@ QImage loadTga(const char* filePath, bool &success)
|
||||||
{
|
{
|
||||||
fsPicture.read(reinterpret_cast<char*>(&tempData), ui32BpP / 8);
|
fsPicture.read(reinterpret_cast<char*>(&tempData), ui32BpP / 8);
|
||||||
|
|
||||||
vui8Pixels->at(tempByteIndex++) = tempData[0];
|
QColor color;
|
||||||
vui8Pixels->at(tempByteIndex++) = tempData[1];
|
|
||||||
vui8Pixels->at(tempByteIndex++) = tempData[2];
|
if (ui32BpP == 32)
|
||||||
if (ui32BpP == 32) vui8Pixels->at(tempByteIndex++) = tempData[3];
|
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
|
// not useable format
|
||||||
else
|
else
|
||||||
|
@ -113,26 +134,6 @@ QImage loadTga(const char* filePath, bool &success)
|
||||||
}
|
}
|
||||||
|
|
||||||
fsPicture.close();
|
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;
|
success = true;
|
||||||
return img;
|
return img;
|
||||||
|
|
|
@ -100,6 +100,8 @@ void GeometryEngine::loadFile(const char* filePath)
|
||||||
for(auto& it : *textureNames)
|
for(auto& it : *textureNames)
|
||||||
loadTexture(path.c_str(), it.c_str());
|
loadTexture(path.c_str(), it.c_str());
|
||||||
|
|
||||||
|
loadTexture("", "");
|
||||||
|
|
||||||
emit requestUpdate();
|
emit requestUpdate();
|
||||||
emit sendMessage("done..", 0);
|
emit sendMessage("done..", 0);
|
||||||
}
|
}
|
||||||
|
@ -114,12 +116,13 @@ void GeometryEngine::loadTexture(const char* filePath, const char* fileName)
|
||||||
bool loadSuccess(false);
|
bool loadSuccess(false);
|
||||||
QImage img;
|
QImage img;
|
||||||
|
|
||||||
//if (!strcmp(fileName, ""))
|
if (!strcmp(fileName, ""))
|
||||||
//{
|
{
|
||||||
// img = QImage(1, 1, QImage::Format_RGB32);
|
loadSuccess = true;
|
||||||
// img.fill(Qt::red);
|
img = QImage(1, 1, QImage::Format_RGB32);
|
||||||
//}
|
img.fill(Qt::red);
|
||||||
//else
|
}
|
||||||
|
else
|
||||||
img = loadTga((std::string(filePath) + std::string(fileName)).c_str(), loadSuccess);
|
img = loadTga((std::string(filePath) + std::string(fileName)).c_str(), loadSuccess);
|
||||||
|
|
||||||
//TODO: emit if not successfull
|
//TODO: emit if not successfull
|
||||||
|
|
|
@ -74,7 +74,7 @@ void MainWindow::aboutTool()
|
||||||
dialog->exec();
|
dialog->exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showMessage(QString message, int severity)
|
void MainWindow::printMessage(QString message, int severity)
|
||||||
{
|
{
|
||||||
if (severity < m_curSeverity)
|
if (severity < m_curSeverity)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -197,7 +197,7 @@ void OglViewerWidget::setConnections()
|
||||||
connect(m_dataEngine, &GeometryEngine::requestResetView, this, &OglViewerWidget::resetView);
|
connect(m_dataEngine, &GeometryEngine::requestResetView, this, &OglViewerWidget::resetView);
|
||||||
connect(parentWidget(), SIGNAL(loadFile(const char*)), m_dataEngine, SLOT(loadFile(const char*)));
|
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(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()));
|
connect(m_dataEngine, SIGNAL(requestUpdate()), this, SLOT(update()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue