From fc9f78f1a851d6aa01d21fe58639ff99e9f5654a Mon Sep 17 00:00:00 2001 From: pionere Date: Thu, 26 Jan 2023 17:08:29 +0100 Subject: [PATCH] support PCX images II. --- source/celview.cpp | 20 ++++++++++++++++++++ source/d1gfx.cpp | 24 +++++++++++++----------- source/mainwindow.cpp | 4 ++-- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/source/celview.cpp b/source/celview.cpp index 98916289..004a05fc 100644 --- a/source/celview.cpp +++ b/source/celview.cpp @@ -305,6 +305,26 @@ void CelView::insertFrame(IMAGE_FILE_MODE mode, int index, const QString &imagef void CelView::replaceCurrentFrame(const QString &imagefilePath) { + if (imagefilePath.toLower().endsWith(".pcx")) { + bool clipped = this->gfx->getFrame(this->currentFrameIndex)->isClipped(), palMod; + D1GfxFrame frame; + bool success = D1Pcx::load(frame, imagefilePath, clipped, this->pal, this->gfx->getPalette(), &palMod); + if (!success) { + dProgressFail() << tr("Failed to load file: %1.").arg(imagefilePath); + return; + } + this->gfx->setFrame(this->currentFrameIndex, frame); + + if (palMod) { + // update the palette + emit this->palModified(); + } + // update the view + this->update(); + this->displayFrame(); + return; + } + QImage image = QImage(imagefilePath); if (image.isNull()) { diff --git a/source/d1gfx.cpp b/source/d1gfx.cpp index 755f5267..e28c5472 100644 --- a/source/d1gfx.cpp +++ b/source/d1gfx.cpp @@ -141,17 +141,6 @@ D1GfxFrame *D1Gfx::insertFrame(int idx, bool *clipped) } this->frames.insert(idx, D1GfxFrame()); - this->modified = true; - return &this->frames[idx]; -} - -D1GfxFrame *D1Gfx::insertFrame(int idx, const QImage &image) -{ - bool clipped; - - D1GfxFrame *frame = this->insertFrame(idx, &clipped); - D1ImageFrame::load(*frame, image, clipped, this->palette); - // this->modified = true; if (this->groupFrameIndices.isEmpty()) { // create new group if this is the first frame @@ -170,6 +159,19 @@ D1GfxFrame *D1Gfx::insertFrame(int idx, const QImage &image) this->groupFrameIndices[i].second++; } } + + this->modified = true; + return &this->frames[idx]; +} + +D1GfxFrame *D1Gfx::insertFrame(int idx, const QImage &image) +{ + bool clipped; + + D1GfxFrame *frame = this->insertFrame(idx, &clipped); + D1ImageFrame::load(*frame, image, clipped, this->palette); + // this->modified = true; + return &this->frames[idx]; } diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index 36c30666..4d8da6e1 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -961,8 +961,8 @@ static QString imageNameFilter() } } // add PCX support - allSupportedFormats.append(".pcx"); - allSupportedFormats.append(".PCX"); + allSupportedFormats.append("*.pcx"); + allSupportedFormats.append("*.PCX"); QString allSupportedFormatsFilter = QApplication::tr("Image files (%1)").arg(allSupportedFormats.join(' ')); return allSupportedFormatsFilter;