Skip to content

Commit

Permalink
DIRECTOR: Refactoring palette loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Iskrich authored and sev- committed Aug 3, 2016
1 parent acc0d70 commit 75a01e0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
41 changes: 19 additions & 22 deletions engines/director/dib.cpp
Expand Up @@ -28,6 +28,7 @@
#include "graphics/pixelformat.h"
#include "graphics/surface.h"
#include "image/codecs/codec.h"
#include "common/util.h"
#include "common/debug.h"

namespace Director {
Expand All @@ -48,39 +49,35 @@ void DIBDecoder::destroy() {

delete[] _palette;
_palette = 0;

_paletteColorCount = 0;

delete _codec;
_codec = 0;
}

void DIBDecoder::loadPalette(Common::SeekableReadStream &stream) {
uint16 palentries = 256;
_palette = new byte[1024];

uint16 size = stream.size();
uint16 index = 0;
for (int i = 6; i < stream.size() + 6; i+=6) {
uint16 n = size - i;
if (i >= palentries) {
break;
}
stream.seek(n + 4);
_palette[index] = stream.readByte();
++index;
stream.seek(n + 2);
_palette[index] = stream.readByte();
++index;
stream.seek(n);
_palette[index] = stream.readByte();
++index;
_palette[index] = 0;
++index;
uint16 steps = stream.size()/6;
uint16 index = (steps * 4) - 1;

for (uint8 i = 0; i < steps; i++) {
_palette[index--] = 0;

_palette[index--] = stream.readByte();
stream.readByte();

_palette[index--] = stream.readByte();
stream.readByte();

_palette[index--] = stream.readByte();
stream.readByte();
}

index = (steps * 4) - 1;

while (index < 1024) {
_palette[index] = 0;
++index;
_palette[index++] = 0;
}
}

Expand Down
6 changes: 3 additions & 3 deletions engines/director/director.cpp
Expand Up @@ -54,11 +54,11 @@ DirectorEngine::DirectorEngine(OSystem *syst, const DirectorGameDescription *gam
//FIXME
RIFFArchive riff;
riff.openFile("bookshelf_example.mmm");
Common::SeekableReadStream *dib = riff.getResource(1145651744, 1103);
Common::SeekableReadStream *pal = riff.getResource(1129076052, 1025);
Director::DIBDecoder img;
img.loadPalette(*pal);
Common::SeekableReadStream *dib = riff.getResource(MKTAG('D', 'I', 'B', ' '), 1103);
img.loadStream(*dib);
Common::SeekableReadStream *pal = riff.getResource(MKTAG('C', 'L', 'U', 'T'), 1025);
img.loadPalette(*pal);
}

DirectorEngine::~DirectorEngine() {
Expand Down

0 comments on commit 75a01e0

Please sign in to comment.