Skip to content

Commit

Permalink
SHERLOCK: bit of work on 3DO graphic resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Kiewitz committed Jun 8, 2015
1 parent 26ed795 commit ae64cca
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 14 deletions.
54 changes: 43 additions & 11 deletions engines/sherlock/resources.cpp
Expand Up @@ -600,6 +600,39 @@ ImageFile3DO::~ImageFile3DO() {
}

void ImageFile3DO::load(Common::SeekableReadStream &stream, bool animImages) {
uint32 headerId = stream.readUint32BE();

// Sekk back to the start
stream.seek(0);

// Identify type of file
switch (headerId) {
case MKTAG('C', 'C', 'B', ' '):
// .cel file (title1a.cel etc.)
load3DOCelFile(stream);
break;

case MKTAG('A', 'N', 'I', 'M'):
// 3DO animation file (walk.anim)
break;

default:
// Sherlock animation file (.3da files)
loadAnimationFile(stream, animImages);
break;
}
}

// 3DO uses RGB555, we use RGB565 internally so that more platforms are able to run us
inline uint16 ImageFile3DO::convertPixel(uint16 pixel3DO) {
byte red = (pixel3DO >> 10) & 0x1F;
byte green = (pixel3DO >> 5) & 0x1F;
byte blue = pixel3DO & 0x1F;;

return ((red << 11) | (green << 6) | (blue));
}

void ImageFile3DO::loadAnimationFile(Common::SeekableReadStream &stream, bool animImages) {
int streamSize = stream.size();
uint32 compressedSize = 0;

Expand Down Expand Up @@ -635,23 +668,18 @@ void ImageFile3DO::load(Common::SeekableReadStream &stream, bool animImages) {
// Load data for frame and decompress it
byte *data = new byte[compressedSize];
stream.read(data, compressedSize);
decompressFrame(&stream, frame, data);
decompressAnimationFrame(&stream, frame, data);
delete[] data;

push_back(frame);
}
}

// 3DO uses RGB555, we use RGB565 internally so that more platforms are able to run us
inline uint16 ImageFile3DO::convertPixel(uint16 pixel3DO) {
byte red = (pixel3DO >> 10) & 0x1F;
byte green = (pixel3DO >> 5) & 0x1F;
byte blue = pixel3DO & 0x1F;;

return ((red << 11) | (green << 6) | (blue));
}

void ImageFile3DO::decompressFrame(Common::SeekableReadStream *stream, ImageFrame &frame, const byte *src) {
// Decompresses an animation frame of a .3DA file
// note: the .3DA files seem to use an "in memory" format, which uses the same compression technique
// as regular 3DO cel files, but every scanline is started with a length UINT16 and each scanline
// also starts on UINT32 boundaries
void ImageFile3DO::decompressAnimationFrame(Common::SeekableReadStream *stream, ImageFrame &frame, const byte *src) {
frame._frame.create(frame._width, frame._height, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
uint16 *dest = (uint16 *)frame._frame.getPixels();
Common::fill(dest, dest + frame._width * frame._height, 0);
Expand Down Expand Up @@ -722,4 +750,8 @@ void ImageFile3DO::decompressFrame(Common::SeekableReadStream *stream, ImageFram
}
}

void ImageFile3DO::load3DOCelFile(Common::SeekableReadStream &stream) {
warning("3DO-cel file loader currently missing");
}

} // End of namespace Sherlock
19 changes: 16 additions & 3 deletions engines/sherlock/resources.h
Expand Up @@ -232,12 +232,25 @@ class ImageFile3DO : public Common::Array<ImageFrame> {
void load(Common::SeekableReadStream &stream, bool animImages);

/**
* Decompress a single frame for the sprite
* convert pixel RGB values from RGB555 to RGB565
*/
void decompressFrame(Common::SeekableReadStream *stream, ImageFrame &frame, const byte *src);

inline uint16 convertPixel(uint16 pixel3DO);

/**
* Load 3DO cel file
*/
void load3DOCelFile(Common::SeekableReadStream &stream);

/**
* Load animation graphics file
*/
void loadAnimationFile(Common::SeekableReadStream &stream, bool animImages);

/**
* Decompress a single frame for the sprite
*/
void decompressAnimationFrame(Common::SeekableReadStream *stream, ImageFrame &frame, const byte *src);

public:
ImageFile3DO(const Common::String &name, bool animImages = false);
ImageFile3DO(Common::SeekableReadStream &stream);
Expand Down

0 comments on commit ae64cca

Please sign in to comment.