[Scummvm-cvs-logs] SF.net SVN: scummvm: [22202] tools/trunk/encode_dxa.cpp

sev at users.sourceforge.net sev at users.sourceforge.net
Fri Apr 28 22:21:00 CEST 2006


Revision: 22202
Author:   sev
Date:     2006-04-28 22:19:36 -0700 (Fri, 28 Apr 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=22202&view=rev

Log Message:
-----------
- Better handling of incorrect PNGs. I.e. exit gracefully instead of crash
- Use best zlib compression method
- Experimental support of ZMBV video. Put zmbv.cpp znd zmbv.h to this directory,
  add it to Makefile and uncomment #define USE_ZMBV. However I modified it a
  bit, i.e. increased compression level and played with block size.

Modified Paths:
--------------
    tools/trunk/encode_dxa.cpp
Modified: tools/trunk/encode_dxa.cpp
===================================================================
--- tools/trunk/encode_dxa.cpp	2006-04-29 02:01:32 UTC (rev 22201)
+++ tools/trunk/encode_dxa.cpp	2006-04-29 05:19:36 UTC (rev 22202)
@@ -35,12 +35,26 @@
 
 #define	 BUFFER_LEN	1024
 
+//#define USE_ZMBV
+
+#ifdef USE_ZMBV
+#include "zmbv.h"
+#endif
+
+
 class DxaEncoder {
 private:
 	FILE *_dxa;
 	int _width, _height, _framerate, _framecount;
 	uint8 *_prevframe, *_prevpalette;
 
+#ifdef USE_ZMBV
+	VideoCodec *_codec;
+
+	byte *_codecBuf;
+	int _codecBufSize;
+#endif
+
 public:
 	DxaEncoder(char *filename, int width, int height, int fps);
 	~DxaEncoder();
@@ -60,6 +74,13 @@
 	_prevpalette = new uint8[768];
 
 	writeHeader();
+
+#ifdef USE_ZMBV
+	_codec = new VideoCodec();
+	_codec->SetupCompress(width, height);
+	_codecBufSize = _codec->NeededSize(width, height, ZMBV_FORMAT_8BPP);
+	_codecBuf = (byte *)malloc(_codecBufSize);
+#endif
 }
 
 DxaEncoder::~DxaEncoder() {
@@ -129,6 +150,7 @@
 }
 
 void DxaEncoder::writeFrame(uint8 *frame, uint8 *palette) {
+	uint8 cpalette[1024];
 
 	if (_framecount == 0 || memcmp(_prevpalette, palette, 768)) {
 		fwrite(&typeCMAP, 4, 1, _dxa);
@@ -139,6 +161,17 @@
 		writeNULL();
 	}
 
+#ifdef USE_ZMBV
+	for (int i = 0; i < 256; i++) {
+		cpalette[i * 4 + 0] = palette[i * 3 + 0];
+		cpalette[i * 4 + 1] = palette[i * 3 + 1];
+		cpalette[i * 4 + 2] = palette[i * 3 + 2];
+		cpalette[i * 4 + 3] = 0;
+	}
+
+	_codec->PrepareCompressFrame(0, ZMBV_FORMAT_8BPP, (char *)cpalette, _codecBuf, _codecBufSize);
+#endif
+
 	if (_framecount == 0 || memcmp(_prevframe, frame, _width * _height)) {
 		//FRAM
 		uint8 compType;
@@ -150,6 +183,10 @@
 		else
 			compType = 3;
 
+#ifdef USE_ZMBV
+		compType = 10;
+#endif
+
 		fwrite(&compType, 1, 1, _dxa);
 
 		switch (compType) {
@@ -158,7 +195,7 @@
 				uLong outsize = _width * _height;
 				uint8 *outbuf = new uint8[outsize];
 
-				compress(outbuf, &outsize, frame, _width * _height);
+				compress2(outbuf, &outsize, frame, _width * _height, 9);
 
 				writeUint32BE(_dxa, outsize);
 
@@ -177,7 +214,7 @@
 				for (int i = 0; i < _width * _height; i++)
 					xorbuf[i] = _prevframe[i] ^ frame[i];
 
-				compress(outbuf, &outsize, xorbuf, _width * _height);
+				compress2(outbuf, &outsize, xorbuf, _width * _height, 9);
 
 				writeUint32BE(_dxa, outsize);
 
@@ -188,6 +225,22 @@
 
 				break;
 			}
+#ifdef USE_ZMBV
+		case 10:
+			{
+				int outsize;
+				void *ptr;
+
+				for (int i = 0; i < _height; i++) {
+					ptr = frame + i * _width;
+					_codec->CompressLines(1, &ptr);
+				}
+				outsize = _codec->FinishCompressFrame();
+				writeUint32BE(_dxa, outsize);
+				fwrite(_codecBuf, outsize, 1, _dxa);
+				break;
+			}
+#endif
 		}
 
 		memcpy(_prevframe, frame, _width * _height);
@@ -453,8 +506,10 @@
 
 		int r = read_png_file(strbuf, image, palette, width, height);
 
-		if (!palette)
+		if (!palette) {
 			printf("Error: 8-bit 256-color image expected!\n");
+			exit(0);
+		}
 
 		if (!r) {
 			dxe.writeFrame(image, palette);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Scummvm-git-logs mailing list