View Full Version : calculate lookup table only once for all frames, possible?
E-Male
2nd December 2004, 17:09
is it possible in avisynth to calculate a lookup table (or anything else for that amtter) once and then use the result in other frames?
i know it can be done by writing the table to a file and read that file on every new frame, but this has the harddrive as bottleneck (except i'd use a ramdisc, but let's not go too far)
is there a better way?
thx
E-Male
esby
3rd December 2004, 02:51
If I am understanding you well...
you want to calculate a table with [x][y][z] which will point to a value.
Each of [x][y][z] combinaison pointing to a fixed value, and only one.
So if I am right, you need to calculate such table in the filter constructor.
For example, the crc calculating filter in dsynth use a crc table, which is of 256 combinaisons, but it may work on any example...
class DirectCalcCRC : public GenericVideoFilter
/**
* Class to select a range of frames from a longer clip
**/
{
public:
virtual ~DirectCalcCRC(void);
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment* env);
private:
void calcCRC32(int n,int size,LPVOID p);
bool debugMode;
unsigned int poly;
unsigned int *crcTable;
ofstream crcFile;
};
// now the cpp implementation
DirectCalcCRC::DirectCalcCRC(PClip _child, const char filename[],bool _debugMode
, IScriptEnvironment* env):GenericVideoFilter(_child),debugMode(_debugMode)
{
poly = 0xEDB88320L;// crc32 poly //;
crcTable = new unsigned int[256]; // table used to fast compute crc32
// intializing crcTable
int i;
int j;
unsigned long crc;
for ( i = 0; i <= 255 ; i++ ) {
crc = i;
for ( j = 8 ; j > 0; j-- ) {
if ( crc & 1 )
crc = ( crc >> 1 ) ^ poly;
else
crc >>= 1;
}
crcTable[ i ] = crc;
}
crcFile.open( filename );
}
void DirectCalcCRC::calcCRC32(int n,int size,LPVOID p)
{
DWORD eax = 0xFFFFFFFF;
DWORD ebx;
for (int cx=0; cx<=size;cx++){
ebx = ((byte*)p)[cx];
DWORD t = crcTable[ebx];
eax^=crcTable[ebx];
}
eax^=0xFFFFFFFF;
char buf[80];
sprintf(buf,"%05i:%08X\n",n,eax);
crcFile << buf;
if (debugMode) {
sprintf(buf,"Frame: %06i CRC32: %08X \n",n,eax);
_RPT0(0,buf);
}
PVideoFrame __stdcall DirectCalcCRC::GetFrame(int n, IScriptEnvironment* env)
{
PVideoFrame tmpFrame = child->GetFrame(n,env);
VideoFrameBuffer *tmpBuffer = tmpFrame->GetFrameBuffer();
int size = tmpBuffer->GetDataSize();
calcCRC32(n,size,tmpBuffer->GetWritePtr());
return tmpFrame;
}
DirectCalcCRC::~DirectCalcCRC(){
delete[256] crcTable;
crcFile.close();
}
Now if you are asking how to transmit (or share) such table to other filters in the chain, you should read the discussion about masktools... (And the obvious answer is : No, it is not possible without hacking or relying on env which is not so good)
esby
E-Male
3rd December 2004, 03:00
i don't wanna share it between filters
i just want to calculate the table once for all frames, and not again for each frame
esby
3rd December 2004, 03:04
then do it in the constructor.
(Supposing the same table is used for each frames)
esby
PS: another way would be to put a :
bool initialized = false;
and to do something like that in GetFrame()
if not(initialized) {
// affect the table
// calc the table as you want
initialized = true;
}
// put the rest of your GetFrame()
Then this way, the table is calculated upon the first frame request, which might be better in some rare cases, besides it cost an if { } statement.
E-Male
3rd December 2004, 03:33
same table of course
thx, i'll have a look at that
i'm not experienced with c++ classes and stuff, so i basicly got no idea what information is lost between the frames and what not
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.