how to render zdepth wihtout zblur plug in ;)

wait a second - mblur using zbuffer? how’s that? having depth info doesn’t help me mith motion… i’d rather say to calculate mblur in post we need motion vectors stored in each pixel. i assume blender does not provide such data per pixel


#include <iostream>
#include <map>
#include <stdio.h>

using namespace std;

typedef unsigned long dword;
typedef unsigned short word;
typedef unsigned char byte;
word ReadWord (FILE *file);
dword ReadDWord (FILE *file);

// Since we dont want to bother with negitive values we will just use words and dwords

word ReadWord (FILE *file) {
word ret;
fread(&ret, 2, 1, file);
byte t;
byte  *ptr = (byte *) &ret; // make a pointer to the word
t = ptr[0];
ptr[0] = ptr[1]; // swap the bytes
ptr[1] = t;

return ret;
}
dword ReadDWord (FILE *file) {
dword ret,t;
byte *ptr;

fread (&ret, 4, 1, file);

ptr = (byte *) &ret;

byte t1,t2,t3,t4;

// flip the dword (this is not the fastest way but it works..)
t1 = ptr[0];
t2 = ptr[1];
t3 = ptr[2];
t4 = ptr[3];

ptr[0] = t4;
ptr[1] = t3;
ptr[2] = t2;
ptr[3] = t1; 

return ret;
}

void RLE_Expand (byte *iptr, byte *optr, int z) {
	byte pixel, count;
	while(1) {
		pixel = *iptr++;
		if ( !(count = (pixel & 0x7f)) ) {
			return;
		if (pixel & 0x80) {
			while (count--) 
				*optr++ = *iptr++;
		}
		else {
			pixel = *iptr++;
			while (count--) 
				*optr++ = pixel;
			
		}
		}
		
}}

byte ReadByte (FILE *file) {
	return fgetc(file);
}

int main() {

FILE *f = fopen("test.iris", "rb"); // for WIN/DOS compatibility not needed on UNIX. :)

word magic = ReadWord(f);
//cout << magic << endl;
if (magic != 474) {
	cerr << "bad file" << endl;
	exit(0x4F);
	
}



byte storage = ReadByte(f);
if (storage == 1) { // RLE! :'(
cout << "We have RLE format" << endl;
} else {  // VERBAITUM!!! w0000t
cout << "We have VERBATUM format" << endl;
}

byte BPC = ReadByte(f);

cout << "BPC : " << (int) BPC << endl;

word dimensions = ReadWord(f);
cout << "DIMENSIONS: " << dimensions << endl;

word xsize = ReadWord(f), ysize = ReadWord(f), zsize = ReadWord(f);

cout << "XSize: "<< xsize << " YSize: " << ysize << " ZSize: " << zsize << endl;

if (zsize == 8) { 
cout << "ZBuffer detected.. so you can use me!" << endl;
}
else {
cout << "Uhh.. there is no zbuffer to rip!" << endl;
return 0;
}

dword pixmin = ReadDWord(f), pixmax = ReadDWord(f);
cout << "Minimum pixel value: " << pixmin << endl << "Maximum Pixel Value: " << pixmax << endl;
fseek(f, 84, SEEK_CUR);
dword colormap = ReadDWord(f);

cout << "Colormap ID: " << colormap <<  endl;

//return 0;
fseek(f, 512, SEEK_SET); // seek to the tables

if (storage >= 1) {
	dword *starttab, *lengthtab;
	dword tablen = ysize*zsize;
	starttab = new dword [tablen];
	lengthtab = new dword [tablen];
	for (int x=0; x < tablen; x++) {
		starttab [x] = ReadDWord(f);
	}
	
//	cout << "Start Table Data: " << endl;
//	for (int x=0; x < tablen; x++) {
//		cout << starttab[x] << endl;
//	}
//	delete [] starttab;
//	delete [] lengthtab;
	for (int x=0; x < tablen; x++) {
		lengthtab [x] = ReadDWord(f);		
	}

	cout << "Tables good to go" << endl;
//	byte *** data = new byte** [zsize-4]; // number of zbuffer bytes
	cout << "allocating memory" << endl;
//	byte *** data = (byte ***) malloc(sizeof(byte**) * (zsize-4));
	map <dword, map <dword, byte *> > data;
	
	cout << "Decompressing RLE Data: " ;
	for (int curplane = 4; curplane < 8; curplane++) {
		cout << curplane << " ";
	//	data[curplane-4] = (byte **) malloc(sizeof(byte*) * ysize);
		for (int rowno = 0; rowno < ysize; rowno++) {
		data[curplane-4][rowno] = new byte [xsize];
		
		int offset = starttab [rowno+curplane*ysize];
		int length = lengthtab [rowno+curplane*ysize];
		byte  *rledata = new byte [length];
		fseek (f,offset,SEEK_SET);
		fread(rledata,1,length,f);
//		cout << offset << endl;
		
		RLE_Expand(rledata,data[curplane][rowno],1);
		delete [] rledata;

		}
	}
cout << endl;	
cout << "writing output file" << endl;
FILE *o = fopen ("output.zbuf", "wb"); // DOS compat..
if (o == 0) { return 0; }
for (int yc = 0; yc < ysize; yc++) {
	cout << "Scanline: " << yc << endl;
	for (int xc=0; xc < xsize; xc++) {
		// some kinda image
		dword pixel;
		byte *z1 = data[3][yc], *z2 = data[2][yc], *z3 = data[1][yc], *z4 = data[0][yc];
		
		byte *bytes = (byte *) &pixel;
		bytes[0] = z1[xc];
		bytes[1] = z2[xc];
		bytes[2] = z3[xc];
		bytes[3] = z4[xc]; // make sure we're in little endian format! 	cout << "ok" << endl
		fwrite (&pixel, 4, 1, o);
	}
	delete [] data[3][yc];
	delete [] data[2][yc];
	delete [] data[1][yc];
	delete [] data[0][yc]; // cleanup on the go!
	
}
	fclose(o);
// time to clean up!
//	map<dword, map <dword, byte* > >::iterator it;
	
//for (int z=0; z < 4; z++) {
//	
//	for (int y=0; y < ysize; y++) {
//		delete [] data[z][y];
//	}
//	free (data[z]);
//}
	
	delete [] starttab;
	delete [] lengthtab;
	


}

fclose(f);
return 0;
}



There… just save an image in iris+zbuffer format as test.iris then compile this code and put it in the same directory
run it…
whammo… zbuffer gets extracted in raw format to output.zbuf

this code is released under the GPL by me.

:o :o :o :o :o :o :o :o :o :o

Why not use Caronte’s method?

This is a 32 bit zbuffer… it’s better