aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreriktorbjorn2011-06-12 19:41:08 +0200
committerAlyssa Milburn2011-06-15 17:34:23 +0200
commit562f1ed8b89fa251f843ee2d8d6565429ea193d5 (patch)
treeb522a8d5c744be15da10d65ba02dafd7e39d5d41
parent3f53cb924463e37fac5973affa498f97569ba80c (diff)
downloadscummvm-rg350-562f1ed8b89fa251f843ee2d8d6565429ea193d5.tar.gz
scummvm-rg350-562f1ed8b89fa251f843ee2d8d6565429ea193d5.tar.bz2
scummvm-rg350-562f1ed8b89fa251f843ee2d8d6565429ea193d5.zip
DREAMWEB: Rewrite the PCX decoder i C++
-rw-r--r--engines/dreamweb/dreamweb.cpp144
1 files changed, 64 insertions, 80 deletions
diff --git a/engines/dreamweb/dreamweb.cpp b/engines/dreamweb/dreamweb.cpp
index 7e6e5e6a17..086aee2e9a 100644
--- a/engines/dreamweb/dreamweb.cpp
+++ b/engines/dreamweb/dreamweb.cpp
@@ -739,94 +739,78 @@ void readoneblock(Context &context) {
void readabyte(Context & context);
void showpcx(Context &context) {
- Graphics::Surface *s = g_system->lockScreen();
+ uint16 name_ptr = context.dx;
+ Common::String name;
+ uint8 c;
+ while((c = context.cs.byte(name_ptr++)) != 0)
+ name += (char)c;
- openfile(context);
- context.ds = context.data.word(kWorkspace);
- context.cx = 128;
- context.dx = 0;
- readfromfile(context);
+ Common::File pcxFile;
- context.ds = context.data.word(kWorkspace);
- context.si = 16;
- context.cx = 48;
- context.es = context.data.word(kBuffers);
- context.di = 0+(228*13)+32+60+(32*32)+(11*10*3)+768+768;
-
-pcxpal:
- context.push(context.cx);
- readabyte(context);
- context._shr(context.al, 1);
- context._shr(context.al, 1);
- context._stosb();
- context.cx = context.pop();
- if (--context.cx) goto pcxpal;
- context.cx = 768 - 48;
- context.ax = 0x0ffff;
- while (context.cx--) context._stosw();
- readoneblock(context);
- context.si = 0;
- context.di = 0;
- context.cx = 480;
-convertpcx:
- context.push(context.cx);
- context.push(context.di);
- context.ds = context.data.word(kWorkspace);
+ if (!pcxFile.open(name)) {
+ warning("showpcx: Could not open '%s'", name.c_str());
+ return;
+ }
+
+ uint8 *maingamepal;
+ int i, j;
+
+ // Read the 16-color palette into the 'maingamepal' buffer. Note that
+ // the color components have to be adjusted from 8 to 6 bits.
+
+ pcxFile.seek(16, SEEK_SET);
context.es = context.data.word(kBuffers);
- context.di = 0+(228*13)+32+60;
- context.bx = 0;
-
- uint8 *src = context.es.ptr(context.di, 320);
-
-sameline:
- readabyte(context);
- context.ah = context.al;
- context._and(context.ah, 0xc0);
- context._cmp(context.ah, 0xc0);
- if (!context.flags.z()) goto normal;
- context.cl = context.al;
- context._and(context.cl, 0x3f);
- context.ch = 0;
- context.push(context.cx);
- readabyte(context);
- context.cx = context.pop();
- context._add(context.bx, context.cx);
- while (context.cx--) context._stosb();
- context._cmp(context.bx, 4 * 80);
- if (!context.flags.z()) goto sameline;
- goto endline;
-normal:
- context._stosb();
- context._add(context.bx, 1);
- context._cmp(context.bx, 4 * 80);
- if (!context.flags.z()) goto sameline;
-
-endline:
- context.di = context.pop();
- context.cx = context.pop();
-
- assert((uint16)context.cx <= 480);
- uint8 *dst = (uint8 *)s->getBasePtr(0, 480 - (uint16)context.cx);
- memset(dst, 0, 640);
-
- for (int i = 0; i < 320; i++) {
- int plane = i / 80;
- int pos = i % 80;
-
- for (int j = 0; j < 8; j++) {
- byte bit = (src[i] >> (7 - j)) & 1;
- dst[8 * pos + j] |= (bit << plane);
- }
+ maingamepal = context.es.ptr(5946, 768);
+ pcxFile.read(maingamepal, 48);
+
+ memset(maingamepal + 48, 0xff, 720);
+ for (i = 0; i < 48; i++) {
+ maingamepal[i] >>= 2;
}
- if (--context.cx) goto convertpcx;
+ // Decode the image data.
- closefile(context);
+ Graphics::Surface *s = g_system->lockScreen();
+ Common::Rect rect(640, 480);
- g_system->unlockScreen();
+ s->fillRect(rect, 0);
+ pcxFile.seek(128, SEEK_SET);
+
+ for (int y = 0; y < 480; y++) {
+ byte *dst = (byte *)s->getBasePtr(0, y);
+ int decoded = 0;
+
+ while (decoded < 320) {
+ byte col = pcxFile.readByte();
+ byte len;
+
+ if ((col & 0xc0) == 0xc0) {
+ len = col & 0x3f;
+ col = pcxFile.readByte();
+ } else {
+ len = 1;
+ }
- // TODO: This is probably not the right place to do this
- g_system->updateScreen();
+ // The image uses 16 colors and is stored as four bit
+ // planes, one for each bit of the color, least
+ // significant bit plane first.
+
+ for (i = 0; i < len; i++) {
+ int plane = decoded / 80;
+ int pos = decoded % 80;
+
+ for (j = 0; j < 8; j++) {
+ byte bit = (col >> (7 - j)) & 1;
+ dst[8 * pos + j] |= (bit << plane);
+ }
+
+ decoded++;
+ }
+ }
+ }
+
+ g_system->unlockScreen();
+ pcxFile.close();
}
} /*namespace dreamgen */