View Full Version : newbie to avisynth plugin programming
CAFxX
27th July 2003, 23:56
hi everyone!
i was trying to write a resizing plugin but i'm stuck at the beginning because every single time i do try to compile something (even working source codes downloaded from the avisynth plugin page) it finds me tons of errors both in avisynth.h and in the .cpp file i'm compiling
i really can't understand what's going on... i got dev-c++ 4, the avisynth source code version is 2.0.8 and i tried to compile simpleresize (non-alpha-2.5) and simplesample (both latest versions) with the same result...
this is part of the log i get
In file included from c:\docume~1\radial~1\avisyn~1.5_a\simple~1.cpp:34:
c:\documenti\radialresize\avisynth.h:43: syntax error before `;'
c:\documenti\radialresize\avisynth.h: In method `bool VideoInfo::IsRGB() const':
c:\documenti\radialresize\avisynth.h:55: `pixel_type' undeclared (first use this function)
c:\documenti\radialresize\avisynth.h:55: (Each undeclared identifier is reported only once
c:\documenti\radialresize\avisynth.h:55: for each function it appears in.)
c:\documenti\radialresize\avisynth.h: In method `int VideoInfo::AudioSamplesFromFrames(int) const':
c:\documenti\radialresize\avisynth.h:64: parse error before `long'
c:\documenti\radialresize\avisynth.h: In method `int VideoInfo::FramesFromAudioSamples(int) const':
c:\documenti\radialresize\avisynth.h:65: parse error before `long'
c:\documenti\radialresize\avisynth.h: At top level:
c:\documenti\radialresize\avisynth.h:89: syntax error before `*'
and so on...
can someone help me to work it out? thanks in advance, CAFxX.
PowerMacG4
30th July 2003, 03:36
I am 99% sure that you need Visual C++.
Yeah, it's evil, I know.
kassandro
30th July 2003, 05:43
Yeah, it's evil to depend on the Evil Empire, but you definitely canīt go the GNU way here.
CAFxX
30th July 2003, 07:36
ok thanks
Lefungus
30th July 2003, 11:17
Maybe you could try with latest avisynth code from version 2.5 and not 2.08 ?
Kurosu
30th July 2003, 13:38
Or, if my guess is right, try forcing the include of windows.h before avisynth.h (or before any include/declaration in avisynth.h, same purpose).
I am 99% sure that you need Visual C++.
Lefungus manages to build valid DLLs using Intel compiler. I dunno what steps are used, but I would guess the problem is the linking (how function names are mangled?). Note: I may be totally wrong.
CAFxX
30th July 2003, 15:25
i tried adding windows.h without success
i don't have a copy of visual c++ right here so I can't try to check if it works, maybe later.
in this moment i'm trying to dl the latest version of dev-c++ (i had version 4, this one is beta 5). maybe i'll be able to work it out...
about the intel compiler, where do i can find it? and how do i have to set it?
Kurosu
30th July 2003, 17:33
Originally posted by CAFxX
bout the intel compiler, where do i can find it? and how do i have to set it?
Unless you are a student, and your college/university has a license, you can only download and test a 30 or 45days trial version for free, otherwise you must shell out quite some money (as for VC++, anyway). The process of registering for that trial is rather painfull. All in all, my post wasn't a suggestion, rather a comment. Sorry.
MrTibs
31st July 2003, 21:40
There are some "Teach yourself Visual C++" manuals out there at the used/discount computer bookstores. They contain a VC++ compiler that should work for you to develop. I don't think you can distribute but you could post the source for others to compile. This should only cost you about $20.
CAFxX
1st August 2003, 21:04
you could post the source for others to compile
i'd like to do it, but it's the very first time I write something in c++ and i'm 99% sure the code won't even compile.
i just have to wait a couple of week to get a copy of vc++... let's wait... (unless i find a visual c++ compiler somewhere on the net, obviously)
CAFxX
2nd August 2003, 00:03
i'd like to do it, but it's the very first time I write something in c++ and i'm 99% sure the code won't even compile.
well, I changed my mind...
but I got a problem. i wrote it in pure c++ to avoid all the errors (those I posted when i started the 3d), so i made an almost unusable c++ function that works *ONLY* on prepared arrays (prepared by who?) like this:
sourcebitmap[sourcewidth][sourceheight][sourcecomponents] where components are (let's say) RGB or YUV or whatever (so if there are 3 components then sourcecomponents = 3)
this "function" returns (or, at least, I hope) another array like destinationbitmap[destinationwidth][destinationheight][sourcecomponents].
yes, i do know this method will be goddamned slow, but i didn't well understand the image storing method of avisynth...
so, here we go:
// RadialResize I, version A (RRI.A)
// (C) 2003 CAFxX
// Personal Notes [Do not read here unless you're Italian ;-)]
// Come si riceve un array come argomento?
// Come si passa indietro un array come risultato?
// Le routine di caricamento delle immagini... ma che bel sogno...
#include <stdio.h>
int RadialResize(int _dw, int _dh, int _sw, int _sh, int _cn, int _range, int _falloff, int _src)
{ //VARIABLES TYPE (unless noted = Internal)
int dx; //Destination image X counter
int dy; //Destination image Y counter
int sx; //Source image X counter
int sy; //Source image Y counter
int c; //Component counter
int dw=_dw; //Destination image width Argument
int dh=_dh; //Destination image height Argument
int sw=_sw; //Source image width Argument
int sh=_sh; //Source image height Argument
int cn=_cn; //Number of components (eg RGB = 3) Argument
int range=_range; //Radial range Argument
int falloff=_falloff; //Falloff type (see below) Argument
int srcbmp [sw] [sh] [c]; //Source bitmap array Argument
int dstbmp [dw] [dh] [c]; //Destination bitmap array Returned
double sex; //Source Equivalent X
double sey; //Source Equivalent Y
double sxinf; //Range lower X
double sxsup; //Range upper X
double syinf; //Range lower Y
double sysup; //Range upper Y
double distance; //Distance from destination pixel
double contribute; //Contribute of source pixel
double component; //Final component value
double totalcontribute; //Sum of contributes of source pixels
// for every single pixel of dst image
for (dy=1; dy <= dh; dy++)
{
for (dx=1; dx <= dw; dx++)
{
// select which pixels are probably inside of range
sex = dx * sw / dw;
sey = dy * sh / dh;
sxinf = sex - range;
sxsup = sex + range;
syinf = sey - range;
sysup = sey + range;
if (sxinf < 1)
{
sxinf = 1;
}
if (sxsup > sw)
{
sxsup = sw;
}
if (syinf < 1)
{
syinf = 1;
}
if (sysup > sh)
{
sysup = sh;
}
// and for every one of those pixels
for (sx=int(sxinf); double(sx)<sxsup; sx++)
{
for (sy=int(syinf); double(sy)<sysup; sy++)
{
for (c=1; c<4; c++)
{
// calculate the distance from the dst pixel
distance = sqrt((sex-sx)*(sex-sx)+(sey-sy)*(sey-sy));
// and if it is less than range
if (distance <= range)
{
// calculate the src pixel contribute with the choosen falloff method
if (falloff=1) // linear
{
contribute = range - distance;
}
if (falloff=2) // inverse
{
contribute = 1 / distance;
}
}
// then simply apply the contribute to the src pixel and sum it
totalcontribute += contribute;
component += double(srcbmp[sx][sy][c]) * contribute;
}
}
}
// and finally calculate the dst pixel value
dstbmp[dx][dy][c]=int(component/totalcontribute);
component = 0;
totalcontribute = 0;
}
}
// let's not forget to pass the destination image array
return dstbmp[dw][dh][c];
}
// and that's all folks!
this compiles in dev-c++. but, as is, it's unusable, i know...
Bidoche
2nd August 2003, 11:19
Well it's more a C version than a C++ one.
enum Fallof { //Fallof enum (to make more sense)
LINEAR,
INVERSE
};
//pass srcbmp and dstbmp as param, return nothing (void)
//avisynth components are BYTE not int
//taking BYTE * but still expecting your arrays behind
//IT DOESN'T WORK, but I am too tired at this time to replace by pointers operations :p
void RadialResize(int dw, int dh, int sw, int sh, int cn, int range, int _falloff, BYTE * srcbmp, BYTE * srcbmp)
{
//no need to redefine all the params in another variable
//in C++ you can define new vars along the way
//it prevents the users to go up wondering what what this one already.
// for every single pixel of dst image
for (int dy = 0; dy < dh; ++dy) //arrays nidex coutn from 0 to size - 1, not 1 to size
{ //indent more
for (int dx = 0; dx < dw; ++dx) //defining dx when using it
{
double component[cn]; //those should be set
double totalcontribute = 0; //at loop start
for(int c = cn; c-- > 0; )
component[c] = 0;
// select which pixels are probably inside of range
double sex = dx * sw / dw;
double sey = dy * sh / dh;
int sxinf = max(int(sex) - range - 1, 0); //why bother with double limits !?
int sxsup = min(int(sex) + range + 1, sw);
int syinf = max(int(sey) - range - 1, 0);
int sysup = min(int(sey) + range + 1, sh);
// and for every one of those pixels
for (int sx = sxinf; sx < sxsup; ++sx)
for (int sy = syinf; sy < sysup; ++sy)
{
//moved out of component loop
// calculate the distance from the dst pixel
double distance = sqrt( sqr(sex - sx) + sqr(sey - sy) );
// and if it is less than range
if (distance <= range)
{
// calculate the src pixel contribute with the choosen falloff method
double contribute = fallof == LINEAR ? range - distance : 1 / distance; //or a switch
for (int c = cn; c-- > 0; ) //you forgot to use cn
component[c] += double(srcbmp[sx][sy][c]) * contribute;
totalcontribute += contribute;
}
}
// and finally calculate the dst pixel value
for (int c = cn; c-- > 0; )
dstbmp[dx][dy][c]=int(component[c]/totalcontribute);
}
}
}
I think I correctly reproduced your code, but I am wondering if it does really do what you wanted. Is it normal for components to affect each other ?
Edit: corrected what I think is a bug
CAFxX
2nd August 2003, 14:09
Is it normal for components to affect each other ? Obviously not :stupid: Stupid me! Each component should be separated (this happened because i initially wrote it for single-component images) .
Anyway in your opinion, do i have to re-write the program with pointers, or can i keep the array style?
Thanks to all of you for your (really) appreciated help.
Bidoche
2nd August 2003, 17:50
Arrays are pointers behind the scene.
Using simple dimensional arrays or pointers is more or less the same.
But multidimensional arrays need costly operations (multiplications...) to find the data designated, and so each time you use it.
So it's definitely better to use a pointer moving into the bitmap
Most of the time in avisynth it is done like this :
for(int y = 0; y < height; ++y, ptr += pitch)
for(int x = 0; x < width; ++x)
//do something with ptr[x]
digitize
21st February 2004, 04:58
Alright, I'm also a newbie with avisynth code compiling and such, basically i just wanted to try to understand and compile the simplesample 1.0b code (http://www.avisynth.org/index.php?page=SimpleSample+1.0b). I have msvc 6.0, and I included both windows.h & avisynth.h. But when trying to compile i get these 3 errors all related to wincon.h:
c:\program files\microsoft visual studio\vc98\include\wincon.h(217) : error C2146: syntax error : missing ';' before identifier 'BOOL'
c:\program files\microsoft visual studio\vc98\include\wincon.h(217) : error C2501: 'WINBASEAPI' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\wincon.h(217) : fatal error C1004: unexpected end of file found
When i take a peek at this header file at the specified line i see (starting with line 215):
WINBASEAPI
BOOL
WINAPI
PeekConsoleInputA(.....
So I'm not really too sure what's wrong here, hoping someone can answer ^^.
Si
21st February 2004, 06:34
The Wikki doesn't seem to be responding to the <code> </code> formatting at the moment (fixed from 21/2/4), so just to sure you've got the right code, try downloading the source from here (http://www.geocities.com/siwalters_uk/SimpleSample10b.zip) (right-click and use save-as)
regards
Simon
digitize
21st February 2004, 06:56
Thanks for the help but unfortunately when I try to compile with that I still get the same three errors. I also downloaded the visual studio 6 service pack 5 to make sure I have all the appropriate files/settings.
Edit: Since you can compile this code (or so I assume you did) it's obviously an error or something lacking on my system most likely the latter. Since I'm a newbie, is there anything specific besides microsoft visual studio (in my case msvs 6.0) that I need in order to compile.
Si
21st February 2004, 11:48
I assume you mean download and install SP5 :)
And just to clarify, if you unzip simplesample10b.zip and open up SimpleSample.dsw and then press CTRL-F7 you get your errors?
regards
Simon
digitize
21st February 2004, 15:31
Yeah, that's exactly what happens when trying to compile those three errors that I pasted in the previous post (following the steps in your previous post).
Si
21st February 2004, 16:24
I wonder if your setup is not finding windows.h and/or other files it references.
Check in Tools, Options and then in the Directories tab
I have
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE
in my setup
regards
Simon
digitize
21st February 2004, 16:54
I have all three directories when looking in tools->options->dir's, and with the error I'm getting I'm thinking perhaps it's a fault in that one file (wincon.h), but I'm not sure.
Si
21st February 2004, 20:18
Unfortunately, I'm out of ideas apart from re-installing SP5 - maybe it didn't quite work.
regards
Simon
digitize
21st February 2004, 23:47
Well koepi asked if I had the msdk which I don't think I have, unless that's basically visual studio, if it isn't that's the only thing I can think of.
Edit: The problem is now solved, reinstalled sp 5 and it compiles, ty for your help sirwalters.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.