[Scummvm-cvs-logs] CVS: residual smush.cpp,1.17,1.18 smush.h,1.4,1.5
James Brown
ender at users.sourceforge.net
Sun Feb 1 05:02:02 CET 2004
- Previous message: [Scummvm-cvs-logs] CVS: residual debug.cpp,1.2,1.3 debug.h,1.2,1.3 smush.cpp,1.16,1.17
- Next message: [Scummvm-cvs-logs] CVS: residual smush.cpp,1.18,1.19 smush.h,1.5,1.6
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/scummvm/residual
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13023
Modified Files:
smush.cpp smush.h
Log Message:
Sync some currently experimental SMUSH code
Index: smush.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/smush.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- smush.cpp 1 Feb 2004 12:38:33 -0000 1.17
+++ smush.cpp 1 Feb 2004 12:59:24 -0000 1.18
@@ -149,8 +149,10 @@
free(f_header);
}
-void Smush::setupAnim(const char *file, const char *directory) {
- _file.open(file, directory);
+bool Smush::setupAnim(const char *file, const char *directory) {
+ if (!_file.open(file))
+ return false;
+
uint32 tag;
int32 size;
@@ -165,10 +167,16 @@
_nbframes = READ_LE_UINT32(s_header + 2);
_width = READ_LE_UINT16(s_header + 8);
_height = READ_LE_UINT16(s_header + 10);
- if ((_width != 640) || (_height != 480))
- error("resolution of smush frame other than 640x480 not supported");
+
+ if ((_width != 640) || (_height != 480)) {
+ warning("resolution of smush frame other than 640x480 not supported");
+ return false;
+ }
+
_speed = READ_LE_UINT32(s_header + 14);
free(s_header);
+
+ return true;
}
void Smush::play(const char *filename, const char *directory) {
@@ -249,17 +257,9 @@
warning("Smush::play() Open okay for %s!\n", filename);
}
- // Verify the specified file exists
- File f;
- f.open(tmpOut, NULL);
- if (!f.isOpen()) {
- warning("Smush::play() File not found %s", filename);
- return;
- }
- f.close();
-
// Load the video
- setupAnim(tmpOut, directory);
+ if (!setupAnim(tmpOut, directory))
+ return;
handleFramesHeader();
SDL_Surface* image;
@@ -524,3 +524,203 @@
uint32 a = readUint16BE();
return (b << 16) | a;
}
+///////////////////////////////////
+
+zlibFile::zlibFile() {
+ _handle = NULL;
+ usedBuffer = 0;
+}
+
+zlibFile::~zlibFile() {
+ close();
+}
+
+bool zlibFile::open(const char *filename) {
+ char flags = 0;
+
+ if (_handle) {
+ warning("File %s already opened", filename);
+ return false;
+ }
+
+ if (filename == NULL || *filename == 0)
+ return false;
+
+ _handle = ResourceLoader::instance()->openNewStream(filename);
+ if (!_handle) {
+ warning("zlibFile %s not found", filename);
+ return false;
+ }
+
+ warning("zlibFile %s opening...", filename);
+
+ // Read in the GZ header
+ fread(inBuf, 4, sizeof(char), _handle); // Header, Method, Flags
+ flags = inBuf[4];
+ fread(inBuf, 6, sizeof(char), _handle); // XFlags
+
+ if (((flags & 0x04) != 0) || ((flags & 0x10) != 0)) // Misc
+ error("Unsupported header flag");
+
+ if ((flags & 0x08) != 0) { // Name
+ do {
+ fread(inBuf, 1, sizeof(char), _handle);
+ } while(inBuf[0] != 0);
+ }
+
+ if ((flags & 0x02 != 0)) // CRC
+ fread(inBuf, 2, sizeof(char), _handle);
+
+ stream.zalloc = NULL;
+ stream.zfree = NULL;
+ stream.opaque = Z_NULL;
+
+ if (inflateInit2(&stream, -15) != Z_OK)
+ error("zlibFile::(constructor) - inflateInit2 failed");
+
+ // Initial buffer pump
+ stream.next_in = (Bytef*)inBuf;
+ stream.avail_in = fread(inBuf, 1, sizeof(inBuf), _handle);
+ stream.next_out = (Bytef *)outBuf;
+ stream.avail_out = sizeof(outBuf);
+ fillZlibBuffer();
+
+ warning("zlibFile %s opened!", filename);
+
+ return true;
+}
+
+void zlibFile::close() {
+ if (_handle)
+ fclose(_handle);
+ _handle = NULL;
+}
+
+bool zlibFile::isOpen() {
+ return _handle != NULL;
+}
+
+bool zlibFile::eof() {
+ error("zlibFile::eof() - Not implemented");
+}
+
+uint32 zlibFile::pos() {
+ error("zlibFile::pos() - Not implemented");
+}
+
+uint32 zlibFile::size() {
+ error("zlibFile::size() - Not implemented");
+}
+
+void zlibFile::seek(int32 offs, int whence) {
+ error("zlibFile::seek() - Not implemented");
+}
+
+uint32 zlibFile::read(void *ptr, uint32 len) {
+ byte *ptr2 = (byte *)ptr;
+
+ if (_handle == NULL) {
+ error("File is not open!");
+ return 0;
+ }
+
+ if (len == 0)
+ return 0;
+ int bufferLeft = sizeof(outBuf) - usedBuffer;
+
+ printf("zlibFile::read(%d). usedBuffer: %d. bufferLeft: %d\n", len, usedBuffer, bufferLeft);
+
+ // Do we need to get more than one buffer-read to complete this request?
+ if (len > bufferLeft) {
+ int maxBuffer = sizeof(outBuf);
+ int ptr2Pos = bufferLeft;
+ int neededAmount = len - bufferLeft;
+
+ memcpy(ptr2, outBuf+usedBuffer, bufferLeft); // Copy what we've got
+
+ while (neededAmount > 0) {
+ fillZlibBuffer();
+
+ if (neededAmount > maxBuffer) {
+ memcpy(ptr2+ptr2Pos, outBuf, maxBuffer);
+
+ neededAmount-=maxBuffer;
+ ptr2Pos+=maxBuffer;
+ usedBuffer+=maxBuffer;
+ } else {
+ memcpy(ptr2+ptr2Pos, outBuf, neededAmount);
+ usedBuffer+=neededAmount;
+ neededAmount = 0;
+ }
+ }
+ } else {
+ memcpy(ptr2, outBuf + usedBuffer, len);
+ usedBuffer+=len;
+ }
+ return len;
+}
+
+void zlibFile::fillZlibBuffer() {
+ int status = 0;
+
+ if (stream.avail_in == 0) {
+ stream.next_in = (Bytef*)inBuf;
+ stream.avail_in = fread(inBuf, 1, sizeof(inBuf), _handle);
+ }
+
+ status = inflate(&stream, Z_NO_FLUSH);
+ if (status == Z_STREAM_END) {
+ if (sizeof(outBuf) - stream.avail_out)
+ warning("fillZlibBuffer: End of buffer");
+ return;
+ }
+
+ if (status != Z_OK) {
+ warning("Smush::play() - Error inflating stream (%d) [-3 means bad data]", status);
+ return;
+ }
+
+
+ if (stream.avail_out == 0) {
+ stream.next_out = (Bytef*)outBuf;
+ stream.avail_out = sizeof(outBuf);
+ }
+ usedBuffer = 0;
+}
+
+byte zlibFile::readByte() {
+ if (_handle == NULL) {
+ error("File is not open!");
+ return 0;
+ }
+
+ if (usedBuffer >= sizeof(outBuf))
+ fillZlibBuffer();
+
+ return outBuf[usedBuffer++];
+}
+
+uint16 zlibFile::readUint16LE() {
+ uint16 a = readByte();
+ uint16 b = readByte();
+ return a | (b << 8);
+}
+
+uint32 zlibFile::readUint32LE() {
+ uint32 a = readUint16LE();
+ uint32 b = readUint16LE();
+ return (b << 16) | a;
+}
+
+uint16 zlibFile::readUint16BE() {
+ uint16 b = readByte();
+ uint16 a = readByte();
+ return a | (b << 8);
+}
+
+uint32 zlibFile::readUint32BE() {
+ uint32 b = readUint16BE();
+ uint32 a = readUint16BE();
+ return (b << 16) | a;
+}
+
Index: smush.h
===================================================================
RCS file: /cvsroot/scummvm/residual/smush.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- smush.h 12 Dec 2003 22:57:40 -0000 1.4
+++ smush.h 1 Feb 2004 12:59:24 -0000 1.5
@@ -21,6 +21,8 @@
#include "bits.h"
#include "debug.h"
#include <cstring>
+#include <zlib.h>
+
#include "blocky16.h"
#include "mixer/mixer.h"
@@ -60,11 +62,39 @@
void setEnc(byte value) { _encbyte = value; }
};
+class zlibFile {
+private:
+ FILE *_handle;
+ z_stream stream; // zlib stream
+ uint32 usedBuffer; // how much of outBuf has been processed by ::read*()
+ char inBuf[1024], outBuf[1024]; // Buffers for decompression
+ void fillZlibBuffer();
+
+public:
+ zlibFile();
+ virtual ~zlibFile();
+ bool open(const char *filename);
+ void close();
+ bool isOpen();
+ bool eof();
+ uint32 pos();
+ uint32 size();
+ void seek(int32 offs, int whence = SEEK_SET);
+
+ uint32 read(void *ptr, uint32 size);
+ uint8 readByte();
+ uint16 readUint16LE();
+ uint32 readUint32LE();
+ uint16 readUint16BE();
+ uint32 readUint32BE();
+};
+
class Smush {
private:
int32 _nbframes;
Blocky16 _blocky16;
File _file;
+ // zlibFile _file;
PlayingSoundHandle _soundHandle;
int32 _frame;
@@ -91,7 +121,7 @@
void handleWave(const byte *src, uint32 size);
void init();
void deinit();
- void setupAnim(const char *file, const char *directory);
+ bool setupAnim(const char *file, const char *directory);
void updateGLScreen();
};
- Previous message: [Scummvm-cvs-logs] CVS: residual debug.cpp,1.2,1.3 debug.h,1.2,1.3 smush.cpp,1.16,1.17
- Next message: [Scummvm-cvs-logs] CVS: residual smush.cpp,1.18,1.19 smush.h,1.5,1.6
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list