Skip to content

Commit a222bae

Browse files
committed
support PCX images
1 parent 7d14043 commit a222bae

File tree

12 files changed

+741
-26
lines changed

12 files changed

+741
-26
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ set(PROJECT_SOURCES
6868
source/d1pal.h
6969
source/d1palhits.cpp
7070
source/d1palhits.h
71+
source/d1pcx.cpp
72+
source/d1pcx.h
7173
source/d1sol.cpp
7274
source/d1sol.h
7375
source/d1til.cpp

source/celview.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <QMimeData>
1313

1414
#include "config.h"
15+
#include "d1pcx.h"
1516
#include "mainwindow.h"
1617
#include "progressdialog.h"
1718
#include "ui_celview.h"
@@ -183,13 +184,19 @@ CelView::~CelView()
183184
delete celScene;
184185
}
185186

186-
void CelView::initialize(D1Gfx *g)
187+
void CelView::initialize(D1Pal *p, D1Gfx *g)
187188
{
189+
this->pal = p;
188190
this->gfx = g;
189191

190192
this->update();
191193
}
192194

195+
void CelView::setPal(D1Pal *p)
196+
{
197+
this->pal = p;
198+
}
199+
193200
void CelView::update()
194201
{
195202
// Displaying CEL file path information
@@ -258,6 +265,19 @@ void CelView::insertImageFiles(IMAGE_FILE_MODE mode, const QStringList &imagefil
258265

259266
void CelView::insertFrame(IMAGE_FILE_MODE mode, int index, const QString &imagefilePath)
260267
{
268+
if (imagefilePath.toLower().endsWith(".pcx")) {
269+
bool wasModified = this->gfx->isModified();
270+
bool clipped, palMod;
271+
D1GfxFrame *frame = this->gfx->insertFrame(index, &clipped);
272+
if (!D1Pcx::load(*frame, imagefilePath, clipped, this->pal, this->gfx->getPalette(), &palMod)) {
273+
this->gfx->removeFrame(index);
274+
this->gfx->setModified(wasModified);
275+
} else if (palMod) {
276+
// update the palette
277+
emit this->palModified();
278+
}
279+
return;
280+
}
261281
QImageReader reader = QImageReader(imagefilePath);
262282
int numImages = 0;
263283

source/celview.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ class CelView : public QWidget {
6363
explicit CelView(QWidget *parent = nullptr);
6464
~CelView();
6565

66-
void initialize(D1Gfx *gfx);
66+
void initialize(D1Pal *pal, D1Gfx *gfx);
67+
void setPal(D1Pal *pal);
68+
6769
int getCurrentFrameIndex();
6870
void framePixelClicked(unsigned x, unsigned y);
6971
void insertImageFiles(IMAGE_FILE_MODE mode, const QStringList &imagefilePaths, bool append);
@@ -77,6 +79,7 @@ class CelView : public QWidget {
7779
signals:
7880
void frameRefreshed();
7981
void pixelClicked(const D1GfxPixel &pixel);
82+
void palModified();
8083

8184
private:
8285
void update();
@@ -120,6 +123,7 @@ private slots:
120123
Ui::CelView *ui;
121124
CelScene *celScene;
122125

126+
D1Pal *pal;
123127
D1Gfx *gfx;
124128
int currentGroupIndex = 0;
125129
int currentFrameIndex = 0;

source/d1gfx.cpp

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ void D1GfxFrame::setFrameType(D1CEL_FRAME_TYPE type)
7171
this->frameType = type;
7272
}
7373

74+
void D1GfxFrame::addPixelLine(QList<D1GfxPixel> &pixelLine)
75+
{
76+
this->pixels.append(pixelLine);
77+
this->height++;
78+
/* if (this->width != pixelLine.size()) {
79+
if (this->width != 0) {
80+
dProgressErr() << QString("Mismatching lines.");
81+
}*/
82+
if (this->width == 0) {
83+
this->width = pixelLine.size();
84+
}
85+
}
86+
7487
bool D1Gfx::isFrameSizeConstant()
7588
{
7689
if (this->frames.isEmpty()) {
@@ -119,20 +132,26 @@ QImage D1Gfx::getFrameImage(quint16 frameIndex)
119132
return image;
120133
}
121134

122-
D1GfxFrame *D1Gfx::insertFrame(int idx, const QImage &image)
135+
D1GfxFrame *D1Gfx::insertFrame(int idx, bool *clipped)
123136
{
124-
bool clipped;
125-
126137
if (!this->frames.isEmpty()) {
127-
clipped = this->frames[0].isClipped();
138+
*clipped = this->frames[0].isClipped();
128139
} else {
129-
clipped = this->type == D1CEL_TYPE::V2_MONO_GROUP || this->type == D1CEL_TYPE::V2_MULTIPLE_GROUPS;
140+
*clipped = this->type == D1CEL_TYPE::V2_MONO_GROUP || this->type == D1CEL_TYPE::V2_MULTIPLE_GROUPS;
130141
}
131142

132-
D1GfxFrame frame;
133-
D1ImageFrame::load(frame, image, clipped, this->palette);
134-
this->frames.insert(idx, frame);
143+
this->frames.insert(idx, D1GfxFrame());
135144
this->modified = true;
145+
return &this->frames[idx];
146+
}
147+
148+
D1GfxFrame *D1Gfx::insertFrame(int idx, const QImage &image)
149+
{
150+
bool clipped;
151+
152+
D1GfxFrame *frame = this->insertFrame(idx, &clipped);
153+
D1ImageFrame::load(*frame, image, clipped, this->palette);
154+
// this->modified = true;
136155

137156
if (this->groupFrameIndices.isEmpty()) {
138157
// create new group if this is the first frame
@@ -213,9 +232,9 @@ bool D1Gfx::isModified() const
213232
return this->modified;
214233
}
215234

216-
void D1Gfx::setModified()
235+
void D1Gfx::setModified(bool modified)
217236
{
218-
this->modified = true;
237+
this->modified = modified;
219238
}
220239

221240
bool D1Gfx::isUpscaled() const
@@ -234,6 +253,11 @@ QString D1Gfx::getFilePath() const
234253
return this->gfxFilePath;
235254
}
236255

256+
D1Pal *D1Gfx::getPalette()
257+
{
258+
return this->palette;
259+
}
260+
237261
void D1Gfx::setPalette(D1Pal *pal)
238262
{
239263
this->palette = pal;
@@ -265,6 +289,12 @@ D1GfxFrame *D1Gfx::getFrame(int frameIndex) const
265289
return const_cast<D1GfxFrame *>(&this->frames[frameIndex]);
266290
}
267291

292+
void D1Gfx::setFrame(int frameIndex, const D1GfxFrame &frame)
293+
{
294+
this->frames[frameIndex] = frame;
295+
this->modified = true;
296+
}
297+
268298
int D1Gfx::getFrameWidth(int frameIndex) const
269299
{
270300
if (frameIndex < 0 || frameIndex >= this->frames.count())

source/d1gfx.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class D1GfxFrame {
4242
friend class D1CelTileset;
4343
friend class D1CelTilesetFrame;
4444
friend class D1ImageFrame;
45+
friend class D1Pcx;
4546
friend class Upscaler;
4647

4748
public:
@@ -54,6 +55,7 @@ class D1GfxFrame {
5455
bool isClipped() const;
5556
D1CEL_FRAME_TYPE getFrameType() const;
5657
void setFrameType(D1CEL_FRAME_TYPE type);
58+
void addPixelLine(QList<D1GfxPixel> &pixelLine);
5759

5860
protected:
5961
int width = 0;
@@ -88,6 +90,7 @@ class D1Gfx : public QObject {
8890

8991
bool isFrameSizeConstant();
9092
QImage getFrameImage(quint16 frameIndex);
93+
D1GfxFrame *insertFrame(int frameIndex, bool *clipped);
9194
D1GfxFrame *insertFrame(int frameIndex, const QImage &image);
9295
D1GfxFrame *replaceFrame(int frameIndex, const QImage &image);
9396
void removeFrame(quint16 frameIndex);
@@ -99,12 +102,14 @@ class D1Gfx : public QObject {
99102
void setUpscaled(bool upscaled);
100103
QString getFilePath() const;
101104
bool isModified() const;
102-
void setModified();
105+
void setModified(bool modified = true);
106+
D1Pal *getPalette();
103107
void setPalette(D1Pal *pal);
104108
int getGroupCount() const;
105109
QPair<quint16, quint16> getGroupFrameIndices(int groupIndex) const;
106110
int getFrameCount() const;
107111
D1GfxFrame *getFrame(int frameIndex) const;
112+
void setFrame(int frameIndex, const D1GfxFrame &frame);
108113
int getFrameWidth(int frameIndex) const;
109114
int getFrameHeight(int frameIndex) const;
110115
bool setFrameType(int frameIndex, D1CEL_FRAME_TYPE frameType);

source/d1pal.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77

88
#include "config.h"
99

10+
D1Pal::D1Pal(const D1Pal &opal)
11+
: QObject()
12+
{
13+
this->palFilePath = opal.palFilePath;
14+
this->modified = opal.modified;
15+
this->undefinedColor = opal.undefinedColor;
16+
this->currentCycleCounter = opal.currentCycleCounter;
17+
this->updateColors(opal);
18+
}
19+
1020
bool D1Pal::load(QString filePath)
1121
{
1222
QFile file = QFile(filePath);
@@ -170,6 +180,13 @@ void D1Pal::setColor(quint8 index, QColor color)
170180
this->modified = true;
171181
}
172182

183+
void D1Pal::updateColors(const D1Pal &opal)
184+
{
185+
for (int i = 0; i < D1PAL_COLORS; i++) {
186+
this->colors[i] = opal.colors[i];
187+
}
188+
}
189+
173190
void D1Pal::cycleColors(D1PAL_CYCLE_TYPE type)
174191
{
175192
QColor celColor;

source/d1pal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class D1Pal : public QObject {
2424
static constexpr const char *DEFAULT_NAME = "_default.pal";
2525

2626
D1Pal() = default;
27+
D1Pal(const D1Pal &opal);
2728
~D1Pal() = default;
2829

2930
bool load(QString path);
@@ -39,6 +40,7 @@ class D1Pal : public QObject {
3940
QColor getColor(quint8 index);
4041
void setColor(quint8 index, QColor);
4142

43+
void updateColors(const D1Pal &opal);
4244
void cycleColors(D1PAL_CYCLE_TYPE type);
4345

4446
private:

0 commit comments

Comments
 (0)