Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 7th August 2005, 00:00   #1  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Ikea Chair
Posts: 2,252
Pascal conversion of avisynth_c.h

One day I got bored and tried to do a conversion. It failed. Then I continued just to not let the computer win (then they'll think they can win every time) and finished it after figuring out how records are passed.

This should allow you to write filters in delphi and free pascal using the avisynth_c interface. It was tested with delphi 7 and free pascal 2.0.2 but will probably work in earlier versions of both. A conversion of the invert sample from avisynth_c is also included to show how it's used.

avisynth_pascal v5

edit Wilbert: working link: http://www.wilbertdijkhof.com/avisynth_pascal_v5.rar

Last edited by Wilbert; 14th August 2010 at 22:35. Reason: changed link to v5
Myrsloik is offline   Reply With Quote
Old 7th August 2005, 20:33   #2  |  Link
vhelp
Registered User
 
vhelp's Avatar
 
Join Date: Feb 2003
Posts: 299
Could you provide some Delphi examples ?

First, GOD bless you, for breaking the barrior between Delphi and
AVIsynth and making a wider street for more languages to create filters
for AVIsynth. (after looking over your source code for this, it was all
spagetti to me -- good work)

Now, I'd like to ask a question.

I am running Delphi 6 (personal edition) under win98x, and I was able to
compile the project successfully, by creating a new invert.dll file

But, in the package you provided (thank you) there were no examples to
begin exploring with as a basic starting point.

Could you please provide a couple of examples (something very, very basic)
that we all could start with ??

Thank you,
-vhelp

EDIT:
The invert.dll was the example in the package.. though it looks a bit
complicted at the moment.. but i'm studying it now.
__________________
ESC K7S5A / XP 1800+ / Windows 98
ADVC-100[dvio] / WTVGO[avio] / DC10+[avio] / Canon ZR-10 / Delphi 6 Personal / JVC S-VHS HR-S3910U / Durabrand SSS w/ DVD Player STS75E / Sony TRV-22
FithElement/Dogma/BladeRunner/Contact

Last edited by vhelp; 7th August 2005 at 21:00.
vhelp is offline   Reply With Quote
Old 7th August 2005, 22:28   #3  |  Link
vhelp
Registered User
 
vhelp's Avatar
 
Join Date: Feb 2003
Posts: 299
Just a quick update.

I am experiencing trouble w/ loading the plugin. When I try and open
my avs script (called, default.avs) with the invert plugin, it pops
up an error message:

AVIsynth open failure..
Plugin c:\invert.dll is not an AviSynth 2.5 plugin.

I've tried various scenarios, including visiting AVIsynth help pages
and using the ..loadpluginEX.dll and loadpluginEX2.dll but same basic
error message.

I think i'm at a dead end, for the time being

-vhelp
__________________
ESC K7S5A / XP 1800+ / Windows 98
ADVC-100[dvio] / WTVGO[avio] / DC10+[avio] / Canon ZR-10 / Delphi 6 Personal / JVC S-VHS HR-S3910U / Durabrand SSS w/ DVD Player STS75E / Sony TRV-22
FithElement/Dogma/BladeRunner/Contact
vhelp is offline   Reply With Quote
Old 7th August 2005, 22:42   #4  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Ikea Chair
Posts: 2,252
Unfortunately I think you've already seen most of the documentation that exists, I still haven't figured out some important parts myself. You can however find the original examples and files with all comments intact here which should make some things clearer (invert.pas is a line by line conversion).

If I figure out the last things annoying me I'll try to write something a bit more helpful tomorrow.

Hint: LoadCPlugin
Myrsloik is offline   Reply With Quote
Old 7th August 2005, 23:09   #5  |  Link
vhelp
Registered User
 
vhelp's Avatar
 
Join Date: Feb 2003
Posts: 299
It works!! Fantastic!!

Right now, I'm studying your invert example. I just noticed you had another
link of info.., I'll head on over there shortly. I hope I can create something
simple with this plugin of yours.

I know I'll have add'l questions, but if I can ask..

When starting a new filter, I would use something like this:
( ie, library myFilterA; )

Also, if its not asking too much, could you provide an example or two, of
creating a filter with 1 or more params? I ask, because at the moment, it all
looks cryptic to me

BWY, your code (at bottom) has this strange char.

// Result := '`Invert'' sample plugin';

I think you ment for it to be this way:
Result := '"Invert" sample plugin';

Great work!
-vhelp
__________________
ESC K7S5A / XP 1800+ / Windows 98
ADVC-100[dvio] / WTVGO[avio] / DC10+[avio] / Canon ZR-10 / Delphi 6 Personal / JVC S-VHS HR-S3910U / Durabrand SSS w/ DVD Player STS75E / Sony TRV-22
FithElement/Dogma/BladeRunner/Contact
vhelp is offline   Reply With Quote
Old 8th August 2005, 02:49   #6  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,173
@Myrsloik,

There is an outstanding issue with the avisynth_c.dll/loadCplugin interface which effects the calling convention and entry point names.

Your thoughts and comments on the issue....

IanB
IanB is offline   Reply With Quote
Old 8th August 2005, 07:37   #7  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Ikea Chair
Posts: 2,252
That explains why I had to export avisynth_c_plugin_init and why it didn't work with avisynth_c_plugin_init_s. After looking at avisynth_c.* I think it'd be best to just keep the current entry point name and remove everything that's in the now not used stdcall ifdefs. At least it should leave everything working and make the entry point name a bit more official.
Myrsloik is offline   Reply With Quote
Old 9th August 2005, 04:54   #8  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,183
I think, we must analyze every useful avisynth_c filters, what interface it use.
All Kevin (smartdecimate, conditionaltemoralmedian) filters use oldest C interface.
My C-plugins (genmotion, equlines, old ctmedian=despot) use old C interface too, but all are obsolete.
I remember some Visual plugin (from vion ?)
Please add the list.
__________________
My Avisynth plugins are now at http://avisynth.org.ru and mirror at http://avisynth.nl/users/fizick
I usually do not provide a technical support in private messages.
Fizick is offline   Reply With Quote
Old 9th August 2005, 09:03   #9  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,173
Okay, here is what I propose :-

1. Formally loose the "_s" from the entry point name it has never been able to be used because of a source bug.

2. Support the @4 suffix decoration as an option. This is how __stdcall is supposed to be.

3. Build Avisynth.dll with __stdcall calling sequence. This is how previous versions have been done. And it allows allows langauges like Delphi, Pascal, VB, Fortran, etc to call the C interfaces.

4. Add a Load_Stdcall_Plugin() alias for LoadCPlugin(). Loading avisynth_c.dll nukes the internal LoadCPlugin() verb.

This will maintain consistancy of interface, and clarify the world.

Kevins filters all link to avisynth_c.dll and use __cdecl so they are not part of this equation and will continue to work as before, the new Load_StdCall_Plugin() verb avoids the conflict with LoadCPlugin() verb.

Thorts anybody!

IanB
IanB is offline   Reply With Quote
Old 9th August 2005, 18:43   #10  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,183
Albertgasset old suggestion:
http://forum.doom9.org/showthread.ph...ht=loadcplugin

By the way, he released "transition" C-plugin
http://forum.doom9.org/showthread.ph...ht=loadcplugin
__________________
My Avisynth plugins are now at http://avisynth.org.ru and mirror at http://avisynth.nl/users/fizick
I usually do not provide a technical support in private messages.
Fizick is offline   Reply With Quote
Old 9th August 2005, 18:49   #11  |  Link
unmei
frying subs
 
unmei's Avatar
 
Join Date: Jan 2003
Location: ch-2500
Posts: 891
Great Job, Myrsloik.
I didn't test it so far, but i tried to translate the header too, about a year ago ..but oh well, then i let the computer win and wrote a C++ wrapper to load my delphi DLL
Maybe i should go back and try to use your work, it would sure eliminate some "sucky hacks".
__________________
-nyo
unmei is offline   Reply With Quote
Old 10th August 2005, 08:18   #12  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,173
Point of clarification.

If you use avisynth_c.dll it is nothing to do with this thread, it is the original independant implementation. You need to first LoadPlugin("Avisynth_c.dll") and then LoadCPlugin("c_plugin.dll"). The entrypoint names and linkage are whatever they are for the version of avisynth_c.dll you are using. The licence is as Kevin specifies.

This thread is talking about the AviSynth.dll internal implementation and support of the C interface defined by Kevin Atkinson. You link with avisynth.lib iff required and use only LoadCPlugin("stdcall_plugin.dll") [ or soon Load_StdCall_Plugin() ]

If you link with avisynth.lib you must comply with the full AviSynth GPL licence i.e. release the source! If you #include "avisynth_c.h" you must comply with Kevin's licence. (If you do both you must satisfy both) If you just call the entry points you can do as you wish.

IanB
IanB is offline   Reply With Quote
Old 10th August 2005, 13:56   #13  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Ikea Chair
Posts: 2,252
Updated the link in the first post to v3. It adds some useful functions (equivalents for avsvalue.AsType(default)) and changes some things back to enumerated types.
Myrsloik is offline   Reply With Quote
Old 11th August 2005, 05:29   #14  |  Link
vhelp
Registered User
 
vhelp's Avatar
 
Join Date: Feb 2003
Posts: 299
@ Myrsloik

Just wanted to give you a heads-up on my experience w/ your on-going updates.

So far, so good. I have been very successful at reproducing your example filters functions.

But, I do have an issue with trying to set other variables inside the code
snip below, I get hard crashes when I run the .avs script inside vdub.

PHP Code:
..
var
  
iinteger;
begin 
.
.
  
i:=1// give I an default number to start with..

    
for := 0 to height do
    
begin
      inc
(I,2)
      for 
:= 0 to row_size do
        
PByteArray(src_data)^[x] := PByteArray(src_data)^[x+I] xor settings^.XorVal;
      
Inc(src_datasrc_pitch);
    
end
Inside the line above.. PByteArray.. ^[x+i] is where it crashes.
If I leave out the I, ie, ^[x] then everything is fine, even though
there is code above ( ie, inc(i,2) )

I know I am missing something, and it probably has something to do
with pointers, but I just don't get it. Its like I get the feeling that
you can't have your own variables. I don't know. I can't quite explain
it in words.

Can you (or anyone else) explain what is going on (why) and if there
is another thing I can do ??
Otherwise, I don't see how I can't alter pixels if this problem stops me.

Thanks again for this avisynth_c port.

-vhelp
__________________
ESC K7S5A / XP 1800+ / Windows 98
ADVC-100[dvio] / WTVGO[avio] / DC10+[avio] / Canon ZR-10 / Delphi 6 Personal / JVC S-VHS HR-S3910U / Durabrand SSS w/ DVD Player STS75E / Sony TRV-22
FithElement/Dogma/BladeRunner/Contact
vhelp is offline   Reply With Quote
Old 11th August 2005, 06:55   #15  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Ikea Chair
Posts: 2,252
I have no idea what you're trying to do but as you increment i by 2 for every line and initialize it to 1 you'll be reading 2*height+1 pixels beyond the image end. That is generally a bad idea.
Myrsloik is offline   Reply With Quote
Old 12th August 2005, 03:16   #16  |  Link
vhelp
Registered User
 
vhelp's Avatar
 
Join Date: Feb 2003
Posts: 299
I was experimenting on what-if scenarios with changing pixel data around
for effects and things. Just trying to get a feel for how things work.
You gotta start somewhere's. And this was the first place I started

(I've been busy w/ other projects and things, and haven't tried further.
But I will have another try tonight, regarding your comment on my code)

-vhelp
__________________
ESC K7S5A / XP 1800+ / Windows 98
ADVC-100[dvio] / WTVGO[avio] / DC10+[avio] / Canon ZR-10 / Delphi 6 Personal / JVC S-VHS HR-S3910U / Durabrand SSS w/ DVD Player STS75E / Sony TRV-22
FithElement/Dogma/BladeRunner/Contact
vhelp is offline   Reply With Quote
Old 5th February 2006, 16:39   #17  |  Link
Amnon82
Paldo-GNU/LinuxMaintainer
 
Amnon82's Avatar
 
Join Date: Oct 2003
Location: Germany
Posts: 1,580
Here some samples for using AVISYNTH_C in Delphi:



Original sample by Myrsloik
Updated sample by Amnon82 (RGB-Preview)

Last edited by Amnon82; 5th February 2006 at 16:45.
Amnon82 is offline   Reply With Quote
Old 5th February 2006, 23:01   #18  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Ikea Chair
Posts: 2,252
When looking some more at the avisynth_c stuff I realized that at least from delphi it seem impossible to destroy a script environment created with avs_create_script_environment(). This seems to be because avisynth_c assumes that you'll use free() or something similar. This however seems to be impossible due to how delphi handles memory. Adding an avs_destroy_script_environment() would probably be the best solution for this. Either that or I'm completely wrong.
Myrsloik is offline   Reply With Quote
Old 6th February 2006, 11:39   #19  |  Link
Inc
Squeeze it!
 
Inc's Avatar
 
Join Date: Oct 2003
Location: Germany
Posts: 472
Why do u use a delphi "CopyMemory()" command to perform an image blocktransfer? I dont know its speed in delphi (neither I do know if delphi generates its executable out of a generated asm code).
Quote:
//get a pointer to the frame, has to be released later
frame:=avs_get_frame(clip,TrackBar1.Position);

//retrieve all values needed to copy the frame
rp:=avs_get_read_ptr(frame);
pitch:=avs_get_pitch(frame);
rs:=avs_get_row_size(frame);

//while BitBlt would be simple and more efficient to use here
//the image would be shown upside down
for counter:=vi.height-1 downto 0 do
begin
CopyMemory(Image1.Picture.Bitmap.ScanLine[counter],rp,rs);
Inc(rp,pitch);
end;

Image1.Repaint;

avs_release_video_frame(frame);
In AVSredirect.dll I do use Bitblt() to copy the imagedata from the smartpointer to the determined final frame-imagepointer. And its not showed upside down.

How do Delphi's internally image procedures handle raw bitmap data to be converted to a compatible bitmap incl. BITMAPINFO and BITMAPINFOHEADER?
A SetDIBits() could be integrated as it could directly use the resulted GetReadPtr() within the function, so the smart pointer problem could be solved by this and the RGB32 Data at GetReadPtr() is imho DWORD aligned which is also the prefered alignement by the GDI functions (like SetDIBits).

Something like this ...
(written out of head so only to be seen as an approach ... reference from here: http://www.everything2.com/index.pl?node_id=918688)

Code:
int __stdcall avs_getvframeRGB32(IScriptEnvironment* env, int clip_num, BYTE *buf, int frm, HBITMAP myBitmap, HWND hwnd )
{
    BITMAPINFO bmInfo;
    HDC myDC;
    HDC myCompatibleDC;

    VideoInfo vi = clip[clip_num]->GetVideoInfo();

    ZeroMemory(&bmInfo, sizeof(BITMAPINFO));

    bmInfo.bmiHeader.biWidth = vi.width;
    bmInfo.bmiHeader.biHeight = vi.height; // use negative value if image flipping is whished
    bmInfo.bmiHeader.biPlanes = 1;
    bmInfo.bmiHeader.biBitCount = 32; // RGB32!
    bmInfo.bmiHeader.biCompression = BI_RGB;

    try {
        PVideoFrame f = clip[clip_num]->GetFrame(frm, env);

        myDC = GetDC(NULL)
        myCompatibleDC = CreateCompatibleDC(myDC);
        SelectObject(myCompatibleDC, myBitmap);
        SetDIBits(myCompatibleDC, myBitmap, 0, vi.height, f->GetReadPtr(), &bmInfo, 0);
        DeleteDC(myCompatibleDC);
        ReleaseDC(NULL, myDC);
        
        g_lasterr[0] = 0;
        return 0;
    } 
        
    catch(AvisynthError err) {
	strncpy(g_lasterr,err.msg,ERRMSG_LEN-1);	
	return -1;
    }

}
So you enter in your function using myBitmap as your CompatibleBitmap created in your appl. where the video will be shown, and hwnd as your appl. Window handle where the video CompatibleBitmap will be shown.

Last edited by Inc; 6th February 2006 at 19:38.
Inc is offline   Reply With Quote
Old 6th February 2006, 22:06   #20  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Ikea Chair
Posts: 2,252
CopyMemory is straight from the windows api so I guess you should be able to figure out its performance if you really want to.

I also just realized that TBitmap.scanline[line] doesn't do something like (image data start)+pitch*line but instead you seem to get (image data start)+pitch*(height-line-1). That at least allows you to simplify it to this.
Code:
with Image1.Picture.Bitmap do
    avs_bit_blt(env,ScanLine[vi.height-1],Integer(ScanLine[0])-
      Integer(ScanLine[1]),avs_get_read_ptr(frame),avs_get_pitch(frame),
      avs_get_row_size(frame),vi.height);
Myrsloik is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:02.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.